From 899523729549416d401889c7c02743a8861ab131 Mon Sep 17 00:00:00 2001 From: Dipen Somani Date: Thu, 18 May 2017 10:51:00 +0530 Subject: [PATCH] e_info_server: Added a new hook Change-Id: I82214877fbbea9a623b1aa46ec266191e8cbefb6 Signed-off-by: Dipen Somani --- src/bin/e_info_server.c | 82 +++++++++++++++++++++++++++++++++++++++++ src/bin/e_info_server.h | 26 +++++++++++++ 2 files changed, 108 insertions(+) mode change 100644 => 100755 src/bin/e_info_server.c mode change 100644 => 100755 src/bin/e_info_server.h diff --git a/src/bin/e_info_server.c b/src/bin/e_info_server.c old mode 100644 new mode 100755 index 0b401b9b0f..4a2f7ea5f0 --- a/src/bin/e_info_server.c +++ b/src/bin/e_info_server.c @@ -93,6 +93,86 @@ static void _e_info_transform_set(E_Info_Transform *transform, int static void _e_info_transform_del(E_Info_Transform *transform); static void _e_info_transform_del_with_id(E_Client *ec, int id); +static int _e_info_server_hooks_delete = 0; +static int _e_info_server_hooks_walking = 0; + +static Eina_Inlist *_e_info_server_hooks[] = +{ + [E_INFO_SERVER_HOOK_BUFFER_DUMP_BEGIN] = NULL, + [E_INFO_SERVER_HOOK_BUFFER_DUMP_END] = NULL +}; + +static void +_e_info_server_hooks_clean(void) +{ + Eina_Inlist *l; + E_Info_Server_Hook *iswh; + unsigned int x; + + for (x = 0; x < E_INFO_SERVER_HOOK_LAST; x++) + EINA_INLIST_FOREACH_SAFE(_e_info_server_hooks[x], l, iswh) + { + if (!iswh->delete_me) continue; + _e_info_server_hooks[x] = eina_inlist_remove(_e_info_server_hooks[x], + EINA_INLIST_GET(iswh)); + free(iswh); + } +} + +static void +_e_info_server_hook_call(E_Info_Server_Hook_Point hookpoint, void *data EINA_UNUSED) +{ + E_Info_Server_Hook *iswh; + + _e_info_server_hooks_walking++; + EINA_INLIST_FOREACH(_e_info_server_hooks[hookpoint], iswh) + { + if (iswh->delete_me) continue; + iswh->func(iswh->data); + } + _e_info_server_hooks_walking--; + if ((_e_info_server_hooks_walking == 0) && (_e_info_server_hooks_delete > 0)) + _e_info_server_hooks_clean(); +} + +E_API E_Info_Server_Hook * +e_info_server_hook_add(E_Info_Server_Hook_Point hookpoint, E_Info_Server_Hook_Cb func, const void *data) +{ + E_Info_Server_Hook *iswh; + + EINA_SAFETY_ON_TRUE_RETURN_VAL(hookpoint >= E_INFO_SERVER_HOOK_LAST, NULL); + iswh = E_NEW(E_Info_Server_Hook, 1); + EINA_SAFETY_ON_NULL_RETURN_VAL(iswh, NULL); + iswh->hookpoint = hookpoint; + iswh->func = func; + iswh->data = (void*)data; + _e_info_server_hooks[hookpoint] = eina_inlist_append(_e_info_server_hooks[hookpoint], + EINA_INLIST_GET(iswh)); + return iswh; +} + +E_API void +e_info_server_hook_del(E_Info_Server_Hook *iswh) +{ + iswh->delete_me = 1; + if (_e_info_server_hooks_walking == 0) + { + _e_info_server_hooks[iswh->hookpoint] = eina_inlist_remove(_e_info_server_hooks[iswh->hookpoint], + EINA_INLIST_GET(iswh)); + free(iswh); + } + else + _e_info_server_hooks_delete++; +} + +E_API void +e_info_server_hook_call(E_Info_Server_Hook_Point hookpoint) +{ + if ((hookpoint < 0) || (hookpoint >= E_INFO_SERVER_HOOK_LAST)) return; + + _e_info_server_hook_call(hookpoint, NULL); +} + static void _msg_clients_append(Eldbus_Message_Iter *iter) { @@ -2452,6 +2532,7 @@ _e_info_server_cb_buffer_dump(const Eldbus_Service_Interface *iface EINA_UNUSED, if (e_info_dump_running == 0) return reply; + e_info_server_hook_call(E_INFO_SERVER_HOOK_BUFFER_DUMP_BEGIN); tdm_helper_dump_stop(); tbm_surface_internal_dump_end(); @@ -2464,6 +2545,7 @@ _e_info_server_cb_buffer_dump(const Eldbus_Service_Interface *iface EINA_UNUSED, } e_info_dump_count = 0; e_info_dump_running = 0; + e_info_server_hook_call(E_INFO_SERVER_HOOK_BUFFER_DUMP_END); } return reply; diff --git a/src/bin/e_info_server.h b/src/bin/e_info_server.h old mode 100644 new mode 100755 index 1f4223e8d7..0de09df82e --- a/src/bin/e_info_server.h +++ b/src/bin/e_info_server.h @@ -57,5 +57,31 @@ struct _E_Info_Hook void *data; }; +typedef struct _E_Info_Server_Hook E_Info_Server_Hook; + +typedef enum _E_Info_Server_Hook_Point +{ + E_INFO_SERVER_HOOK_BUFFER_DUMP_BEGIN, + E_INFO_SERVER_HOOK_BUFFER_DUMP_END, + E_INFO_SERVER_HOOK_LAST +} E_Info_Server_Hook_Point; + +typedef void (*E_Info_Server_Hook_Cb)(void *data); + +struct _E_Info_Server_Hook +{ + EINA_INLIST; + E_Info_Server_Hook_Point hookpoint; + E_Info_Server_Hook_Cb func; + void *data; + unsigned char delete_me : 1; +}; + +E_API E_Info_Server_Hook *e_info_server_hook_add(E_Info_Server_Hook_Point hookpoint, E_Info_Server_Hook_Cb func, const void *data); + +E_API void e_info_server_hook_del(E_Info_Server_Hook *ph); + +E_API void e_info_server_hook_call(E_Info_Server_Hook_Point hookpoint); + #endif #endif -- 2.34.1