rc: allow specify different DBus service name at command line.
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Tue, 21 Aug 2012 14:45:15 +0000 (11:45 -0300)
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>
Tue, 21 Aug 2012 14:45:15 +0000 (11:45 -0300)
this allows one to run multiple instances of the dialer on the same
machine for demo purposes.

dialer/main.c
dialer/rc.c
dialer/rc.h

index 78d75dd..12449a7 100644 (file)
@@ -24,6 +24,9 @@ static const char def_modem_hfp_api[] =
 static const char def_modem_type[] =
        "hardware";
 
+static const char def_rc_service[] = "org.tizen.dialer";
+
+
 static const Ecore_Getopt options = {
        PACKAGE_NAME,
        "%prog [options]",
@@ -42,6 +45,8 @@ static const Ecore_Getopt options = {
                                        def_modem_type),
         ECORE_GETOPT_STORE_TRUE('T', "list-types",
                                        "list all oFono modem types."),
+        ECORE_GETOPT_STORE_STR('R', "rc-dbus-name",
+                               "The DBus name to use for the remote control."),
         ECORE_GETOPT_VERSION('V', "version"),
         ECORE_GETOPT_COPYRIGHT('C', "copyright"),
         ECORE_GETOPT_LICENSE('L', "license"),
@@ -60,6 +65,7 @@ EAPI int elm_main(int argc, char **argv)
        char *modem_api = NULL;
        char *modem_type = NULL;
        char *theme = NULL;
+       char *rc_service = NULL;
        Eina_Bool list_api = EINA_FALSE;
        Eina_Bool list_type = EINA_FALSE;
        Eina_Bool quit_option = EINA_FALSE;
@@ -70,6 +76,7 @@ EAPI int elm_main(int argc, char **argv)
                ECORE_GETOPT_VALUE_BOOL(list_api),
                ECORE_GETOPT_VALUE_STR(modem_type),
                ECORE_GETOPT_VALUE_BOOL(list_type),
+               ECORE_GETOPT_VALUE_STR(rc_service),
                ECORE_GETOPT_VALUE_BOOL(quit_option),
                ECORE_GETOPT_VALUE_BOOL(quit_option),
                ECORE_GETOPT_VALUE_BOOL(quit_option),
@@ -106,7 +113,15 @@ EAPI int elm_main(int argc, char **argv)
        if (quit_option)
                goto end;
 
-       if (!rc_init()) {
+       if (rc_service) {
+               INF("User-defined DBus remote control service name: %s",
+                       rc_service);
+       } else {
+               INF("Using default DBus remote control service name: %s",
+                       def_rc_service);
+       }
+
+       if (!rc_init(rc_service ? rc_service : def_rc_service)) {
                CRITICAL("Could not setup remote control via DBus.");
                _app_exit_code = EXIT_FAILURE;
                goto end;
index 340f466..85d47bd 100644 (file)
@@ -10,10 +10,11 @@ static E_DBus_Connection *bus_conn = NULL;
 static E_DBus_Object *bus_obj = NULL;
 static E_DBus_Interface *bus_iface = NULL;
 
-#define RC_SERVICE "org.tizen.dialer"
 #define RC_IFACE "org.tizen.dialer.Control"
 #define RC_PATH "/"
 
+static const char *rc_service = NULL;
+
 static DBusMessage *
 _rc_activate(E_DBus_Object *obj __UNUSED__, DBusMessage *msg)
 {
@@ -81,7 +82,7 @@ static void _rc_activate_existing_reply(void *data __UNUSED__,
 static void _rc_activate_existing(void)
 {
        DBusMessage *msg = dbus_message_new_method_call(
-               RC_SERVICE, RC_PATH, RC_IFACE, "Activate");
+               rc_service, RC_PATH, RC_IFACE, "Activate");
        e_dbus_message_send(bus_conn, msg,  _rc_activate_existing_reply,
                                -1, NULL);
        dbus_message_unref(msg);
@@ -113,8 +114,10 @@ static void _rc_request_name_reply(void *data __UNUSED__, DBusMessage *msg,
        }
 }
 
-Eina_Bool rc_init(void)
+Eina_Bool rc_init(const char *service)
 {
+       rc_service = service;
+
        if (!elm_need_e_dbus()) {
                CRITICAL("Elementary does not support DBus.");
                return EINA_FALSE;
@@ -126,7 +129,7 @@ Eina_Bool rc_init(void)
                return EINA_FALSE;
        }
 
-       e_dbus_request_name(bus_conn, RC_SERVICE, DBUS_NAME_FLAG_DO_NOT_QUEUE,
+       e_dbus_request_name(bus_conn, rc_service, DBUS_NAME_FLAG_DO_NOT_QUEUE,
                                _rc_request_name_reply, NULL);
        return EINA_TRUE;
 }
index b67dc72..7bc01cc 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef _EFL_OFONO_RC_H__
 #define _EFL_OFONO_RC_H__ 1
 
-Eina_Bool rc_init(void);
+Eina_Bool rc_init(const char *service);
 void rc_shutdown(void);
 
 #endif