From 834156c40b70c24bb88adc9f1ce94ee21c5fdfcc Mon Sep 17 00:00:00 2001 From: Sangjin Lee Date: Mon, 3 Apr 2017 21:29:02 +0900 Subject: [PATCH] e_policy_wl: add new funtion for tizen_ws_shell extension For make extension protocol for tzsh in seperate module, added the two functions. 1) e_tizen_extension_add : this funtion should be called in module_init 2) e_tizen_extension_del : this funtion should be called in module_deinit When received tizen_ws_shell::get_extension, server call the callback to create specific resource for extension. In callback function, it should be make new wl_resource. Change-Id: If34fa96ee3460ca8df20c6fddb66bccd2b845006 --- src/bin/e_policy_wl.c | 123 ++++++++++++++++++++++++++++++++++++++++++ src/bin/e_policy_wl.h | 6 +++ 2 files changed, 129 insertions(+) diff --git a/src/bin/e_policy_wl.c b/src/bin/e_policy_wl.c index b427b3666f..77a7707fae 100644 --- a/src/bin/e_policy_wl.c +++ b/src/bin/e_policy_wl.c @@ -101,6 +101,12 @@ typedef struct _E_Policy_Wl_Tzsh_Region struct wl_listener destroy_listener; } E_Policy_Wl_Tzsh_Region; +typedef struct _E_Policy_Wl_Tzsh_Extension +{ + char *name; + E_Policy_Wl_Tzsh_Ext_Hook_Cb cb; +} E_Policy_Wl_Tzsh_Extension; + typedef struct _E_Policy_Wl_Surface { struct wl_resource *surf; @@ -231,6 +237,9 @@ typedef struct _E_Policy_Wl #ifdef HAVE_CYNARA cynara *p_cynara; #endif + + /* tizen_ws_shell_interface ver_2 */ + Eina_List *tzsh_extensions; /* list of E_Policy_Wl_Tzsh_Extension */ } E_Policy_Wl; typedef struct _E_Tzsh_QP_Event @@ -821,6 +830,23 @@ _e_policy_wl_tzsh_client_del(E_Policy_Wl_Tzsh_Client *tzsh_client) E_FREE(tzsh_client); } +static E_Policy_Wl_Tzsh_Extension* +_e_policy_wl_tzsh_extension_get(const char *name) +{ + E_Policy_Wl_Tzsh_Extension *tzsh_ext; + Eina_List *l; + + EINA_LIST_FOREACH(polwl->tzsh_extensions, l, tzsh_ext) + { + if (strcmp(tzsh_ext->name, name)) continue; + + return tzsh_ext; + } + + return NULL; +} + + // -------------------------------------------------------- // E_Policy_Wl_Surface // -------------------------------------------------------- @@ -3856,6 +3882,57 @@ _tzsh_iface_cb_srv_create(struct wl_client *client, struct wl_resource *res_tzsh e_service_cbhm_client_set(tzsh->ec); } +// -------------------------------------------------------- +// tizen_ws_shell common +// -------------------------------------------------------- +E_API Eina_Bool +e_tzsh_extension_add(const char *name, E_Policy_Wl_Tzsh_Ext_Hook_Cb cb) +{ + E_Policy_Wl_Tzsh_Extension *tzsh_ext; + + if (_e_policy_wl_tzsh_extension_get(name)) + { + ERR("Already exists the %s extension\n", name); + return EINA_FALSE; + } + + tzsh_ext = E_NEW(E_Policy_Wl_Tzsh_Extension, 1); + EINA_SAFETY_ON_NULL_RETURN_VAL(tzsh_ext, EINA_FALSE); + + tzsh_ext->name = strndup(name, 512); + tzsh_ext->cb = cb; + + polwl->tzsh_extensions = eina_list_append(polwl->tzsh_extensions, tzsh_ext); + ELOGF("TZSH", + "EXTENSION_ADD | name:%s | cb:%p", + NULL, NULL, + name, cb); + + return EINA_TRUE; +} + +E_API void +e_tzsh_extension_del(const char *name) +{ + E_Policy_Wl_Tzsh_Extension *tzsh_ext; + + tzsh_ext = _e_policy_wl_tzsh_extension_get(name); + if (!tzsh_ext) + { + ERR("Cannot find the %s extension\n", name); + return; + } + + polwl->tzsh_extensions = eina_list_remove(polwl->tzsh_extensions, tzsh_ext); + memset(tzsh_ext, 0x0, sizeof(E_Policy_Wl_Tzsh_Extension)); + E_FREE(tzsh_ext); + + ELOGF("TZSH", + "EXTENSION_DEL | name:%s", + NULL, NULL, + name); +} + // -------------------------------------------------------- // tizen_ws_shell_interface::region // -------------------------------------------------------- @@ -4583,6 +4660,45 @@ _tzsh_iface_cb_tvsrv_get(struct wl_client *client, struct wl_resource *res_tzsh, _tzsh_cb_tvsrv_destroy); } +static void _tzsh_iface_cb_extension_get(struct wl_client *client, struct wl_resource *res_tzsh, uint32_t id, const char *name) +{ + E_Policy_Wl_Tzsh *tzsh; + E_Policy_Wl_Tzsh_Extension *tzsh_ext; + struct wl_resource *res_ext; + + tzsh = wl_resource_get_user_data(res_tzsh); + if (!tzsh) + { + wl_resource_post_error + (res_tzsh, + WL_DISPLAY_ERROR_INVALID_OBJECT, + "Invalid res_tzsh's user data"); + return; + } + + tzsh_ext = _e_policy_wl_tzsh_extension_get(name); + if (!tzsh_ext) + { + ERR("Could not find tzsh_extension(%s)", name); + wl_resource_post_error + (res_tzsh, + WL_DISPLAY_ERROR_INVALID_OBJECT, + "unregistered ext:%s", name); + } + else + { + res_ext = tzsh_ext->cb(client, res_tzsh, id); + if (!res_ext) + { + ERR("Could not create extension(%s) resource", name); + wl_resource_post_error + (res_tzsh, + WL_DISPLAY_ERROR_INVALID_OBJECT, + "Unknown error:%s", name); + } + } +} + // -------------------------------------------------------- // tizen_ws_shell_interface // -------------------------------------------------------- @@ -4599,6 +4715,7 @@ static const struct tizen_ws_shell_interface _tzsh_iface = _tzsh_iface_cb_reg_create, _tzsh_iface_cb_qp_get, _tzsh_iface_cb_tvsrv_get, + _tzsh_iface_cb_extension_get, }; static void @@ -6801,6 +6918,7 @@ e_policy_wl_shutdown(void) { E_Policy_Wl_Tzsh *tzsh; E_Policy_Wl_Tzsh_Srv *tzsh_srv; + E_Policy_Wl_Tzsh_Extension *tzsh_extension; E_Policy_Wl_Tzlaunch *tzlaunch; E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol; E_Policy_Wl_Tz_Indicator *tz_indicator; @@ -6847,6 +6965,11 @@ e_policy_wl_shutdown(void) wl_resource_destroy(tz_indicator->res_tz_indicator); } + EINA_LIST_FREE(polwl->tzsh_extensions, tzsh_extension) + { + free(tzsh_extension->name); + } + EINA_LIST_FREE(polwl->globals, global) wl_global_destroy(global); diff --git a/src/bin/e_policy_wl.h b/src/bin/e_policy_wl.h index beda40c705..b38c586662 100644 --- a/src/bin/e_policy_wl.h +++ b/src/bin/e_policy_wl.h @@ -37,6 +37,12 @@ void e_policy_wl_eval_pre_post_fetch(E_Client *ec); /* window brightness */ Eina_Bool e_policy_wl_win_brightness_apply(E_Client *ec); +/* tzsh common */ +typedef struct wl_resource* (*E_Policy_Wl_Tzsh_Ext_Hook_Cb)(struct wl_client* client, struct wl_resource* res, uint32_t id); +E_API Eina_Bool e_tzsh_extension_add(const char* name, E_Policy_Wl_Tzsh_Ext_Hook_Cb cb); +E_API void e_tzsh_extension_del(const char* name); + + /* tzsh quickpanel */ E_API void e_tzsh_qp_state_visible_update(E_Client *ec, Eina_Bool vis); E_API void e_tzsh_qp_state_orientation_update(E_Client *ec, int ridx); -- 2.34.1