4 #include <Elementary.h>
7 #ifdef HAVE_NOTIFICATION
9 #include <notification.h>
16 static Eldbus_Connection *bus_conn = NULL;
17 static Eldbus_Service_Interface *bus_iface = NULL;
19 #define RC_IFACE "org.tizen.dialer.Control"
21 #define RC_SIG_CALL_ADDED "AddedCall"
22 #define RC_SIG_CALL_REMOVED "RemovedCall"
26 RC_SIGNAL_CALL_REMOVED
29 static const char *rc_service = NULL;
30 static OFono_Callback_List_Modem_Node *modem_changed_node = NULL;
31 static OFono_Callback_List_Call_Node *call_added = NULL;
32 static OFono_Callback_List_Call_Node *call_removed = NULL;
33 static OFono_Callback_List_Call_Node *call_changed = NULL;
34 static Eldbus_Message *pending_dial = NULL;
35 static OFono_Call *waiting = NULL;
37 static void _dial_number(const char *number, Eina_Bool do_auto)
39 INF("dial '%s' auto=%d!", number, do_auto);
42 gui_number_set(number, do_auto);
45 static void _modem_changed_cb(void *data __UNUSED__)
49 Eldbus_Message *reply;
51 if (!ofono_voice_is_online() || !pending_dial)
54 if (!eldbus_message_arguments_get(pending_dial, "sb", &number, &do_auto)) {
55 ERR("Could not pending dial arguments");
56 reply = eldbus_message_error_new(pending_dial, "Pending dial", "Invalid argument");
60 _dial_number(number, do_auto);
61 reply = eldbus_message_method_return_new(pending_dial);
63 eldbus_connection_send(bus_conn, reply, NULL, NULL, -1);
64 eldbus_message_unref(pending_dial);
68 static Eldbus_Message *
69 _rc_activate(Eldbus_Object *obj __UNUSED__, Eldbus_Message *msg)
71 INF("Remotely activated!");
73 return eldbus_message_method_return_new(msg);
76 static Eldbus_Message *
77 _rc_dial(Eldbus_Object *obj __UNUSED__, Eldbus_Message *msg)
82 if (!ofono_voice_is_online()) {
84 eldbus_message_unref(pending_dial);
85 pending_dial = eldbus_message_ref(msg);
89 if (!eldbus_message_arguments_get(msg, "sb", &number, &do_auto)) {
90 ERR("Could not get rc dial arguments");
91 return eldbus_message_error_new(msg, "RC dial", "Invalid argument");
94 _dial_number(number, do_auto);
95 return eldbus_message_method_return_new(msg);
98 static Eldbus_Message *_rc_hangup_call(Eldbus_Object *obj __UNUSED__,
102 return eldbus_message_error_new(msg,
103 "org.tizen.dialer.error.NotAvailable",
104 "No calls available");
107 ofono_call_hangup(waiting, NULL, NULL);
109 return eldbus_message_method_return_new(msg);
112 static Eldbus_Message *_rc_answer_call(Eldbus_Object *obj __UNUSED__,
115 OFono_Call_State state;
118 return eldbus_message_error_new(msg,
119 "org.tizen.dialer.error.NotAvailable",
120 "No calls available");
123 state = ofono_call_state_get(waiting);
124 if (state == OFONO_CALL_STATE_INCOMING)
125 ofono_call_answer(waiting, NULL, NULL);
126 else if (state == OFONO_CALL_STATE_WAITING)
127 ofono_hold_and_answer(NULL, NULL);
129 return eldbus_message_method_return_new(msg);
132 static void _new_call_sig_emit(OFono_Call *call)
135 const char *line_id, *name = "", *type = "", *img = "";
136 Contact_Info *c_info;
138 line_id = ofono_call_line_id_get(call);
139 c_info = gui_contact_search(line_id, &type);
142 name = contact_info_full_name_get(c_info);
143 img = contact_info_picture_get(c_info);
148 msg = eldbus_service_signal_new(bus_iface, RC_SIGNAL_CALL_ADDED);
149 EINA_SAFETY_ON_NULL_RETURN(msg);
151 eldbus_message_arguments_append(msg,"ssss", img, line_id, name, type);
152 eldbus_service_signal_send(bus_iface, msg);
155 #ifdef HAVE_NOTIFICATION
156 static void _system_notification_emit(OFono_Call *call)
158 const char *line_id, *type="", *content = "";
159 const char *title = "Incoming call";
160 Contact_Info *c_info;
161 notification_h noti = NULL;
162 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
164 noti = notification_new(NOTIFICATION_TYPE_NOTI,
165 NOTIFICATION_GROUP_ID_NONE,
166 NOTIFICATION_PRIV_ID_NONE);
168 ERR("Failed to create notification");
172 noti_err = notification_set_pkgname(noti, "org.tizen.dialer");
173 if (noti_err != NOTIFICATION_ERROR_NONE) {
174 ERR("Failed to set pkgname: %d", noti_err);
178 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_TITLE,
181 NOTIFICATION_VARIABLE_TYPE_NONE);
182 if (noti_err != NOTIFICATION_ERROR_NONE) {
183 ERR("Failed to set notification title: %d", noti_err);
187 line_id = ofono_call_line_id_get(call);
188 c_info = gui_contact_search(line_id, &type);
191 content = contact_info_full_name_get(c_info);
196 noti_err = notification_set_text(noti, NOTIFICATION_TEXT_TYPE_CONTENT,
199 NOTIFICATION_VARIABLE_TYPE_NONE);
200 if (noti_err != NOTIFICATION_ERROR_NONE) {
201 ERR("Failed to set notification content: %d", noti_err);
207 appsvc_set_pkgname(b, "org.tizen.dialer");
208 noti_err = notification_set_execute_option(noti, NOTIFICATION_EXECUTE_TYPE_SINGLE_LAUNCH, "Launch", NULL, b);
209 if (noti_err != NOTIFICATION_ERROR_NONE) {
210 ERR("Failed to set notification execute option: %d", noti_err);
214 noti_err = notification_insert(noti, NULL);
215 if (noti_err != NOTIFICATION_ERROR_NONE) {
216 ERR("Failed to send notification: %d", noti_err);
219 DBG("Sent notification: %s : %s", title, content);
221 noti_err = notification_free(noti);
222 if (noti_err != NOTIFICATION_ERROR_NONE) {
223 ERR("Failed to free notification: %d", noti_err);
229 static Eldbus_Message *_rc_waiting_call_get(Eldbus_Object *obj __UNUSED__,
233 const char *line_id, *name = "", *type = "", *img = "";
234 Contact_Info *c_info;
238 return eldbus_message_error_new(msg,
239 "org.tizen.dialer.error.NotAvailable",
240 "No calls available");
243 line_id = ofono_call_line_id_get(waiting);
244 c_info = gui_contact_search(line_id, &type);
247 name = contact_info_full_name_get(c_info);
248 img = contact_info_picture_get(c_info);
253 ret = eldbus_message_method_return_new(msg);
254 eldbus_message_arguments_append(msg,"ssss", img, line_id, name, type);
259 static const Eldbus_Method rc_methods[] = {
260 { "Activate", NULL, NULL, _rc_activate, },
261 { "Dial", ELDBUS_ARGS(
263 {"b", "do_auto"}), NULL, _rc_dial },
264 { "HangupCall", NULL, NULL, _rc_hangup_call, },
265 { "AnswerCall", NULL, NULL, _rc_answer_call, },
266 { "GetAvailableCall", NULL, ELDBUS_ARGS(
270 {"s", "type"}), _rc_waiting_call_get, ELDBUS_METHOD_FLAG_DEPRECATED },
274 static const Eldbus_Signal rc_signals[] = {
275 [RC_SIGNAL_CALL_ADDED] = { "AddedCall", ELDBUS_ARGS(
280 [RC_SIGNAL_CALL_REMOVED] = { "RemovedCall", NULL, 0 },
284 static const Eldbus_Service_Interface_Desc rc_iface_desc = {
285 RC_IFACE, rc_methods, rc_signals, NULL, NULL, NULL
288 static void _rc_object_register(void)
290 bus_iface = eldbus_service_interface_register(bus_conn, RC_PATH, &rc_iface_desc);
293 static void _rc_activate_existing_reply(void *data __UNUSED__, const Eldbus_Message *msg,
294 Eldbus_Pending *pending __UNUSED__)
296 const char *err_name, *err_message;
298 EINA_SAFETY_ON_NULL_RETURN(msg);
300 if (eldbus_message_error_get(msg, &err_name, &err_message)) {
301 ERR("Failed to activate existing dialer: %s: %s", err_name, err_message);
302 _app_exit_code = EXIT_FAILURE;
303 ecore_main_loop_quit();
307 INF("Activated the existing dialer!");
308 ecore_main_loop_quit();
311 static void _rc_activate_existing(void)
313 Eldbus_Message *msg = eldbus_message_method_call_new(
314 rc_service, RC_PATH, RC_IFACE, "Activate");
315 eldbus_connection_send(bus_conn, msg, _rc_activate_existing_reply, NULL, -1);
318 static void _rc_request_name_reply(void *data __UNUSED__, Eldbus_Message *msg,
319 Eldbus_Pending *pending __UNUSED__)
322 const char *err_name, *err_message;
324 EINA_SAFETY_ON_NULL_RETURN(msg);
326 if (eldbus_message_error_get(msg, &err_name, &err_message)) {
327 ERR("Failed to request name: %s: %s", err_name, err_message);
331 if (!eldbus_message_arguments_get(msg, "u", &t)) {
332 ERR("Could not get request name arguments");
333 _rc_activate_existing();
337 if (t == ELDBUS_NAME_REQUEST_REPLY_PRIMARY_OWNER) {
338 _rc_object_register();
341 WRN("Dialer already running! Activate it!");
342 _rc_activate_existing();
346 static void _removed_signal_send(void)
350 msg = eldbus_service_signal_new(bus_iface, RC_SIGNAL_CALL_REMOVED);
351 EINA_SAFETY_ON_NULL_RETURN(msg);
353 eldbus_service_signal_send(bus_iface, msg);
356 static void _rc_call_added_cb(void *data __UNUSED__, OFono_Call *call)
358 OFono_Call_State state = ofono_call_state_get(call);
360 if (state != OFONO_CALL_STATE_INCOMING &&
361 state != OFONO_CALL_STATE_WAITING)
365 _removed_signal_send();
368 _new_call_sig_emit(call);
370 #ifdef HAVE_NOTIFICATION
371 _system_notification_emit(call);
375 static void _rc_call_removed_cb(void *data __UNUSED__, OFono_Call *call)
379 _removed_signal_send();
383 static void _rc_call_changed_cb(void *data __UNUSED__, OFono_Call *call)
385 OFono_Call_State state;
390 state = ofono_call_state_get(call);
391 if (state == OFONO_CALL_STATE_INCOMING ||
392 state == OFONO_CALL_STATE_WAITING)
395 _removed_signal_send();
399 Eina_Bool rc_init(const char *service)
401 rc_service = service;
403 if (!elm_need_eldbus()) {
404 CRITICAL("Elementary does not support DBus.");
408 INF("Running on Session bus");
409 bus_conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SESSION);
412 CRITICAL("Could not get DBus Bus");
416 eldbus_name_request(bus_conn, rc_service, ELDBUS_NAME_REQUEST_FLAG_DO_NOT_QUEUE,
417 _rc_request_name_reply, NULL);
419 modem_changed_node = ofono_modem_changed_cb_add(_modem_changed_cb,
422 call_added = ofono_call_added_cb_add(_rc_call_added_cb, NULL);
423 call_removed = ofono_call_removed_cb_add(_rc_call_removed_cb, NULL);
424 call_changed = ofono_call_changed_cb_add(_rc_call_changed_cb, NULL);
429 void rc_shutdown(void)
432 eldbus_service_interface_unregister(bus_iface);
434 ofono_modem_changed_cb_del(modem_changed_node);
435 ofono_call_added_cb_del(call_added);
436 ofono_call_removed_cb_del(call_removed);
437 ofono_call_changed_cb_del(call_changed);
440 eldbus_message_unref(pending_dial);