From: Gwanglim Lee Date: Mon, 12 Nov 2018 07:18:57 +0000 (+0900) Subject: changed to use e_dbus_conn instead of using eldbus directly when connecting D-BUS X-Git-Tag: accepted/tizen/5.0/unified/20181115.063703^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a131082133ca7f6a32a9c3d17b772210cf746eea;p=platform%2Fcore%2Fuifw%2Fe-mod-tizen-processmgr.git changed to use e_dbus_conn instead of using eldbus directly when connecting D-BUS Change-Id: I9d0a367106b0e2b23f530531d8d3edb9cf0b9e93 --- diff --git a/src/e_mod_processmgr.c b/src/e_mod_processmgr.c index 4a4efb7..6935fa8 100644 --- a/src/e_mod_processmgr.c +++ b/src/e_mod_processmgr.c @@ -8,8 +8,9 @@ static Eina_List *hooks_ec = NULL; static Eina_List *_e_processmgr_ec_handlers = NULL; static Eina_List *_e_processmgr_wl_hooks = NULL; -Eldbus_Connection *_e_processmgr_conn; -Eldbus_Service_Interface *_e_processmgr_iface; +static Eldbus_Connection *_dbus_conn = NULL; +static Eldbus_Service_Interface *_dbus_iface = NULL; +static Ecore_Event_Handler *_dbus_init_done = NULL; // global res_id, geo(x,y,w,h), alpha, visibility, focused, pid, parent pid, acestor pid, noti level, opaque #define VALUE_TYPE_FOR_VISIBLE_WINS "uiiiibibiiiib" @@ -41,7 +42,7 @@ _e_processmgr_process_action_send(int pid, E_Process_Action act) int param_pid; int param_act; - if (!_e_processmgr_conn) return; + EINA_SAFETY_ON_NULL_RETURN(_dbus_conn); // set up msg for resourced msg = eldbus_message_signal_new("/Org/Tizen/ResourceD/Process", @@ -61,7 +62,7 @@ _e_processmgr_process_action_send(int pid, E_Process_Action act) ELOGF("PROCESSMGR", "SEND ACTION:%d to PID:%d", NULL, NULL, act, pid); // send the message - if (!eldbus_connection_send(_e_processmgr_conn, msg, NULL, NULL, -1)) + if (!eldbus_connection_send(_dbus_conn, msg, NULL, NULL, -1)) return; eldbus_message_unref(msg); @@ -299,53 +300,6 @@ _e_processmgr_focus_pid_get(const Eldbus_Service_Interface *iface EINA_UNUSED, c return reply; } -static Eina_Bool -_e_processmgr_dbus_init(void *data EINA_UNUSED) -{ - if (_e_processmgr_conn) return ECORE_CALLBACK_CANCEL; - - if (!_e_processmgr_conn) - _e_processmgr_conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM); - - if(!_e_processmgr_conn) - { - ecore_timer_add(1, _e_processmgr_dbus_init, NULL); - return ECORE_CALLBACK_CANCEL; - } - - _e_processmgr_iface = eldbus_service_interface_register(_e_processmgr_conn, - PATH, - &iface_desc); - EINA_SAFETY_ON_NULL_GOTO(_e_processmgr_iface, err); - - return ECORE_CALLBACK_CANCEL; - -err: - if (_e_processmgr_conn) - { - eldbus_connection_unref(_e_processmgr_conn); - _e_processmgr_conn = NULL; - } - - return ECORE_CALLBACK_CANCEL; -} - -static void -_e_processmgr_dbus_shutdown(void) -{ - if (_e_processmgr_iface) - { - eldbus_service_interface_unregister(_e_processmgr_iface); - _e_processmgr_iface = NULL; - } - - if (_e_processmgr_conn) - { - eldbus_connection_unref(_e_processmgr_conn); - _e_processmgr_conn = NULL; - } -} - static void _e_processmgr_cb_launch_done(void *data, Evas_Object *obj, const char *signal, const char *source) { @@ -411,15 +365,70 @@ _e_processmgr_cb_client_reuse(void *data EINA_UNUSED, E_Client *ec) ec); } +static Eina_Bool +_dbus_init(void) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(_dbus_conn, EINA_FALSE); + + _dbus_iface = eldbus_service_interface_register(_dbus_conn, + PATH, + &iface_desc); + EINA_SAFETY_ON_NULL_RETURN_VAL(_dbus_iface, EINA_FALSE); + + return EINA_TRUE; +} + +static Eina_Bool +_cb_dbus_init_done(void *data, int type, void *ev) +{ + E_DBus_Conn_Init_Done_Event *e = ev; + Eina_Bool res; + + if (!((e->conn_type == ELDBUS_CONNECTION_TYPE_SYSTEM) && + (e->status == E_DBUS_CONN_INIT_SUCCESS))) + { + return ECORE_CALLBACK_PASS_ON; + } + + _dbus_conn = e_dbus_conn_connection_ref(ELDBUS_CONNECTION_TYPE_SYSTEM); + EINA_SAFETY_ON_NULL_GOTO(_dbus_conn, cleanup); + + res = _dbus_init(); + if (!res) + { + eldbus_connection_unref(_dbus_conn); + _dbus_conn = NULL; + } + +cleanup: + ecore_event_handler_del(_dbus_init_done); + _dbus_init_done = NULL; + + return ECORE_CALLBACK_PASS_ON; +} + EAPI Eina_Bool e_mod_processmgr_init(void) { E_Process_Hook *hook; + Eina_Bool res; - if (!eldbus_init()) - return EINA_FALSE; + if (e_dbus_conn_init() > 0) + { + _dbus_init_done = ecore_event_handler_add(E_EVENT_DBUS_CONN_INIT_DONE, + _cb_dbus_init_done, + NULL); - _e_processmgr_dbus_init(NULL); + e_dbus_conn_dbus_init(ELDBUS_CONNECTION_TYPE_SYSTEM); + } + else + { + _dbus_conn = e_dbus_conn_connection_ref(ELDBUS_CONNECTION_TYPE_SYSTEM); + EINA_SAFETY_ON_NULL_RETURN_VAL(_dbus_conn, EINA_FALSE); + + res = _dbus_init(); + EINA_SAFETY_ON_FALSE_GOTO(res, err); + } hook = e_process_hook_add(E_PROCESS_HOOK_ACTION_CHANGE, _e_processmgr_cb_hook_action_change, NULL); if (hook) hooks_ec = eina_list_append(hooks_ec, hook); @@ -430,6 +439,15 @@ e_mod_processmgr_init(void) E_COMP_WL_HOOK_APPEND(_e_processmgr_wl_hooks, E_COMP_WL_HOOK_CLIENT_REUSE, _e_processmgr_cb_client_reuse, NULL); return EINA_TRUE; + +err: + if (_dbus_conn) + { + e_dbus_conn_connection_unref(_dbus_conn); + e_dbus_conn_shutdown(); + _dbus_conn = NULL; + } + return EINA_FALSE; } EAPI void @@ -437,13 +455,23 @@ e_mod_processmgr_shutdown(void) { E_Process_Hook *hook; - _e_processmgr_dbus_shutdown(); + if (_dbus_init_done) + ecore_event_handler_del(_dbus_init_done); + + if (_dbus_iface) + eldbus_service_interface_unregister(_dbus_iface); - eldbus_shutdown(); + if (_dbus_conn) + e_dbus_conn_connection_unref(_dbus_conn); + + e_dbus_conn_shutdown(); + + _dbus_init_done = NULL; + _dbus_iface = NULL; + _dbus_conn = NULL; E_FREE_LIST(_e_processmgr_wl_hooks, e_comp_wl_hook_del); E_FREE_LIST(_e_processmgr_ec_handlers, ecore_event_handler_del); EINA_LIST_FREE(hooks_ec, hook) e_process_hook_del(hook); } -