build-sys: honour the --enable/disable-dbus command line option.
authorKrisztian Litkey <kli@iki.fi>
Tue, 20 Aug 2013 13:10:50 +0000 (16:10 +0300)
committerKrisztian Litkey <kli@iki.fi>
Tue, 20 Aug 2013 13:21:05 +0000 (16:21 +0300)
All components that depend on D-Bus are now disabled unless the
--enable-dbus option (and --enable-gpl that the former depends
on) is specified on the command line. Moreover, the client D-Bus
interace has been turned into a plugin, so the core does not depend
or know anything about D-Bus any more.

Note that after converting to a plugin the D-Bus client interface
has not been tested at all yet...

configure.ac
src/Makefile.am
src/client/client.c
src/daemon/config.c
src/daemon/context.h
src/daemon/daemon.c
src/daemon/dbusif.h [deleted file]
src/plugins/dbus-client-interface/Makefile [new file with mode: 0644]
src/plugins/dbus-client-interface/dbus-client.c [moved from src/daemon/dbusif.c with 72% similarity]
src/plugins/dbus-client-interface/dbus-config.h [moved from src/daemon/dbus-config.h with 94% similarity]

index 94491b1..0c88793 100644 (file)
@@ -93,10 +93,17 @@ AC_SUBST(WARNING_CFLAGS)
 
 # Check for the necessary Murphy components.
 PKG_CHECK_MODULES(MURPHY_COMMON,    murphy-common)
-PKG_CHECK_MODULES(MURPHY_DBUS,      murphy-dbus)
 PKG_CHECK_MODULES(MURPHY_PULSE,     murphy-pulse)
 PKG_CHECK_MODULES(MURPHY_RESOURCE,  murphy-resource)
 PKG_CHECK_MODULES(MURPHY_BREEDLINE, breedline-murphy)
+AC_SUBST(MURPHY_COMMON_CFLAGS)
+AC_SUBST(MURPHY_COMMON_LIBS)
+AC_SUBST(MURPHY_PULSE_CFLAGS)
+AC_SUBST(MURPHY_PULSE_LIBS)
+AC_SUBST(MURPHY_RESOURCE_CFLAGS)
+AC_SUBST(MURPHY_RESOURCE_LIBS)
+AC_SUBST(MURPHY_BREEDLINE_CFLAGS)
+AC_SUBST(MURPHY_BREEDLINE_LIBS)
 
 # Check for PulseAudio.
 PKG_CHECK_MODULES(PULSE, libpulse >= 0.9.22)
@@ -118,9 +125,10 @@ if test "$enable_dbus" = "yes"; then
         AC_MSG_ERROR([D-Bus support requires the --enable-gpl option.])
     fi
     PKG_CHECK_MODULES(DBUS, dbus-1 >= 0.70)
-
     DBUS_SESSION_DIR="`pkg-config --variable session_bus_services_dir dbus-1`"
     AC_SUBST(DBUS_SESSION_DIR)
+
+    PKG_CHECK_MODULES(MURPHY_DBUS, murphy-dbus)
 else
     AC_MSG_NOTICE([D-Bus support is disabled.])
 fi
@@ -131,6 +139,8 @@ fi
 
 AM_CONDITIONAL(DBUS_ENABLED, [test "$enable_dbus" = "yes"])
 AC_SUBST(DBUS_ENABLED)
+AC_SUBST(MURPHY_DBUS_CFLAGS)
+AC_SUBST(MURPHY_DBUS_LIBS)
 AC_SUBST(DBUS_CFLAGS)
 AC_SUBST(DBUS_LIBS)
 
@@ -145,19 +155,6 @@ AC_MSG_CHECKING([libdir])
 AC_MSG_RESULT([$libdir])
 AC_SUBST(LIBDIR, [$libdir])
 
