diff options
author | Tomeu Vizoso <tomeu@sugarlabs.org> | 2009-04-29 12:01:04 (GMT) |
---|---|---|
committer | Tomeu Vizoso <tomeu@sugarlabs.org> | 2009-04-29 12:01:04 (GMT) |
commit | dd6c13fdbed6e4f3027872aa01b1c0fc1f46d2ab (patch) | |
tree | 54af40d1f8bd8815e997ab9fc1bac9f6f70e5a31 | |
parent | 5f6631967433599ef375214fa7d9f63ed73c2549 (diff) |
Implement the D-Bus side of get_properties
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | datastore/Makefile.am | 8 | ||||
-rw-r--r-- | datastore/datastore.cpp | 124 | ||||
-rw-r--r-- | datastore/datastore.h | 2 |
4 files changed, 105 insertions, 33 deletions
diff --git a/configure.ac b/configure.ac index 05fed90..80890c7 100644 --- a/configure.ac +++ b/configure.ac @@ -13,6 +13,10 @@ AC_PROG_LIBTOOL PKG_CHECK_MODULES(GNASH, [gnash]) +PKG_CHECK_MODULES([DBUS], [gobject-2.0 dbus-1 dbus-glib-1]) +AC_SUBST([DBUS_CFLAGS]) +AC_SUBST([DBUS_LIBS]) + AC_OUTPUT([ Makefile datastore/Makefile diff --git a/datastore/Makefile.am b/datastore/Makefile.am index fabe829..507990f 100644 --- a/datastore/Makefile.am +++ b/datastore/Makefile.am @@ -2,10 +2,14 @@ pluginsdir = $(libdir)/gnash/plugins plugins_LTLIBRARIES = datastore.la -INCLUDES = $(GNASH_CFLAGS) +INCLUDES = \ + $(GNASH_CFLAGS) \ + $(DBUS_CFLAGS) datastore_la_LDFLAGS = -module -avoid-version -datastore_la_LIBADD = $(GNASH_LIBS) +datastore_la_LIBADD = \ + $(GNASH_LIBS) \ + $(DBUS_LIBS) datastore_la_SOURCES = \ datastore.cpp \ diff --git a/datastore/datastore.cpp b/datastore/datastore.cpp index 245cc48..b910821 100644 --- a/datastore/datastore.cpp +++ b/datastore/datastore.cpp @@ -3,6 +3,13 @@ #include <string> #include <builtin_function.h> // need builtin_function #include <VM.h> +#include <dbus/dbus-glib.h> + +#define DS_DBUS_SERVICE "org.laptop.sugar.DataStore" +#define DS_DBUS_INTERFACE "org.laptop.sugar.DataStore" +#define DS_DBUS_PATH "/org/laptop/sugar/DataStore" + +#define DBUS_TYPE_G_STRING_VARIANT_HASHTABLE (dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE)) namespace gnash { @@ -22,7 +29,8 @@ getInterface() DataStore::DataStore(std::string &object_id) : - as_object(getInterface()) + as_object(getInterface()), + _object_id(object_id) { GNASH_REPORT_FUNCTION; } @@ -36,9 +44,61 @@ Properties * DataStore::get_properties() { GNASH_REPORT_FUNCTION; - Properties *properties = new Properties; - (*properties)["mec"] = "braf"; - (*properties)["moc"] = "bref"; + Properties *properties = new Properties; + + DBusGConnection *connection; + GError *error; + DBusGProxy *proxy; + GHashTable *dict; + + error = NULL; + connection = dbus_g_bus_get (DBUS_BUS_SESSION, + &error); + if (connection == NULL) + { + g_printerr ("Failed to open connection to bus: %s\n", + error->message); + g_error_free (error); + exit (1); + } + + proxy = dbus_g_proxy_new_for_name (connection, + DS_DBUS_SERVICE, + DS_DBUS_PATH, + DS_DBUS_INTERFACE); + + error = NULL; + if (!dbus_g_proxy_call (proxy, "get_properties", &error, + G_TYPE_STRING, _object_id.c_str(), G_TYPE_INVALID, + DBUS_TYPE_G_STRING_VARIANT_HASHTABLE, &dict, G_TYPE_INVALID)) + { + if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_REMOTE_EXCEPTION) + g_printerr ("Caught remote method exception %s: %s", + dbus_g_error_get_name (error), + error->message); + else + g_printerr ("Error: %s\n", error->message); + g_error_free (error); + exit (1); + } + + g_object_unref (proxy); + + GHashTableIter iter; + gchar *key; + GValue *value; + g_hash_table_iter_init (&iter, dict); + while (g_hash_table_iter_next (&iter, (gpointer *)&key, (gpointer *)&value)) + { + if( G_VALUE_HOLDS(value, G_TYPE_BOXED) ) { + GArray *array = (GArray *) g_value_get_boxed(value); + std::string value_s((gchar *) array->data, array->len); + (*properties)[key] = value_s; + } else { + (*properties)[key] = ""; + } + } + return properties; } @@ -51,21 +111,22 @@ datastore_get_properties(const fn_call& fn) if ( fn.nargs > 0 ) { - IF_VERBOSE_ASCODING_ERRORS( - std::stringstream ss; fn.dump_args(ss); - log_aserror("DataStore.get_properties(%s): all arguments discarded", ss.str().c_str()); - ); + IF_VERBOSE_ASCODING_ERRORS( + std::stringstream ss; fn.dump_args(ss); + log_aserror("DataStore.get_properties(%s): all arguments discarded", ss.str().c_str()); + ); } Properties *properties = ptr->get_properties(); - as_object *as_properties = new as_object; - string_table& st = ptr->getVM().getStringTable(); + as_object *as_properties = new as_object; + string_table& st = ptr->getVM().getStringTable(); for (Properties::iterator it=properties->begin(), - itE=properties->end(); - it != itE; ++it) - { - as_properties->set_member(st.find(it->first), it->second); + itE=properties->end(); + it != itE; ++it) + { + as_properties->set_member(st.find(it->first), + as_value(it->second)); } return as_value(as_properties); @@ -85,11 +146,11 @@ datastore_ctor(const fn_call& fn) if (fn.nargs < 1) { - IF_VERBOSE_ASCODING_ERRORS( - std::stringstream ss; fn.dump_args(ss); - log_aserror("new DataStore(%s): must pass an object id as argument", ss.str().c_str()); - ); - return as_value(); + IF_VERBOSE_ASCODING_ERRORS( + std::stringstream ss; fn.dump_args(ss); + log_aserror("new DataStore(%s): must pass an object id as argument", ss.str().c_str()); + ); + return as_value(); } std::string object_id = fn.arg(0).to_string(); @@ -102,17 +163,20 @@ extern "C" { void datastore_class_init(as_object &obj) { - GNASH_REPORT_FUNCTION; - // This is going to be the global "class"/"function" - static boost::intrusive_ptr<builtin_function> cl; - if (cl == NULL) { - cl = new builtin_function(&datastore_ctor, getInterface()); -// // replicate all interface to class, to be able to access -// // all methods as static functions - //attachInterface(*cl); - } - - obj.init_member("DataStore", cl.get()); + GNASH_REPORT_FUNCTION; + // This is going to be the global "class"/"function" + + g_type_init (); + + static boost::intrusive_ptr<builtin_function> cl; + if (cl == NULL) { + cl = new builtin_function(&datastore_ctor, getInterface()); +// // replicate all interface to class, to be able to access +// // all methods as static functions + //attachInterface(*cl); + } + + obj.init_member("DataStore", cl.get()); } } // end of extern C diff --git a/datastore/datastore.h b/datastore/datastore.h index 5f3b59b..9ad9fe9 100644 --- a/datastore/datastore.h +++ b/datastore/datastore.h @@ -32,7 +32,7 @@ public: ~DataStore(); Properties *get_properties(); private: -// GtkWidget *_window; + std::string _object_id; }; extern "C" { |