e_policy_wl: add new funtion for tizen_ws_shell extension accepted/tizen/3.0/common/20170508.153004 accepted/tizen/3.0/ivi/20170508.050038 accepted/tizen/3.0/mobile/20170508.045947 accepted/tizen/3.0/tv/20170508.050000 accepted/tizen/3.0/wearable/20170508.050017 submit/tizen_3.0-common/20170508.080135 submit/tizen_3.0-common/20170508.081301 submit/tizen_3.0-common/20170508.091535 submit/tizen_3.0/20170421.053757 submit/tizen_3.0_common/20170508.091735
authorSangjin Lee <lsj119@samsung.com>
Mon, 3 Apr 2017 12:29:02 +0000 (21:29 +0900)
committerJuyeon Lee <juyeonne.lee@samsung.com>
Fri, 21 Apr 2017 05:55:00 +0000 (14:55 +0900)
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
src/bin/e_policy_wl.h

index b427b3666f87d6bcc541b4aaa7ab4ec1247e6c98..77a7707faeeb0f6bb5e29ba705526bf5c7722f76 100644 (file)
@@ -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);
 
index beda40c705eb1793754898b4808c3a5fc738cce4..b38c586662aec075b6f0a19190c9a0e573e5adbe 100644 (file)
@@ -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);