From 1f822bf64b8891dab03937060dd47b8003bb8ab5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 6 Oct 2009 15:28:41 -0400 Subject: Building a base object. --- .bzrignore | 1 + libindicator/Makefile.am | 10 +++++++- libindicator/indicator-object.c | 55 +++++++++++++++++++++++++++++++++++++++++ libindicator/indicator-object.h | 33 +++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 libindicator/indicator-object.c create mode 100644 libindicator/indicator-object.h diff --git a/.bzrignore b/.bzrignore index b8537d5..ae13edd 100644 --- a/.bzrignore +++ b/.bzrignore @@ -103,3 +103,4 @@ src-sus/indicator-applet-sus data/GNOME_IndicatorAppletSUS.server data/GNOME_IndicatorAppletSUS.server.in src-sus/indicator-applet-no-sus +libindicator/libindicator.la diff --git a/libindicator/Makefile.am b/libindicator/Makefile.am index be68721..29b7bb5 100644 --- a/libindicator/Makefile.am +++ b/libindicator/Makefile.am @@ -4,11 +4,19 @@ EXTRA_DIST = \ libindicatorincludedir=$(includedir)/libindicator-0.1/libindicator indicator_headers = \ - indicator.h + indicator.h \ + indicator-object.h libindicatorinclude_HEADERS = \ $(indicator_headers) +lib_LTLIBRARIES = \ + libindicator.la + +libindicator_la_SOURCES = \ + $(indicator_headers) \ + indicator-object.c + pkgconfig_DATA = indicator.pc pkgconfigdir = $(libdir)/pkgconfig diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c new file mode 100644 index 0000000..772110b --- /dev/null +++ b/libindicator/indicator-object.c @@ -0,0 +1,55 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "indicator-object.h" + +typedef struct _IndicatorObjectPrivate IndicatorObjectPrivate; +struct _IndicatorObjectPrivate { +}; + +#define INDICATOR_OBJECT_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_OBJECT_TYPE, IndicatorObjectPrivate)) + +static void indicator_object_class_init (IndicatorObjectClass *klass); +static void indicator_object_init (IndicatorObject *self); +static void indicator_object_dispose (GObject *object); +static void indicator_object_finalize (GObject *object); + +G_DEFINE_TYPE (IndicatorObject, indicator_object, G_TYPE_OBJECT); + +static void +indicator_object_class_init (IndicatorObjectClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (IndicatorObjectPrivate)); + + object_class->dispose = indicator_object_dispose; + object_class->finalize = indicator_object_finalize; + + return; +} + +static void +indicator_object_init (IndicatorObject *self) +{ + + return; +} + +static void +indicator_object_dispose (GObject *object) +{ + + G_OBJECT_CLASS (indicator_object_parent_class)->dispose (object); + return; +} + +static void +indicator_object_finalize (GObject *object) +{ + + G_OBJECT_CLASS (indicator_object_parent_class)->finalize (object); + return; +} diff --git a/libindicator/indicator-object.h b/libindicator/indicator-object.h new file mode 100644 index 0000000..9c6c103 --- /dev/null +++ b/libindicator/indicator-object.h @@ -0,0 +1,33 @@ +#ifndef __INDICATOR_OBJECT_H__ +#define __INDICATOR_OBJECT_H__ + +#include +#include + +G_BEGIN_DECLS + +#define INDICATOR_OBJECT_TYPE (indicator_object_get_type ()) +#define INDICATOR_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_OBJECT_TYPE, IndicatorObject)) +#define INDICATOR_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_OBJECT_TYPE, IndicatorObjectClass)) +#define IS_INDICATOR_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_OBJECT_TYPE)) +#define IS_INDICATOR_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_OBJECT_TYPE)) +#define INDICATOR_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_OBJECT_TYPE, IndicatorObjectClass)) + +typedef struct _IndicatorObject IndicatorObject; +typedef struct _IndicatorObjectClass IndicatorObjectClass; + +struct _IndicatorObjectClass { + GObjectClass parent_class; + +}; + +struct _IndicatorObject { + GObject parent; + +}; + +GType indicator_object_get_type (void); + +G_END_DECLS + +#endif -- cgit v1.2.3 From 24d025363c4a708c61acee26456a42a0b9a4b609 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 6 Oct 2009 16:32:23 -0400 Subject: Adding some pkg-config love to get things compiling all nice like. --- configure.ac | 13 +++++++++++++ libindicator/Makefile.am | 7 +++++++ 2 files changed, 20 insertions(+) diff --git a/configure.ac b/configure.ac index 70ef98b..fc7fcab 100644 --- a/configure.ac +++ b/configure.ac @@ -20,6 +20,19 @@ AC_CONFIG_MACRO_DIR([m4]) m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) +############################## +# Dependencies +############################## + +GLIB_REQUIRED_VERSION=2.18 +DBUS_REQUIRED_VERSION=0.76 + +PKG_CHECK_MODULES(LIBINDICATOR, glib-2.0 >= $GLIB_REQUIRED_VERSION + dbus-glib-1 >= $DBUS_REQUIRED_VERSION) + +AC_SUBST(LIBINDICATOR_CFLAGS) +AC_SUBST(LIBINDICATOR_LIBS) + ############################## # Custom Junk ############################## diff --git a/libindicator/Makefile.am b/libindicator/Makefile.am index 29b7bb5..db45f3c 100644 --- a/libindicator/Makefile.am +++ b/libindicator/Makefile.am @@ -17,6 +17,13 @@ libindicator_la_SOURCES = \ $(indicator_headers) \ indicator-object.c +libindicator_la_CFLAGS = \ + $(LIBINDICATOR_CFLAGS) \ + -Wall -Werror + +libindicator_la_LIBADD = \ + $(LIBINDICATOR_LIBS) + pkgconfig_DATA = indicator.pc pkgconfigdir = $(libdir)/pkgconfig -- cgit v1.2.3 From 1ca966660489e088fe0e3fd7154ee54997209cff Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 12:05:36 -0400 Subject: Ignoring our new file. --- .bzrignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.bzrignore b/.bzrignore index ae13edd..0faee7c 100644 --- a/.bzrignore +++ b/.bzrignore @@ -104,3 +104,5 @@ data/GNOME_IndicatorAppletSUS.server data/GNOME_IndicatorAppletSUS.server.in src-sus/indicator-applet-no-sus libindicator/libindicator.la +libindicator/libindicator_la-indicator-object. +libindicator/libindicator_la-indicator-object.lo -- cgit v1.2.3 From fa946df247f0e16de3a355dd5696f4671277348a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 12:18:23 -0400 Subject: Adding in a tests folder --- Makefile.am | 3 ++- configure.ac | 1 + tests/Makefile.am | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tests/Makefile.am diff --git a/Makefile.am b/Makefile.am index ae85ded..f0211b0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,7 @@ SUBDIRS = \ - libindicator + libindicator \ + tests DISTCLEANFILES = \ libindicator-*.tar.gz diff --git a/configure.ac b/configure.ac index fc7fcab..db437a6 100644 --- a/configure.ac +++ b/configure.ac @@ -86,6 +86,7 @@ AC_OUTPUT([ Makefile libindicator/Makefile libindicator/indicator.pc +tests/Makefile ]) ########################### diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..8ac6544 --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1 @@ +#Something should go here -- cgit v1.2.3 From c314d6040b93da70359e19a8b7475c94fc86fb1c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 12:29:12 -0400 Subject: Adding in a simple little test. --- .bzrignore | 3 +++ tests/Makefile.am | 25 ++++++++++++++++++++++++- tests/test-loader.c | 7 +++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/test-loader.c diff --git a/.bzrignore b/.bzrignore index 0faee7c..a947a1a 100644 --- a/.bzrignore +++ b/.bzrignore @@ -106,3 +106,6 @@ src-sus/indicator-applet-no-sus libindicator/libindicator.la libindicator/libindicator_la-indicator-object. libindicator/libindicator_la-indicator-object.lo +tests/loader-check-results.xml +tests/loader-check-results.html +tests/test-loader diff --git a/tests/Makefile.am b/tests/Makefile.am index 8ac6544..a04855c 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1 +1,24 @@ -#Something should go here + +noinst_PROGRAMS = \ + test-loader + +test_loader_SOURCES = \ + test-loader.c + +test_loader_CFLAGS = \ + -Wall -Werror \ + $(UPANEL_CFLAGS) -I$(top_srcdir) + +test_loader_LDADD = \ + $(UPANEL_LIBS) $(top_builddir)/libindicator/.libs/libindicator.a + +XML_REPORT = loader-check-results.xml +HTML_REPORT = loader-check-results.html + +loader-tester: test-loader + @gtester -o=$(XML_REPORT) ./test-loader + +check-local: loader-tester + +DISTCLEANFILES = $(XML_REPORT) $(HTML_REPORT) + diff --git a/tests/test-loader.c b/tests/test-loader.c new file mode 100644 index 0000000..63590c7 --- /dev/null +++ b/tests/test-loader.c @@ -0,0 +1,7 @@ + +int +main (int argc, char ** argv) +{ + + return 0; +} -- cgit v1.2.3 From 1386478a87fd0f228dd31a00d8f3d969d6a6a98c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 13:00:00 -0400 Subject: Fleshing out the test a little bit. --- tests/Makefile.am | 6 +++--- tests/test-loader.c | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index a04855c..2779ad7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,5 @@ -noinst_PROGRAMS = \ +check_PROGRAMS = \ test-loader test_loader_SOURCES = \ @@ -7,10 +7,10 @@ test_loader_SOURCES = \ test_loader_CFLAGS = \ -Wall -Werror \ - $(UPANEL_CFLAGS) -I$(top_srcdir) + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) test_loader_LDADD = \ - $(UPANEL_LIBS) $(top_builddir)/libindicator/.libs/libindicator.a + $(LIBINDICATOR_LIBS) $(top_builddir)/libindicator/.libs/libindicator.a XML_REPORT = loader-check-results.xml HTML_REPORT = loader-check-results.html diff --git a/tests/test-loader.c b/tests/test-loader.c index 63590c7..7e77195 100644 --- a/tests/test-loader.c +++ b/tests/test-loader.c @@ -1,7 +1,29 @@ +#include +#include "libindicator/indicator-object.h" + +void +test_loader_refunref (void) +{ + + return; +} + +void +test_loader_creation_deletion_suite (void) +{ + g_test_add_func ("/libindicator/loader/ref_and_unref", test_loader_refunref); + + return; +} + int main (int argc, char ** argv) { + g_type_init (); + g_test_init (&argc, &argv, NULL); + + test_loader_creation_deletion_suite(); - return 0; + return g_test_run(); } -- cgit v1.2.3 From 4658844f6c1d0e4352ee7baf0e7fcf56bde01d10 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 16:29:36 -0400 Subject: Test to build the object and unref it. --- tests/test-loader.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test-loader.c b/tests/test-loader.c index 7e77195..68bfe48 100644 --- a/tests/test-loader.c +++ b/tests/test-loader.c @@ -1,9 +1,25 @@ #include #include "libindicator/indicator-object.h" +void +destroy_cb (gpointer data) +{ + gboolean * bob = (gboolean *)data; + *bob = TRUE; + return; +} + void test_loader_refunref (void) { + GObject * object = g_object_new(INDICATOR_OBJECT_TYPE, NULL); + + gboolean unreffed = FALSE; + g_signal_connect(object, "destroy", G_CALLBACK(destroy_cb), &unreffed); + + g_object_unref(object); + + g_assert(unreffed == TRUE); return; } -- cgit v1.2.3 From 3bf9efb38a2bd564bede8e542d5adc267056ec0a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 16:32:19 -0400 Subject: Putting data in the private --- libindicator/indicator-object.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 772110b..bb154fc 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -6,6 +6,7 @@ typedef struct _IndicatorObjectPrivate IndicatorObjectPrivate; struct _IndicatorObjectPrivate { + guint data; }; #define INDICATOR_OBJECT_GET_PRIVATE(o) \ -- cgit v1.2.3 From 26ced5cdf75d022c4b40cc3ef8658bf486a0dba1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 16:34:13 -0400 Subject: Using a weak ref instead of connecting to a signal that doesn't exist --- tests/test-loader.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test-loader.c b/tests/test-loader.c index 68bfe48..f754685 100644 --- a/tests/test-loader.c +++ b/tests/test-loader.c @@ -2,7 +2,7 @@ #include "libindicator/indicator-object.h" void -destroy_cb (gpointer data) +destroy_cb (gpointer data, GObject * object) { gboolean * bob = (gboolean *)data; *bob = TRUE; @@ -15,7 +15,7 @@ test_loader_refunref (void) GObject * object = g_object_new(INDICATOR_OBJECT_TYPE, NULL); gboolean unreffed = FALSE; - g_signal_connect(object, "destroy", G_CALLBACK(destroy_cb), &unreffed); + g_object_weak_ref(object, destroy_cb, &unreffed); g_object_unref(object); -- cgit v1.2.3 From 605f74bd18652f40b619771e60978d6abd23c65f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 17:02:06 -0400 Subject: Switch from GLib to GTK as that's what we really needed. --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index db437a6..51706ef 100644 --- a/configure.ac +++ b/configure.ac @@ -24,10 +24,10 @@ m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) # Dependencies ############################## -GLIB_REQUIRED_VERSION=2.18 +GTK_REQUIRED_VERSION=2.18 DBUS_REQUIRED_VERSION=0.76 -PKG_CHECK_MODULES(LIBINDICATOR, glib-2.0 >= $GLIB_REQUIRED_VERSION +PKG_CHECK_MODULES(LIBINDICATOR, gtk+-2.0 >= $GTK_REQUIRED_VERSION dbus-glib-1 >= $DBUS_REQUIRED_VERSION) AC_SUBST(LIBINDICATOR_CFLAGS) -- cgit v1.2.3 From c594126850cb7b59294069f2711fa0a5d96febbb Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 17:03:20 -0400 Subject: Creating a dummy indicator that returns null --- .bzrignore | 2 ++ tests/Makefile.am | 31 ++++++++++++++++++++++++++++++- tests/dummy-indicator-null.c | 23 +++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 tests/dummy-indicator-null.c diff --git a/.bzrignore b/.bzrignore index a947a1a..24efd20 100644 --- a/.bzrignore +++ b/.bzrignore @@ -109,3 +109,5 @@ libindicator/libindicator_la-indicator-object.lo tests/loader-check-results.xml tests/loader-check-results.html tests/test-loader +tests/libdummy-indicator-null.la +tests/libdummy_indicator_null_la-dummy-indicator-null.lo diff --git a/tests/Makefile.am b/tests/Makefile.am index 2779ad7..ad5e5c6 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,6 +2,13 @@ check_PROGRAMS = \ test-loader +check_LTLIBRARIES = \ + libdummy-indicator-null.la + +############################# +# Test Loader +############################# + test_loader_SOURCES = \ test-loader.c @@ -12,10 +19,32 @@ test_loader_CFLAGS = \ test_loader_LDADD = \ $(LIBINDICATOR_LIBS) $(top_builddir)/libindicator/.libs/libindicator.a +############################# +# Dummy Indicator +############################# + +libdummy_indicator_null_la_SOURCES = \ + dummy-indicator-null.c + +libdummy_indicator_null_la_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + +libdummy_indicator_null_la_LIBADD = \ + $(LIBINDICATOR_LIBS) + +libdummy_indicator_null_la_LDFLAGS = \ + -module \ + -avoid-version + +############################# +# Test stuff +############################# + XML_REPORT = loader-check-results.xml HTML_REPORT = loader-check-results.html -loader-tester: test-loader +loader-tester: test-loader libdummy-indicator-null.la @gtester -o=$(XML_REPORT) ./test-loader check-local: loader-tester diff --git a/tests/dummy-indicator-null.c b/tests/dummy-indicator-null.c new file mode 100644 index 0000000..ff99d71 --- /dev/null +++ b/tests/dummy-indicator-null.c @@ -0,0 +1,23 @@ + +#include "libindicator/indicator.h" + +INDICATOR_SET_VERSION +INDICATOR_SET_NAME("dummy-indicator-null") + +GtkLabel * +get_label (void) +{ + return NULL; +} + +GtkImage * +get_icon (void) +{ + return NULL; +} + +GtkMenu * +get_menu (void) +{ + return NULL; +} -- cgit v1.2.3 From b4d20eb0049cc36dbdd03754f820bd46df6e60ec Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 17:09:21 -0400 Subject: Adding a function to create an object from a file --- libindicator/indicator-object.c | 6 ++++++ libindicator/indicator-object.h | 1 + 2 files changed, 7 insertions(+) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index bb154fc..00ede90 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -54,3 +54,9 @@ indicator_object_finalize (GObject *object) G_OBJECT_CLASS (indicator_object_parent_class)->finalize (object); return; } + +IndicatorObject * +indicator_object_new_from_file (const gchar * file) +{ + return NULL; +} diff --git a/libindicator/indicator-object.h b/libindicator/indicator-object.h index 9c6c103..fd7f470 100644 --- a/libindicator/indicator-object.h +++ b/libindicator/indicator-object.h @@ -27,6 +27,7 @@ struct _IndicatorObject { }; GType indicator_object_get_type (void); +IndicatorObject * indicator_object_new_from_file (const gchar * file); G_END_DECLS -- cgit v1.2.3 From d946049ea36d1c6a0946750655eac070566f4974 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 17:11:47 -0400 Subject: Adding a test that should pass as given a bad filename we should get no object back. --- tests/test-loader.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test-loader.c b/tests/test-loader.c index f754685..85cb924 100644 --- a/tests/test-loader.c +++ b/tests/test-loader.c @@ -1,6 +1,14 @@ #include #include "libindicator/indicator-object.h" +void +test_loader_filename_bad (void) +{ + IndicatorObject * object = indicator_object_new_from_file("/this/file/should/not/exist.so"); + g_assert(object == NULL); + return; +} + void destroy_cb (gpointer data, GObject * object) { @@ -28,6 +36,7 @@ void test_loader_creation_deletion_suite (void) { g_test_add_func ("/libindicator/loader/ref_and_unref", test_loader_refunref); + g_test_add_func ("/libindicator/loader/filename_bad", test_loader_filename_bad); return; } -- cgit v1.2.3 From 1b828c9f669ce1364618387d13fc8a134244e2ba Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 17:53:01 -0400 Subject: Apparently they have to be installable to get the .so. Fail. --- tests/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index ad5e5c6..52cc224 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,7 +2,7 @@ check_PROGRAMS = \ test-loader -check_LTLIBRARIES = \ +lib_LTLIBRARIES = \ libdummy-indicator-null.la ############################# -- cgit v1.2.3 From bce9f5143bfbe49972aebe3fa3e0a4566e2502b7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 17:57:14 -0400 Subject: A test to load the dummy indicator --- tests/test-loader.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/test-loader.c b/tests/test-loader.c index 85cb924..3e94981 100644 --- a/tests/test-loader.c +++ b/tests/test-loader.c @@ -1,6 +1,23 @@ #include #include "libindicator/indicator-object.h" +void destroy_cb (gpointer data, GObject * object); + +void +test_loader_filename_dummy_null (void) +{ + IndicatorObject * object = indicator_object_new_from_file("./.libs/libdummy-indicator-null.so"); + g_assert(object != NULL); + + gboolean unreffed = FALSE; + g_object_weak_ref(G_OBJECT(object), destroy_cb, &unreffed); + + g_object_unref(object); + g_assert(unreffed == TRUE); + + return; +} + void test_loader_filename_bad (void) { @@ -37,6 +54,7 @@ test_loader_creation_deletion_suite (void) { g_test_add_func ("/libindicator/loader/ref_and_unref", test_loader_refunref); g_test_add_func ("/libindicator/loader/filename_bad", test_loader_filename_bad); + g_test_add_func ("/libindicator/loader/dummy/null_load", test_loader_filename_dummy_null); return; } -- cgit v1.2.3 From f4b307cda5b10c41dd733d6189fd5a1ce7fe3111 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 18:36:06 -0400 Subject: Fleshing out the load from file function. Still fails. --- libindicator/indicator-object.c | 68 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 00ede90..afeaf19 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -1,12 +1,16 @@ + #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include "indicator.h" #include "indicator-object.h" typedef struct _IndicatorObjectPrivate IndicatorObjectPrivate; struct _IndicatorObjectPrivate { - guint data; + GtkLabel * label; + GtkImage * icon; + GtkMenu * menu; }; #define INDICATOR_OBJECT_GET_PRIVATE(o) \ @@ -35,6 +39,11 @@ indicator_object_class_init (IndicatorObjectClass *klass) static void indicator_object_init (IndicatorObject *self) { + IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(self); + + priv->label = NULL; + priv->icon = NULL; + priv->menu = NULL; return; } @@ -42,6 +51,22 @@ indicator_object_init (IndicatorObject *self) static void indicator_object_dispose (GObject *object) { + IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(object); + + if (priv->label != NULL) { + g_object_unref(priv->label); + priv->label = NULL; + } + + if (priv->icon != NULL) { + g_object_unref(priv->icon); + priv->icon = NULL; + } + + if (priv->menu != NULL) { + g_object_unref(priv->menu); + priv->menu = NULL; + } G_OBJECT_CLASS (indicator_object_parent_class)->dispose (object); return; @@ -58,5 +83,44 @@ indicator_object_finalize (GObject *object) IndicatorObject * indicator_object_new_from_file (const gchar * file) { - return NULL; + g_return_val_if_fail(file != NULL, NULL); + + GModule * module = g_module_open(file, + G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); + g_return_val_if_fail(module != NULL, NULL); + + get_version_t lget_version = NULL; + g_return_val_if_fail(g_module_symbol(module, INDICATOR_GET_VERSION_S, (gpointer *)(&lget_version)), FALSE); + if (!INDICATOR_VERSION_CHECK(lget_version())) { + g_warning("Indicator using API version '%s' we're expecting '%s'", lget_version(), INDICATOR_VERSION); + return NULL; + } + + GObject * object = g_object_new(INDICATOR_OBJECT_TYPE, NULL); + IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(object); + + get_label_t lget_label = NULL; + g_return_val_if_fail(g_module_symbol(module, INDICATOR_GET_LABEL_S, (gpointer *)(&lget_label)), FALSE); + g_return_val_if_fail(lget_label != NULL, FALSE); + priv->label = lget_label(); + + get_icon_t lget_icon = NULL; + g_return_val_if_fail(g_module_symbol(module, INDICATOR_GET_ICON_S, (gpointer *)(&lget_icon)), FALSE); + g_return_val_if_fail(lget_icon != NULL, FALSE); + priv->icon = lget_icon(); + + get_menu_t lget_menu = NULL; + g_return_val_if_fail(g_module_symbol(module, INDICATOR_GET_MENU_S, (gpointer *)(&lget_menu)), FALSE); + g_return_val_if_fail(lget_menu != NULL, FALSE); + priv->menu = lget_menu(); + + if (priv->label == NULL && priv->icon == NULL) { + /* This is the case where there is nothing to display, + kinda odd that we'd have a module with nothing. */ + g_warning("No label or icon. Odd."); + g_object_unref(object); + return NULL; + } + + return INDICATOR_OBJECT(object); } -- cgit v1.2.3 From bece9de31705d57c83822ce3ece6dd24f92b9283 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 18:43:10 -0400 Subject: Making it so that we're not using g_return_if_fail as it messes up the test suite. --- libindicator/indicator-object.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index afeaf19..06ca48f 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -83,14 +83,20 @@ indicator_object_finalize (GObject *object) IndicatorObject * indicator_object_new_from_file (const gchar * file) { - g_return_val_if_fail(file != NULL, NULL); + if (file != NULL) + return NULL; GModule * module = g_module_open(file, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); - g_return_val_if_fail(module != NULL, NULL); + if(module != NULL) { + g_warning("Unable to load module: %s", file); + return NULL; + } get_version_t lget_version = NULL; - g_return_val_if_fail(g_module_symbol(module, INDICATOR_GET_VERSION_S, (gpointer *)(&lget_version)), FALSE); + if (!g_module_symbol(module, INDICATOR_GET_VERSION_S, (gpointer *)(&lget_version))) + return NULL; + if (!INDICATOR_VERSION_CHECK(lget_version())) { g_warning("Indicator using API version '%s' we're expecting '%s'", lget_version(), INDICATOR_VERSION); return NULL; -- cgit v1.2.3 From 376658695b00a0d272b9463722a9d7914a7d7ffc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 18:48:59 -0400 Subject: Build dir fix and making gtester run all of them even if one fails. --- tests/Makefile.am | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 52cc224..2048a9a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -14,7 +14,8 @@ test_loader_SOURCES = \ test_loader_CFLAGS = \ -Wall -Werror \ - $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) \ + -DBUILD_DIR="\"$(builddir)\"" test_loader_LDADD = \ $(LIBINDICATOR_LIBS) $(top_builddir)/libindicator/.libs/libindicator.a @@ -45,7 +46,7 @@ XML_REPORT = loader-check-results.xml HTML_REPORT = loader-check-results.html loader-tester: test-loader libdummy-indicator-null.la - @gtester -o=$(XML_REPORT) ./test-loader + @gtester -k -o=$(XML_REPORT) ./test-loader check-local: loader-tester -- cgit v1.2.3 From 3bafca747c5c9a1508bc93fdcf9efa77af99710b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 18:49:08 -0400 Subject: Use the new build dir flag --- tests/test-loader.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test-loader.c b/tests/test-loader.c index 3e94981..16c0292 100644 --- a/tests/test-loader.c +++ b/tests/test-loader.c @@ -6,7 +6,7 @@ void destroy_cb (gpointer data, GObject * object); void test_loader_filename_dummy_null (void) { - IndicatorObject * object = indicator_object_new_from_file("./.libs/libdummy-indicator-null.so"); + IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-null.so"); g_assert(object != NULL); gboolean unreffed = FALSE; -- cgit v1.2.3 From a65694f2fc7c4c3aa4b955f101617278e4f1c9b4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 19:04:51 -0400 Subject: Turning all the return if fails into proper if's with warning and unref the object so there aren't any memory leaks. --- libindicator/indicator-object.c | 48 ++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 06ca48f..d7f18d3 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -83,8 +83,10 @@ indicator_object_finalize (GObject *object) IndicatorObject * indicator_object_new_from_file (const gchar * file) { - if (file != NULL) + if (file != NULL) { + g_warning("Invalid filename."); return NULL; + } GModule * module = g_module_open(file, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); @@ -94,8 +96,10 @@ indicator_object_new_from_file (const gchar * file) } get_version_t lget_version = NULL; - if (!g_module_symbol(module, INDICATOR_GET_VERSION_S, (gpointer *)(&lget_version))) + if (!g_module_symbol(module, INDICATOR_GET_VERSION_S, (gpointer *)(&lget_version))) { + g_warning("Unable to get the symbol for getting the version."); return NULL; + } if (!INDICATOR_VERSION_CHECK(lget_version())) { g_warning("Indicator using API version '%s' we're expecting '%s'", lget_version(), INDICATOR_VERSION); @@ -105,19 +109,43 @@ indicator_object_new_from_file (const gchar * file) GObject * object = g_object_new(INDICATOR_OBJECT_TYPE, NULL); IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(object); + /* The function for grabbing a label from the module + execute it, and make sure everything is a-okay */ get_label_t lget_label = NULL; - g_return_val_if_fail(g_module_symbol(module, INDICATOR_GET_LABEL_S, (gpointer *)(&lget_label)), FALSE); - g_return_val_if_fail(lget_label != NULL, FALSE); + if (!g_module_symbol(module, INDICATOR_GET_LABEL_S, (gpointer *)(&lget_label))) { + g_warning("Unable to get '" INDICATOR_GET_LABEL_S "' symbol from module: %s", file); + goto unrefandout; + } + if (lget_label == NULL) { + g_warning("Symbol '" INDICATOR_GET_LABEL_S "' is (null) in module: %s", file); + goto unrefandout; + } priv->label = lget_label(); + /* The function for grabbing an icon from the module + execute it, and make sure everything is a-okay */ get_icon_t lget_icon = NULL; - g_return_val_if_fail(g_module_symbol(module, INDICATOR_GET_ICON_S, (gpointer *)(&lget_icon)), FALSE); - g_return_val_if_fail(lget_icon != NULL, FALSE); + if (!g_module_symbol(module, INDICATOR_GET_ICON_S, (gpointer *)(&lget_icon))) { + g_warning("Unable to get '" INDICATOR_GET_ICON_S "' symbol from module: %s", file); + goto unrefandout; + } + if (lget_icon == NULL) { + g_warning("Symbol '" INDICATOR_GET_ICON_S "' is (null) in module: %s", file); + goto unrefandout; + } priv->icon = lget_icon(); + /* The function for grabbing a menu from the module + execute it, and make sure everything is a-okay */ get_menu_t lget_menu = NULL; - g_return_val_if_fail(g_module_symbol(module, INDICATOR_GET_MENU_S, (gpointer *)(&lget_menu)), FALSE); - g_return_val_if_fail(lget_menu != NULL, FALSE); + if (!g_module_symbol(module, INDICATOR_GET_MENU_S, (gpointer *)(&lget_menu))) { + g_warning("Unable to get '" INDICATOR_GET_MENU_S "' symbol from module: %s", file); + goto unrefandout; + } + if (lget_menu == NULL) { + g_warning("Symbol '" INDICATOR_GET_MENU_S "' is (null) in module: %s", file); + goto unrefandout; + } priv->menu = lget_menu(); if (priv->label == NULL && priv->icon == NULL) { @@ -129,4 +157,8 @@ indicator_object_new_from_file (const gchar * file) } return INDICATOR_OBJECT(object); + +unrefandout: + g_object_unref(object); + return NULL; } -- cgit v1.2.3 From 18f63963ad625504956f753677927bda0e83d0dc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 19:07:03 -0400 Subject: Truth. Sucks. --- libindicator/indicator-object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index d7f18d3..7188a07 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -83,7 +83,7 @@ indicator_object_finalize (GObject *object) IndicatorObject * indicator_object_new_from_file (const gchar * file) { - if (file != NULL) { + if (file == NULL) { g_warning("Invalid filename."); return NULL; } -- cgit v1.2.3 From b2942d9cc8631275fe8abdc53bd518b5b9f9ffcc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 19:12:47 -0400 Subject: Checking to see if a file exists before trying to load it. --- libindicator/indicator-object.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 7188a07..9fc439e 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -88,6 +88,11 @@ indicator_object_new_from_file (const gchar * file) return NULL; } + if (!g_file_test(file, G_FILE_TEST_EXISTS)) { + g_warning("File '%s' does not exist.", file); + return NULL; + } + GModule * module = g_module_open(file, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); if(module != NULL) { -- cgit v1.2.3 From 4ea28685563e8f7267ca75c28541582b4f3e544b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 19:17:15 -0400 Subject: Truth again. Keeps bitting back. I shouldn't of lied in the 2nd grade, I confess! No more, please. --- libindicator/indicator-object.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 9fc439e..a70a3ec 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -95,7 +95,7 @@ indicator_object_new_from_file (const gchar * file) GModule * module = g_module_open(file, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); - if(module != NULL) { + if(module == NULL) { g_warning("Unable to load module: %s", file); return NULL; } -- cgit v1.2.3 From 66b0d1beb9907963f35dd36ccf3e193eb641f694 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 19:48:44 -0400 Subject: Making it so that we use the same unref code as everyone else. --- libindicator/indicator-object.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index a70a3ec..6a638ec 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -157,8 +157,7 @@ indicator_object_new_from_file (const gchar * file) /* This is the case where there is nothing to display, kinda odd that we'd have a module with nothing. */ g_warning("No label or icon. Odd."); - g_object_unref(object); - return NULL; + goto unrefandout; } return INDICATOR_OBJECT(object); -- cgit v1.2.3 From 56450cfd530c876adc4ad33b1a5ab53a6a6078fa Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 19:49:23 -0400 Subject: Making it so that the null test checks for failure as we shoudln't have a null image and label. Also making it so that warnings don't cause the test to fail. --- tests/test-loader.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/test-loader.c b/tests/test-loader.c index 16c0292..3dcc595 100644 --- a/tests/test-loader.c +++ b/tests/test-loader.c @@ -4,9 +4,9 @@ void destroy_cb (gpointer data, GObject * object); void -test_loader_filename_dummy_null (void) +test_loader_filename_dummy_simple (void) { - IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-null.so"); + IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-simple.so"); g_assert(object != NULL); gboolean unreffed = FALSE; @@ -18,6 +18,14 @@ test_loader_filename_dummy_null (void) return; } +void +test_loader_filename_dummy_null (void) +{ + IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-null.so"); + g_assert(object == NULL); + return; +} + void test_loader_filename_bad (void) { @@ -68,5 +76,7 @@ main (int argc, char ** argv) test_loader_creation_deletion_suite(); + g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); + return g_test_run(); } -- cgit v1.2.3 From a28e917b914b07de67027c97eb29d533e3fe9393 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 19:50:40 -0400 Subject: Being a bit more verbose --- tests/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 2048a9a..461bb51 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -46,7 +46,7 @@ XML_REPORT = loader-check-results.xml HTML_REPORT = loader-check-results.html loader-tester: test-loader libdummy-indicator-null.la - @gtester -k -o=$(XML_REPORT) ./test-loader + @gtester -k --verbose -o=$(XML_REPORT) ./test-loader check-local: loader-tester -- cgit v1.2.3 From 97a4004d26cd5ebec0b25b51d4793d1df51b5dba Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 20:12:48 -0400 Subject: Create a very simple indicator and testing it. --- .bzrignore | 2 ++ tests/Makefile.am | 25 ++++++++++++++++++++++--- tests/dummy-indicator-simple.c | 23 +++++++++++++++++++++++ tests/test-loader.c | 1 + 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 tests/dummy-indicator-simple.c diff --git a/.bzrignore b/.bzrignore index 24efd20..6a346c8 100644 --- a/.bzrignore +++ b/.bzrignore @@ -111,3 +111,5 @@ tests/loader-check-results.html tests/test-loader tests/libdummy-indicator-null.la tests/libdummy_indicator_null_la-dummy-indicator-null.lo +tests/libdummy-indicator-simple.la +tests/libdummy_indicator_simple_la-dummy-indicator-simple.lo diff --git a/tests/Makefile.am b/tests/Makefile.am index 461bb51..c21ff09 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,7 +3,8 @@ check_PROGRAMS = \ test-loader lib_LTLIBRARIES = \ - libdummy-indicator-null.la + libdummy-indicator-null.la \ + libdummy-indicator-simple.la ############################# # Test Loader @@ -21,7 +22,7 @@ test_loader_LDADD = \ $(LIBINDICATOR_LIBS) $(top_builddir)/libindicator/.libs/libindicator.a ############################# -# Dummy Indicator +# Dummy Indicator NULL ############################# libdummy_indicator_null_la_SOURCES = \ @@ -38,6 +39,24 @@ libdummy_indicator_null_la_LDFLAGS = \ -module \ -avoid-version +############################# +# Dummy Indicator Simple +############################# + +libdummy_indicator_simple_la_SOURCES = \ + dummy-indicator-simple.c + +libdummy_indicator_simple_la_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + +libdummy_indicator_simple_la_LIBADD = \ + $(LIBINDICATOR_LIBS) + +libdummy_indicator_simple_la_LDFLAGS = \ + -module \ + -avoid-version + ############################# # Test stuff ############################# @@ -45,7 +64,7 @@ libdummy_indicator_null_la_LDFLAGS = \ XML_REPORT = loader-check-results.xml HTML_REPORT = loader-check-results.html -loader-tester: test-loader libdummy-indicator-null.la +loader-tester: test-loader libdummy-indicator-null.la libdummy-indicator-simple.la @gtester -k --verbose -o=$(XML_REPORT) ./test-loader check-local: loader-tester diff --git a/tests/dummy-indicator-simple.c b/tests/dummy-indicator-simple.c new file mode 100644 index 0000000..d939141 --- /dev/null +++ b/tests/dummy-indicator-simple.c @@ -0,0 +1,23 @@ + +#include "libindicator/indicator.h" + +INDICATOR_SET_VERSION +INDICATOR_SET_NAME("dummy-indicator-simple") + +GtkLabel * +get_label (void) +{ + return GTK_LABEL(gtk_label_new("Simple Item")); +} + +GtkImage * +get_icon (void) +{ + return GTK_IMAGE(gtk_image_new()); +} + +GtkMenu * +get_menu (void) +{ + return GTK_MENU(gtk_menu_new()); +} diff --git a/tests/test-loader.c b/tests/test-loader.c index 3dcc595..1d6a7c3 100644 --- a/tests/test-loader.c +++ b/tests/test-loader.c @@ -63,6 +63,7 @@ test_loader_creation_deletion_suite (void) g_test_add_func ("/libindicator/loader/ref_and_unref", test_loader_refunref); g_test_add_func ("/libindicator/loader/filename_bad", test_loader_filename_bad); g_test_add_func ("/libindicator/loader/dummy/null_load", test_loader_filename_dummy_null); + g_test_add_func ("/libindicator/loader/dummy/simple_load", test_loader_filename_dummy_simple); return; } -- cgit v1.2.3 From 9c16e7c9708c757c46be1e96d58ab6430d729b0a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 20:17:04 -0400 Subject: A better dummy menu. --- tests/dummy-indicator-simple.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tests/dummy-indicator-simple.c b/tests/dummy-indicator-simple.c index d939141..cee4eac 100644 --- a/tests/dummy-indicator-simple.c +++ b/tests/dummy-indicator-simple.c @@ -19,5 +19,10 @@ get_icon (void) GtkMenu * get_menu (void) { - return GTK_MENU(gtk_menu_new()); + GtkMenu * main_menu = GTK_MENU(gtk_menu_new()); + GtkWidget * loading_item = gtk_menu_item_new_with_label("Loading..."); + gtk_menu_shell_append(GTK_MENU_SHELL(main_menu), loading_item); + gtk_widget_show(GTK_WIDGET(loading_item)); + + return main_menu; } -- cgit v1.2.3 From 32fc4b833fd948270eaa16f33d5b80eafef6f281 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 20:18:20 -0400 Subject: We need to use GTK. --- tests/test-loader.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test-loader.c b/tests/test-loader.c index 1d6a7c3..0409a6f 100644 --- a/tests/test-loader.c +++ b/tests/test-loader.c @@ -1,4 +1,4 @@ -#include +#include #include "libindicator/indicator-object.h" void destroy_cb (gpointer data, GObject * object); @@ -74,6 +74,7 @@ main (int argc, char ** argv) { g_type_init (); g_test_init (&argc, &argv, NULL); + gtk_init(&argc, &argv); test_loader_creation_deletion_suite(); -- cgit v1.2.3 From fda24e437ad0664e7287237e5bcffcbe15faade4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 20:22:59 -0400 Subject: Maintaining a reference to the objects we create in the object. --- libindicator/indicator-object.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 6a638ec..71e72d8 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -126,6 +126,9 @@ indicator_object_new_from_file (const gchar * file) goto unrefandout; } priv->label = lget_label(); + if (priv->label) { + g_object_ref(G_OBJECT(priv->label)); + } /* The function for grabbing an icon from the module execute it, and make sure everything is a-okay */ @@ -139,6 +142,9 @@ indicator_object_new_from_file (const gchar * file) goto unrefandout; } priv->icon = lget_icon(); + if (priv->icon) { + g_object_ref(G_OBJECT(priv->icon)); + } /* The function for grabbing a menu from the module execute it, and make sure everything is a-okay */ @@ -152,6 +158,9 @@ indicator_object_new_from_file (const gchar * file) goto unrefandout; } priv->menu = lget_menu(); + if (priv->menu) { + g_object_ref(G_OBJECT(priv->menu)); + } if (priv->label == NULL && priv->icon == NULL) { /* This is the case where there is nothing to display, -- cgit v1.2.3 From 5144944dbe90e1eaf65bfeedbd6057b858880abc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 20:47:19 -0400 Subject: Adding some accessor functions for the various GTK objects. --- libindicator/indicator-object.c | 24 ++++++++++++++++++++++++ libindicator/indicator-object.h | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 71e72d8..38847dd 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -175,3 +175,27 @@ unrefandout: g_object_unref(object); return NULL; } + +GtkLabel * +indicator_object_get_label (IndicatorObject * io) +{ + g_return_val_if_fail(IS_INDICATOR_OBJECT(io), NULL); + IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(io); + return priv->label; +} + +GtkImage * +indicator_object_get_icon (IndicatorObject * io) +{ + g_return_val_if_fail(IS_INDICATOR_OBJECT(io), NULL); + IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(io); + return priv->icon; +} + +GtkMenu * +indicator_object_get_menu (IndicatorObject * io) +{ + g_return_val_if_fail(IS_INDICATOR_OBJECT(io), NULL); + IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(io); + return priv->menu; +} diff --git a/libindicator/indicator-object.h b/libindicator/indicator-object.h index fd7f470..d06355b 100644 --- a/libindicator/indicator-object.h +++ b/libindicator/indicator-object.h @@ -29,6 +29,10 @@ struct _IndicatorObject { GType indicator_object_get_type (void); IndicatorObject * indicator_object_new_from_file (const gchar * file); +GtkLabel * indicator_object_get_label (IndicatorObject * io); +GtkImage * indicator_object_get_icon (IndicatorObject * io); +GtkMenu * indicator_object_get_menu (IndicatorObject * io); + G_END_DECLS #endif -- cgit v1.2.3 From bb7b49ae82deb1f551ec8892511e4a19c881f6cc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Oct 2009 21:03:30 -0400 Subject: Testing the accessors --- tests/test-loader.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test-loader.c b/tests/test-loader.c index 0409a6f..ecbf502 100644 --- a/tests/test-loader.c +++ b/tests/test-loader.c @@ -3,6 +3,21 @@ void destroy_cb (gpointer data, GObject * object); +void +test_loader_filename_dummy_simple_accessors (void) +{ + IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-simple.so"); + g_assert(object != NULL); + + g_assert(indicator_object_get_label(object) != NULL); + g_assert(indicator_object_get_menu(object) != NULL); + g_assert(indicator_object_get_icon(object) != NULL); + + g_object_unref(object); + + return; +} + void test_loader_filename_dummy_simple (void) { @@ -64,6 +79,7 @@ test_loader_creation_deletion_suite (void) g_test_add_func ("/libindicator/loader/filename_bad", test_loader_filename_bad); g_test_add_func ("/libindicator/loader/dummy/null_load", test_loader_filename_dummy_null); g_test_add_func ("/libindicator/loader/dummy/simple_load", test_loader_filename_dummy_simple); + g_test_add_func ("/libindicator/loader/dummy/simple_accessors", test_loader_filename_dummy_simple_accessors); return; } -- cgit v1.2.3 From a2f4f868e8744fd6aea1ffb0b335e70c54e039ea Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 11 Oct 2009 21:49:22 -0500 Subject: Building a new dummy indicator that doesn't have any symbols in it. --- .bzrignore | 2 ++ tests/Makefile.am | 19 +++++++++++++++++++ tests/dummy-indicator-blank.c | 6 ++++++ 3 files changed, 27 insertions(+) create mode 100644 tests/dummy-indicator-blank.c diff --git a/.bzrignore b/.bzrignore index 6a346c8..52613e0 100644 --- a/.bzrignore +++ b/.bzrignore @@ -113,3 +113,5 @@ tests/libdummy-indicator-null.la tests/libdummy_indicator_null_la-dummy-indicator-null.lo tests/libdummy-indicator-simple.la tests/libdummy_indicator_simple_la-dummy-indicator-simple.lo +tests/libdummy-indicator-blank.la +tests/libdummy_indicator_blank_la-dummy-indicator-blank.lo diff --git a/tests/Makefile.am b/tests/Makefile.am index c21ff09..8121136 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,6 +3,7 @@ check_PROGRAMS = \ test-loader lib_LTLIBRARIES = \ + libdummy-indicator-blank.la \ libdummy-indicator-null.la \ libdummy-indicator-simple.la @@ -21,6 +22,24 @@ test_loader_CFLAGS = \ test_loader_LDADD = \ $(LIBINDICATOR_LIBS) $(top_builddir)/libindicator/.libs/libindicator.a +############################# +# Dummy Indicator Blank +############################# + +libdummy_indicator_blank_la_SOURCES = \ + dummy-indicator-blank.c + +libdummy_indicator_blank_la_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + +libdummy_indicator_blank_la_LIBADD = \ + $(LIBINDICATOR_LIBS) + +libdummy_indicator_blank_la_LDFLAGS = \ + -module \ + -avoid-version + ############################# # Dummy Indicator NULL ############################# diff --git a/tests/dummy-indicator-blank.c b/tests/dummy-indicator-blank.c new file mode 100644 index 0000000..41249f2 --- /dev/null +++ b/tests/dummy-indicator-blank.c @@ -0,0 +1,6 @@ + +#include "libindicator/indicator.h" + +INDICATOR_SET_VERSION +INDICATOR_SET_NAME("dummy-indicator-null") + -- cgit v1.2.3 From ccc7f82c202d8f0691fbbfbdd36d08624ae44e0c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 11 Oct 2009 21:50:46 -0500 Subject: using the blank dummy indicator --- tests/test-loader.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/test-loader.c b/tests/test-loader.c index ecbf502..4b2b096 100644 --- a/tests/test-loader.c +++ b/tests/test-loader.c @@ -33,6 +33,14 @@ test_loader_filename_dummy_simple (void) return; } +void +test_loader_filename_dummy_blank (void) +{ + IndicatorObject * object = indicator_object_new_from_file(BUILD_DIR "/.libs/libdummy-indicator-blank.so"); + g_assert(object == NULL); + return; +} + void test_loader_filename_dummy_null (void) { @@ -78,6 +86,7 @@ test_loader_creation_deletion_suite (void) g_test_add_func ("/libindicator/loader/ref_and_unref", test_loader_refunref); g_test_add_func ("/libindicator/loader/filename_bad", test_loader_filename_bad); g_test_add_func ("/libindicator/loader/dummy/null_load", test_loader_filename_dummy_null); + g_test_add_func ("/libindicator/loader/dummy/blank_load", test_loader_filename_dummy_null); g_test_add_func ("/libindicator/loader/dummy/simple_load", test_loader_filename_dummy_simple); g_test_add_func ("/libindicator/loader/dummy/simple_accessors", test_loader_filename_dummy_simple_accessors); -- cgit v1.2.3 From 0b18e53f290d8c536f42ce2ee7d0c905e95e27f2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 11 Oct 2009 22:05:28 -0500 Subject: Making a tools directory --- Makefile.am | 3 ++- configure.ac | 1 + tools/Makefile.am | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 tools/Makefile.am diff --git a/Makefile.am b/Makefile.am index f0211b0..8894e24 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,8 @@ SUBDIRS = \ libindicator \ - tests + tests \ + tools DISTCLEANFILES = \ libindicator-*.tar.gz diff --git a/configure.ac b/configure.ac index 51706ef..fe4aec5 100644 --- a/configure.ac +++ b/configure.ac @@ -87,6 +87,7 @@ Makefile libindicator/Makefile libindicator/indicator.pc tests/Makefile +tools/Makefile ]) ########################### diff --git a/tools/Makefile.am b/tools/Makefile.am new file mode 100644 index 0000000..9de44fc --- /dev/null +++ b/tools/Makefile.am @@ -0,0 +1 @@ +#Something -- cgit v1.2.3 From 7cc9b8f4e41087d11dfec4d55dd80b7e3c865bcc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 11 Oct 2009 22:06:46 -0500 Subject: Adding the terballs into ignore --- .bzrignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.bzrignore b/.bzrignore index 52613e0..e81c2cd 100644 --- a/.bzrignore +++ b/.bzrignore @@ -115,3 +115,5 @@ tests/libdummy-indicator-simple.la tests/libdummy_indicator_simple_la-dummy-indicator-simple.lo tests/libdummy-indicator-blank.la tests/libdummy_indicator_blank_la-dummy-indicator-blank.lo +libindicator-[0-9].[0-9].[0-9].tar.gz +libindicator-[0-9].[0-9].[0-9].tar.gz.asc -- cgit v1.2.3 From f28c65a127b070d5ad6f78b1b4a77b43557aadb9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 14 Oct 2009 09:08:40 -0500 Subject: Adding in check for valgrind that we'll need for the test tools. --- configure.ac | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/configure.ac b/configure.ac index fe4aec5..586807e 100644 --- a/configure.ac +++ b/configure.ac @@ -33,6 +33,16 @@ PKG_CHECK_MODULES(LIBINDICATOR, gtk+-2.0 >= $GTK_REQUIRED_VERSION AC_SUBST(LIBINDICATOR_CFLAGS) AC_SUBST(LIBINDICATOR_LIBS) +############################## +# Valgrind +############################## + +PKG_CHECK_MODULES(VALGRIND, valgrind) + +AC_SUBST(VALGRIND_CFLAGS) +AC_SUBST(VALGRIND_LIBS) + + ############################## # Custom Junk ############################## -- cgit v1.2.3 From a8b1436ded0d74d44a414b0ab3df9334e24eb426 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 28 Oct 2009 16:37:49 -0500 Subject: Adding in comments. --- libindicator/indicator-object.c | 66 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 38847dd..e80c1d5 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -6,6 +6,14 @@ #include "indicator.h" #include "indicator-object.h" +/** + IndicatorObjectPrivate: + @label: The label representing this indicator or #NULL if none. + @icon: The icon representing this indicator or #NULL if none. + @menu: The menu representing this indicator or #NULL if none. + + Private data for the object. +*/ typedef struct _IndicatorObjectPrivate IndicatorObjectPrivate; struct _IndicatorObjectPrivate { GtkLabel * label; @@ -23,6 +31,8 @@ static void indicator_object_finalize (GObject *object); G_DEFINE_TYPE (IndicatorObject, indicator_object, G_TYPE_OBJECT); +/* Setup the class and put the functions into the + class structure */ static void indicator_object_class_init (IndicatorObjectClass *klass) { @@ -36,6 +46,7 @@ indicator_object_class_init (IndicatorObjectClass *klass) return; } +/* Inititalize an instance */ static void indicator_object_init (IndicatorObject *self) { @@ -48,6 +59,7 @@ indicator_object_init (IndicatorObject *self) return; } +/* Unref the objects that we're holding on to. */ static void indicator_object_dispose (GObject *object) { @@ -72,6 +84,7 @@ indicator_object_dispose (GObject *object) return; } +/* Free memory */ static void indicator_object_finalize (GObject *object) { @@ -80,9 +93,22 @@ indicator_object_finalize (GObject *object) return; } +/** + indicator_object_new_from_file: + @file: Filename containing a loadable module + + This function builds an #IndicatorObject using the symbols + that are found in @file. The module is loaded and the + references are all kept by the object. To unload the + module the object must be destroyed. + + Return value: A valid #IndicatorObject or #NULL if error. +*/ IndicatorObject * indicator_object_new_from_file (const gchar * file) { + /* Check to make sure the name exists and that the + file itself exists */ if (file == NULL) { g_warning("Invalid filename."); return NULL; @@ -93,6 +119,8 @@ indicator_object_new_from_file (const gchar * file) return NULL; } + /* Grab the g_module reference, pull it in but let's + keep the symbols local to avoid conflicts. */ GModule * module = g_module_open(file, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); if(module == NULL) { @@ -100,17 +128,23 @@ indicator_object_new_from_file (const gchar * file) return NULL; } + /* Look for the version function, error if not found. */ get_version_t lget_version = NULL; if (!g_module_symbol(module, INDICATOR_GET_VERSION_S, (gpointer *)(&lget_version))) { g_warning("Unable to get the symbol for getting the version."); return NULL; } + /* Check the version with the macro and make sure we're + all talking the same language. */ if (!INDICATOR_VERSION_CHECK(lget_version())) { g_warning("Indicator using API version '%s' we're expecting '%s'", lget_version(), INDICATOR_VERSION); return NULL; } + /* A this point we allocate the object, any code beyond + here needs to deallocate it if we're returning in an + error'd state. */ GObject * object = g_object_new(INDICATOR_OBJECT_TYPE, NULL); IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(object); @@ -171,11 +205,23 @@ indicator_object_new_from_file (const gchar * file) return INDICATOR_OBJECT(object); + /* Error, let's drop the object and return NULL. Sad when + this happens. */ unrefandout: g_object_unref(object); return NULL; } +/** + indicator_object_get_label: + @io: An #IndicatorObject. + + A function to get the label for a particular object. This + function does not increase the refcount. That's your job + if you want to do it. + + Return value: A #GtkLabel or #NULL if unavailable. +*/ GtkLabel * indicator_object_get_label (IndicatorObject * io) { @@ -184,6 +230,16 @@ indicator_object_get_label (IndicatorObject * io) return priv->label; } +/** + indicator_object_get_icon: + @io: An #IndicatorObject. + + A function to get the icon for a particular object. This + function does not increase the refcount. That's your job + if you want to do it. + + Return value: A #GtkImage or #NULL if unavailable. +*/ GtkImage * indicator_object_get_icon (IndicatorObject * io) { @@ -192,6 +248,16 @@ indicator_object_get_icon (IndicatorObject * io) return priv->icon; } +/** + indicator_object_get_menu: + @io: An #IndicatorObject. + + A function to get the menu for a particular object. This + function does not increase the refcount. That's your job + if you want to do it. + + Return value: A #GtkMenu or #NULL if unavailable. +*/ GtkMenu * indicator_object_get_menu (IndicatorObject * io) { -- cgit v1.2.3 From 755adf0afbb0b0478f6c9f3534f04f21bcdea910 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 28 Oct 2009 16:41:34 -0500 Subject: Oh, legal headers. Fun, fun. --- libindicator/indicator-object.c | 21 +++++++++++++++++++++ libindicator/indicator-object.h | 22 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index e80c1d5..5921ce5 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -1,3 +1,24 @@ +/* +An interface for indicators to link to for creation. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 3.0 as published by the Free Software Foundation. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License version 3.0 for more details. + +You should have received a copy of the GNU General Public +License along with this library. If not, see +. +*/ #ifdef HAVE_CONFIG_H #include "config.h" diff --git a/libindicator/indicator-object.h b/libindicator/indicator-object.h index d06355b..cb01b85 100644 --- a/libindicator/indicator-object.h +++ b/libindicator/indicator-object.h @@ -1,3 +1,25 @@ +/* +An interface for indicators to link to for creation. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 3.0 as published by the Free Software Foundation. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License version 3.0 for more details. + +You should have received a copy of the GNU General Public +License along with this library. If not, see +. +*/ + #ifndef __INDICATOR_OBJECT_H__ #define __INDICATOR_OBJECT_H__ -- cgit v1.2.3 From b98a4811a0b03335da1fad3d0e0bce08bdad2a00 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 28 Oct 2009 16:43:19 -0500 Subject: Removing valgrind as I want to clean this branch up and make another for that. --- configure.ac | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/configure.ac b/configure.ac index 586807e..fe4aec5 100644 --- a/configure.ac +++ b/configure.ac @@ -33,16 +33,6 @@ PKG_CHECK_MODULES(LIBINDICATOR, gtk+-2.0 >= $GTK_REQUIRED_VERSION AC_SUBST(LIBINDICATOR_CFLAGS) AC_SUBST(LIBINDICATOR_LIBS) -############################## -# Valgrind -############################## - -PKG_CHECK_MODULES(VALGRIND, valgrind) - -AC_SUBST(VALGRIND_CFLAGS) -AC_SUBST(VALGRIND_LIBS) - - ############################## # Custom Junk ############################## -- cgit v1.2.3 From 15995b7acd5a51c03298c9c671dd82718921ad4e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 28 Oct 2009 16:55:18 -0500 Subject: Adding a description for the indicator service. --- libindicator/indicator-service.xml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 libindicator/indicator-service.xml 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 @@ + + + + + + + + + + + + + + + + + -- cgit v1.2.3 From 606b4939df9845c82d92029abfe8403eb891a26b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 28 Oct 2009 16:58:19 -0500 Subject: Building ourselves a little dbus spec --- .bzrignore | 2 ++ libindicator/Makefile.am | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/.bzrignore b/.bzrignore index e81c2cd..0859cc8 100644 --- a/.bzrignore +++ b/.bzrignore @@ -117,3 +117,5 @@ tests/libdummy-indicator-blank.la tests/libdummy_indicator_blank_la-dummy-indicator-blank.lo libindicator-[0-9].[0-9].[0-9].tar.gz libindicator-[0-9].[0-9].[0-9].tar.gz.asc +libindicator/indicator-service-client.h +libindicator/indicator-service-server.h diff --git a/libindicator/Makefile.am b/libindicator/Makefile.am index db45f3c..6061ad8 100644 --- a/libindicator/Makefile.am +++ b/libindicator/Makefile.am @@ -1,3 +1,5 @@ +BUILT_SOURCES = +CLEANFILES = EXTRA_DIST = \ indicator.pc.in @@ -27,3 +29,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 -,_,$(<:.xml=))_client \ + --mode=glib-client \ + --output=$@ \ + $< + +%-server.h: %.xml + dbus-binding-tool \ + --prefix=_$(subst -,_,$(<:.xml=))_server \ + --mode=glib-server \ + --output=$@ \ + $< + +BUILT_SOURCES += \ + $(DBUS_SPECS:.xml=-client.h) \ + $(DBUS_SPECS:.xml=-server.h) + +CLEANFILES += $(BUILT_SOURCES) + +EXTRA_DIST += $(DBUS_SPECS) -- cgit v1.2.3 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. --- .bzrignore | 2 ++ libindicator/Makefile.am | 8 +++-- libindicator/indicator-service-manager.c | 57 +++++++++++++++++++++++++++++++ libindicator/indicator-service-manager.h | 32 ++++++++++++++++++ libindicator/indicator-service.c | 58 ++++++++++++++++++++++++++++++++ libindicator/indicator-service.h | 33 ++++++++++++++++++ 6 files changed, 188 insertions(+), 2 deletions(-) create mode 100644 libindicator/indicator-service-manager.c create mode 100644 libindicator/indicator-service-manager.h create mode 100644 libindicator/indicator-service.c create mode 100644 libindicator/indicator-service.h diff --git a/.bzrignore b/.bzrignore index 0859cc8..0213668 100644 --- a/.bzrignore +++ b/.bzrignore @@ -119,3 +119,5 @@ libindicator-[0-9].[0-9].[0-9].tar.gz libindicator-[0-9].[0-9].[0-9].tar.gz.asc libindicator/indicator-service-client.h libindicator/indicator-service-server.h +libindicator/libindicator_la-indicator-service.lo +libindicator/libindicator_la-indicator-service-manager.lo diff --git a/libindicator/Makefile.am b/libindicator/Makefile.am index 6061ad8..cce87ca 100644 --- a/libindicator/Makefile.am +++ b/libindicator/Makefile.am @@ -7,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) @@ -17,7 +19,9 @@ lib_LTLIBRARIES = \ libindicator_la_SOURCES = \ $(indicator_headers) \ - indicator-object.c + indicator-object.c \ + indicator-service.c \ + indicator-service-manager.c libindicator_la_CFLAGS = \ $(LIBINDICATOR_CFLAGS) \ 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; +} diff --git a/libindicator/indicator-service-manager.h b/libindicator/indicator-service-manager.h new file mode 100644 index 0000000..61c6e64 --- /dev/null +++ b/libindicator/indicator-service-manager.h @@ -0,0 +1,32 @@ +#ifndef __INDICATOR_SERVICE_MANAGER_H__ +#define __INDICATOR_SERVICE_MANAGER_H__ + +#include +#include + +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 IS_INDICATOR_SERVICE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_SERVICE_MANAGER_TYPE)) +#define IS_INDICATOR_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)) + +typedef struct _IndicatorServiceManager IndicatorServiceManager; +typedef struct _IndicatorServiceManagerClass IndicatorServiceManagerClass; + +struct _IndicatorServiceManagerClass { + GObjectClass parent_class; + +}; + +struct _IndicatorServiceManager { + GObject parent; +}; + +GType indicator_service_manager_get_type (void); + +G_END_DECLS + +#endif diff --git a/libindicator/indicator-service.c b/libindicator/indicator-service.c new file mode 100644 index 0000000..089c9ad --- /dev/null +++ b/libindicator/indicator-service.c @@ -0,0 +1,58 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "indicator-service.h" + +typedef struct _IndicatorServicePrivate IndicatorServicePrivate; + +struct _IndicatorServicePrivate { + int dummy; +}; + +#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); + +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; + + + return; +} + +static void +indicator_service_init (IndicatorService *self) +{ + + return; +} + +static void +indicator_service_dispose (GObject *object) +{ + + G_OBJECT_CLASS (indicator_service_parent_class)->dispose (object); + return; +} + +static void +indicator_service_finalize (GObject *object) +{ + + G_OBJECT_CLASS (indicator_service_parent_class)->finalize (object); + return; +} diff --git a/libindicator/indicator-service.h b/libindicator/indicator-service.h new file mode 100644 index 0000000..0cec28c --- /dev/null +++ b/libindicator/indicator-service.h @@ -0,0 +1,33 @@ +#ifndef __INDICATOR_SERVICE_H__ +#define __INDICATOR_SERVICE_H__ + +#include +#include + +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 IS_INDICATOR_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_SERVICE_TYPE)) +#define IS_INDICATOR_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)) + +typedef struct _IndicatorService IndicatorService; +typedef struct _IndicatorServiceClass IndicatorServiceClass; + +struct _IndicatorServiceClass { + GObjectClass parent_class; + +}; + +struct _IndicatorService { + GObject parent; + +}; + +GType indicator_service_get_type (void); + +G_END_DECLS + +#endif -- cgit v1.2.3 From b8db81899bc6903c7c1a21b434caaa862c29ea32 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 09:33:21 -0500 Subject: Making 'INDICATOR' the prefix for the objects. --- libindicator/indicator-object.c | 6 +++--- libindicator/indicator-object.h | 4 ++-- libindicator/indicator-service-manager.h | 4 ++-- libindicator/indicator-service.h | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libindicator/indicator-object.c b/libindicator/indicator-object.c index 5921ce5..ed9214c 100644 --- a/libindicator/indicator-object.c +++ b/libindicator/indicator-object.c @@ -246,7 +246,7 @@ unrefandout: GtkLabel * indicator_object_get_label (IndicatorObject * io) { - g_return_val_if_fail(IS_INDICATOR_OBJECT(io), NULL); + g_return_val_if_fail(INDICATOR_IS_OBJECT(io), NULL); IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(io); return priv->label; } @@ -264,7 +264,7 @@ indicator_object_get_label (IndicatorObject * io) GtkImage * indicator_object_get_icon (IndicatorObject * io) { - g_return_val_if_fail(IS_INDICATOR_OBJECT(io), NULL); + g_return_val_if_fail(INDICATOR_IS_OBJECT(io), NULL); IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(io); return priv->icon; } @@ -282,7 +282,7 @@ indicator_object_get_icon (IndicatorObject * io) GtkMenu * indicator_object_get_menu (IndicatorObject * io) { - g_return_val_if_fail(IS_INDICATOR_OBJECT(io), NULL); + g_return_val_if_fail(INDICATOR_IS_OBJECT(io), NULL); IndicatorObjectPrivate * priv = INDICATOR_OBJECT_GET_PRIVATE(io); return priv->menu; } diff --git a/libindicator/indicator-object.h b/libindicator/indicator-object.h index cb01b85..ea3f52e 100644 --- a/libindicator/indicator-object.h +++ b/libindicator/indicator-object.h @@ -31,8 +31,8 @@ G_BEGIN_DECLS #define INDICATOR_OBJECT_TYPE (indicator_object_get_type ()) #define INDICATOR_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_OBJECT_TYPE, IndicatorObject)) #define INDICATOR_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_OBJECT_TYPE, IndicatorObjectClass)) -#define IS_INDICATOR_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_OBJECT_TYPE)) -#define IS_INDICATOR_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_OBJECT_TYPE)) +#define INDICATOR_IS_OBJECT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_OBJECT_TYPE)) +#define INDICATOR_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_OBJECT_TYPE)) #define INDICATOR_OBJECT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_OBJECT_TYPE, IndicatorObjectClass)) typedef struct _IndicatorObject IndicatorObject; diff --git a/libindicator/indicator-service-manager.h b/libindicator/indicator-service-manager.h index 61c6e64..f2e4d75 100644 --- a/libindicator/indicator-service-manager.h +++ b/libindicator/indicator-service-manager.h @@ -9,8 +9,8 @@ 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 IS_INDICATOR_SERVICE_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_SERVICE_MANAGER_TYPE)) -#define IS_INDICATOR_SERVICE_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_SERVICE_MANAGER_TYPE)) +#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)) typedef struct _IndicatorServiceManager IndicatorServiceManager; diff --git a/libindicator/indicator-service.h b/libindicator/indicator-service.h index 0cec28c..48f1d81 100644 --- a/libindicator/indicator-service.h +++ b/libindicator/indicator-service.h @@ -9,8 +9,8 @@ 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 IS_INDICATOR_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_SERVICE_TYPE)) -#define IS_INDICATOR_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_SERVICE_TYPE)) +#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)) typedef struct _IndicatorService IndicatorService; -- cgit v1.2.3 From 0af9206bc55a78a2e39ba86b07450a15ed399eee Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 09:56:39 -0500 Subject: Defining some API and boot strapping documentation. --- libindicator/indicator-service-manager.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/libindicator/indicator-service-manager.h b/libindicator/indicator-service-manager.h index f2e4d75..127d56b 100644 --- a/libindicator/indicator-service-manager.h +++ b/libindicator/indicator-service-manager.h @@ -13,20 +13,51 @@ G_BEGIN_DECLS #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 -- cgit v1.2.3 From b60a7f11342b8711e4bea8a51cc558d30ebbb293 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 10:49:12 -0500 Subject: Adding basic interfaces and docs to IndicatorService --- libindicator/indicator-service.h | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/libindicator/indicator-service.h b/libindicator/indicator-service.h index 48f1d81..63c3f4b 100644 --- a/libindicator/indicator-service.h +++ b/libindicator/indicator-service.h @@ -13,14 +13,39 @@ G_BEGIN_DECLS #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; @@ -28,6 +53,8 @@ struct _IndicatorService { GType indicator_service_get_type (void); +IndicatorService * inidcator_service_new (gchar * name); + G_END_DECLS #endif -- cgit v1.2.3 From ec0809ed60a94f582ad7111a992fa0f60e493016 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 11:33:37 -0500 Subject: Putting a dummy implementation in for _new for linking --- libindicator/indicator-service.c | 8 ++++++++ libindicator/indicator-service.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libindicator/indicator-service.c b/libindicator/indicator-service.c index 089c9ad..7a1fa8a 100644 --- a/libindicator/indicator-service.c +++ b/libindicator/indicator-service.c @@ -56,3 +56,11 @@ indicator_service_finalize (GObject *object) G_OBJECT_CLASS (indicator_service_parent_class)->finalize (object); return; } + +IndicatorService * +indicator_service_new (gchar * name) +{ + GObject * obj = g_object_new(INDICATOR_SERVICE_TYPE, NULL); + + return INDICATOR_SERVICE(obj); +} diff --git a/libindicator/indicator-service.h b/libindicator/indicator-service.h index 63c3f4b..b47a91a 100644 --- a/libindicator/indicator-service.h +++ b/libindicator/indicator-service.h @@ -53,7 +53,7 @@ struct _IndicatorService { GType indicator_service_get_type (void); -IndicatorService * inidcator_service_new (gchar * name); +IndicatorService * indicator_service_new (gchar * name); G_END_DECLS -- cgit v1.2.3 From fc573dc11ca279d7a6aaf3c5164fb6e772f8d37c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 11:34:44 -0500 Subject: Creating a new test and linking it into things. --- .bzrignore | 1 + tests/Makefile.am | 18 +++++++++++++++- tests/service-shutdown-timeout.c | 45 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tests/service-shutdown-timeout.c diff --git a/.bzrignore b/.bzrignore index 0213668..1068e99 100644 --- a/.bzrignore +++ b/.bzrignore @@ -121,3 +121,4 @@ libindicator/indicator-service-client.h libindicator/indicator-service-server.h libindicator/libindicator_la-indicator-service.lo libindicator/libindicator_la-indicator-service-manager.lo +tests/service-shutdown-timeout diff --git a/tests/Makefile.am b/tests/Makefile.am index 8121136..fc83186 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,7 @@ check_PROGRAMS = \ - test-loader + test-loader \ + service-shutdown-timeout lib_LTLIBRARIES = \ libdummy-indicator-blank.la \ @@ -76,6 +77,21 @@ libdummy_indicator_simple_la_LDFLAGS = \ -module \ -avoid-version +############################# +# Service Shutdown Timeout +############################# + +service_shutdown_timeout_SOURCES = \ + service-shutdown-timeout.c + +service_shutdown_timeout_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + +service_shutdown_timeout_LDADD = \ + $(LIBINDICATOR_LIBS) \ + $(top_builddir)/libindicator/.libs/libindicator.a + ############################# # Test stuff ############################# diff --git a/tests/service-shutdown-timeout.c b/tests/service-shutdown-timeout.c new file mode 100644 index 0000000..9682202 --- /dev/null +++ b/tests/service-shutdown-timeout.c @@ -0,0 +1,45 @@ + +#include +#include "libindicator/indicator-service.h" + +static GMainLoop * mainloop = NULL; +static gboolean passed = FALSE; + +gboolean +timeout (gpointer data) +{ + passed = FALSE; + g_error("Timeout with no shutdown."); + g_main_loop_quit(mainloop); + return FALSE; +} + +void +shutdown (void) +{ + g_debug("Shutdown"); + g_main_loop_quit(mainloop); + return; +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + + IndicatorService * is = indicator_service_new("my.test.name"); + g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_SIGNAL_SHUTDOWN, shutdown, NULL); + + g_timeout_add_seconds(1, timeout, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + g_debug("Quiting"); + if (passed) { + g_debug("Passed"); + return 0; + } + g_debug("Failed"); + return 1; +} -- cgit v1.2.3 From a72fc583b5ae76ee0d4183ae72e4d905c0304bb7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 12:57:56 -0500 Subject: Making the gtester stuff into a autotest thingy. --- .bzrignore | 1 + tests/Makefile.am | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.bzrignore b/.bzrignore index 1068e99..cfc3a2c 100644 --- a/.bzrignore +++ b/.bzrignore @@ -122,3 +122,4 @@ libindicator/indicator-service-server.h libindicator/libindicator_la-indicator-service.lo libindicator/libindicator_la-indicator-service-manager.lo tests/service-shutdown-timeout +tests/loader-tester diff --git a/tests/Makefile.am b/tests/Makefile.am index fc83186..bacdce6 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,3 +1,5 @@ +TESTS = +DISTCLEANFILES = check_PROGRAMS = \ test-loader \ @@ -99,10 +101,13 @@ service_shutdown_timeout_LDADD = \ XML_REPORT = loader-check-results.xml HTML_REPORT = loader-check-results.html -loader-tester: test-loader libdummy-indicator-null.la libdummy-indicator-simple.la - @gtester -k --verbose -o=$(XML_REPORT) ./test-loader +loader-tester: test-loader libdummy-indicator-null.la libdummy-indicator-simple.la Makefile + @echo "#!/bin/sh" > loader-tester + @echo gtester -k --verbose -o=$(XML_REPORT) ./test-loader >> loader-tester + @chmod +x loader-tester -check-local: loader-tester +TESTS += loader-tester +DISTCLEANFILES += loader-tester -DISTCLEANFILES = $(XML_REPORT) $(HTML_REPORT) +DISTCLEANFILES += $(XML_REPORT) $(HTML_REPORT) -- cgit v1.2.3 From 22a5b08a9ddb76888f580141617d67a319fbfad9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 13:03:39 -0500 Subject: Woot! A failing test. Look how TDD I am. --- .bzrignore | 1 + tests/Makefile.am | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/.bzrignore b/.bzrignore index cfc3a2c..1bdd142 100644 --- a/.bzrignore +++ b/.bzrignore @@ -123,3 +123,4 @@ libindicator/libindicator_la-indicator-service.lo libindicator/libindicator_la-indicator-service-manager.lo tests/service-shutdown-timeout tests/loader-tester +tests/service-shutdown-timeout-tester diff --git a/tests/Makefile.am b/tests/Makefile.am index bacdce6..485d02e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -10,6 +10,8 @@ lib_LTLIBRARIES = \ libdummy-indicator-null.la \ libdummy-indicator-simple.la +DBUS_RUNNER=dbus-test-runner --dbus-config /usr/share/dbus-test-runner/session.conf + ############################# # Test Loader ############################# @@ -94,6 +96,14 @@ service_shutdown_timeout_LDADD = \ $(LIBINDICATOR_LIBS) \ $(top_builddir)/libindicator/.libs/libindicator.a +service-shutdown-timeout-tester: service-shutdown-timeout Makefile + @echo "#!/bin/sh" > service-shutdown-timeout-tester + @echo $(DBUS_RUNNER) --task ./service-shutdown-timeout >> service-shutdown-timeout-tester + @chmod +x service-shutdown-timeout-tester + +TESTS += service-shutdown-timeout-tester +DISTCLEANFILES += service-shutdown-timeout-tester + ############################# # Test stuff ############################# -- cgit v1.2.3 From 621a7ba6b53826e95011940b90d9bf8a684534b8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 13:13:07 -0500 Subject: Adding the shutdown signal --- libindicator/indicator-service.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/libindicator/indicator-service.c b/libindicator/indicator-service.c index 7a1fa8a..5a252f8 100644 --- a/libindicator/indicator-service.c +++ b/libindicator/indicator-service.c @@ -4,12 +4,21 @@ #include "indicator-service.h" +/* Private Stuff */ typedef struct _IndicatorServicePrivate IndicatorServicePrivate; struct _IndicatorServicePrivate { int dummy; }; +/* Signals Stuff */ +enum { + SHUTDOWN, + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = { 0 }; + #define INDICATOR_SERVICE_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_SERVICE_TYPE, IndicatorServicePrivate)) @@ -30,6 +39,22 @@ indicator_service_class_init (IndicatorServiceClass *klass) object_class->dispose = indicator_service_dispose; object_class->finalize = indicator_service_finalize; + /* 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); return; } -- cgit v1.2.3 From fbb2bc9cf94cb7a89856a8820f26f9311985fcc8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 13:45:37 -0500 Subject: Adding in the 'name' property --- libindicator/indicator-service.c | 88 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/libindicator/indicator-service.c b/libindicator/indicator-service.c index 5a252f8..64aa986 100644 --- a/libindicator/indicator-service.c +++ b/libindicator/indicator-service.c @@ -19,6 +19,18 @@ enum { 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)) @@ -27,6 +39,10 @@ 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); + G_DEFINE_TYPE (IndicatorService, indicator_service, G_TYPE_OBJECT); static void @@ -39,6 +55,18 @@ indicator_service_class_init (IndicatorServiceClass *klass) 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 */ /** @@ -82,10 +110,68 @@ indicator_service_finalize (GObject *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: + 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: + break; + /* *********************** */ + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } + + return; +} + +/** + 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, NULL); + GObject * obj = g_object_new(INDICATOR_SERVICE_TYPE, + PROP_NAME_S, name, + NULL); return INDICATOR_SERVICE(obj); } -- cgit v1.2.3 From 145b214353d592e234387d03fbcabab28b14b34b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 14:55:25 -0500 Subject: Filling in more of the name property. --- libindicator/indicator-service.c | 54 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/libindicator/indicator-service.c b/libindicator/indicator-service.c index 64aa986..ecbb238 100644 --- a/libindicator/indicator-service.c +++ b/libindicator/indicator-service.c @@ -1,6 +1,7 @@ #ifdef HAVE_CONFIG_H #include "config.h" #endif +#include #include "indicator-service.h" @@ -8,7 +9,7 @@ typedef struct _IndicatorServicePrivate IndicatorServicePrivate; struct _IndicatorServicePrivate { - int dummy; + gchar * name; }; /* Signals Stuff */ @@ -42,6 +43,7 @@ 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); @@ -90,6 +92,9 @@ indicator_service_class_init (IndicatorServiceClass *klass) static void indicator_service_init (IndicatorService *self) { + IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(self); + + priv->name = NULL; return; } @@ -105,6 +110,11 @@ indicator_service_dispose (GObject *object) static void indicator_service_finalize (GObject *object) { + IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(object); + + if (priv->name) { + g_free(priv->name); + } G_OBJECT_CLASS (indicator_service_parent_class)->finalize (object); return; @@ -122,6 +132,16 @@ set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec 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 is a string bud."); + } break; /* *********************** */ default: @@ -144,6 +164,11 @@ get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspe 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: @@ -154,6 +179,33 @@ get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspe return; } +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); + + +} + +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, */ NULL, + priv->name, + 0, + try_and_get_name_cb, + service); + + return; +} + +/* API */ + /** indicator_service_new: @name: The name for the service on dbus -- cgit v1.2.3 From f99a9f269a702b2db3f96e1b6740e9eceb6b9ca8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 15:24:49 -0500 Subject: Building ourselves a DBus proxy. --- libindicator/indicator-service.c | 43 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/libindicator/indicator-service.c b/libindicator/indicator-service.c index ecbb238..9b7e885 100644 --- a/libindicator/indicator-service.c +++ b/libindicator/indicator-service.c @@ -10,6 +10,7 @@ typedef struct _IndicatorServicePrivate IndicatorServicePrivate; struct _IndicatorServicePrivate { gchar * name; + DBusGProxy * dbus_proxy; }; /* Signals Stuff */ @@ -94,7 +95,29 @@ 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; + + /* 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; } @@ -102,6 +125,12 @@ indicator_service_init (IndicatorService *self) 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; + } G_OBJECT_CLASS (indicator_service_parent_class)->dispose (object); return; @@ -185,19 +214,27 @@ try_and_get_name_cb (DBusGProxy * proxy, guint status, GError * error, gpointer 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; + } + 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->dbus_proxy != NULL); g_return_if_fail(priv->name != NULL); - org_freedesktop_DBus_request_name_async(/* priv->dbus_proxy, */ NULL, + org_freedesktop_DBus_request_name_async(priv->dbus_proxy, priv->name, - 0, + DBUS_NAME_FLAG_DO_NOT_QUEUE, try_and_get_name_cb, service); -- cgit v1.2.3 From 2e39b18fd87c298eeb9e104d3e80f76b1d937c21 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 16:11:02 -0500 Subject: Woot! We're a DBus service now. --- libindicator/indicator-service.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libindicator/indicator-service.c b/libindicator/indicator-service.c index 9b7e885..125ecfc 100644 --- a/libindicator/indicator-service.c +++ b/libindicator/indicator-service.c @@ -5,6 +5,11 @@ #include "indicator-service.h" +/* DBus Prototypes */ +void _indicator_service_server_watch (void); + +#include "indicator-service-server.h" + /* Private Stuff */ typedef struct _IndicatorServicePrivate IndicatorServicePrivate; @@ -87,6 +92,10 @@ indicator_service_class_init (IndicatorServiceClass *klass) 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; } @@ -119,6 +128,10 @@ indicator_service_init (IndicatorService *self) return; } + dbus_g_connection_register_g_object(session_bus, + "/need/a/path", + G_OBJECT(self)); + return; } @@ -241,6 +254,8 @@ try_and_get_name (IndicatorService * service) return; } +void _indicator_service_server_watch (void) { } + /* API */ /** -- cgit v1.2.3 From 82aaaed9788d56fa2739da70621e56f1e21ec0a8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 16:29:47 -0500 Subject: Adding in some shared strings for finding intefaces and objects. --- libindicator/Makefile.am | 1 + libindicator/dbus-shared.h | 4 ++++ libindicator/indicator-service.c | 3 ++- 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 libindicator/dbus-shared.h diff --git a/libindicator/Makefile.am b/libindicator/Makefile.am index cce87ca..209b787 100644 --- a/libindicator/Makefile.am +++ b/libindicator/Makefile.am @@ -19,6 +19,7 @@ lib_LTLIBRARIES = \ libindicator_la_SOURCES = \ $(indicator_headers) \ + dbus-shared.h \ indicator-object.c \ indicator-service.c \ indicator-service-manager.c diff --git a/libindicator/dbus-shared.h b/libindicator/dbus-shared.h new file mode 100644 index 0000000..f64588c --- /dev/null +++ b/libindicator/dbus-shared.h @@ -0,0 +1,4 @@ + +#define INDICATOR_SERVICE_INTERFACE "org.ayatana.indicator.service" +#define INDICATOR_SERVICE_OBJECT "/org/ayatana/indicator/service" + diff --git a/libindicator/indicator-service.c b/libindicator/indicator-service.c index 125ecfc..eef916b 100644 --- a/libindicator/indicator-service.c +++ b/libindicator/indicator-service.c @@ -9,6 +9,7 @@ void _indicator_service_server_watch (void); #include "indicator-service-server.h" +#include "dbus-shared.h" /* Private Stuff */ typedef struct _IndicatorServicePrivate IndicatorServicePrivate; @@ -129,7 +130,7 @@ indicator_service_init (IndicatorService *self) } dbus_g_connection_register_g_object(session_bus, - "/need/a/path", + INDICATOR_SERVICE_OBJECT, G_OBJECT(self)); return; -- cgit v1.2.3 From fbba41584475d598deab170e12ba81b16f3601aa Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 17:18:51 -0500 Subject: Adding in the watchers and timeout parameter. --- libindicator/indicator-service.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/libindicator/indicator-service.c b/libindicator/indicator-service.c index eef916b..cf02bac 100644 --- a/libindicator/indicator-service.c +++ b/libindicator/indicator-service.c @@ -2,11 +2,12 @@ #include "config.h" #endif #include +#include #include "indicator-service.h" /* DBus Prototypes */ -void _indicator_service_server_watch (void); +static gboolean _indicator_service_server_watch (IndicatorService * service, DBusGMethodInvocation * method); #include "indicator-service-server.h" #include "dbus-shared.h" @@ -17,6 +18,8 @@ typedef struct _IndicatorServicePrivate IndicatorServicePrivate; struct _IndicatorServicePrivate { gchar * name; DBusGProxy * dbus_proxy; + guint timeout; + GList * watchers; }; /* Signals Stuff */ @@ -108,6 +111,8 @@ indicator_service_init (IndicatorService *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; @@ -146,6 +151,11 @@ indicator_service_dispose (GObject *object) 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; } @@ -155,10 +165,16 @@ indicator_service_finalize (GObject *object) { IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(object); - if (priv->name) { + 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; } @@ -255,7 +271,23 @@ try_and_get_name (IndicatorService * service) return; } -void _indicator_service_server_watch (void) { } +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 */ -- cgit v1.2.3 From 58194766a1163b1e1df94ef391403a2a827e3e95 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 17:21:39 -0500 Subject: Sending shutdown signal 500 ms after getting a name if we have no watchers. --- libindicator/indicator-service.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libindicator/indicator-service.c b/libindicator/indicator-service.c index cf02bac..4cc99d2 100644 --- a/libindicator/indicator-service.c +++ b/libindicator/indicator-service.c @@ -238,6 +238,13 @@ get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspe 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) { @@ -252,6 +259,9 @@ try_and_get_name_cb (DBusGProxy * proxy, guint status, GError * error, gpointer return; } + IndicatorServicePrivate * priv = INDICATOR_SERVICE_GET_PRIVATE(service); + priv->timeout = g_timeout_add(500, timeout_no_watchers, service); + return; } -- cgit v1.2.3 From 74296a68665e9c582c37a61894a9c1ba1630cb9d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Oct 2009 17:22:29 -0500 Subject: Oops, forgot to set to passed. --- tests/service-shutdown-timeout.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/service-shutdown-timeout.c b/tests/service-shutdown-timeout.c index 9682202..666739a 100644 --- a/tests/service-shutdown-timeout.c +++ b/tests/service-shutdown-timeout.c @@ -18,6 +18,7 @@ void shutdown (void) { g_debug("Shutdown"); + passed = TRUE; g_main_loop_quit(mainloop); 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(+) 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(-) 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(+) 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(+) 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(+) 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(+) 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/dbus-shared.h | 2 ++ libindicator/indicator-service-manager.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/libindicator/dbus-shared.h b/libindicator/dbus-shared.h index f64588c..f3dbd83 100644 --- a/libindicator/dbus-shared.h +++ b/libindicator/dbus-shared.h @@ -2,3 +2,5 @@ #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 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 911b9d7f93b4319665b5fa63b84032df230412ba Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 30 Oct 2009 17:18:10 -0500 Subject: Adding a test that ensures we don't get a connect signal. --- .bzrignore | 2 ++ tests/Makefile.am | 24 ++++++++++++++++++++ tests/service-manager-no-connect.c | 46 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 tests/service-manager-no-connect.c diff --git a/.bzrignore b/.bzrignore index 1bdd142..8bbe474 100644 --- a/.bzrignore +++ b/.bzrignore @@ -124,3 +124,5 @@ libindicator/libindicator_la-indicator-service-manager.lo tests/service-shutdown-timeout tests/loader-tester tests/service-shutdown-timeout-tester +tests/service-manager-no-connect +tests/service-manager-no-connect-tester diff --git a/tests/Makefile.am b/tests/Makefile.am index 485d02e..dd047d3 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -3,6 +3,7 @@ DISTCLEANFILES = check_PROGRAMS = \ test-loader \ + service-manager-no-connect \ service-shutdown-timeout lib_LTLIBRARIES = \ @@ -104,6 +105,29 @@ service-shutdown-timeout-tester: service-shutdown-timeout Makefile TESTS += service-shutdown-timeout-tester DISTCLEANFILES += service-shutdown-timeout-tester +############################# +# Service Manager No Connect +############################# + +service_manager_no_connect_SOURCES = \ + service-manager-no-connect.c + +service_manager_no_connect_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + +service_manager_no_connect_LDADD = \ + $(LIBINDICATOR_LIBS) \ + $(top_builddir)/libindicator/.libs/libindicator.a + +service-manager-no-connect-tester: service-manager-no-connect Makefile + @echo "#!/bin/sh" > service-manager-no-connect-tester + @echo $(DBUS_RUNNER) --task ./service-manager-no-connect >> service-manager-no-connect-tester + @chmod +x service-manager-no-connect-tester + +TESTS += service-manager-no-connect-tester +DISTCLEANFILES += service-manager-no-connect-tester + ############################# # Test stuff ############################# diff --git a/tests/service-manager-no-connect.c b/tests/service-manager-no-connect.c new file mode 100644 index 0000000..8006eda --- /dev/null +++ b/tests/service-manager-no-connect.c @@ -0,0 +1,46 @@ + +#include +#include "libindicator/indicator-service-manager.h" + +static GMainLoop * mainloop = NULL; +static gboolean passed = FALSE; + +gboolean +timeout (gpointer data) +{ + passed = TRUE; + g_error("Timeout with no connection."); + g_main_loop_quit(mainloop); + return FALSE; +} + +void +connection (void) +{ + g_debug("Connection"); + passed = FALSE; + g_main_loop_quit(mainloop); + return; +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + + IndicatorServiceManager * is = indicator_service_manager_new("my.test.name"); + g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, connection, NULL); + + g_timeout_add_seconds(1, timeout, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + g_debug("Quiting"); + if (passed) { + g_debug("Passed"); + return 0; + } + g_debug("Failed"); + return 1; +} -- cgit v1.2.3 From 0745e42d7032a400e1661da94faef05de7be7527 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 2 Nov 2009 09:31:43 -0600 Subject: Ah, we can't throw an error on success. --- tests/service-manager-no-connect.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/service-manager-no-connect.c b/tests/service-manager-no-connect.c index 8006eda..1c32eb2 100644 --- a/tests/service-manager-no-connect.c +++ b/tests/service-manager-no-connect.c @@ -9,7 +9,7 @@ gboolean timeout (gpointer data) { passed = TRUE; - g_error("Timeout with no connection."); + g_debug("Timeout with no connection."); g_main_loop_quit(mainloop); return FALSE; } @@ -27,6 +27,7 @@ int main (int argc, char ** argv) { g_type_init(); + g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); IndicatorServiceManager * is = indicator_service_manager_new("my.test.name"); g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, connection, NULL); -- 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(-) 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 90446e0f46aec726341a8e178bfa65ddcb057deb Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 2 Nov 2009 10:48:18 -0600 Subject: Fixing up the build rules so that they're directory independent. --- libindicator/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libindicator/Makefile.am b/libindicator/Makefile.am index 209b787..5c512cd 100644 --- a/libindicator/Makefile.am +++ b/libindicator/Makefile.am @@ -43,14 +43,14 @@ DBUS_SPECS = \ %-client.h: %.xml dbus-binding-tool \ - --prefix=_$(subst -,_,$(<:.xml=))_client \ + --prefix=_$(subst -,_,$(basename $(notdir $<)))_client \ --mode=glib-client \ --output=$@ \ $< %-server.h: %.xml dbus-binding-tool \ - --prefix=_$(subst -,_,$(<:.xml=))_server \ + --prefix=_$(subst -,_,$(basename $(notdir $<)))_server \ --mode=glib-server \ --output=$@ \ $< -- cgit v1.2.3 From 9a15eec1f5fc9609b877a411564abbf600a22ee5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 2 Nov 2009 11:17:10 -0600 Subject: Adding in the basic data needed to start bringing up a test to start the service. --- .bzrignore | 4 +++ tests/Makefile.am | 41 +++++++++++++++++++++++++++- tests/service-manager-connect-service.c | 46 ++++++++++++++++++++++++++++++++ tests/service-manager-connect.c | 47 +++++++++++++++++++++++++++++++++ tests/session.conf.in | 40 ++++++++++++++++++++++++++++ 5 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 tests/service-manager-connect-service.c create mode 100644 tests/service-manager-connect.c create mode 100644 tests/session.conf.in diff --git a/.bzrignore b/.bzrignore index 8bbe474..c4038b4 100644 --- a/.bzrignore +++ b/.bzrignore @@ -126,3 +126,7 @@ tests/loader-tester tests/service-shutdown-timeout-tester tests/service-manager-no-connect tests/service-manager-no-connect-tester +tests/service-manager-connect +tests/service-manager-connect-service +tests/service-manager-connect-tester +tests/session.conf diff --git a/tests/Makefile.am b/tests/Makefile.am index dd047d3..744c807 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -4,6 +4,8 @@ DISTCLEANFILES = check_PROGRAMS = \ test-loader \ service-manager-no-connect \ + service-manager-connect \ + service-manager-connect-service \ service-shutdown-timeout lib_LTLIBRARIES = \ @@ -120,7 +122,7 @@ service_manager_no_connect_LDADD = \ $(LIBINDICATOR_LIBS) \ $(top_builddir)/libindicator/.libs/libindicator.a -service-manager-no-connect-tester: service-manager-no-connect Makefile +service-manager-no-connect-tester: service-manager-no-connect Makefile.am @echo "#!/bin/sh" > service-manager-no-connect-tester @echo $(DBUS_RUNNER) --task ./service-manager-no-connect >> service-manager-no-connect-tester @chmod +x service-manager-no-connect-tester @@ -128,6 +130,43 @@ service-manager-no-connect-tester: service-manager-no-connect Makefile TESTS += service-manager-no-connect-tester DISTCLEANFILES += service-manager-no-connect-tester +############################# +# Service Manager Connect +############################# + +session.conf: session.conf.in Makefile.am + sed -e "s|\@servicedir\@|$(abspath $(builddir))|" $< > $@ + +service_manager_connect_SOURCES = \ + service-manager-connect.c + +service_manager_connect_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + +service_manager_connect_LDADD = \ + $(LIBINDICATOR_LIBS) \ + $(top_builddir)/libindicator/.libs/libindicator.a + +service_manager_connect_service_SOURCES = \ + service-manager-connect-service.c + +service_manager_connect_service_CFLAGS = \ + -Wall -Werror \ + $(LIBINDICATOR_CFLAGS) -I$(top_srcdir) + +service_manager_connect_service_LDADD = \ + $(LIBINDICATOR_LIBS) \ + $(top_builddir)/libindicator/.libs/libindicator.a + +service-manager-connect-tester: service-manager-connect service-manager-connect-service session.conf Makefile.am + @echo "#!/bin/sh" > service-manager-connect-tester + @echo dbus-test-runner --dbus-config $(builddir)/session.conf --task ./service-manager-connect >> service-manager-connect-tester + @chmod +x service-manager-connect-tester + +TESTS += service-manager-connect-tester +DISTCLEANFILES += service-manager-connect-tester + ############################# # Test stuff ############################# diff --git a/tests/service-manager-connect-service.c b/tests/service-manager-connect-service.c new file mode 100644 index 0000000..666739a --- /dev/null +++ b/tests/service-manager-connect-service.c @@ -0,0 +1,46 @@ + +#include +#include "libindicator/indicator-service.h" + +static GMainLoop * mainloop = NULL; +static gboolean passed = FALSE; + +gboolean +timeout (gpointer data) +{ + passed = FALSE; + g_error("Timeout with no shutdown."); + g_main_loop_quit(mainloop); + return FALSE; +} + +void +shutdown (void) +{ + g_debug("Shutdown"); + passed = TRUE; + g_main_loop_quit(mainloop); + return; +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + + IndicatorService * is = indicator_service_new("my.test.name"); + g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_SIGNAL_SHUTDOWN, shutdown, NULL); + + g_timeout_add_seconds(1, timeout, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + g_debug("Quiting"); + if (passed) { + g_debug("Passed"); + return 0; + } + g_debug("Failed"); + return 1; +} diff --git a/tests/service-manager-connect.c b/tests/service-manager-connect.c new file mode 100644 index 0000000..1c32eb2 --- /dev/null +++ b/tests/service-manager-connect.c @@ -0,0 +1,47 @@ + +#include +#include "libindicator/indicator-service-manager.h" + +static GMainLoop * mainloop = NULL; +static gboolean passed = FALSE; + +gboolean +timeout (gpointer data) +{ + passed = TRUE; + g_debug("Timeout with no connection."); + g_main_loop_quit(mainloop); + return FALSE; +} + +void +connection (void) +{ + g_debug("Connection"); + passed = FALSE; + g_main_loop_quit(mainloop); + return; +} + +int +main (int argc, char ** argv) +{ + g_type_init(); + g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); + + IndicatorServiceManager * is = indicator_service_manager_new("my.test.name"); + g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, connection, NULL); + + g_timeout_add_seconds(1, timeout, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + g_debug("Quiting"); + if (passed) { + g_debug("Passed"); + return 0; + } + g_debug("Failed"); + return 1; +} diff --git a/tests/session.conf.in b/tests/session.conf.in new file mode 100644 index 0000000..d1e2805 --- /dev/null +++ b/tests/session.conf.in @@ -0,0 +1,40 @@ + + + + + + unix:tmpdir=/tmp + + @servicedir@ + + + + + + + + + + + + 60000 + + + 1000000000 + 1000000000 + 1000000000 + 120000 + 240000 + 100000 + 10000 + 100000 + 10000 + 50000 + 50000 + 50000 + 300000 + + -- cgit v1.2.3 From dc5fbef86dc82fbc1d768dba489fe4ba0b09adfc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 2 Nov 2009 11:21:20 -0600 Subject: Building a service file. --- .bzrignore | 1 + tests/Makefile.am | 5 ++++- tests/service-manager-connect.service.in | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/service-manager-connect.service.in diff --git a/.bzrignore b/.bzrignore index c4038b4..1f72eaf 100644 --- a/.bzrignore +++ b/.bzrignore @@ -130,3 +130,4 @@ tests/service-manager-connect tests/service-manager-connect-service tests/service-manager-connect-tester tests/session.conf +tests/service-manager-connect.service diff --git a/tests/Makefile.am b/tests/Makefile.am index 744c807..3703259 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -137,6 +137,9 @@ DISTCLEANFILES += service-manager-no-connect-tester session.conf: session.conf.in Makefile.am sed -e "s|\@servicedir\@|$(abspath $(builddir))|" $< > $@ +service-manager-connect.service: service-manager-connect.service.in Makefile.am + sed -e "s|\@builddir\@|$(abspath $(builddir))|" $< > $@ + service_manager_connect_SOURCES = \ service-manager-connect.c @@ -159,7 +162,7 @@ service_manager_connect_service_LDADD = \ $(LIBINDICATOR_LIBS) \ $(top_builddir)/libindicator/.libs/libindicator.a -service-manager-connect-tester: service-manager-connect service-manager-connect-service session.conf Makefile.am +service-manager-connect-tester: service-manager-connect service-manager-connect-service session.conf service-manager-connect.service Makefile.am @echo "#!/bin/sh" > service-manager-connect-tester @echo dbus-test-runner --dbus-config $(builddir)/session.conf --task ./service-manager-connect >> service-manager-connect-tester @chmod +x service-manager-connect-tester diff --git a/tests/service-manager-connect.service.in b/tests/service-manager-connect.service.in new file mode 100644 index 0000000..7d3da6b --- /dev/null +++ b/tests/service-manager-connect.service.in @@ -0,0 +1,3 @@ +[D-BUS Service] +Name=org.ayatana.test +Exec=@builddir@/service-manager-connect-service -- cgit v1.2.3 From 5e5f49521da190319a54ee5a7d18f9b824823027 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 2 Nov 2009 11:24:03 -0600 Subject: Switching the name to match the service file... should fail. --- tests/service-manager-connect.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/service-manager-connect.c b/tests/service-manager-connect.c index 1c32eb2..c7c9282 100644 --- a/tests/service-manager-connect.c +++ b/tests/service-manager-connect.c @@ -29,7 +29,7 @@ main (int argc, char ** argv) g_type_init(); g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL); - IndicatorServiceManager * is = indicator_service_manager_new("my.test.name"); + IndicatorServiceManager * is = indicator_service_manager_new("org.ayatana.test"); g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, connection, NULL); g_timeout_add_seconds(1, timeout, NULL); -- cgit v1.2.3 From ddb2ab7cba0d8b2c7ea5171595e06c04520f4b81 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 2 Nov 2009 16:08:04 -0600 Subject: Adding a fallback to the session bus after trying the starter bus. --- libindicator/indicator-service.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/libindicator/indicator-service.c b/libindicator/indicator-service.c index 4cc99d2..ff0bd03 100644 --- a/libindicator/indicator-service.c +++ b/libindicator/indicator-service.c @@ -116,14 +116,24 @@ indicator_service_init (IndicatorService *self) /* Start talkin' dbus */ GError * error = NULL; - DBusGConnection * session_bus = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + DBusGConnection * bus = dbus_g_bus_get(DBUS_BUS_STARTER, &error); if (error != NULL) { - g_error("Unable to get session bus: %s", error->message); + g_error("Unable to get starter bus: %s", error->message); g_error_free(error); - return; + + /* 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(session_bus, + priv->dbus_proxy = dbus_g_proxy_new_for_name_owner(bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, @@ -134,7 +144,7 @@ indicator_service_init (IndicatorService *self) return; } - dbus_g_connection_register_g_object(session_bus, + dbus_g_connection_register_g_object(bus, INDICATOR_SERVICE_OBJECT, G_OBJECT(self)); -- cgit v1.2.3 From 6cb18e9a371158977143c198d43e69c73895496d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 2 Nov 2009 16:13:28 -0600 Subject: We want to not get the shutdown. Since we're testing that we get it without connection we can now assume that if we don't get it we should pass. --- tests/service-manager-connect-service.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/service-manager-connect-service.c b/tests/service-manager-connect-service.c index 666739a..297f3ba 100644 --- a/tests/service-manager-connect-service.c +++ b/tests/service-manager-connect-service.c @@ -8,8 +8,8 @@ static gboolean passed = FALSE; gboolean timeout (gpointer data) { - passed = FALSE; - g_error("Timeout with no shutdown."); + passed = TRUE; + g_debug("Timeout with no shutdown."); g_main_loop_quit(mainloop); return FALSE; } @@ -17,8 +17,8 @@ timeout (gpointer data) void shutdown (void) { - g_debug("Shutdown"); - passed = TRUE; + g_error("Shutdown"); + passed = FALSE; g_main_loop_quit(mainloop); return; } @@ -28,7 +28,7 @@ main (int argc, char ** argv) { g_type_init(); - IndicatorService * is = indicator_service_new("my.test.name"); + IndicatorService * is = indicator_service_new("org.ayatana.test"); g_signal_connect(G_OBJECT(is), INDICATOR_SERVICE_SIGNAL_SHUTDOWN, shutdown, NULL); g_timeout_add_seconds(1, timeout, NULL); -- cgit v1.2.3 From c3d30bd0cfd9f29072424f7a4c63bab7618d45fa Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 2 Nov 2009 16:14:53 -0600 Subject: We should pass the test if we get a connection, it means we activated. --- tests/service-manager-connect.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/service-manager-connect.c b/tests/service-manager-connect.c index c7c9282..c252542 100644 --- a/tests/service-manager-connect.c +++ b/tests/service-manager-connect.c @@ -8,8 +8,8 @@ static gboolean passed = FALSE; gboolean timeout (gpointer data) { - passed = TRUE; - g_debug("Timeout with no connection."); + passed = FALSE; + g_error("Timeout with no connection."); g_main_loop_quit(mainloop); return FALSE; } @@ -18,7 +18,7 @@ void connection (void) { g_debug("Connection"); - passed = FALSE; + passed = TRUE; g_main_loop_quit(mainloop); return; } -- cgit v1.2.3 From 5ccc73bea6b75cc3a027f831bb60bfcf43714deb Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 2 Nov 2009 16:17:31 -0600 Subject: Distcheck fixes. Looking for the files in the right place and making sure we clean up after ourselves. --- tests/Makefile.am | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Makefile.am b/tests/Makefile.am index 3703259..7c306bc 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -134,10 +134,10 @@ DISTCLEANFILES += service-manager-no-connect-tester # Service Manager Connect ############################# -session.conf: session.conf.in Makefile.am +session.conf: $(srcdir)/session.conf.in Makefile.am sed -e "s|\@servicedir\@|$(abspath $(builddir))|" $< > $@ -service-manager-connect.service: service-manager-connect.service.in Makefile.am +service-manager-connect.service: $(srcdir)/service-manager-connect.service.in Makefile.am sed -e "s|\@builddir\@|$(abspath $(builddir))|" $< > $@ service_manager_connect_SOURCES = \ @@ -168,7 +168,7 @@ service-manager-connect-tester: service-manager-connect service-manager-connect- @chmod +x service-manager-connect-tester TESTS += service-manager-connect-tester -DISTCLEANFILES += service-manager-connect-tester +DISTCLEANFILES += service-manager-connect-tester session.conf service-manager-connect.service ############################# # Test stuff -- cgit v1.2.3