From ba8af8211f01a5c470ac30275e907bc5a26be910 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 09:27:05 -0500 Subject: Putting in some templated objects. --- libindicator/indicator-service-manager.c | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 libindicator/indicator-service-manager.c (limited to 'libindicator/indicator-service-manager.c') diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c new file mode 100644 index 0000000..6fd9a5b --- /dev/null +++ b/libindicator/indicator-service-manager.c @@ -0,0 +1,57 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "indicator-service-manager.h" + +typedef struct _IndicatorServiceManagerPrivate IndicatorServiceManagerPrivate; +struct _IndicatorServiceManagerPrivate { + int dummy; +}; + +#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); + +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; + + + return; +} + +static void +indicator_service_manager_init (IndicatorServiceManager *self) +{ + + return; +} + +static void +indicator_service_manager_dispose (GObject *object) +{ + + G_OBJECT_CLASS (indicator_service_manager_parent_class)->dispose (object); + return; +} + +static void +indicator_service_manager_finalize (GObject *object) +{ + + G_OBJECT_CLASS (indicator_service_manager_parent_class)->finalize (object); + return; +} -- cgit v1.2.3 From c099b0332adb448caa987370d95fbbc808f00935 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 17:34:00 -0500 Subject: Adding the API functions. --- libindicator/indicator-service-manager.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'libindicator/indicator-service-manager.c') diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c index 6fd9a5b..cd16cf6 100644 --- a/libindicator/indicator-service-manager.c +++ b/libindicator/indicator-service-manager.c @@ -55,3 +55,28 @@ indicator_service_manager_finalize (GObject *object) G_OBJECT_CLASS (indicator_service_manager_parent_class)->finalize (object); return; } + +/* API */ +IndicatorServiceManager * +indicator_service_manager_new (gchar * dbus_name) +{ + GObject * obj = g_object_new(INDICATOR_SERVICE_MANAGER_TYPE, + "name", 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; +} -- cgit v1.2.3 From 9af4097a1f0df273ca8891e3ef6ec579e5032060 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 20:02:46 -0500 Subject: Signals and properties, oh my! --- libindicator/indicator-service-manager.c | 49 ++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'libindicator/indicator-service-manager.c') diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c index cd16cf6..dbf96b1 100644 --- a/libindicator/indicator-service-manager.c +++ b/libindicator/indicator-service-manager.c @@ -4,11 +4,33 @@ #include "indicator-service-manager.h" +/* Private Stuff */ typedef struct _IndicatorServiceManagerPrivate IndicatorServiceManagerPrivate; struct _IndicatorServiceManagerPrivate { - int dummy; + gchar * name; }; +/* 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)) @@ -29,6 +51,29 @@ indicator_service_manager_class_init (IndicatorServiceManagerClass *klass) object_class->dispose = indicator_service_manager_dispose; object_class->finalize = indicator_service_manager_finalize; + /** + 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; } @@ -61,7 +106,7 @@ IndicatorServiceManager * indicator_service_manager_new (gchar * dbus_name) { GObject * obj = g_object_new(INDICATOR_SERVICE_MANAGER_TYPE, - "name", dbus_name, + PROP_NAME_S, dbus_name, NULL); return INDICATOR_SERVICE_MANAGER(obj); -- cgit v1.2.3 From 12fbcd5566d35303777958048c069d0e8e775b3f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 20:12:44 -0500 Subject: Properties functions. --- libindicator/indicator-service-manager.c | 76 ++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'libindicator/indicator-service-manager.c') diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c index dbf96b1..1b169cd 100644 --- a/libindicator/indicator-service-manager.c +++ b/libindicator/indicator-service-manager.c @@ -39,6 +39,11 @@ 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 @@ -51,6 +56,10 @@ indicator_service_manager_class_init (IndicatorServiceManagerClass *klass) 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 @@ -101,6 +110,73 @@ indicator_service_manager_finalize (GObject *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 +start_service (IndicatorServiceManager * service) +{ + + + return; +} + /* API */ IndicatorServiceManager * indicator_service_manager_new (gchar * dbus_name) -- cgit v1.2.3 From c87569c1ac75b5a97318587df4d913e4841a913c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 20:23:54 -0500 Subject: Ah, forgot to free name --- libindicator/indicator-service-manager.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libindicator/indicator-service-manager.c') diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c index 1b169cd..b15aaa8 100644 --- a/libindicator/indicator-service-manager.c +++ b/libindicator/indicator-service-manager.c @@ -105,6 +105,12 @@ indicator_service_manager_dispose (GObject *object) 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; -- cgit v1.2.3 From 02ce4f5c45f255c4058f1f2c8d5545569b498e64 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 21:28:48 -0500 Subject: Building the dbus proxy and using it a little bit. --- libindicator/indicator-service-manager.c | 62 ++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'libindicator/indicator-service-manager.c') diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c index b15aaa8..011f9c6 100644 --- a/libindicator/indicator-service-manager.c +++ b/libindicator/indicator-service-manager.c @@ -2,12 +2,16 @@ #include "config.h" #endif +#include +#include + #include "indicator-service-manager.h" /* Private Stuff */ typedef struct _IndicatorServiceManagerPrivate IndicatorServiceManagerPrivate; struct _IndicatorServiceManagerPrivate { gchar * name; + DBusGProxy * dbus_proxy; }; /* Signals Stuff */ @@ -90,6 +94,31 @@ indicator_service_manager_class_init (IndicatorServiceManagerClass *klass) 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; + + /* 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; } @@ -97,6 +126,12 @@ indicator_service_manager_init (IndicatorServiceManager *self) static void indicator_service_manager_dispose (GObject *object) { + IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(object); + + if (priv->dbus_proxy != NULL) { + g_object_unref(G_OBJECT(priv->dbus_proxy)); + priv->dbus_proxy = NULL; + } G_OBJECT_CLASS (indicator_service_manager_parent_class)->dispose (object); return; @@ -175,10 +210,37 @@ get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspe 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_error("Unable to start service '%s': %s", priv->name, error->message); + return; + } + + if (status != DBUS_START_REPLY_SUCCESS && status != DBUS_START_REPLY_ALREADY_RUNNING) { + g_error("Status of starting the process '%s' was an error: %d", priv->name, status); + return; + } + + 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; } -- cgit v1.2.3 From a9e61b6f6196c06f79791de768e426b3e6539cec Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 21:58:48 -0500 Subject: A service proxy, and then calling watch. --- libindicator/indicator-service-manager.c | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'libindicator/indicator-service-manager.c') diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c index 011f9c6..321b026 100644 --- a/libindicator/indicator-service-manager.c +++ b/libindicator/indicator-service-manager.c @@ -6,12 +6,15 @@ #include #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; }; /* Signals Stuff */ @@ -99,6 +102,7 @@ indicator_service_manager_init (IndicatorServiceManager *self) /* Get the private variables in a decent state */ priv->name = NULL; priv->dbus_proxy = NULL; + priv->service_proxy = NULL; /* Start talkin' dbus */ GError * error = NULL; @@ -133,6 +137,11 @@ indicator_service_manager_dispose (GObject *object) priv->dbus_proxy = NULL; } + if (priv->service_proxy != NULL) { + g_object_unref(G_OBJECT(priv->service_proxy)); + priv->service_proxy = NULL; + } + G_OBJECT_CLASS (indicator_service_manager_parent_class)->dispose (object); return; } @@ -210,6 +219,20 @@ get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspe return; } +static void +watch_cb (DBusGProxy * proxy, gint version, GError * error, gpointer user_data) +{ + IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(user_data); + + if (error != NULL) { + g_error("Unable to set watch on '%s': '%s'", priv->name, error->message); + g_error_free(error); + return; + } + + return; +} + static void start_service_cb (DBusGProxy * proxy, guint status, GError * error, gpointer user_data) { @@ -225,6 +248,24 @@ start_service_cb (DBusGProxy * proxy, guint status, GError * error, gpointer use 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; } -- cgit v1.2.3 From aa1549d81d1d0eb1f92d4fb5b0339ba4ceab72cd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 30 Oct 2009 15:58:57 -0500 Subject: Adding in the connected property and signalling when we're all hooked up. --- libindicator/indicator-service-manager.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'libindicator/indicator-service-manager.c') diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c index 321b026..2d668ff 100644 --- a/libindicator/indicator-service-manager.c +++ b/libindicator/indicator-service-manager.c @@ -15,6 +15,7 @@ struct _IndicatorServiceManagerPrivate { gchar * name; DBusGProxy * dbus_proxy; DBusGProxy * service_proxy; + gboolean connected; }; /* Signals Stuff */ @@ -103,6 +104,7 @@ indicator_service_manager_init (IndicatorServiceManager *self) priv->name = NULL; priv->dbus_proxy = NULL; priv->service_proxy = NULL; + priv->connected = FALSE; /* Start talkin' dbus */ GError * error = NULL; @@ -132,16 +134,26 @@ 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; } @@ -230,6 +242,16 @@ watch_cb (DBusGProxy * proxy, gint version, GError * error, gpointer user_data) return; } + if (version != INDICATOR_SERVICE_VERSION) { + g_error("Service is using a different version of the service interface. Expecting %d and got %d.", INDICATOR_SERVICE_VERSION, version); + return; + } + + if (!priv->connected) { + priv->connected = TRUE; + g_signal_emit(G_OBJECT(user_data), signals[CONNECTION_CHANGE], 0, TRUE, TRUE); + } + return; } -- cgit v1.2.3 From c99ef2256a94f1ce7c4b54f8c7d5321e29faffa9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 2 Nov 2009 09:35:48 -0600 Subject: Some things are errors that should really be warnings. --- libindicator/indicator-service-manager.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libindicator/indicator-service-manager.c') diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c index 2d668ff..656472d 100644 --- a/libindicator/indicator-service-manager.c +++ b/libindicator/indicator-service-manager.c @@ -237,13 +237,13 @@ watch_cb (DBusGProxy * proxy, gint version, GError * error, gpointer user_data) IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(user_data); if (error != NULL) { - g_error("Unable to set watch on '%s': '%s'", priv->name, error->message); + g_warning("Unable to set watch on '%s': '%s'", priv->name, error->message); g_error_free(error); return; } if (version != INDICATOR_SERVICE_VERSION) { - g_error("Service is using a different version of the service interface. Expecting %d and got %d.", INDICATOR_SERVICE_VERSION, version); + g_warning("Service is using a different version of the service interface. Expecting %d and got %d.", INDICATOR_SERVICE_VERSION, version); return; } @@ -261,12 +261,12 @@ start_service_cb (DBusGProxy * proxy, guint status, GError * error, gpointer use IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(user_data); if (error != NULL) { - g_error("Unable to start service '%s': %s", priv->name, error->message); + 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_error("Status of starting the process '%s' was an error: %d", priv->name, status); + g_warning("Status of starting the process '%s' was an error: %d", priv->name, status); return; } -- cgit v1.2.3 From cfa83c08d769ba10eb90718e3c856b18e49c691b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 3 Nov 2009 22:40:05 -0600 Subject: Changing version to service_version --- libindicator/indicator-service-manager.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libindicator/indicator-service-manager.c') diff --git a/libindicator/indicator-service-manager.c b/libindicator/indicator-service-manager.c index 656472d..4eaed23 100644 --- a/libindicator/indicator-service-manager.c +++ b/libindicator/indicator-service-manager.c @@ -232,7 +232,7 @@ get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspe } static void -watch_cb (DBusGProxy * proxy, gint version, GError * error, gpointer user_data) +watch_cb (DBusGProxy * proxy, gint service_version, GError * error, gpointer user_data) { IndicatorServiceManagerPrivate * priv = INDICATOR_SERVICE_MANAGER_GET_PRIVATE(user_data); @@ -242,8 +242,8 @@ watch_cb (DBusGProxy * proxy, gint version, GError * error, gpointer user_data) return; } - if (version != INDICATOR_SERVICE_VERSION) { - g_warning("Service is using a different version of the service interface. Expecting %d and got %d.", INDICATOR_SERVICE_VERSION, version); + 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; } -- cgit v1.2.3