4 #include <Elementary.h>
9 static E_DBus_Connection *bus_conn = NULL;
10 static E_DBus_Object *bus_obj = NULL;
11 static E_DBus_Interface *bus_iface = NULL;
13 #define RC_SERVICE "org.tizen.dialer"
14 #define RC_IFACE "org.tizen.dialer.Control"
18 _rc_activate(E_DBus_Object *obj __UNUSED__, DBusMessage *msg)
20 INF("Remotely activated!");
22 return dbus_message_new_method_return(msg);
26 _rc_dial(E_DBus_Object *obj __UNUSED__, DBusMessage *msg)
32 dbus_error_init(&err);
33 dbus_message_get_args(msg, &err, DBUS_TYPE_STRING, &number,
34 DBUS_TYPE_BOOLEAN, &do_auto, DBUS_TYPE_INVALID);
35 if (dbus_error_is_set(&err)) {
36 ERR("Could not parse message: %s: %s", err.name, err.message);
37 return dbus_message_new_error(msg, err.name, err.message);
40 INF("dial '%s' auto=%d!", number, do_auto);
43 gui_number_set(number, do_auto);
44 return dbus_message_new_method_return(msg);
47 static void _rc_object_register(void)
49 bus_obj = e_dbus_object_add(bus_conn, RC_PATH, NULL);
51 CRITICAL("Could not create "RC_PATH" DBus object.");
54 bus_iface = e_dbus_interface_new(RC_IFACE);
55 e_dbus_object_interface_attach(bus_obj, bus_iface);
57 #define IF_ADD(name, par, ret, cb) \
58 e_dbus_interface_method_add(bus_iface, name, par, ret, cb)
60 IF_ADD("Activate", "", "", _rc_activate);
61 IF_ADD("Dial", "sb", "", _rc_dial);
65 static void _rc_activate_existing_reply(void *data __UNUSED__,
66 DBusMessage *msg __UNUSED__,
69 if (dbus_error_is_set(err)) {
70 CRITICAL("Failed to activate existing dialer: %s: %s",
71 err->name, err->message);
72 _app_exit_code = EXIT_FAILURE;
73 ecore_main_loop_quit();
77 INF("Activated the existing dialer!");
78 ecore_main_loop_quit();
81 static void _rc_activate_existing(void)
83 DBusMessage *msg = dbus_message_new_method_call(
84 RC_SERVICE, RC_PATH, RC_IFACE, "Activate");
85 e_dbus_message_send(bus_conn, msg, _rc_activate_existing_reply,
87 dbus_message_unref(msg);
90 static void _rc_request_name_reply(void *data __UNUSED__, DBusMessage *msg,
98 WRN("%s: %s", err->name, err->message);
101 _rc_activate_existing();
106 dbus_message_get_args(msg, &e, DBUS_TYPE_UINT32, &t, DBUS_TYPE_INVALID);
107 if (t == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
108 _rc_object_register();
111 WRN("Dialer already running! Activate it!");
112 _rc_activate_existing();
116 Eina_Bool rc_init(void)
118 if (!elm_need_e_dbus()) {
119 CRITICAL("Elementary does not support DBus.");
123 bus_conn = e_dbus_bus_get(DBUS_BUS_SESSION);
125 CRITICAL("Could not get DBus System Bus");
129 e_dbus_request_name(bus_conn, RC_SERVICE, DBUS_NAME_FLAG_DO_NOT_QUEUE,
130 _rc_request_name_reply, NULL);
134 void rc_shutdown(void)
137 e_dbus_object_free(bus_obj);
139 e_dbus_interface_unref(bus_iface);