-# Check for Check (unit test framework).
-PKG_CHECK_MODULES(CHECK, 
-                  check >= 0.9.4,
-                  [has_check="yes"], [has_check="no"])
-AM_CONDITIONAL(HAVE_CHECK, test "x$has_check" = "xyes")
-
-AC_SUBST(CHECK_CFLAGS)
-AC_SUBST(CHECK_LIBS)
-
-if test "x$has_check" = "xno"; then
-    AC_MSG_WARN([Check framework not found, unit tests are DISABLED.])
-fi
-
 # Check if sphinx was enabled.
 AC_ARG_ENABLE(sphinx,
               [  --enable-sphinx         enable pocketsphinx support in SRS],
index 89d887a..a49cdff 100644 (file)
@@ -1,11 +1,11 @@
 sbin_PROGRAMS      = srs-daemon
-bin_PROGRAMS       = srs-client
+bin_PROGRAMS       =
 
 plugindir          = $(libdir)/src/plugins
 plugin_LTLIBRARIES =
 
 INCLUDES           = -I$(top_builddir)
-AM_CFLAGS          = $(INCLUDES) $(DBUS_CFLAGS)
+AM_CFLAGS          = $(INCLUDES)
 
 QUIET_GEN          = $(Q:@=@echo '  GEN   '$@;)
 
@@ -19,7 +19,6 @@ srs_daemon_PUBLIC_SYMBOLS =                   \
 srs_daemon_SOURCES =                           \
                daemon/daemon.c                 \
                daemon/config.c                 \
-               daemon/dbusif.c                 \
                daemon/resourceif.c             \
                daemon/client.c                 \
                daemon/plugin.c                 \
@@ -30,25 +29,24 @@ srs_daemon_SOURCES =                                \
 srs_daemon_CFLAGS =                            \
                $(AM_CFLAGS)                    \
                $(MURPHY_PULSE_CFLAGS)          \
-               $(MURPHY_DBUS_CFLAGS)           \
                $(MURPHY_COMMON_CFLAGS)         \
                $(MURPHY_RESOURCE_CFLAGS)       \
-               $(PULSE_CFLAGS)                 \
-               $(DBUS_CFLAGS)
+               $(PULSE_CFLAGS)
 
 srs_daemon_LDADD =                             \
                $(MURPHY_PULSE_LIBS)            \
-               $(MURPHY_DBUS_LIBS)             \
                $(MURPHY_RESOURCE_LIBS)         \
                $(MURPHY_COMMON_LIBS)           \
                $(PULSE_LIBS)                   \
-               $(DBUS_LIBS)                    \
                -ldl
 
 srs_daemon_LDFLAGS =                           \
                -rdynamic
 
+if DBUS_ENABLED
 # SRS command line test clinet
+bin_PROGRAMS += srs-client
+
 srs_client_SOURCES =                           \
                client/client.c
 
@@ -67,6 +65,27 @@ srs_client_LDADD =                           \
                $(MURPHY_COMMON_LIBS)           \
                $(PULSE_LIBS)                   \
                $(DBUS_LIBS)
+endif
+
+
+if DBUS_ENABLED
+# D-Bus client interface plugin
+plugin_LTLIBRARIES += plugin-dbus-client.la
+
+plugin_dbus_client_la_SOURCES =                \
+               plugins/dbus-client-interface/dbus-client.c
+
+plugin_dbus_client_la_CFLAGS =                 \
+               $(AM_CFLAGS)                    \
+               $(DBUS_CFLAGS)                  \
+               $(MURPHY_DBUS_CFLAGS)
+
+plugin_dbus_client_la_LDFLAGS =                        \
+               -module -avoid-version
+
+plugin_dbus_client_la_LIBADD =                 \
+               $(MURPHY_DBUS_LIBS)
+endif
 
 # SRS fake speech engine plugin
 plugin_LTLIBRARIES += plugin-fake-speech.la
@@ -108,7 +127,6 @@ plugin_sphinx_speech_la_LIBADD  =                   \
                $(SPHINX_LIBS)
 endif
 
-
 # SRS Nuance speech engine plugin
 plugin_LTLIBRARIES += plugin-nuance-speech.la
 
@@ -137,6 +155,7 @@ plugin_simple_disambiguator_la_LDFLAGS =                    \
 
 plugin_simple_disambiguator_la_LIBADD  =
 
+if DBUS_ENABLED
 # Mpris2 client plugin
 plugin_LTLIBRARIES += plugin-mpris2-client.la
 
@@ -146,14 +165,20 @@ plugin_mpris2_client_la_SOURCES =                         \
                plugins/mpris2-client/clients.c
 
 plugin_mpris2_client_la_CFLAGS  =                              \
-               $(AM_CFLAGS)
+               $(AM_CFLAGS)                                    \
+               $(MURPHY_DBUS_CFLAGS)                           \
+               $(DBUS_CFLAGS)
 
 plugin_mpris2_client_la_LDFLAGS =                              \
                -module -avoid-version
 
-plugin_mpris2_client_la_LIBADD  =
+plugin_mpris2_client_la_LIBADD  =                              \
+               $(MURPHY_DBUS_LIBS)                             \
+               $(DBUS_LIBS)
+endif
 
 
+if DBUS_ENABLED
 # Bluetooth client plugin
 plugin_LTLIBRARIES += plugin-bluetooth-client.la
 
@@ -164,12 +189,18 @@ plugin_bluetooth_client_la_SOURCES =                              \
                plugins/bluetooth-client/clients.c
 
 plugin_bluetooth_client_la_CFLAGS  =                           \
-               $(AM_CFLAGS)
+               $(AM_CFLAGS)                                    \
+               $(MURPHY_DBUS_CFLAGS)                           \
+               $(DBUS_CFLAGS)
 
 plugin_bluetooth_client_la_LDFLAGS =                           \
                -module -avoid-version
 
-plugin_bluetooth_client_la_LIBADD  =
+plugin_bluetooth_client_la_LIBADD  =                           \
+               $(MURPHY_DBUS_LIBS)                             \
+               $(DBUS_LIBS)
+
+endif
 
 # search plugin
 plugin_LTLIBRARIES += plugin-search-client.la
index b0347e4..cd40af5 100644 (file)
@@ -41,7 +41,7 @@
 
 #include <breedline/breedline-murphy.h>
 
-#include "src/daemon/dbus-config.h"
+#include "plugins/dbus-client-interface/dbus-config.h"
 
 
 static const char *default_commands[] = {
index 7f2970b..629b96f 100644 (file)
@@ -67,8 +67,6 @@ static void print_usage(const char *argv0, int exit_code, const char *fmt, ...)
            "The possible options are:\n"
            "  -c, --config-file=PATH         main configuration file to use\n"
            "      The default configuration file is '%s'.\n"
-           "  -B, --dbus=BUS                 D-BUS type or address to use\n"
-           "      The default D-BUS is 'session'.\n"
            "  -P, --plugin-dir=PATH          use DIR to search for plugins\n"
            "      The default plugin directory is '%s'.\n"
            "  -L, --load-plugin=NAME         load the given plugin\n"
@@ -94,11 +92,10 @@ static void print_usage(const char *argv0, int exit_code, const char *fmt, ...)
 
 static void config_set_defaults(srs_context_t *srs)
 {
-    srs->config_file  = SRS_DEFAULT_CONFIG_FILE;
-    srs->plugin_dir   = SRS_DEFAULT_PLUGIN_DIR;
-    srs->dbus_address = "session";
-    srs->log_mask     = MRP_LOG_MASK_ERROR;
-    srs->log_target   = MRP_LOG_TO_STDERR;
+    srs->config_file = SRS_DEFAULT_CONFIG_FILE;
+    srs->plugin_dir  = SRS_DEFAULT_PLUGIN_DIR;
+    srs->log_mask    = MRP_LOG_MASK_ERROR;
+    srs->log_target  = MRP_LOG_TO_STDERR;
 }
 
 
@@ -243,7 +240,6 @@ void config_parse_cmdline(srs_context_t *srs, int argc, char **argv)
         { "load-plugin"  , required_argument, NULL, 'L' },
         { "log-level"    , required_argument, NULL, 'l' },
         { "log-target"   , required_argument, NULL, 't' },
-        { "dbus"         , required_argument, NULL, 'B' },
         { "set"          , required_argument, NULL, 's' },
         { "verbose"      , optional_argument, NULL, 'v' },
         { "debug"        , required_argument, NULL, 'd' },
@@ -297,10 +293,6 @@ void config_parse_cmdline(srs_context_t *srs, int argc, char **argv)
             srs->log_target = optarg;
             break;
 
-        case 'B':
-            srs->dbus_address = mrp_strdup(optarg);
-            break;
-
         case 's':
             config_parse_settings(srs, optarg);
             break;
index 39b7c13..f1153b7 100644 (file)
@@ -32,7 +32,6 @@
 
 #include <murphy/common/list.h>
 #include <murphy/common/pulse-glue.h>
-#include <murphy/common/dbus.h>
 #include <murphy/common/hashtbl.h>
 
 #include <murphy/plugins/resource-native/libmurphy-resource/resource-api.h>
@@ -49,7 +48,6 @@ typedef struct srs_context_s srs_context_t;
 struct srs_context_s {
     pa_mainloop       *pa;               /* pulseaudio mainloop */
     mrp_mainloop_t    *ml;               /* associated murphy mainloop */
-    mrp_dbus_t        *dbus;             /* D-BUS connection */
     mrp_list_hook_t    clients;          /* connected clients */
     mrp_list_hook_t    plugins;          /* loaded plugins */
     mrp_timer_t       *rtmr;             /* resource reconnect timer */
@@ -71,7 +69,6 @@ struct srs_context_s {
     const char      *log_target;         /* and where to log to */
 
     /* miscellaneous runtime settings and status */
-    const char      *dbus_address;       /* 'system', 'session', or address */
     int              foreground : 1;     /* whether to stay in foreground */
     int              exit_status;        /* mainloop exit status */
 
index 6a9ced0..e3f392b 100644 (file)
@@ -36,7 +36,6 @@
 
 #include "src/daemon/context.h"
 #include "src/daemon/config.h"
-#include "src/daemon/dbusif.h"
 #include "src/daemon/resourceif.h"
 #include "src/daemon/plugin.h"
 #include "src/daemon/client.h"
@@ -175,7 +174,6 @@ int main(int argc, char *argv[])
         setup_signals(srs);
         config_parse_cmdline(srs, argc, argv);
         setup_logging(srs);
-        dbusif_setup(srs);
 
         if (!srs_configure_plugins(srs)) {
             mrp_log_error("Some plugins failed to configure.");
@@ -198,7 +196,6 @@ int main(int argc, char *argv[])
         srs_stop_plugins(srs);
         srs_destroy_plugins(srs);
 
-        dbusif_cleanup(srs);
         cleanup_context(srs);
 
         exit(0);
diff --git a/src/daemon/dbusif.h b/src/daemon/dbusif.h
deleted file mode 100644 (file)
index 048ce4f..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (c) 2012, Intel Corporation
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- *   * Redistributions of source code must retain the above copyright notice,
- *     this list of conditions and the following disclaimer.
- *   * Redistributions in binary form must reproduce the above copyright
- *     notice, this list of conditions and the following disclaimer in the
- *     documentation and/or other materials provided with the distribution.
- *   * Neither the name of Intel Corporation nor the names of its contributors
- *     may be used to endorse or promote products derived from this software
- *     without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef __SRS_DAEMON_DBUSIF_H__
-#define __SRS_DAEMON_DBUSIF_H__
-
-#include "src/daemon/context.h"
-#include "src/daemon/dbus-config.h"
-
-void dbusif_setup(srs_context_t *srs);
-void dbusif_cleanup(srs_context_t *srs);
-
-#endif /* __SRS_DAEMON_DBUSIF_H__ */
diff --git a/src/plugins/dbus-client-interface/Makefile b/src/plugins/dbus-client-interface/Makefile
new file mode 100644 (file)
index 0000000..adcfe7e
--- /dev/null
@@ -0,0 +1,5 @@
+all:
+       $(MAKE) -C ../.. $@
+
+%:
+       $(MAKE) -C ../.. $(MAKECMDGOALS)
similarity index 72%
rename from src/daemon/dbusif.c
rename to src/plugins/dbus-client-interface/dbus-client.c
index 7892623..64f459e 100644 (file)
 
 #include <murphy/common/log.h>
 #include <murphy/common/debug.h>
+#include <murphy/common/debug.h>
 #include <murphy/common/dbus.h>
 
-#include "src/daemon/context.h"
+#include "src/daemon/plugin.h"
 #include "src/daemon/client.h"
-#include "src/daemon/dbusif.h"
+#include "dbus-config.h"
+
+#define PLUGIN_NAME    "search-client"
+#define PLUGIN_DESCR   "A trivial search plugin for SRS."
+#define PLUGIN_AUTHORS "Krisztian Litkey <kli@iki.fi>"
+#define PLUGIN_VERSION "0.0.1"
 
 #define MAX_COMMANDS 256
 
@@ -53,42 +59,52 @@ static int command_notify(srs_client_t *c, int idx, int ntoken, char **tokens,
 #define reply_unregister simple_reply
 #define reply_focus      simple_reply
 
+typedef struct {
+    srs_plugin_t *self;                  /* our plugin instance */
+    const char   *address;               /* bus address */
+    mrp_dbus_t   *dbus;                  /* bus we're on */
+} dbusif_t;
+
+
+static void dbusif_cleanup(dbusif_t *bus);
 
-void dbusif_setup(srs_context_t *srs)
+
+static int dbusif_setup(dbusif_t *bus)
 {
-    const char *path, *iface, *method;
-    int       (*cb)(mrp_dbus_t *, DBusMessage *, void *);
+    srs_context_t  *srs = bus->self->srs;
+    const char     *path, *iface, *method;
+    int           (*cb)(mrp_dbus_t *, DBusMessage *, void *);
 
-    mrp_debug("setting up client D-BUS interface (%s)", srs->dbus_address);
+    mrp_debug("setting up client D-BUS interface (%s)", bus->address);
 
-    srs->dbus = mrp_dbus_get(srs->ml, srs->dbus_address, NULL);
+    bus->dbus = mrp_dbus_get(srs->ml, bus->address, NULL);
 
-    if (srs->dbus != NULL) {
+    if (bus->dbus != NULL) {
         path   = SRS_SERVICE_PATH;
         iface  = SRS_SERVICE_INTERFACE;
 
         method = SRS_METHOD_REGISTER;
         cb     = register_cb;
-        if (!mrp_dbus_export_method(srs->dbus, path, iface, method, cb, srs)) {
+        if (!mrp_dbus_export_method(bus->dbus, path, iface, method, cb, bus)) {
             mrp_log_error("Failed to register D-BUS '%s' method.", method);
             goto fail;
         }
 
         method = SRS_METHOD_UNREGISTER;
         cb     = unregister_cb;
-        if (!mrp_dbus_export_method(srs->dbus, path, iface, method, cb, srs)) {
+        if (!mrp_dbus_export_method(bus->dbus, path, iface, method, cb, bus)) {
             mrp_log_error("Failed to register D-BUS '%s' method.", method);
             goto fail;
         }
 
         method = SRS_METHOD_FOCUS;
         cb     = focus_cb;
-        if (!mrp_dbus_export_method(srs->dbus, path, iface, method, cb, srs)) {
+        if (!mrp_dbus_export_method(bus->dbus, path, iface, method, cb, bus)) {
             mrp_log_error("Failed to register D-BUS '%s' method.", method);
             goto fail;
         }
 
-        if (!mrp_dbus_acquire_name(srs->dbus, SRS_SERVICE_NAME, NULL)) {
+        if (!mrp_dbus_acquire_name(bus->dbus, SRS_SERVICE_NAME, NULL)) {
             mrp_log_error("Failed to acquire D-BUS name '%s'.",
                           SRS_SERVICE_NAME);
             goto fail;
@@ -96,44 +112,46 @@ void dbusif_setup(srs_context_t *srs)
 
     }
     else {
-        mrp_log_error("Failed to connect to D-BUS (%s).", srs->dbus_address);
-        exit(1);
+        mrp_log_error("Failed to connect to D-BUS (%s).", bus->address);
+        goto fail;
     }
 
-    return;
+    return TRUE;
 
  fail:
-    dbusif_cleanup(srs);
+    dbusif_cleanup(bus);
+    return FALSE;
 }
 
 
-void dbusif_cleanup(srs_context_t *srs)
+static void dbusif_cleanup(dbusif_t *bus)
 {
-    const char *path, *iface, *method;
-    int       (*cb)(mrp_dbus_t *, DBusMessage *, void *);
+    srs_context_t  *srs = bus->self->srs;
+    const char     *path, *iface, *method;
+    int           (*cb)(mrp_dbus_t *, DBusMessage *, void *);
 
     mrp_debug("cleaning up client D-BUS interface");
 
-    if (srs->dbus != NULL) {
-        mrp_dbus_release_name(srs->dbus, SRS_SERVICE_NAME, NULL);
+    if (bus->dbus != NULL) {
+        mrp_dbus_release_name(bus->dbus, SRS_SERVICE_NAME, NULL);
 
         path   = SRS_SERVICE_PATH;
         iface  = SRS_SERVICE_INTERFACE;
 
         method = SRS_METHOD_REGISTER;
         cb     = register_cb;
-        mrp_dbus_remove_method(srs->dbus, path, iface, method, cb, srs);
+        mrp_dbus_remove_method(bus->dbus, path, iface, method, cb, bus);
 
         method = SRS_METHOD_UNREGISTER;
         cb     = unregister_cb;
-        mrp_dbus_remove_method(srs->dbus, path, iface, method, cb, srs);
+        mrp_dbus_remove_method(bus->dbus, path, iface, method, cb, bus);
 
         method = SRS_METHOD_FOCUS;
         cb     = focus_cb;
-        mrp_dbus_remove_method(srs->dbus, path, iface, method, cb, srs);
+        mrp_dbus_remove_method(bus->dbus, path, iface, method, cb, bus);
 
-        mrp_dbus_unref(srs->dbus);
-        srs->dbus = NULL;
+        mrp_dbus_unref(bus->dbus);
+        bus->dbus = NULL;
     }
 }
 
@@ -141,7 +159,8 @@ void dbusif_cleanup(srs_context_t *srs)
 static void name_change_cb(mrp_dbus_t *dbus, const char *name, int running,
                            const char *owner, void *user_data)
 {
-    srs_context_t *srs = (srs_context_t *)user_data;
+    dbusif_t      *bus = (dbusif_t *)user_data;
+    srs_context_t *srs = bus->self->srs;
     srs_client_t  *c;
 
     MRP_UNUSED(owner);
@@ -154,7 +173,7 @@ static void name_change_cb(mrp_dbus_t *dbus, const char *name, int running,
         if (c != NULL) {
             mrp_log_info("client %s disconnected from D-BUS", name);
             client_destroy(c);
-            mrp_dbus_forget_name(dbus, name, name_change_cb, user_data);
+            mrp_dbus_forget_name(dbus, name, name_change_cb, bus);
         }
     }
 }
@@ -248,7 +267,8 @@ static int register_cb(mrp_dbus_t *dbus, DBusMessage *req, void *user_data)
         .notify_command = command_notify
     };
 
-    srs_context_t   *srs = (srs_context_t *)user_data;
+    dbusif_t        *bus = (dbusif_t *)user_data;
+    srs_context_t   *srs = bus->self->srs;
     const char      *id, *name, *appcls, *errmsg;
     char            *cmds[MAX_COMMANDS];
     int              ncmd, err;
@@ -269,7 +289,7 @@ static int register_cb(mrp_dbus_t *dbus, DBusMessage *req, void *user_data)
                       id, &ops, NULL);
 
     if (c != NULL) {
-        if (mrp_dbus_follow_name(dbus, id, name_change_cb, srs)) {
+        if (mrp_dbus_follow_name(dbus, id, name_change_cb, bus)) {
             err    = 0;
             errmsg = NULL;
         }
@@ -305,7 +325,8 @@ static int parse_unregister(DBusMessage *req, const char **id,
 
 static int unregister_cb(mrp_dbus_t *dbus, DBusMessage *req, void *user_data)
 {
-    srs_context_t *srs = (srs_context_t *)user_data;
+    dbusif_t      *bus = (dbusif_t *)user_data;
+    srs_context_t *srs = bus->self->srs;
     const char    *id, *errmsg;
     srs_client_t  *c;
     int            err;
@@ -318,7 +339,7 @@ static int unregister_cb(mrp_dbus_t *dbus, DBusMessage *req, void *user_data)
         c = client_lookup_by_id(srs, id);
 
         if (c != NULL) {
-            mrp_dbus_forget_name(dbus, c->id, name_change_cb, srs);
+            mrp_dbus_forget_name(dbus, c->id, name_change_cb, bus);
             client_destroy(c);
             reply_unregister(dbus, req, 0, NULL);
         }
@@ -367,7 +388,8 @@ static int parse_focus(DBusMessage *req, const char **id, int *focus,
 
 static int focus_cb(mrp_dbus_t *dbus, DBusMessage *req, void *user_data)
 {
-    srs_context_t *srs = (srs_context_t *)user_data;
+    dbusif_t      *bus = (dbusif_t *)user_data;
+    srs_context_t *srs = bus->self->srs;
     const char    *id, *errmsg;
     int            focus, err;
     srs_client_t  *c;
@@ -397,6 +419,7 @@ static int focus_cb(mrp_dbus_t *dbus, DBusMessage *req, void *user_data)
 
 static int focus_notify(srs_client_t *c, srs_voice_focus_t focus)
 {
+    dbusif_t      *bus   = c->user_data;
     srs_context_t *srs   = c->srs;
     const char    *dest  = c->id;
     const char    *path  = SRS_SERVICE_PATH;
@@ -411,7 +434,7 @@ static int focus_notify(srs_client_t *c, srs_voice_focus_t focus)
     default:                        return FALSE;
     }
 
-    return mrp_dbus_signal(srs->dbus, dest, path, iface, sig,
+    return mrp_dbus_signal(bus->dbus, dest, path, iface, sig,
                            DBUS_TYPE_STRING, &state, DBUS_TYPE_INVALID);
 }
 
@@ -419,6 +442,7 @@ static int focus_notify(srs_client_t *c, srs_voice_focus_t focus)
 static int command_notify(srs_client_t *c, int idx, int ntoken, char **tokens,
                           uint32_t *start, uint32_t *end, srs_audiobuf_t *audio)
 {
+    dbusif_t      *bus   = c->user_data;
     srs_context_t *srs   = c->srs;
     const char    *dest  = c->id;
     const char    *path  = SRS_SERVICE_PATH;
@@ -448,6 +472,81 @@ static int command_notify(srs_client_t *c, int idx, int ntoken, char **tokens,
         t  = " ";
     }
 
-    return mrp_dbus_signal(srs->dbus, dest, path, iface, sig,
+    return mrp_dbus_signal(bus->dbus, dest, path, iface, sig,
                            DBUS_TYPE_STRING, &cmd, DBUS_TYPE_INVALID);
 }
+
+
+static int create_dbusif(srs_plugin_t *plugin)
+{
+    dbusif_t *bus;
+
+    mrp_debug("creating D-Bus client interface plugin");
+
+    bus = mrp_allocz(sizeof(*bus));
+
+    if (bus != NULL) {
+        bus->self = plugin;
+        plugin->plugin_data = bus;
+        return TRUE;
+    }
+    else
+        return FALSE;
+}
+
+
+static int config_dbusif(srs_plugin_t *plugin, srs_cfg_t *settings)
+{
+    dbusif_t *bus = (dbusif_t *)plugin->plugin_data;
+
+    MRP_UNUSED(settings);
+
+    mrp_debug("configure D-Bus client interface plugin");
+
+    bus->address = srs_get_string_config(settings, "dbus.address", "session");
+
+    mrp_log_info("Client interface D-Bus address: '%s'", bus->address);
+
+    return dbusif_setup(bus);
+}
+
+
+static int start_dbusif(srs_plugin_t *plugin)
+{
+    dbusif_t *bus = (dbusif_t *)plugin->plugin_data;
+
+    MRP_UNUSED(bus);
+
+    mrp_debug("start D-Bus client interface plugin");
+
+    return TRUE;
+}
+
+
+static void stop_dbusif(srs_plugin_t *plugin)
+{
+    dbusif_t *bus = (dbusif_t *)plugin->plugin_data;
+
+    mrp_debug("stop D-Bus client interface plugin");
+
+    return;
+}
+
+
+static void destroy_dbusif(srs_plugin_t *plugin)
+{
+    srs_context_t *srs = plugin->srs;
+    dbusif_t      *dbus = (dbusif_t *)plugin->plugin_data;
+
+    MRP_UNUSED(srs);
+
+    mrp_debug("destroy D-Bus client interface plugin");
+
+    dbusif_cleanup(dbus);
+    mrp_free(dbus);
+}
+
+
+SRS_DECLARE_PLUGIN(PLUGIN_NAME, PLUGIN_DESCR, PLUGIN_AUTHORS, PLUGIN_VERSION,
+                   create_dbusif, config_dbusif, start_dbusif, stop_dbusif,
+                   destroy_dbusif)
similarity index 94%
rename from src/daemon/dbus-config.h
rename to src/plugins/dbus-client-interface/dbus-config.h
index d8a33b1..c52e938 100644 (file)
@@ -27,8 +27,8 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef __SRS_DAEMON_DBUS_SETUP_H__
-#define __SRS_DAEMON_DBUS_SETUP_H__
+#ifndef __SRS_DBUS_PLUGIN_CONFIG_H__
+#define __SRS_DBUS_PLUGIN_CONFIG_H__
 
 #define SRS_SERVICE_NAME      "org.tizen.srs"
 #define SRS_SERVICE_PATH      "/srs"
@@ -41,4 +41,4 @@
 #define SRS_SIGNAL_FOCUS      "FocusChanged"  /* voice focus notification */
 #define SRS_SIGNAL_COMMAND    "VoiceCommand"  /* voice command notification */
 
-#endif /* __SRS_DAEMON_DBUS_SETUP_H__ */
+#endif /* __SRS_DBUS_PLUGIN_CONFIG_H__ */