aboutsummaryrefslogtreecommitdiff
path: root/src/datetime-interface.c
diff options
context:
space:
mode:
authorMichael Terry <mike@mterry.name>2011-01-10 15:16:49 -0600
committerMichael Terry <mike@mterry.name>2011-01-10 15:16:49 -0600
commit4132432b89cedf30cae89042a296ac299cef2161 (patch)
treef29d51c998d27f29c536d1076961ffded697944e /src/datetime-interface.c
parent9402dbecd6db1b004a0cb5e894260106b1a5f537 (diff)
downloadayatana-indicator-datetime-4132432b89cedf30cae89042a296ac299cef2161.tar.gz
ayatana-indicator-datetime-4132432b89cedf30cae89042a296ac299cef2161.tar.bz2
ayatana-indicator-datetime-4132432b89cedf30cae89042a296ac299cef2161.zip
first, untested pass at gdbus port
Diffstat (limited to 'src/datetime-interface.c')
-rw-r--r--src/datetime-interface.c119
1 files changed, 113 insertions, 6 deletions
diff --git a/src/datetime-interface.c b/src/datetime-interface.c
index c58c5af..2bb56b0 100644
--- a/src/datetime-interface.c
+++ b/src/datetime-interface.c
@@ -23,21 +23,44 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include "config.h"
#endif
+#include <gio/gio.h>
+
#include "datetime-interface.h"
-#include "datetime-service-server.h"
+#include "gen-datetime-service.xml.h"
#include "dbus-shared.h"
+/**
+ DatetimeInterfacePrivate:
+ @dbus_registration: The handle for this object being registered
+ on dbus.
+
+ Structure to define the memory for the private area
+ of the datetime interface instance.
+*/
+struct _DatetimeInterfacePrivate {
+ GDBusConnection * bus;
+ GCancellable * bus_cancel;
+ guint dbus_registration;
+};
+
+#define DATETIME_INTERFACE_GET_PRIVATE(o) (DATETIME_INTERFACE(o)->priv)
+
enum {
UPDATE_TIME,
LAST_SIGNAL
};
+/* GDBus Stuff */
+static GDBusNodeInfo * node_info = NULL;
+static GDBusInterfaceInfo * interface_info = NULL;
+
static guint signals[LAST_SIGNAL] = { 0 };
static void datetime_interface_class_init (DatetimeInterfaceClass *klass);
static void datetime_interface_init (DatetimeInterface *self);
static void datetime_interface_dispose (GObject *object);
static void datetime_interface_finalize (GObject *object);
+static void bus_get_cb (GObject * object, GAsyncResult * res, gpointer user_data);
G_DEFINE_TYPE (DatetimeInterface, datetime_interface, G_TYPE_OBJECT);
@@ -46,6 +69,8 @@ datetime_interface_class_init (DatetimeInterfaceClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ g_type_class_add_private (klass, sizeof (DatetimeInterfacePrivate));
+
object_class->dispose = datetime_interface_dispose;
object_class->finalize = datetime_interface_finalize;
@@ -57,7 +82,24 @@ datetime_interface_class_init (DatetimeInterfaceClass *klass)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE, 0, G_TYPE_NONE);
- dbus_g_object_type_install_info(DATETIME_INTERFACE_TYPE, &dbus_glib__datetime_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(_datetime_service, &error);
+ if (error != NULL) {
+ g_error("Unable to parse Datetime Service Interface description: %s", error->message);
+ g_error_free(error);
+ }
+ }
+
+ if (interface_info == NULL) {
+ interface_info = g_dbus_node_info_lookup_interface(node_info, SERVICE_IFACE);
+
+ if (interface_info == NULL) {
+ g_error("Unable to find interface '" SERVICE_IFACE "'");
+ }
+ }
return;
}
@@ -65,17 +107,82 @@ datetime_interface_class_init (DatetimeInterfaceClass *klass)
static void
datetime_interface_init (DatetimeInterface *self)
{
- DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL);
- dbus_g_connection_register_g_object(connection,
- SERVICE_OBJ,
- G_OBJECT(self));
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, DATETIME_INTERFACE_TYPE, DatetimeInterfacePrivate);
+
+ self->priv->bus = NULL;
+ self->priv->bus_cancel = NULL;
+ self->priv->dbus_registration = 0;
+
+ self->priv->bus_cancel = g_cancellable_new();
+ g_bus_get(G_BUS_TYPE_SESSION,
+ self->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;
+ }
+
+ DatetimeInterfacePrivate * priv = DATETIME_INTERFACE_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,
+ SERVICE_OBJ,
+ interface_info,
+ NULL,
+ 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;
+}
+
+static void
datetime_interface_dispose (GObject *object)
{
+ DatetimeInterfacePrivate * priv = DATETIME_INTERFACE_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 (datetime_interface_parent_class)->dispose (object);
return;