]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Maemo: Register with libosso and init Glib main loop.
authorTobias Brunner <tobias@strongswan.org>
Mon, 20 Sep 2010 15:35:28 +0000 (17:35 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 14 Oct 2010 15:36:18 +0000 (17:36 +0200)
configure.in
src/libcharon/plugins/maemo/Makefile.am
src/libcharon/plugins/maemo/maemo_plugin.c

index cefd258c1f52e5404f8efbe66a04b19e05753b56..7a21d22f76406b1e5e4ee982281dc031297656ae 100644 (file)
@@ -626,6 +626,9 @@ if test x$android = xtrue; then
 fi
 
 if test x$maemo = xtrue; then
+       PKG_CHECK_MODULES(maemo, [glib-2.0 gthread-2.0 libosso osso-af-settings])
+       AC_SUBST(maemo_CFLAGS)
+       AC_SUBST(maemo_LIBS)
        dbusservicedir="/usr/share/dbus-1/system-services"
        AC_SUBST(dbusservicedir)
 fi
index 850f9040e9d7c39b8abdb1375b95d8fa5eafdf26..71e9c9ae99447ba4022a61b0ad8c719b472ddbfa 100644 (file)
@@ -14,6 +14,7 @@ libstrongswan_maemo_la_SOURCES = \
        maemo_plugin.h maemo_plugin.c
 
 libstrongswan_maemo_la_LDFLAGS = -module -avoid-version
+libstrongswan_maemo_la_LIBADD  = ${maemo_LIBS}
 
 dbusservice_DATA = org.strongswan.charon.service
 
index ebf0c969c4f3b09053d12de5e6b8bf1f52078cb1..8673c339e56de4f5b3a599f44fa2e4c50cf1d3ac 100644 (file)
  * for more details.
  */
 
+#include <glib.h>
+#include <libosso.h>
+
 #include "maemo_plugin.h"
 
 #include <daemon.h>
+#include <processing/jobs/callback_job.h>
+
+#define OSSO_CHARON_NAME       "charon"
+#define OSSO_CHARON_SERVICE    "org.strongswan."OSSO_CHARON_NAME
+#define OSSO_CHARON_OBJECT     "/org/strongswan/"OSSO_CHARON_NAME
+#define OSSO_CHARON_IFACE      "org.strongswan."OSSO_CHARON_NAME
 
 typedef struct private_maemo_plugin_t private_maemo_plugin_t;
 
@@ -29,11 +38,53 @@ struct private_maemo_plugin_t {
         */
        maemo_plugin_t public;
 
+       /**
+        * Glib main loop for a thread, handles DBUS calls
+        */
+       GMainLoop *loop;
+
+       /**
+        * Context for OSSO
+        */
+       osso_context_t *context;
+
 };
 
+/**
+ * Callback for libosso dbus wrapper
+ */
+static gint dbus_req_handler(const gchar *interface, const gchar *method,
+                                                        GArray *arguments, private_maemo_plugin_t *this,
+                                                        osso_rpc_t *retval)
+{
+       return OSSO_OK;
+}
+
+/**
+ * Main loop to handle D-BUS messages.
+ */
+static job_requeue_t run(private_maemo_plugin_t *this)
+{
+       this->loop = g_main_loop_new(NULL, FALSE);
+       g_main_loop_run(this->loop);
+       return JOB_REQUEUE_NONE;
+}
+
 METHOD(plugin_t, destroy, void,
           private_maemo_plugin_t *this)
 {
+       if (this->loop)
+       {
+               if (g_main_loop_is_running(this->loop))
+               {
+                       g_main_loop_quit(this->loop);
+               }
+               g_main_loop_unref(this->loop);
+       }
+       if (this->context)
+       {
+               osso_deinitialize(this->context);
+       }
        free(this);
 }
 
@@ -42,6 +93,7 @@ METHOD(plugin_t, destroy, void,
  */
 plugin_t *maemo_plugin_create()
 {
+       osso_return_t result;
        private_maemo_plugin_t *this;
 
        INIT(this,
@@ -50,6 +102,36 @@ plugin_t *maemo_plugin_create()
                },
        );
 
+       this->context = osso_initialize(OSSO_CHARON_SERVICE, "0.0.1", TRUE, NULL);
+       if (!this->context)
+       {
+               DBG1(DBG_CFG, "failed to initialize OSSO context");
+               destroy(this);
+               return NULL;
+       }
+
+       result = osso_rpc_set_cb_f(this->context,
+                                                          OSSO_CHARON_SERVICE,
+                                                          OSSO_CHARON_OBJECT,
+                                                          OSSO_CHARON_IFACE,
+                                                          (osso_rpc_cb_f*)dbus_req_handler,
+                                                          this);
+       if (result != OSSO_OK)
+       {
+               DBG1(DBG_CFG, "failed to set D-BUS callback (%d)", result);
+               destroy(this);
+               return NULL;
+       }
+
+       this->loop = NULL;
+       if (!g_thread_supported())
+       {
+               g_thread_init(NULL);
+       }
+
+       lib->processor->queue_job(lib->processor,
+               (job_t*)callback_job_create((callback_job_cb_t)run, this, NULL, NULL));
+
        return &this->public.plugin;
 }