aboutsummaryrefslogtreecommitdiff
path: root/libindicator
diff options
context:
space:
mode:
authorTed Gould <ted@canonical.com>2009-11-04 11:24:25 -0600
committerTed Gould <ted@canonical.com>2009-11-04 11:24:25 -0600
commit2b754cb1b6e7a69fd90f0d562e32e02204575561 (patch)
treefe779a4cf56532e520e6a88b1520321648465584 /libindicator
parent534aab3aa87e4ffcca3e14f5c19498843c0adbca (diff)
parentc547687a407d935654aa71f7afa1e4392e50d5c5 (diff)
downloadlibayatana-indicator-2b754cb1b6e7a69fd90f0d562e32e02204575561.tar.gz
libayatana-indicator-2b754cb1b6e7a69fd90f0d562e32e02204575561.tar.bz2
libayatana-indicator-2b754cb1b6e7a69fd90f0d562e32e02204575561.zip
Updating to current trunk.
Diffstat (limited to 'libindicator')
-rw-r--r--libindicator/Makefile.am39
-rw-r--r--libindicator/dbus-shared.h6
-rw-r--r--libindicator/indicator-service-manager.c334
-rw-r--r--libindicator/indicator-service-manager.h63
-rw-r--r--libindicator/indicator-service.c334
-rw-r--r--libindicator/indicator-service.h60
-rw-r--r--libindicator/indicator-service.xml17
-rw-r--r--libindicator/indicator.pc.in2
8 files changed, 852 insertions, 3 deletions
diff --git a/libindicator/Makefile.am b/libindicator/Makefile.am
index db45f3c..5c512cd 100644
--- a/libindicator/Makefile.am
+++ b/libindicator/Makefile.am
@@ -1,3 +1,5 @@
+BUILT_SOURCES =
+CLEANFILES =
EXTRA_DIST = \
indicator.pc.in
@@ -5,7 +7,9 @@ libindicatorincludedir=$(includedir)/libindicator-0.1/libindicator
indicator_headers = \
indicator.h \
- indicator-object.h
+ indicator-object.h \
+ indicator-service.h \
+ indicator-service-manager.h
libindicatorinclude_HEADERS = \
$(indicator_headers)
@@ -15,7 +19,10 @@ lib_LTLIBRARIES = \
libindicator_la_SOURCES = \
$(indicator_headers) \
- indicator-object.c
+ dbus-shared.h \
+ indicator-object.c \
+ indicator-service.c \
+ indicator-service-manager.c
libindicator_la_CFLAGS = \
$(LIBINDICATOR_CFLAGS) \
@@ -27,3 +34,31 @@ libindicator_la_LIBADD = \
pkgconfig_DATA = indicator.pc
pkgconfigdir = $(libdir)/pkgconfig
+##################################
+# DBus Specs
+##################################
+
+DBUS_SPECS = \
+ indicator-service.xml
+
+%-client.h: %.xml
+ dbus-binding-tool \
+ --prefix=_$(subst -,_,$(basename $(notdir $<)))_client \
+ --mode=glib-client \
+ --output=$@ \
+ $<
+
+%-server.h: %.xml
+ dbus-binding-tool \
+ --prefix=_$(subst -,_,$(basename $(notdir $<)))_server \
+ --mode=glib-server \
+ --output=$@ \
+ $<
+
+BUILT_SOURCES += \
+ $(DBUS_SPECS:.xml=-client.h) \
+ $(DBUS_SPECS:.xml=-server.h)
+
+CLEANFILES += $(BUILT_SOURCES)
+
+EXTRA_DIST += $(DBUS_SPECS)
diff --git a/libindicator/dbus-shared.h b/libindicator/dbus-shared.h
new file mode 100644
index 0000000..f3dbd83
--- /dev/null
+++ b/libindicator/dbus-shared.h
@@ -0,0 +1,6 @@
+
+#define INDICATOR_SERVICE_INTERFACE "org.ayatana.indicator.service"
+#define INDICATOR_SERVICE_OBJECT "/org/ayatana/indicator/service"
+
+#define INDICATOR_SERVICE_VERSION 1
+
diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c
new file mode 100644
index 0000000..4eaed23
--- /dev/null
+++ b/libindicator/indicator-service-manager.c
@@ -0,0 +1,334 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <dbus/dbus-glib-bindings.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "indicator-service-manager.h"
+#include "indicator-service-client.h"
+#include "dbus-shared.h"
+
+/* Private Stuff */
+typedef struct _IndicatorServiceManagerPrivate IndicatorServiceManagerPrivate;
+struct _IndicatorServiceManagerPrivate {
+ gchar * name;
+ DBusGProxy * dbus_proxy;
+ DBusGProxy * service_proxy;
+ gboolean connected;
+};
+
+/* Signals Stuff */
+enum {
+ CONNECTION_CHANGE,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+
+/* Properties */
+/* Enum for the properties so that they can be quickly
+ found and looked up. */
+enum {
+ PROP_0,
+ PROP_NAME,
+};
+
+/* The strings so that they can be slowly looked up. */
+#define PROP_NAME_S "name"
+
+/* GObject Stuff */
+#define INDICATOR_SERVICE_MANAGER_GET_PRIVATE(o) \
+(G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_SERVICE_MANAGER_TYPE, IndicatorServiceManagerPrivate))
+
+static void indicator_service_manager_class_init (IndicatorServiceManagerClass *klass);
+static void indicator_service_manager_init (IndicatorServiceManager *self);
+static void indicator_service_manager_dispose (GObject *object);
+static void indicator_service_manager_finalize (GObject *object);
+
+/* Prototypes */
+static void set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec);
+static void get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec);
+static void start_service (IndicatorServiceManager * service);
+
+G_DEFINE_TYPE (IndicatorServiceManager, indicator_service_manager, G_TYPE_OBJECT);
+
+static void
+indicator_service_manager_class_init (IndicatorServiceManagerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (IndicatorServiceManagerPrivate));
+
+ object_class->dispose = indicator_service_manager_dispose;
+ object_class->finalize = indicator_service_manager_finalize;
+
+ /* Property funcs */
+ object_class->set_property = set_property;
+ object_class->get_property = get_property;
+
+ /**
+ IndicatorServiceManager::connecton-change:
+ @arg0: The #IndicatorServiceManager object
+ @arg1: The state of the connection, TRUE is connected.
+
+ Signaled when the service is connected or disconnected
+ depending on it's previous state.
+ */
+ signals[CONNECTION_CHANGE] = g_signal_new (INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE,
+ G_TYPE_FROM_CLASS(klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (IndicatorServiceManagerClass, connection_change),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__BOOLEAN,
+ G_TYPE_NONE, 1, G_TYPE_BOOLEAN, G_TYPE_NONE);
+
+ /* Properties */
+ g_object_class_install_property(object_class, PROP_NAME,
+ g_param_spec_string(PROP_NAME_S,
+ "The DBus name for the service to monitor",
+ "This is the name that should be used to start a service.",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ return;
+}
+
+static void
+indicator_service_manager_init (IndicatorServiceManager *self)
+{
+ IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(self);
+
+ /* Get the private variables in a decent state */
+ priv->name = NULL;
+ priv->dbus_proxy = NULL;
+ priv->service_proxy = NULL;
+ priv->connected = FALSE;
+
+ /* Start talkin' dbus */
+ GError * error = NULL;
+ DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (error != NULL) {
+ g_error("Unable to get session bus: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
+ priv->dbus_proxy = dbus_g_proxy_new_for_name_owner(session_bus,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS,
+ &error);
+ if (error != NULL) {
+ g_error("Unable to get the proxy to DBus: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
+ return;
+}
+
+static void
+indicator_service_manager_dispose (GObject *object)
+{
+ IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(object);
+
+ /* If we were connected we need to make sure to
+ tell people that it's no longer the case. */
+ if (priv->connected) {
+ priv->connected = FALSE;
+ g_signal_emit(object, signals[CONNECTION_CHANGE], 0, FALSE, TRUE);
+ }
+
+ /* Destory our DBus proxy, we won't need it. */
+ if (priv->dbus_proxy != NULL) {
+ g_object_unref(G_OBJECT(priv->dbus_proxy));
+ priv->dbus_proxy = NULL;
+ }
+
+ /* Destory our service proxy, we won't need it. */
+ if (priv->service_proxy != NULL) {
+ g_object_unref(G_OBJECT(priv->service_proxy));
+ priv->service_proxy = NULL;
+ }
+
+ /* Let's see if our parents want to do anything. */
+ G_OBJECT_CLASS (indicator_service_manager_parent_class)->dispose (object);
+ return;
+}
+
+static void
+indicator_service_manager_finalize (GObject *object)
+{
+ IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(object);
+
+ if (priv->name != NULL) {
+ g_free(priv->name);
+ priv->name = NULL;
+ }
+
+ G_OBJECT_CLASS (indicator_service_manager_parent_class)->finalize (object);
+ return;
+}
+
+static void
+set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec)
+{
+ IndicatorServiceManager * self = INDICATOR_SERVICE_MANAGER(object);
+ g_return_if_fail(self != NULL);
+
+ IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(self);
+ g_return_if_fail(priv != NULL);
+
+ switch (prop_id) {
+ /* *********************** */
+ case PROP_NAME:
+ if (G_VALUE_HOLDS_STRING(value)) {
+ if (priv->name != NULL) {
+ g_error("Name can not be set twice!");
+ return;
+ }
+ priv->name = g_value_dup_string(value);
+ start_service(self);
+ } else {
+ g_warning("Name is a string bud.");
+ }
+ break;
+ /* *********************** */
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+
+ return;
+}
+
+static void
+get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec)
+{
+ IndicatorServiceManager * self = INDICATOR_SERVICE_MANAGER(object);
+ g_return_if_fail(self != NULL);
+
+ IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(self);
+ g_return_if_fail(priv != NULL);
+
+ switch (prop_id) {
+ /* *********************** */
+ case PROP_NAME:
+ if (G_VALUE_HOLDS_STRING(value)) {
+ g_value_set_string(value, priv->name);
+ } else {
+ g_warning("Name is a string bud.");
+ }
+ break;
+ /* *********************** */
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+
+ return;
+}
+
+static void
+watch_cb (DBusGProxy * proxy, gint service_version, GError * error, gpointer user_data)
+{
+ IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(user_data);
+
+ if (error != NULL) {
+ g_warning("Unable to set watch on '%s': '%s'", priv->name, error->message);
+ g_error_free(error);
+ return;
+ }
+
+ if (service_version != INDICATOR_SERVICE_VERSION) {
+ g_warning("Service is using a different version of the service interface. Expecting %d and got %d.", INDICATOR_SERVICE_VERSION, service_version);
+ return;
+ }
+
+ if (!priv->connected) {
+ priv->connected = TRUE;
+ g_signal_emit(G_OBJECT(user_data), signals[CONNECTION_CHANGE], 0, TRUE, TRUE);
+ }
+
+ return;
+}
+
+static void
+start_service_cb (DBusGProxy * proxy, guint status, GError * error, gpointer user_data)
+{
+ IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(user_data);
+
+ if (error != NULL) {
+ g_warning("Unable to start service '%s': %s", priv->name, error->message);
+ return;
+ }
+
+ if (status != DBUS_START_REPLY_SUCCESS && status != DBUS_START_REPLY_ALREADY_RUNNING) {
+ g_warning("Status of starting the process '%s' was an error: %d", priv->name, status);
+ return;
+ }
+
+ /* Woot! it's running. Let's do it some more. */
+ DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (error != NULL) {
+ g_error("Unable to get session bus: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
+ priv->service_proxy = dbus_g_proxy_new_for_name_owner(session_bus,
+ priv->name,
+ INDICATOR_SERVICE_OBJECT,
+ INDICATOR_SERVICE_INTERFACE,
+ &error);
+
+ org_ayatana_indicator_service_watch_async(priv->service_proxy,
+ watch_cb,
+ user_data);
+
+ return;
+}
+
+static void
+start_service (IndicatorServiceManager * service)
+{
+ IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(service);
+
+ g_return_if_fail(priv->dbus_proxy != NULL);
+ g_return_if_fail(priv->name != NULL);
+
+ org_freedesktop_DBus_start_service_by_name_async (priv->dbus_proxy,
+ priv->name,
+ 0,
+ start_service_cb,
+ service);
+
+ return;
+}
+
+/* API */
+IndicatorServiceManager *
+indicator_service_manager_new (gchar * dbus_name)
+{
+ GObject * obj = g_object_new(INDICATOR_SERVICE_MANAGER_TYPE,
+ PROP_NAME_S, dbus_name,
+ NULL);
+
+ return INDICATOR_SERVICE_MANAGER(obj);
+}
+
+gboolean
+indicator_service_manager_connected (IndicatorServiceManager * sm)
+{
+
+ return FALSE;
+}
+
+void
+indicator_service_manager_set_refresh (IndicatorServiceManager * sm, guint time_in_ms)
+{
+
+ return;
+}
diff --git a/libindicator/indicator-service-manager.h b/libindicator/indicator-service-manager.h
new file mode 100644
index 0000000..127d56b
--- /dev/null
+++ b/libindicator/indicator-service-manager.h
@@ -0,0 +1,63 @@
+#ifndef __INDICATOR_SERVICE_MANAGER_H__
+#define __INDICATOR_SERVICE_MANAGER_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define INDICATOR_SERVICE_MANAGER_TYPE (indicator_service_manager_get_type ())
+#define INDICATOR_SERVICE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_SERVICE_MANAGER_TYPE, IndicatorServiceManager))
+#define INDICATOR_SERVICE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_SERVICE_MANAGER_TYPE, IndicatorServiceManagerClass))
+#define INDICATOR_IS_SERVICE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_SERVICE_MANAGER_TYPE))
+#define INDICATOR_IS_SERVICE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_SERVICE_MANAGER_TYPE))
+#define INDICATOR_SERVICE_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_SERVICE_MANAGER_TYPE, IndicatorServiceManagerClass))
+
+#define INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE "connection-change"
+
+typedef struct _IndicatorServiceManager IndicatorServiceManager;
+typedef struct _IndicatorServiceManagerClass IndicatorServiceManagerClass;
+
+/**
+ IndicatorServiceManagerClass:
+ @parent: #GObjectClass
+ @connection_changed: Slot for #IndicatorServiceManager::connection-changed.
+ @indicator_service_manager_reserved1: Reserved for future use.
+ @indicator_service_manager_reserved2: Reserved for future use.
+ @indicator_service_manager_reserved3: Reserved for future use.
+ @indicator_service_manager_reserved4: Reserved for future use.
+
+*/
+struct _IndicatorServiceManagerClass {
+ GObjectClass parent_class;
+
+ /* Signals */
+ void (*connection_change) (IndicatorServiceManager * sm, gboolean connected, gpointer user_data);
+
+ /* Buffer */
+ void (*indicator_service_manager_reserved1) (void);
+ void (*indicator_service_manager_reserved2) (void);
+ void (*indicator_service_manager_reserved3) (void);
+ void (*indicator_service_manager_reserved4) (void);
+};
+
+/**
+ IndicatorServiceManager:
+ @parent: #GObject
+
+*/
+struct _IndicatorServiceManager {
+ GObject parent;
+
+};
+
+GType indicator_service_manager_get_type (void);
+
+IndicatorServiceManager * indicator_service_manager_new (gchar * dbus_name);
+gboolean indicator_service_manager_connected (IndicatorServiceManager * sm);
+void indicator_service_manager_set_refresh (IndicatorServiceManager * sm,
+ guint time_in_ms);
+
+G_END_DECLS
+
+#endif
diff --git a/libindicator/indicator-service.c b/libindicator/indicator-service.c
new file mode 100644
index 0000000..69422c5
--- /dev/null
+++ b/libindicator/indicator-service.c
@@ -0,0 +1,334 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <dbus/dbus-glib-bindings.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "indicator-service.h"
+
+/* DBus Prototypes */
+static gboolean _indicator_service_server_watch (IndicatorService * service, DBusGMethodInvocation * method);
+
+#include "indicator-service-server.h"
+#include "dbus-shared.h"
+
+/* Private Stuff */
+typedef struct _IndicatorServicePrivate IndicatorServicePrivate;
+
+struct _IndicatorServicePrivate {
+ gchar * name;
+ DBusGProxy * dbus_proxy;
+ guint timeout;
+ GList * watchers;
+};
+
+/* Signals Stuff */
+enum {
+ SHUTDOWN,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+/* Properties */
+/* Enum for the properties so that they can be quickly
+ found and looked up. */
+enum {
+ PROP_0,
+ PROP_NAME,
+};
+
+/* The strings so that they can be slowly looked up. */
+#define PROP_NAME_S "name"
+
+/* GObject Stuff */
+#define INDICATOR_SERVICE_GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_SERVICE_TYPE, IndicatorServicePrivate))
+
+static void indicator_service_class_init (IndicatorServiceClass *klass);
+static void indicator_service_init (IndicatorService *self);
+static void indicator_service_dispose (GObject *object);
+static void indicator_service_finalize (GObject *object);
+
+/* Other prototypes */
+static void set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec);
+static void get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec);
+static void try_and_get_name (IndicatorService * service);
+
+G_DEFINE_TYPE (IndicatorService, indicator_service, G_TYPE_OBJECT);
+
+static void
+indicator_service_class_init (IndicatorServiceClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (IndicatorServicePrivate));
+
+ object_class->dispose = indicator_service_dispose;
+ object_class->finalize = indicator_service_finalize;
+
+ /* Property funcs */
+ object_class->set_property = set_property;
+ object_class->get_property = get_property;
+
+ /* Properties */
+ g_object_class_install_property(object_class, PROP_NAME,
+ g_param_spec_string(PROP_NAME_S,
+ "The DBus name for this service",
+ "This is the name that should be used on DBus for this service.",
+ NULL,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
+ /* Signals */
+
+ /**
+ IndicatorService::shutdown:
+ @arg0: The #IndicatorService object
+
+ Signaled when the service should shutdown as no one
+ is listening anymore.
+ */
+ signals[SHUTDOWN] = g_signal_new (INDICATOR_SERVICE_SIGNAL_SHUTDOWN,
+ G_TYPE_FROM_CLASS(klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (IndicatorServiceClass, shutdown),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0, G_TYPE_NONE);
+
+ /* Initialize the object as a DBus type */
+ dbus_g_object_type_install_info(INDICATOR_SERVICE_TYPE,
+ &dbus_glib__indicator_service_server_object_info);
+
+ return;
+}
+
+static void
+indicator_service_init (IndicatorService *self)
+{
+ IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(self);
+
+ /* Get the private variables in a decent state */
+ priv->name = NULL;
+ priv->dbus_proxy = NULL;
+ priv->timeout = 0;
+ priv->watchers = NULL;
+
+ /* Start talkin' dbus */
+ GError * error = NULL;
+ DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_STARTER, &error);
+ if (error != NULL) {
+ g_error("Unable to get starter bus: %s", error->message);
+ g_error_free(error);
+
+ /* Okay, fine let's try the session bus then. */
+ /* I think this should automatically, but I can't find confirmation
+ of that, so we're putting the extra little code in here. */
+ error = NULL;
+ bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error);
+ if (error != NULL) {
+ g_error("Unable to get session bus: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+ }
+
+ priv->dbus_proxy = dbus_g_proxy_new_for_name_owner(bus,
+ DBUS_SERVICE_DBUS,
+ DBUS_PATH_DBUS,
+ DBUS_INTERFACE_DBUS,
+ &error);
+ if (error != NULL) {
+ g_error("Unable to get the proxy to DBus: %s", error->message);
+ g_error_free(error);
+ return;
+ }
+
+ dbus_g_connection_register_g_object(bus,
+ INDICATOR_SERVICE_OBJECT,
+ G_OBJECT(self));
+
+ return;
+}
+
+static void
+indicator_service_dispose (GObject *object)
+{
+ IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(object);
+
+ if (priv->dbus_proxy != NULL) {
+ g_object_unref(G_OBJECT(priv->dbus_proxy));
+ priv->dbus_proxy = NULL;
+ }
+
+ if (priv->timeout != 0) {
+ g_source_remove(priv->timeout);
+ priv->timeout = 0;
+ }
+
+ G_OBJECT_CLASS (indicator_service_parent_class)->dispose (object);
+ return;
+}
+
+static void
+indicator_service_finalize (GObject *object)
+{
+ IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(object);
+
+ if (priv->name != NULL) {
+ g_free(priv->name);
+ }
+
+ if (priv->watchers != NULL) {
+ g_list_foreach(priv->watchers, (GFunc)g_free, NULL);
+ g_list_free(priv->watchers);
+ priv->watchers = NULL;
+ }
+
+ G_OBJECT_CLASS (indicator_service_parent_class)->finalize (object);
+ return;
+}
+
+static void
+set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec)
+{
+ IndicatorService * self = INDICATOR_SERVICE(object);
+ g_return_if_fail(self != NULL);
+
+ IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(self);
+ g_return_if_fail(priv != NULL);
+
+ switch (prop_id) {
+ /* *********************** */
+ case PROP_NAME:
+ if (G_VALUE_HOLDS_STRING(value)) {
+ if (priv->name != NULL) {
+ g_error("Name can not be set twice!");
+ return;
+ }
+ priv->name = g_value_dup_string(value);
+ try_and_get_name(self);
+ } else {
+ g_warning("Name property requires a string value.");
+ }
+ break;
+ /* *********************** */
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+
+ return;
+}
+
+static void
+get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec)
+{
+ IndicatorService * self = INDICATOR_SERVICE(object);
+ g_return_if_fail(self != NULL);
+
+ IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(self);
+ g_return_if_fail(priv != NULL);
+
+ switch (prop_id) {
+ /* *********************** */
+ case PROP_NAME:
+ if (G_VALUE_HOLDS_STRING(value)) {
+ g_value_set_string(value, priv->name);
+ } else {
+ g_warning("Name property requires a string value.");
+ }
+ break;
+ /* *********************** */
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ break;
+ }
+
+ return;
+}
+
+static gboolean
+timeout_no_watchers (gpointer data)
+{
+ g_signal_emit(G_OBJECT(data), signals[SHUTDOWN], 0, TRUE);
+ return FALSE;
+}
+
+static void
+try_and_get_name_cb (DBusGProxy * proxy, guint status, GError * error, gpointer data)
+{
+ IndicatorService * service = INDICATOR_SERVICE(data);
+ g_return_if_fail(service != NULL);
+
+ if (status != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER && status != DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER) {
+ /* The already owner seems like it shouldn't ever
+ happen, but I have a hard time throwing an error
+ on it as we did achieve our goals. */
+ g_signal_emit(G_OBJECT(data), signals[SHUTDOWN], 0, TRUE);
+ return;
+ }
+
+ IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(service);
+ priv->timeout = g_timeout_add(500, timeout_no_watchers, service);
+
+ return;
+}
+
+static void
+try_and_get_name (IndicatorService * service)
+{
+ IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(service);
+ g_return_if_fail(priv->dbus_proxy != NULL);
+ g_return_if_fail(priv->name != NULL);
+
+ org_freedesktop_DBus_request_name_async(priv->dbus_proxy,
+ priv->name,
+ DBUS_NAME_FLAG_DO_NOT_QUEUE,
+ try_and_get_name_cb,
+ service);
+
+ return;
+}
+
+static gboolean
+_indicator_service_server_watch (IndicatorService * service, DBusGMethodInvocation * method)
+{
+ g_return_val_if_fail(INDICATOR_IS_SERVICE(service), FALSE);
+ IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(service);
+
+ priv->watchers = g_list_append(priv->watchers,
+ g_strdup(dbus_g_method_get_sender(method)));
+
+ if (priv->timeout != 0) {
+ g_source_remove(priv->timeout);
+ priv->timeout = 0;
+ }
+
+ dbus_g_method_return(method, 1);
+ return TRUE;
+}
+
+/* API */
+
+/**
+ indicator_service_new:
+ @name: The name for the service on dbus
+
+ This function creates the service on DBus and tries to
+ get a well-known name specified in @name. If the name
+ can't be estabilished then the #IndicatorService::shutdown
+ signal will be sent.
+
+ Return value: A brand new #IndicatorService object or #NULL
+ if there is an error.
+*/
+IndicatorService *
+indicator_service_new (gchar * name)
+{
+ GObject * obj = g_object_new(INDICATOR_SERVICE_TYPE,
+ PROP_NAME_S, name,
+ NULL);
+
+ return INDICATOR_SERVICE(obj);
+}
diff --git a/libindicator/indicator-service.h b/libindicator/indicator-service.h
new file mode 100644
index 0000000..b47a91a
--- /dev/null
+++ b/libindicator/indicator-service.h
@@ -0,0 +1,60 @@
+#ifndef __INDICATOR_SERVICE_H__
+#define __INDICATOR_SERVICE_H__
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define INDICATOR_SERVICE_TYPE (indicator_service_get_type ())
+#define INDICATOR_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_SERVICE_TYPE, IndicatorService))
+#define INDICATOR_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_SERVICE_TYPE, IndicatorServiceClass))
+#define INDICATOR_IS_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_SERVICE_TYPE))
+#define INDICATOR_IS_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_SERVICE_TYPE))
+#define INDICATOR_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_SERVICE_TYPE, IndicatorServiceClass))
+
+#define INDICATOR_SERVICE_SIGNAL_SHUTDOWN "shutdown"
+
+typedef struct _IndicatorService IndicatorService;
+typedef struct _IndicatorServiceClass IndicatorServiceClass;
+
+/**
+ IndicatorServiceClass:
+ @parent_class: #GObjectClass
+ @shutdown: Slot for IndicatorServiceClass::shutdown
+ @indicator_service_reserved1: Reserved for future use
+ @indicator_service_reserved2: Reserved for future use
+ @indicator_service_reserved3: Reserved for future use
+ @indicator_service_reserved4: Reserved for future use
+
+*/
+struct _IndicatorServiceClass {
+ GObjectClass parent_class;
+
+ /* Signals */
+ void (*shutdown) (IndicatorService * service, gpointer user_data);
+
+ /* Reserved */
+ void (*indicator_service_reserved1) (void);
+ void (*indicator_service_reserved2) (void);
+ void (*indicator_service_reserved3) (void);
+ void (*indicator_service_reserved4) (void);
+};
+
+/**
+ IndicatorService:
+ @parent: #GObject
+
+*/
+struct _IndicatorService {
+ GObject parent;
+
+};
+
+GType indicator_service_get_type (void);
+
+IndicatorService * indicator_service_new (gchar * name);
+
+G_END_DECLS
+
+#endif
diff --git a/libindicator/indicator-service.xml b/libindicator/indicator-service.xml
new file mode 100644
index 0000000..d876ea8
--- /dev/null
+++ b/libindicator/indicator-service.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<node name="/">
+ <interface name="org.ayatana.indicator.service">
+<!-- Properties -->
+ <!-- None currently -->
+
+<!-- Methods -->
+ <method name="Watch">
+ <annotation name="org.freedesktop.DBus.GLib.Async" value="true" />
+ <arg type="i" name="version" direction="out" />
+ </method>
+
+<!-- Signals -->
+ <!-- None currently -->
+
+ </interface>
+</node>
diff --git a/libindicator/indicator.pc.in b/libindicator/indicator.pc.in
index 2835115..9a8169e 100644
--- a/libindicator/indicator.pc.in
+++ b/libindicator/indicator.pc.in
@@ -9,7 +9,7 @@ iconsdir=@datarootdir@/@PACKAGE@/icons/
Cflags: -I${includedir}/libindicator-0.1
Requires: gtk+-2.0
-Libs:
+Libs: -lindicator
Name: libindicator
Description: libindicator.