ayatana-commits team mailing list archive
-
ayatana-commits team
-
Mailing list archive
-
Message #02747
[Branch ~indicator-applet-developers/indicator-me/trunk] Rev 119: Ported service to gdbus
------------------------------------------------------------
revno: 119
committer: Ken VanDine <ken.vandine@xxxxxxxxxxxxx>
branch nick: indicator-me-gdbus
timestamp: Thu 2011-01-13 14:37:08 -0600
message:
Ported service to gdbus
modified:
.bzrignore
src/Makefile.am
src/indicator-me.c
src/me-service-dbus.c
--
lp:indicator-me
https://code.launchpad.net/~indicator-applet-developers/indicator-me/trunk
Your team ayatana-commits is subscribed to branch lp:indicator-me.
To unsubscribe from this branch go to https://code.launchpad.net/~indicator-applet-developers/indicator-me/trunk/+edit-subscription
=== modified file '.bzrignore'
--- .bzrignore 2011-01-12 22:40:11 +0000
+++ .bzrignore 2011-01-13 20:37:08 +0000
@@ -59,5 +59,5 @@
src/libme.la
src/libme_la-indicator-me.lo
po/indicator-me.pot
-src/gen-datetime-service.xml.c
-src/gen-datetime-service.xml.h
+src/gen-me-service.xml.c
+src/gen-me-service.xml.h
=== modified file 'src/Makefile.am'
--- src/Makefile.am 2011-01-13 16:28:28 +0000
+++ src/Makefile.am 2011-01-13 20:37:08 +0000
@@ -28,7 +28,8 @@
me-service.c \
me-service-dbus.h \
me-service-dbus.c \
- me-service-server.h \
+ gen-me-service.xml.h \
+ gen-me-service.xml.c \
me-service-gwibber.c \
me-service-gwibber.h \
status-provider.h \
@@ -48,13 +49,6 @@
indicator_me_service_CFLAGS = $(MESERVICE_CFLAGS) -Wall -Werror
indicator_me_service_LDADD = $(MESERVICE_LIBS)
-me-service-server.h: $(srcdir)/me-service.xml
- dbus-binding-tool \
- --prefix=_me_service_server \
- --mode=glib-server \
- --output=me-service-server.h \
- $(srcdir)/me-service.xml
-
gen-%.xml.h: %.xml
@echo "Building $@ from $<"
@echo "extern const char * _$(subst -,_,$(subst .,_,$(basename $<)));" > $@
@@ -100,7 +94,6 @@
###############
BUILT_SOURCES = \
- me-service-server.h \
gen-me-service.xml.h \
gen-me-service.xml.c \
status-provider-mc5-marshal.h \
=== modified file 'src/indicator-me.c'
--- src/indicator-me.c 2011-01-13 16:28:28 +0000
+++ src/indicator-me.c 2011-01-13 20:37:08 +0000
@@ -95,9 +95,9 @@
static void entry_prop_change_cb (DbusmenuMenuitem *mi, gchar *prop, GVariant *value, GtkEntry *entry);
static gboolean entry_hint_is_shown (GtkWidget *widget);
static void status_proxy_cb (GObject * object, GAsyncResult * res, gpointer user_data);
-static void status_icon_changed (IndicatorMe * self, char * icon);
+static void status_icon_changed (IndicatorMe * self, gchar * icon);
static void status_icon_cb (GObject * object, GAsyncResult * res, gpointer user_data);
-static void username_changed (IndicatorMe * self, char * username);
+static void username_changed (IndicatorMe * self, gchar * username);
static void username_cb (GObject * object, GAsyncResult * res, gpointer user_data);
G_DEFINE_TYPE (IndicatorMe, indicator_me, INDICATOR_OBJECT_TYPE);
@@ -169,7 +169,7 @@
username_cb (GObject * object, GAsyncResult * res, gpointer user_data)
{
GError * error = NULL;
- char * username;
+ gchar * username;
GVariant * result;
IndicatorMe * self = INDICATOR_ME (user_data);
@@ -193,7 +193,7 @@
}
static void
-username_changed (IndicatorMe * self, char * username)
+username_changed (IndicatorMe * self, gchar * username)
{
if (label == NULL) {
label = GTK_LABEL(gtk_label_new(NULL));
@@ -234,7 +234,7 @@
status_icon_cb (GObject * object, GAsyncResult * res, gpointer user_data)
{
GError * error = NULL;
- char * icon;
+ gchar * icon = NULL;
GVariant * result;
IndicatorMe * self = INDICATOR_ME (user_data);
@@ -258,7 +258,7 @@
}
static void
-status_icon_changed (IndicatorMe * self, char * icon)
+status_icon_changed (IndicatorMe * self, gchar * icon)
{
g_return_if_fail(icon != NULL);
g_return_if_fail(icon[0] != '\0');
@@ -283,12 +283,12 @@
IndicatorMe * self = INDICATOR_ME(user_data);
if (g_strcmp0(signal_name, "StatusIconsChanged") == 0) {
- char * icon;
+ gchar * icon;
g_variant_get (parameters, "(&s)", &icon);
status_icon_changed (self, icon);
}
else if (g_strcmp0(signal_name, "UserChanged") == 0) {
- char * username;
+ gchar * username;
g_variant_get (parameters, "(&s)", &username);
username_changed(self, username);
}
@@ -392,7 +392,7 @@
/* Query to get the status icon */
g_debug("Get the status icon");
- g_dbus_proxy_call(status_proxy, "StatusIcon", NULL,
+ g_dbus_proxy_call(status_proxy, "StatusIcons", NULL,
G_DBUS_CALL_FLAGS_NONE, -1, NULL,
(GAsyncReadyCallback) status_icon_cb, self);
=== modified file 'src/me-service-dbus.c'
--- src/me-service-dbus.c 2011-01-12 22:40:11 +0000
+++ src/me-service-dbus.c 2011-01-13 20:37:08 +0000
@@ -24,8 +24,9 @@
#include "config.h"
#endif
-#include <dbus/dbus-glib.h>
+#include <gio/gio.h>
+#include "gen-me-service.xml.h"
#include "dbus-shared-names.h"
#include "me-service-dbus.h"
@@ -33,17 +34,28 @@
static void status_service_dbus_init (StatusServiceDbus *self);
static void status_service_dbus_dispose (GObject *object);
static void status_service_dbus_finalize (GObject *object);
-static gboolean _me_service_server_watch (StatusServiceDbus * service, GError ** error);
-static gboolean _me_service_server_status_icons (StatusServiceDbus * service, gchar ** icon, GError ** error);
-static gboolean _me_service_server_pretty_user_name (StatusServiceDbus * service, gchar ** username, GError ** error);
-
-#include "me-service-server.h"
-#include "gen-me-service.xml.h"
-
-/* Private */
+static GVariant * get_icon (StatusServiceDbus * service);
+static GVariant * get_username (StatusServiceDbus * service);
+static GVariant * status_service_dbus_watch (StatusServiceDbus * service);
+static void bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data);
+static void bus_method_call (GDBusConnection * connection, const gchar * sender, const gchar * path, const gchar * interface, const gchar * method, GVariant * params, GDBusMethodInvocation * invocation, gpointer user_data);
+
+
+
+/**
+ StatusServiceDbusPrivate:
+ @dbus_registration: The handle for this object being registered
+ on dbus.
+
+ Structure to define the memory for the private area
+ of the status service dbus instance.
+*/
typedef struct _StatusServiceDbusPrivate StatusServiceDbusPrivate;
struct _StatusServiceDbusPrivate
{
+ GDBusConnection * bus;
+ GCancellable * bus_cancel;
+ guint dbus_registration;
gchar * name;
gchar * icon;
};
@@ -51,15 +63,15 @@
#define STATUS_SERVICE_DBUS_GET_PRIVATE(o) \
(G_TYPE_INSTANCE_GET_PRIVATE ((o), STATUS_SERVICE_DBUS_TYPE, StatusServiceDbusPrivate))
-/* Signals */
-enum {
- USER_CHANGED,
- STATUS_ICONS_CHANGED,
- LAST_SIGNAL
+/* GDBus Stuff */
+static GDBusNodeInfo * node_info = NULL;
+static GDBusInterfaceInfo * interface_info = NULL;
+static GDBusInterfaceVTable interface_table = {
+ method_call: bus_method_call,
+ get_property: NULL, /* No properties */
+ set_property: NULL /* No properties */
};
-static guint signals[LAST_SIGNAL] = { 0 };
-
/* GObject Boilerplate */
G_DEFINE_TYPE (StatusServiceDbus, status_service_dbus, G_TYPE_OBJECT);
@@ -73,64 +85,135 @@
object_class->dispose = status_service_dbus_dispose;
object_class->finalize = status_service_dbus_finalize;
- /**
- StatusServiceDbus::user-changed:
- @arg0: The #StatusServiceDbus object.
- @arg1: The place to put the new user name
-
- Signals that the user name has changed and gives the
- new user name.
- */
- signals[USER_CHANGED] = g_signal_new("user-changed",
- G_TYPE_FROM_CLASS(klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(StatusServiceDbusClass, user_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1, G_TYPE_STRING);
-
- /**
- StatusServiceDbus::status-icons-changed:
- @arg0: The #StatusServiceDbus object.
- @arg1: The list of icon names representing the statuses in
- the order they should be displayed. Left to right.
-
- Signals that the user status set has changed and that
- new icons may need to be loaded. The list of icons will
- always be complete.
- */
- signals[STATUS_ICONS_CHANGED] = g_signal_new("status-icons-changed",
- G_TYPE_FROM_CLASS(klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(StatusServiceDbusClass, status_icons_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__STRING,
- G_TYPE_NONE, 1, G_TYPE_STRING);
-
- dbus_g_object_type_install_info(STATUS_SERVICE_DBUS_TYPE, &dbus_glib__me_service_server_object_info);
-
+ /* Setting up the DBus interfaces */
+ if (node_info == NULL) {
+ GError * error = NULL;
+
+ node_info = g_dbus_node_info_new_for_xml(_me_service, &error);
+ if (error != NULL) {
+ g_error("Unable to parse Me Service Interface description: %s", error->message);
+ g_error_free(error);
+ }
+ }
+
+ if (interface_info == NULL) {
+ interface_info = g_dbus_node_info_lookup_interface(node_info, INDICATOR_ME_SERVICE_DBUS_INTERFACE);
+
+ if (interface_info == NULL) {
+ g_error("Unable to find interface '" INDICATOR_ME_SERVICE_DBUS_INTERFACE "'");
+ }
+ }
+
return;
}
static void
status_service_dbus_init (StatusServiceDbus *self)
{
-
- DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
- dbus_g_connection_register_g_object(connection,
- INDICATOR_ME_SERVICE_DBUS_OBJECT,
- G_OBJECT(self));
-
StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self);
priv->name = NULL;
priv->icon = NULL;
- return;
-}
+ priv->bus = NULL;
+ priv->bus_cancel = NULL;
+ priv->dbus_registration = 0;
+
+ priv->bus_cancel = g_cancellable_new();
+ g_bus_get(G_BUS_TYPE_SESSION,
+ priv->bus_cancel,
+ bus_get_cb,
+ self);
+
+ return;
+}
+
+static void
+bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data)
+{
+ GError * error = NULL;
+ GDBusConnection * connection = g_bus_get_finish(res, &error);
+
+ if (error != NULL) {
+ g_error("OMG! Unable to get a connection to DBus: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
+ StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(user_data);
+
+ g_warn_if_fail(priv->bus == NULL);
+ priv->bus = connection;
+
+ if (priv->bus_cancel != NULL) {
+ g_object_unref(priv->bus_cancel);
+ priv->bus_cancel = NULL;
+ }
+
+ /* Now register our object on our new connection */
+ priv->dbus_registration = g_dbus_connection_register_object(connection,
+ INDICATOR_ME_SERVICE_DBUS_OBJECT,
+ interface_info,
+ &interface_table,
+ user_data,
+ NULL,
+ &error);
+
+ if (error != NULL) {
+ g_error("Unable to register the object to DBus: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
+ return;
+}
+
+/* A method has been called from our dbus inteface. Figure out what it
+ is and dispatch it. */
+static void
+bus_method_call (GDBusConnection * connection, const gchar * sender,
+ const gchar * path, const gchar * interface,
+ const gchar * method, GVariant * params,
+ GDBusMethodInvocation * invocation, gpointer user_data)
+{
+ StatusServiceDbus * service = STATUS_SERVICE_DBUS(user_data);
+ GVariant * retval = NULL;
+
+ if (g_strcmp0(method, "PrettyUserName") == 0) {
+ retval = get_username(service);
+ } else if (g_strcmp0(method, "StatusIcons") == 0) {
+ retval = get_icon(service);
+ } else if (g_strcmp0(method, "Watch") == 0) {
+ retval = status_service_dbus_watch(service);
+ } else {
+ g_warning("Calling method '%s' on the indicator service and it's unknown", method);
+ }
+
+ g_dbus_method_invocation_return_value(invocation, retval);
+ return;
+}
+
static void
status_service_dbus_dispose (GObject *object)
{
+ StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(object);
+
+ if (priv->dbus_registration != 0) {
+ g_dbus_connection_unregister_object(priv->bus, priv->dbus_registration);
+ /* Don't care if it fails, there's nothing we can do */
+ priv->dbus_registration = 0;
+ }
+
+ if (priv->bus != NULL) {
+ g_object_unref(priv->bus);
+ priv->bus = NULL;
+ }
+
+ if (priv->bus_cancel != NULL) {
+ g_cancellable_cancel(priv->bus_cancel);
+ g_object_unref(priv->bus_cancel);
+ priv->bus_cancel = NULL;
+ }
G_OBJECT_CLASS (status_service_dbus_parent_class)->dispose (object);
return;
@@ -144,47 +227,25 @@
return;
}
-static gboolean
-_me_service_server_watch (StatusServiceDbus * service, GError ** error)
-{
-
- return TRUE;
-}
-
-static gboolean
-_me_service_server_status_icons (StatusServiceDbus * service, gchar ** icon, GError ** error)
-{
- if (!IS_STATUS_SERVICE_DBUS(service)) {
- g_warning("NO BAD EVIL!");
- return FALSE;
- }
-
- StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(service);
- if (priv->icon == NULL) {
- *icon = g_strdup("");
- } else {
- *icon = g_strdup(priv->icon);
- }
-
- return TRUE;
-}
-
-static gboolean
-_me_service_server_pretty_user_name (StatusServiceDbus * service, gchar ** username, GError ** error)
-{
- if (!IS_STATUS_SERVICE_DBUS(service)) {
- g_warning("NO BAD EVIL!");
- return FALSE;
- }
-
- StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(service);
- if (priv->name == NULL) {
- *username = g_strdup("");
- } else {
- *username = g_strdup(priv->name);
- }
-
- return TRUE;
+static GVariant *
+status_service_dbus_watch (StatusServiceDbus * service)
+{
+ return g_variant_new("(b)", TRUE);
+}
+
+
+static GVariant *
+get_username (StatusServiceDbus * service)
+{
+ StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(service);
+ return g_variant_new("(s)", priv->name);
+}
+
+static GVariant *
+get_icon (StatusServiceDbus * service)
+{
+ StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(service);
+ return g_variant_new("(s)", priv->icon);
}
void
@@ -196,12 +257,31 @@
StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self);
+ GError * error = NULL;
+
if (priv->icon != NULL) {
g_free(priv->icon);
}
priv->icon = g_strdup(icon);
- g_signal_emit(G_OBJECT(self), signals[STATUS_ICONS_CHANGED], 0, priv->icon, TRUE);
+ if (priv->bus == NULL) {
+ return;
+ }
+
+ g_dbus_connection_emit_signal (priv->bus,
+ NULL,
+ INDICATOR_ME_SERVICE_DBUS_OBJECT,
+ INDICATOR_ME_SERVICE_DBUS_INTERFACE,
+ "StatusIconsChanged",
+ g_variant_new("(s)", icon),
+ &error);
+
+ if (error != NULL) {
+ g_error("Unable to send StatusIconsChanged signal: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
return;
}
@@ -214,11 +294,30 @@
StatusServiceDbusPrivate * priv = STATUS_SERVICE_DBUS_GET_PRIVATE(self);
+ GError * error = NULL;
+
if (priv->name != NULL) {
g_free(priv->name);
}
priv->name = g_strdup(username);
- g_signal_emit(G_OBJECT(self), signals[USER_CHANGED], 0, priv->name, TRUE);
+ if (priv->bus == NULL) {
+ return;
+ }
+
+ g_dbus_connection_emit_signal (priv->bus,
+ NULL,
+ INDICATOR_ME_SERVICE_DBUS_OBJECT,
+ INDICATOR_ME_SERVICE_DBUS_INTERFACE,
+ "UserChanged",
+ NULL,
+ &error);
+
+ if (error != NULL) {
+ g_error("Unable to send UserChanged signal: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
return;
}