From 689dfde91b20189805c67664bd3417b4eed88187 Mon Sep 17 00:00:00 2001 From: "Carsten Haitzler (Rasterman)" Date: Tue, 14 Jan 2020 22:37:17 +0000 Subject: [PATCH] bluez5 - move from enlightenment_sys to e_system for l2ping and rfkill --- src/modules/bluez5/bz.h | 3 +- src/modules/bluez5/bz_obj.c | 120 +++++++++++++------------------- src/modules/bluez5/e_mod_main.c | 57 +++++---------- 3 files changed, 67 insertions(+), 113 deletions(-) diff --git a/src/modules/bluez5/bz.h b/src/modules/bluez5/bz.h index 63ebe00de..766ad85db 100644 --- a/src/modules/bluez5/bz.h +++ b/src/modules/bluez5/bz.h @@ -21,9 +21,8 @@ struct _Obj { Eina_Bool in_table : 1; Eina_Bool add_called : 1; Eina_Bool ping_ok : 1; + Eina_Bool ping_busy : 1; Ecore_Timer *ping_timer; - Ecore_Exe *ping_exe; - Ecore_Event_Handler *ping_exe_handler; //// public data to read const char *path; Obj_Type type; diff --git a/src/modules/bluez5/bz_obj.c b/src/modules/bluez5/bz_obj.c index b61dc698f..2728d63fd 100644 --- a/src/modules/bluez5/bz_obj.c +++ b/src/modules/bluez5/bz_obj.c @@ -537,35 +537,42 @@ bz_obj_disconnect(Obj *o) (o->proxy, "Disconnect", cb_disconnect, o, -1, ""); } -static Eina_Bool -cb_ping_exit(void *data, int type EINA_UNUSED, void *event) +static void +_cb_l2ping(void *data, const char *params) { Obj *o = data; - Ecore_Exe_Event_Del *ev = event; + char addr[256]; + int timeout = 0; - printf("@@@EXE EXIT.. %p == %p\n", ev->exe, o->ping_exe); - if (ev->exe != o->ping_exe) return ECORE_CALLBACK_PASS_ON; - printf("@@@PING RESULT... %i\n", ev->exit_code); - o->ping_exe = NULL; - if (ev->exit_code == 0) + if (sscanf(params, "%255s %i", addr, &timeout) == 2) { - if (!o->ping_ok) + if (!strcmp(o->address, addr)) { - printf("@@@PING SUCCEED\n"); - o->ping_ok = EINA_TRUE; - if (o->fn_change) o->fn_change(o); + if (o->ping_busy) + { + e_system_handler_del("l2ping-ping", _cb_l2ping, o); + o->ping_busy = EINA_FALSE; + } + if (timeout >= 0) + { + if (!o->ping_ok) + { + printf("@@@PING SUCCEED\n"); + o->ping_ok = EINA_TRUE; + if (o->fn_change) o->fn_change(o); + } + } + else + { + if (o->ping_ok) + { + printf("@@@PING FAIL\n"); + o->ping_ok = EINA_FALSE; + if (o->fn_change) o->fn_change(o); + } + } } } - else - { - if (o->ping_ok) - { - printf("@@@PING FAIL\n"); - o->ping_ok = EINA_FALSE; - if (o->fn_change) o->fn_change(o); - } - } - return ECORE_CALLBACK_PASS_ON; } static int @@ -584,24 +591,13 @@ ping_powersave_timeout_get(void) static void ping_do(Obj *o) { - Eina_Strbuf *buf; - - if (!o->ping_exe_handler) - o->ping_exe_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, - cb_ping_exit, o); - buf = eina_strbuf_new(); - if (buf) - { - int timeout = ping_powersave_timeout_get(); - - timeout *= 1000; - eina_strbuf_append_printf - (buf, "%s/enlightenment/utils/enlightenment_sys l2ping %s %i", - e_prefix_lib_get(), o->address, timeout); - o->ping_exe = ecore_exe_run(eina_strbuf_string_get(buf), NULL); - eina_strbuf_free(buf); - printf("@@@ run new ping %s %i = %p\n", o->address, timeout, o->ping_exe); - } + int timeout = 1000 * ping_powersave_timeout_get(); + if (o->ping_busy) + e_system_handler_del("l2ping-ping", _cb_l2ping, o); + o->ping_busy = EINA_TRUE; + e_system_handler_add("l2ping-ping", _cb_l2ping, o); + e_system_send("l2ping-ping", "%s %i", o->address, timeout); + printf("@@@ run new ping %s %i\n", o->address, timeout); } static Eina_Bool cb_ping_timer(void *data); @@ -621,11 +617,10 @@ cb_ping_timer(void *data) Obj *o = data; printf("@@@ ping timer %s\n", o->address); - if (o->ping_exe) + if (o->ping_busy) { - printf("@@@PING TIMEOUT\n"); - ecore_exe_free(o->ping_exe); - o->ping_exe = NULL; + o->ping_busy = EINA_FALSE; + e_system_handler_del("l2ping-ping", _cb_l2ping, o); if (o->ping_ok) { o->ping_ok = EINA_FALSE; @@ -641,15 +636,10 @@ void bz_obj_ping_begin(Obj *o) { if (o->ping_timer) return; - if (o->ping_exe_handler) + if (o->ping_busy) { - ecore_event_handler_del(o->ping_exe_handler); - o->ping_exe_handler = NULL; - } - if (o->ping_exe) - { - ecore_exe_free(o->ping_exe); - o->ping_exe = NULL; + o->ping_busy = EINA_FALSE; + e_system_handler_del("l2ping-ping", _cb_l2ping, o); } ping_do(o); ping_schedule(o); @@ -658,20 +648,15 @@ bz_obj_ping_begin(Obj *o) void bz_obj_ping_end(Obj *o) { - if (o->ping_exe_handler) - { - ecore_event_handler_del(o->ping_exe_handler); - o->ping_exe_handler = NULL; - } if (o->ping_timer) { ecore_timer_del(o->ping_timer); o->ping_timer = NULL; } - if (o->ping_exe) + if (o->ping_busy) { - ecore_exe_free(o->ping_exe); - o->ping_exe = NULL; + o->ping_busy = EINA_FALSE; + e_system_handler_del("l2ping-ping", _cb_l2ping, o); } if (o->ping_ok) { @@ -735,6 +720,11 @@ bz_obj_unref(Obj *o) o->in_table = EINA_FALSE; eina_hash_del(obj_table, o->path, o); } + if (o->ping_busy) + { + o->ping_busy = EINA_FALSE; + e_system_handler_del("l2ping-ping", _cb_l2ping, o); + } _obj_clear(o); if (o->prop_sig) { @@ -761,21 +751,11 @@ bz_obj_unref(Obj *o) bz_agent_msg_drop(o->agent_msg_ok); o->agent_msg_ok = NULL; } - if (o->ping_exe_handler) - { - ecore_event_handler_del(o->ping_exe_handler); - o->ping_exe_handler = NULL; - } if (o->ping_timer) { ecore_timer_del(o->ping_timer); o->ping_timer = NULL; } - if (o->ping_exe) - { - ecore_exe_free(o->ping_exe); - o->ping_exe = NULL; - } if (o->proxy) { eldbus_proxy_unref(o->proxy); diff --git a/src/modules/bluez5/e_mod_main.c b/src/modules/bluez5/e_mod_main.c index a581c466c..74a8a815a 100644 --- a/src/modules/bluez5/e_mod_main.c +++ b/src/modules/bluez5/e_mod_main.c @@ -9,9 +9,6 @@ static E_Config_DD *conf_device_edd = NULL; static E_Config_DD *conf_edd = NULL; Config *ebluez5_config = NULL; -static Ecore_Event_Handler *_exe_exit_handler = NULL; -static Ecore_Exe *_rfkill_exe = NULL; - E_API E_Module_Api e_modapi = {E_MODULE_API_VERSION, "Bluez5"}; static void @@ -288,44 +285,27 @@ ebluez5_popups_show(void) } } -static Eina_Bool -_exe_cb_exit(void *data EINA_UNUSED, int type EINA_UNUSED, void *event) +static void +_cb_rfkill_unblock(void *datam EINA_UNUSED, const char *params) { - Ecore_Exe_Event_Del *ev = event; + int ret_code = 0; - if (!ev->exe) return ECORE_CALLBACK_PASS_ON; - if (ev->exe == _rfkill_exe) - { - if ((ev->exited) && (ev->exit_code != EXIT_SUCCESS)) - { - e_util_dialog_show - (_("Bluetooth rfkill run Error"), - _("Trying to rfkill unblock the bluetooth adapter failed.
" - "Do you have rfkill installed? Check sysactions.conf
" - "to ensure the command is right and your user is
" - "permitted to use the rfkill unblock action. Check the
" - "users and groups there to be sure.")); - } - _rfkill_exe = NULL; - } - return ECORE_CALLBACK_PASS_ON; + sscanf(params, "%i %*s", &ret_code); + if (ret_code == 0) return; + + e_util_dialog_show + (_("Bluetooth rfkill run Error"), + _("Trying to rfkill unblock the bluetooth adapter failed.
" + "Do you have rfkill installed? Check sysactions.conf
" + "to ensure the command is right and your user is
" + "permitted to use the rfkill unblock action. Check the
" + "users and groups there to be sure.")); } void ebluez5_rfkill_unblock(const char *name) { - Eina_Strbuf *buf; - - // XXX: need config tp enable or disable this behavior - buf = eina_strbuf_new(); - if (buf) - { - eina_strbuf_append_printf - (buf, "%s/enlightenment/utils/enlightenment_sys rfkill-unblock %s", - e_prefix_lib_get(), name); - _rfkill_exe = ecore_exe_run(eina_strbuf_string_get(buf), NULL); - eina_strbuf_free(buf); - } + e_system_send("rfkill-unblock", "%s", name); } void @@ -475,8 +455,7 @@ e_modapi_init(E_Module *m) E_CONFIG_LIST(D, T, adapters, conf_adapter_edd); E_CONFIG_LIST(D, T, devices, conf_device_edd); - _exe_exit_handler = - ecore_event_handler_add(ECORE_EXE_EVENT_DEL, _exe_cb_exit, NULL); + e_system_handler_add("rfkill-unblock", _cb_rfkill_unblock, NULL); ebluez5_config = e_config_domain_load("module.ebluez5", conf_edd); if (!ebluez5_config) ebluez5_config = E_NEW(Config, 1); @@ -496,6 +475,7 @@ e_modapi_shutdown(E_Module *m EINA_UNUSED) Config_Adapter *ad; Config_Device *dev; + e_system_handler_del("rfkill-unblock", _cb_rfkill_unblock, NULL); EINA_LIST_FREE(ebluez5_config->adapters, ad) { eina_stringshare_del(ad->addr); @@ -515,11 +495,6 @@ e_modapi_shutdown(E_Module *m EINA_UNUSED) e_gadget_type_del("Bluetooth"); e_gadcon_provider_unregister(&_gc_class); - if (_exe_exit_handler) - { - ecore_event_handler_del(_exe_exit_handler); - _exe_exit_handler = NULL; - } E_CONFIG_DD_FREE(conf_edd); E_CONFIG_DD_FREE(conf_adapter_edd); return 1;