Add surface creator pid managing logic 48/96748/2 submit/tizen_3.0/20161111.000156
authorHyunho Kang <hhstark.kang@samsung.com>
Thu, 10 Nov 2016 05:42:33 +0000 (14:42 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Thu, 10 Nov 2016 06:01:06 +0000 (15:01 +0900)
- watch needs creator's pid to terminated old watch face

Change-Id: If514cde01623f60a926d716ba88c07b7f951e32f
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
include/aul_rsm_viewer.h
src/aul_rsm.c

index 9bb112d..bbaa549 100644 (file)
@@ -36,10 +36,9 @@ struct aul_rsm_handler_s {
 typedef struct aul_rsm_handler_s aul_rsm_handler;
 
 int aul_rsm_viewer_set_surface_handler(const char *id, aul_rsm_handler *cbs, void *data);
-
 int aul_rsm_viewer_set_surface_handler_by_rid(int resource_id, aul_rsm_handler *cbs, void *data);
-
 int aul_rsm_viewer_get_surface_rid(const char *id, int *resource_id);
+int aul_rsm_viewer_get_surface_pid(const char *id, int *pid);
 
 
 #ifdef __cplusplus
index c643291..7a0a770 100644 (file)
@@ -36,6 +36,7 @@ struct __remote_surface_s {
 
 struct __surface_s {
        char *id;
+       int pid;
        void (*update_cb)(struct tizen_remote_surface *trs, struct wl_buffer *buffer, uint32_t time, void *data);
        void (*missing_cb)(struct tizen_remote_surface *trs, void *data);
        void *data;
@@ -124,6 +125,7 @@ static void __rsp_resource_id_cb(void *data, struct tizen_remote_surface_provide
 {
        struct __remote_surface_s *remote = (struct __remote_surface_s *)data;
        bundle *envelope = bundle_create();
+       int pid = getpid();
 
        if (envelope == NULL) {
                _E("failed to create envelope");
@@ -132,6 +134,7 @@ static void __rsp_resource_id_cb(void *data, struct tizen_remote_surface_provide
 
        bundle_add_str(envelope, "__AUL_RSP_RESOURCE_ID__", remote->id);
        bundle_add_byte(envelope, "__AUL_RSP_SURFACE_ID__", &res_id, sizeof(uint32_t));
+       bundle_add_byte(envelope, "__AUL_RSP_SURFACE_CREATOR_PID__", &pid, sizeof(int));
 
        if (aul_app_com_send("tbm_surface_notify", envelope) < 0) {
                _E("failed to send surface notify");
@@ -235,21 +238,8 @@ static const struct tizen_remote_surface_listener __rs_listener = {
        __rs_missing_cb,
 };
 
-static void __redirect_surface(char *id, int res_id)
+static void __redirect_surface(struct __surface_s *surface)
 {
-       struct __surface_s *surface = NULL;
-
-       if (id) {
-               surface = g_hash_table_lookup(__viewer_tbl, id);
-               if (!surface) {
-                       _E("unknown surface");
-                       return;
-               }
-       }
-
-       surface->resource_id = res_id;
-       surface->surface = tizen_remote_surface_manager_create_surface(__rsm,
-                                       (uint32_t)res_id, __tbm);
        tizen_remote_surface_add_listener(surface->surface, &__rs_listener,
                                                        surface);
        tizen_remote_surface_redirect(surface->surface);
@@ -261,13 +251,31 @@ static int __tbm_handler(const char *endpoint, aul_app_com_result_e e,
        char *id = NULL;
        uint32_t *res_id = NULL;
        size_t sz;
+       int *pid = NULL;
+       struct __surface_s *surface = NULL;
 
        bundle_get_str(envelope, "__AUL_RSP_RESOURCE_ID__", &id);
-       bundle_get_byte(envelope, "__AUL_RSP_SURFACE_ID__", (void **)&res_id,
-                                                                       &sz);
+       bundle_get_byte(envelope, "__AUL_RSP_SURFACE_ID__", (void **)&res_id, &sz);
+       bundle_get_byte(envelope, "__AUL_RSP_SURFACE_CREATOR_PID__", (void **)&pid, &sz);
+       if (id) {
+               surface = g_hash_table_lookup(__viewer_tbl, id);
+               if (!surface) {
+                       _E("unknown surface");
+                       return 0;
+               }
+       }
+
+       if (pid != NULL)
+               surface->pid = (int)*pid;
+
+       surface->resource_id = *res_id;
+       surface->surface = tizen_remote_surface_manager_create_surface(__rsm,
+                                       (uint32_t)*res_id, __tbm);
+
+       _D("__tbm_handler %d, %d, %s", *pid, *res_id, id);
 
        if (id && res_id)
-               __redirect_surface(id, (int)*res_id);
+               __redirect_surface(surface);
        else
                _E("bad tbm message received. missing arguments");
 
@@ -349,10 +357,12 @@ API int aul_rsm_viewer_set_surface_handler(const char *id, aul_rsm_handler *cbs,
 API int aul_rsm_viewer_set_surface_handler_by_rid(int resource_id, aul_rsm_handler *cbs, void *data)
 {
        char buf[32];
+       struct __surface_s *surface;
 
        snprintf(buf, sizeof(buf), "%d", resource_id);
        aul_rsm_viewer_set_surface_handler(buf, cbs, data);
-       __redirect_surface(buf, resource_id);
+       surface = g_hash_table_lookup(__viewer_tbl, buf);
+       __redirect_surface(surface);
 
        return 0;
 }
@@ -380,3 +390,27 @@ API int aul_rsm_viewer_get_surface_rid(const char *id, int *resource_id)
        *resource_id = surface->resource_id;
        return 0;
 }
+
+API int aul_rsm_viewer_get_surface_pid(const char *id, int *pid)
+{
+       struct __surface_s *surface;
+
+       if (!id || !pid) {
+               _E("illegal arguments");
+               return -1;
+       }
+
+       surface = g_hash_table_lookup(__viewer_tbl, id);
+       if (!surface) {
+               _E("unknown surface");
+               return -1;
+       }
+
+       if (surface->pid < 1) {
+               _E("resource id not yet initialized");
+               return -1;
+       }
+
+       *pid = surface->pid;
+       return 0;
+}