1
#include "test_service_panel.h"
5
static const char * panel_interface =
6
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
8
" <interface name=\"com.canonical.Unity.Panel.Service\">\n"
10
"<!-- Begin of real methods/signals -->\n"
11
" <method name='Sync'>"
12
" <arg type='a(ssssbbusbbi)' name='state' direction='out'/>"
15
" <signal name='ReSync'>"
16
" <arg type='s' name='indicator_id' />"
19
"<!-- Begin of test only methods/signals -->\n"
21
" <method name='TriggerResync1' />"
23
" <method name='TriggerResync1Sent'>"
24
" <arg type='b' name='sent' direction='out'/>"
30
static void bus_got_cb (GObject *object, GAsyncResult * res, gpointer user_data);
31
static void bus_method (GDBusConnection *connection,
33
const gchar *object_path,
34
const gchar *interface_name,
35
const gchar *method_name,
37
GDBusMethodInvocation *invocation,
40
G_DEFINE_TYPE(ServicePanel, service_panel, G_TYPE_OBJECT);
41
static GDBusNodeInfo * node_info = NULL;
42
static GDBusInterfaceInfo * iface_info = NULL;
43
static GDBusInterfaceVTable bus_vtable = {
44
method_call: bus_method,
49
struct _ServicePanelPrivate
51
GDBusConnection * bus;
52
GCancellable * bus_lookup;
53
guint bus_registration;
54
guint sig_emission_handle;
58
service_panel_dispose(GObject* object)
60
ServicePanel* self = SERVICE_PANEL(object);
61
if (self->priv->bus_lookup != NULL) {
62
g_cancellable_cancel(self->priv->bus_lookup);
63
g_object_unref(self->priv->bus_lookup);
64
self->priv->bus_lookup = NULL;
67
if (self->priv->bus_registration != 0) {
68
g_dbus_connection_unregister_object(self->priv->bus, self->priv->bus_registration);
69
self->priv->bus_registration = 0;
72
if (self->priv->bus != NULL) {
73
g_object_unref(self->priv->bus);
74
self->priv->bus = NULL;
77
if (self->priv->sig_emission_handle) {
78
g_source_remove(self->priv->sig_emission_handle);
79
self->priv->sig_emission_handle = 0;
85
service_panel_class_init(ServicePanelClass* klass)
87
G_OBJECT_CLASS(klass)->dispose = service_panel_dispose;
88
g_type_class_add_private (klass, sizeof (ServicePanelPrivate));
90
if (node_info == NULL)
92
GError * error = NULL;
94
node_info = g_dbus_node_info_new_for_xml(panel_interface, &error);
97
g_error("Unable to parse Panel interface: %s", error->message);
102
if (node_info != NULL && iface_info == NULL)
104
iface_info = g_dbus_node_info_lookup_interface(node_info,"com.canonical.Unity.Panel.Service");
105
if (iface_info == NULL)
107
g_error("Unable to find interface 'com.canonical.Unity.Panel.Service'");
114
service_panel_init(ServicePanel* self)
116
self->priv = G_TYPE_INSTANCE_GET_PRIVATE(self, SERVICE_TYPE_PANEL, ServicePanelPrivate);
117
self->priv->bus = NULL;
118
self->priv->bus_lookup = NULL;
119
self->priv->bus_registration = 0;
121
self->priv->bus_lookup = g_cancellable_new();
122
g_bus_get(G_BUS_TYPE_SESSION, self->priv->bus_lookup, bus_got_cb, self);
128
return g_object_new(SERVICE_TYPE_PANEL, NULL);
132
bus_got_cb (GObject *object, GAsyncResult * res, gpointer user_data)
134
GError * error = NULL;
135
ServicePanel * self = SERVICE_PANEL(user_data);
136
GDBusConnection * bus;
138
bus = g_bus_get_finish(res, &error);
140
g_critical("Unable to get bus: %s", error->message);
145
self->priv->bus = bus;
147
/* Register object */
148
self->priv->bus_registration = g_dbus_connection_register_object(bus,
149
/* path */ "/com/canonical/Unity/Panel/Service",
150
/* interface */ iface_info,
151
/* vtable */ &bus_vtable,
157
g_critical ("Unable to create bus connection object, %s", error->message);
166
add_entry_id(GVariantBuilder *b)
168
g_variant_builder_add (b, "(ssssbbusbbi)",
171
"test_entry_name_hint",
173
TRUE, /* label sensitive */
174
TRUE, /* label visible */
177
TRUE, /* image sensitive */
178
TRUE, /* image visible */
183
add_entry_id_2(GVariantBuilder *b)
185
g_variant_builder_add (b, "(ssssbbusbbi)",
188
"test_entry_name_hint2",
190
TRUE, /* label sensitive */
191
TRUE, /* label visible */
194
TRUE, /* image sensitive */
195
TRUE, /* image visible */
199
static int sync_return_mode = 0;
200
static int trigger_resync1_sent = FALSE;
203
bus_method (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, GVariant *parameters, GDBusMethodInvocation *invocation, gpointer user_data)
205
if (g_strcmp0(method_name, "Sync") == 0)
209
g_variant_builder_init (&b, G_VARIANT_TYPE ("(a(ssssbbusbbi))"));
210
g_variant_builder_open (&b, G_VARIANT_TYPE ("a(ssssbbusbbi)"));
212
if (sync_return_mode == 0)
217
else if (sync_return_mode == 1)
223
g_variant_builder_close (&b);
225
g_dbus_method_invocation_return_value(invocation, g_variant_builder_end (&b));
227
if (sync_return_mode == 1)
229
trigger_resync1_sent = TRUE;
232
else if (g_strcmp0(method_name, "TriggerResync1") == 0)
234
sync_return_mode = 1;
235
trigger_resync1_sent = FALSE;
237
g_dbus_method_invocation_return_value(invocation, NULL);
238
GVariantBuilder ret_builder;
239
g_variant_builder_init(&ret_builder, G_VARIANT_TYPE_TUPLE);
240
g_variant_builder_add_value(&ret_builder, g_variant_new_string(""));
241
g_dbus_connection_emit_signal (connection, NULL, "/com/canonical/Unity/Panel/Service", "com.canonical.Unity.Panel.Service", "ReSync", g_variant_builder_end(&ret_builder), NULL);
243
else if (g_strcmp0(method_name, "TriggerResync1Sent") == 0)
245
GVariantBuilder ret_builder;
246
g_variant_builder_init(&ret_builder, G_VARIANT_TYPE ("(b)"));
247
g_variant_builder_add_value (&ret_builder, g_variant_new_boolean(trigger_resync1_sent));
248
g_dbus_method_invocation_return_value(invocation, g_variant_builder_end (&ret_builder));