From 6ee7dcdd0c09f98fe3dbd12d8417a326e30b628c Mon Sep 17 00:00:00 2001 From: Hyunho Kang Date: Tue, 4 Jul 2017 21:12:36 +0900 Subject: [PATCH] Add screen viewer state update feature In screen-connector multi viewer senario, provider should decide it's resume/pause state using every viewer's visibility. So, every viewer should share their visibility to AMD. Requires: - https://review.tizen.org/gerrit/#/c/137133/ (aul-1) - https://review.tizen.org/gerrit/#/c/137134/ (amd) - https://review.tizen.org/gerrit/#/c/137136/ (widget-viewer) - https://review.tizen.org/gerrit/#/c/137437/ (appcore-watch) Change-Id: I6437586abe67f732aa302ebca0d4c06613405d07 Signed-off-by: Hyunho Kang --- include/aul_cmd.h | 4 +- include/aul_screen_connector.h | 22 +++++- src/aul_screen_connector.c | 174 ++++++++++++++++++++++++++++++++--------- 3 files changed, 159 insertions(+), 41 deletions(-) diff --git a/include/aul_cmd.h b/include/aul_cmd.h index 4077bdf..79772e0 100644 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -122,7 +122,9 @@ enum app_cmd { APP_WINDOW_DETACH = 91, APP_START_RES_ASYNC = 92, APP_NOTIFY_EXIT = 93, - GET_APPID_BY_SURFACE_ID = 94, + APP_GET_APPID_BY_SURFACE_ID = 94, + APP_GET_INSTANCE_ID_BY_SURFACE_ID = 95, + UPDATE_SCREEN_VIEWER_STATUS = 96, APP_CMD_MAX }; diff --git a/include/aul_screen_connector.h b/include/aul_screen_connector.h index f435901..e0cab3e 100644 --- a/include/aul_screen_connector.h +++ b/include/aul_screen_connector.h @@ -37,6 +37,11 @@ typedef enum { AUL_SCREEN_CONNECTOR_EVENT_TYPE_UPDATE, } aul_screen_connector_event_type_e; +typedef enum { + AUL_SCREEN_STATUS_RESUME, + AUL_SCREEN_STATUS_PAUSE, +} aul_screen_status_e; + typedef void (*aul_screen_viewer_cb)(const char *appid, const char *instance_id, const int pid, const unsigned int surface_id, @@ -73,9 +78,24 @@ int aul_screen_connector_add_screen_viewer(aul_screen_viewer_cb callback, */ int aul_screen_connector_remove_screen_viewer(aul_screen_viewer_h handle); -int aul_screen_connector_get_appid_by_surface_id_request(unsigned int surface_id, +/* + * This API is only for Appfw internally. + */ +int aul_screen_connector_get_appid_by_surface_id(unsigned int surface_id, char **appid); +/* + * This API is only for Appfw internally. + */ +int aul_screen_connector_get_instance_id_by_surface_id(unsigned int surface_id, + char **instance_id); + +/* + * This API is only for Appfw internally. + */ +int aul_screen_connector_update_screen_viewer_status(aul_screen_status_e status, + const char *provider_instance_id); + #ifdef __cplusplus } #endif diff --git a/src/aul_screen_connector.c b/src/aul_screen_connector.c index 3ab25c9..8e836ae 100644 --- a/src/aul_screen_connector.c +++ b/src/aul_screen_connector.c @@ -402,61 +402,157 @@ API int aul_screen_connector_send_update_request(const char *appid, return AUL_R_OK; } -API int aul_screen_connector_get_appid_by_surface_id_request( - unsigned int surface_id, - char **appid) +static bundle *__send_request_with_surface_id(int cmd, unsigned int surface_id) { - int ret; + app_pkt_t *pkt = NULL; + bundle *b; int fd; + int r; + + b = bundle_create(); + if (b == NULL) { + _E("Out of memory"); + return NULL; + } + + r = bundle_add_byte(b, "__AUL_SC_SURFACE__", + &surface_id, sizeof(unsigned int)); + if (r != BUNDLE_ERROR_NONE) { + _E("Failed to add surface id(%u)", surface_id); + bundle_free(b); + return NULL; + } + + fd = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), cmd, b, + AUL_SOCK_ASYNC); + bundle_free(b); + if (fd < 0) { + _E("Failed to send request(%d)", cmd); + return NULL; + } + + aul_sock_recv_reply_pkt(fd, &pkt); + if (pkt == NULL) { + _E("Failed to receive the packet"); + return NULL; + } + + b = bundle_decode(pkt->data, pkt->len); + free(pkt); + if (b == NULL) { + _E("Failed to decode bundle data"); + return NULL; + } + + return b; +} + +API int aul_screen_connector_get_appid_by_surface_id(unsigned int surface_id, + char **appid) +{ + const char *val; bundle *b; - bundle *ret_kb; - app_pkt_t *pkt = NULL; - char *ret_appid = NULL; if (appid == NULL) { _E("Invalid parameter"); return AUL_R_ERROR; } + b = __send_request_with_surface_id(APP_GET_APPID_BY_SURFACE_ID, + surface_id); + if (b == NULL) + return AUL_R_ERROR; + + val = bundle_get_val(b, AUL_K_APPID); + if (val == NULL) { + _E("Failed to get appid"); + bundle_free(b); + return AUL_R_ERROR; + } + + *appid = strdup(val); + if (*appid == NULL) { + _E("Out of memory"); + bundle_free(b); + return AUL_R_ERROR; + } + bundle_free(b); + + return AUL_R_OK; +} + +API int aul_screen_connector_get_instance_id_by_surface_id( + unsigned int surface_id, char **instance_id) +{ + const char *val; + bundle *b; + + if (instance_id == NULL) { + _E("Invalid parameter"); + return AUL_R_ERROR; + } + + b = __send_request_with_surface_id(APP_GET_INSTANCE_ID_BY_SURFACE_ID, + surface_id); + if (b == NULL) + return AUL_R_ERROR; + + val = bundle_get_val(b, AUL_K_INSTANCE_ID); + if (val == NULL) { + _E("Failed to get instance id"); + bundle_free(b); + return AUL_R_ERROR; + } + + *instance_id = strdup(val); + if (*instance_id == NULL) { + _E("Out of memory"); + bundle_free(b); + return AUL_R_ERROR; + } + bundle_free(b); + + return AUL_R_OK; +} + + +API int aul_screen_connector_update_screen_viewer_status( + aul_screen_status_e status, const char *provider_instance_id) +{ + bundle *b; + int ret; + + if (provider_instance_id == NULL || + status < AUL_SCREEN_STATUS_RESUME || + status > AUL_SCREEN_STATUS_PAUSE) { + _E("Invalid parameter"); + return AUL_R_ERROR; + } + b = bundle_create(); if (b == NULL) { - _E("out of memory"); + _E("Out of memory"); return AUL_R_ERROR; } - bundle_add_byte(b, "__AUL_SC_SURFACE__", - &surface_id, sizeof(unsigned int)); - - fd = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), - GET_APPID_BY_SURFACE_ID, b, AUL_SOCK_ASYNC); - - if (fd > 0) { - ret = aul_sock_recv_reply_pkt(fd, &pkt); - if (ret < 0 || pkt == NULL) { - _E("failed to get appid of %d", surface_id); - } else { - ret_kb = bundle_decode(pkt->data, pkt->len); - if (ret_kb) { - bundle_get_str(ret_kb, AUL_K_APPID, &ret_appid); - if (ret_appid) - *appid = strdup(ret_appid); - bundle_free(ret_kb); - if (*appid == NULL) { - _E("Out of memory"); - bundle_free(b); - return AUL_R_ERROR; - } - } - } - } else { - ret = fd; + ret = bundle_add(b, AUL_K_INSTANCE_ID, provider_instance_id); + if (ret != BUNDLE_ERROR_NONE) { + _E("Failed to add provider instance id"); + bundle_free(b); + return AUL_R_ERROR; } - bundle_free(b); - if (ret < 0) { - _E("Failed to get appid"); - return ret; + ret = bundle_add_byte(b, "__AUL_SC_VIEWER_STATUS__", + &status, sizeof(aul_screen_status_e)); + if (ret != BUNDLE_ERROR_NONE) { + _E("Failed to add screen status"); + bundle_free(b); + return AUL_R_ERROR; } - return AUL_R_OK; + ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), + UPDATE_SCREEN_VIEWER_STATUS, b, AUL_SOCK_NOREPLY); + bundle_free(b); + + return ret; } -- 2.7.4