diff options
Diffstat (limited to 'screen_connector_watcher/src/screen_connector_watcher.c')
-rw-r--r-- | screen_connector_watcher/src/screen_connector_watcher.c | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/screen_connector_watcher/src/screen_connector_watcher.c b/screen_connector_watcher/src/screen_connector_watcher.c index acf1e07..c1bcfb1 100644 --- a/screen_connector_watcher/src/screen_connector_watcher.c +++ b/screen_connector_watcher/src/screen_connector_watcher.c @@ -1,5 +1,4 @@ /* - * Screen Connector Watcher * Copyright (c) 2016 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the License); @@ -14,10 +13,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + #include <stdio.h> #include <errno.h> #include <glib.h> - #include <dlog.h> #include <wayland-client.h> #include <Ecore_Wayland.h> @@ -40,7 +39,7 @@ struct _screen_connector_watcher_h { 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 (*change_cb)(struct tizen_remote_surface *trs, uint32_t type, struct wl_buffer *tbm, - int32_t img_file_fd, uint32_t img_file_size, uint32_t time, struct wl_array *keys, void *data); + int32_t img_file_fd, uint32_t img_file_size, uint32_t time, struct wl_array *keys, void *data); void *data; struct tizen_remote_surface *surface; int resource_id; @@ -51,7 +50,7 @@ typedef struct _screen_connector_watcher_h *screen_connector_watcher_h; static struct tizen_remote_surface_manager *__rsm; static struct wayland_tbm_client *__tbm_client; static struct wl_tbm *__tbm; -static bool __is_init = false; +static bool __is_init; static GList *__watcher_list; static GList *__pending_watcher_list; static aul_screen_viewer_handler __aul_cbs; @@ -59,6 +58,7 @@ static aul_screen_viewer_handler __aul_cbs; static void __buffer_updated(void *data, struct tizen_remote_surface *trs, struct wl_buffer *buffer, uint32_t time) { screen_connector_watcher_h watcher_h = (screen_connector_watcher_h)data; + if (watcher_h) watcher_h->update_cb(trs, buffer, time, watcher_h->data); } @@ -66,15 +66,17 @@ static void __buffer_updated(void *data, struct tizen_remote_surface *trs, struc static void __buffer_missing(void *data, struct tizen_remote_surface *trs) { screen_connector_watcher_h watcher_h = (screen_connector_watcher_h)data; + if (watcher_h) watcher_h->missing_cb(trs, watcher_h->data); } #if 0 static void __buffer_changed(void *data, struct tizen_remote_surface *trs, uint32_t type, struct wl_buffer *tbm, - int32_t img_file_fd, uint32_t img_file_size, uint32_t time, struct wl_array *keys) + int32_t img_file_fd, uint32_t img_file_size, uint32_t time, struct wl_array *keys) { screen_connector_watcher_h watcher_h = (screen_connector_watcher_h)data; + if (watcher_h) watcher_h->change_cb(trs, type, tbm, img_file_fd, img_file_size, time, keys, watcher_h->data); } @@ -97,35 +99,43 @@ static void __app_removed(const char *appid, const int pid, void *data) EXPORT_API void screen_connector_watcher_redirect_surface(screen_connector_watcher_h watcher_h) { - watcher_h->surface = - tizen_remote_surface_manager_create_surface(__rsm, (uint32_t)watcher_h->resource_id, __tbm); + if (watcher_h == NULL) + return; + + watcher_h->surface = tizen_remote_surface_manager_create_surface(__rsm, (uint32_t)watcher_h->resource_id, __tbm); LOGD("resource_id : %d, (%p)", watcher_h->resource_id, watcher_h->surface); - tizen_remote_surface_add_listener(watcher_h->surface, &__rs_listener, - watcher_h); + tizen_remote_surface_add_listener(watcher_h->surface, &__rs_listener, watcher_h); tizen_remote_surface_redirect(watcher_h->surface); } static screen_connector_watcher_h __create_watcher_handle_info(char *appid) { - screen_connector_watcher_h watcher_h = NULL; + screen_connector_watcher_h watcher_h; + watcher_h = (screen_connector_watcher_h)calloc(1, sizeof(struct _screen_connector_watcher_h)); if (watcher_h == NULL) { LOGE("watcher_h calloc fail"); return NULL; } + watcher_h->appid = strdup(appid); + if (watcher_h->appid == NULL) { + LOGE("out of memory"); + free(watcher_h); + return NULL; + } return watcher_h; } static void __app_added(const char *appid, const int pid, const unsigned int resource_id, void *data) { - LOGD("__app_added pid: %d, resource_id: %d, appid: %s", pid, resource_id, appid); screen_connector_watcher_h watcher_h = NULL; - screen_connector_watcher_h cur_h = NULL; + screen_connector_watcher_h cur_h; GList *watcher_list = __watcher_list; + LOGD("__app_added pid: %d, resource_id: %d, appid: %s", pid, resource_id, appid); for (; watcher_list != NULL; watcher_list = watcher_list->next) { cur_h = (screen_connector_watcher_h)watcher_list->data; if (strcmp(cur_h->appid, appid) == 0) { @@ -151,10 +161,9 @@ static void __app_added(const char *appid, const int pid, const unsigned int res screen_connector_watcher_redirect_surface(watcher_h); else LOGE("bad tbm message received. missing arguments"); - } -EXPORT_API int screen_connector_watcher_init() +EXPORT_API int screen_connector_watcher_init(void) { int ret = 0; struct wl_registry *registry; @@ -171,15 +180,15 @@ EXPORT_API int screen_connector_watcher_init() if (!registry || !globals) { LOGE("could not get registry(%p) or global list(%p)", registry, - globals); + globals); return -1; } EINA_INLIST_FOREACH(globals, global) { if (!strcmp(global->interface, "tizen_remote_surface_manager")) { __rsm = wl_registry_bind(registry, global->id, - &tizen_remote_surface_manager_interface, - global->version < 2 ? global->version : 2); + &tizen_remote_surface_manager_interface, + global->version < 2 ? global->version : 2); } } @@ -209,7 +218,7 @@ EXPORT_API int screen_connector_watcher_init() return ret; } -EXPORT_API int screen_connector_watcher_fini() +EXPORT_API int screen_connector_watcher_fini(void) { if (!__is_init) return 0; @@ -245,6 +254,9 @@ EXPORT_API screen_connector_watcher_h screen_connector_watcher_create_handle(cha screen_connector_watcher_h watcher_h = NULL; watcher_h = __create_watcher_handle_info(id); + if (watcher_h == NULL) + return NULL; + watcher_h->update_cb = ops->update_cb; watcher_h->change_cb = ops->change_cb; watcher_h->missing_cb = ops->missing_cb; @@ -256,9 +268,8 @@ EXPORT_API screen_connector_watcher_h screen_connector_watcher_create_handle(cha EXPORT_API screen_connector_watcher_h screen_connector_watcher_add(screen_connector_watcher_ops *ops, char *id, void *data) { - screen_connector_watcher_h watcher_h = NULL; - screen_connector_watcher_h cur_h = NULL; + screen_connector_watcher_h cur_h; GList *watcher_list = __pending_watcher_list; for (; watcher_list != NULL; watcher_list = watcher_list->next) { @@ -290,16 +301,14 @@ EXPORT_API screen_connector_watcher_h screen_connector_watcher_add(screen_connec EXPORT_API int screen_connector_watcher_remove(screen_connector_watcher_h h) { - int ret = 0; __destroy_watcher_h(h); - return ret; + + return 0; } EXPORT_API int screen_connector_watcher_update(const char *appid) { - int ret = 0; - ret = aul_screen_connector_update_app_screen(appid); - return ret; + return aul_screen_connector_update_app_screen(appid); } EXPORT_API char *screen_connector_watcher_get_appid(screen_connector_watcher_h h) |