From b14acdd722084f62a2bee2ded3d4ce7f8400559a Mon Sep 17 00:00:00 2001 From: Daehyeon Jung Date: Mon, 4 Jul 2016 15:06:10 +0900 Subject: [PATCH] Add aul_widget_instance_* function - Add aul_widget_instance_* functions to store instance to AMD Change-Id: I3c657cc81181031d0ffd644e2d726c456b9fc0d8 Signed-off-by: Daehyeon Jung --- CMakeLists.txt | 1 + include/aul.h | 33 ++++++++++ include/aul_cmd.h | 11 ++++ src/launch.c | 1 + src/widget.c | 194 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 240 insertions(+) create mode 100644 src/widget.c diff --git a/CMakeLists.txt b/CMakeLists.txt index f814a5c..088b6d0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,7 @@ add_library(aul SHARED src/aul_proc.c src/app_com.c src/aul_error.c + src/widget.c ) TARGET_LINK_LIBRARIES(aul ${libpkgs_LDFLAGS}) SET_TARGET_PROPERTIES(aul PROPERTIES SOVERSION ${MAJORVER}) diff --git a/include/aul.h b/include/aul.h index 8bdd212..1470fe9 100644 --- a/include/aul.h +++ b/include/aul.h @@ -202,6 +202,14 @@ typedef enum _aul_type { #define AUL_K_CHILD_PID "__AUL_CHILD_PID__" /** AUL internal private key */ #define AUL_K_WIDGET_VIEWER "__AUL_WIDGET_VIEWER__" +/** AUL internal private key */ +#define AUL_K_WIDGET_ID "__AUL_WIDGET_ID__" +/** AUL internal private key */ +#define AUL_K_WIDGET_INSTANCE_ID "__AUL_WIDGET_INSTANCE_ID__" +/** AUL internal private key */ +#define AUL_K_APP_DATA_KEY "__AUL_APP_DATA_KEY__" +/** AUL internal private key */ +#define AUL_K_TARGET_PID "__AUL_TARGET_PID__" /** * @brief This is callback function for aul_launch_init @@ -2749,6 +2757,31 @@ int aul_launch_app_async_for_uid(const char *appid, bundle *kb, uid_t uid); */ int aul_prepare_candidate_process(void); +/* + * This API is only for Appfw internally. + */ +int aul_widget_instance_add(const char *widget_id, const char *instance_id); + +/* + * This API is only for Appfw internally. + */ +int aul_widget_instance_del(const char *widget_id, const char *instance_id); + +/* + * This API is only for Appfw internally. + */ +typedef void (*aul_widget_instance_foreach_cb)(const char *instance_id, void *data); + +/* + * This API is only for Appfw internally. + */ +int aul_widget_instance_foreach(const char *widget_id, aul_widget_instance_foreach_cb cb, void *data); + +/* + * This API is only for Appfw internally. + */ +int aul_widget_instance_update(const char *widget_id, const char *instance_id, bundle *b); + #ifdef __cplusplus } #endif diff --git a/include/aul_cmd.h b/include/aul_cmd.h index 99fc1e6..77615fa 100644 --- a/include/aul_cmd.h +++ b/include/aul_cmd.h @@ -74,6 +74,17 @@ enum app_cmd { APP_COM_SEND, APP_COM_LEAVE, APP_COM_MESSAGE, + APP_DATA_NEW, + APP_DATA_GET_RAW, + APP_DATA_PUT, + APP_DATA_GET, + APP_DATA_GET_OWNER, + APP_DATA_DEL, + + WIDGET_ADD, + WIDGET_DEL, + WIDGET_LIST, + WIDGET_UPDATE, APP_REGISTER_PID, diff --git a/src/launch.c b/src/launch.c index add3a53..72d8a9d 100644 --- a/src/launch.c +++ b/src/launch.c @@ -321,6 +321,7 @@ int app_request_to_launchpad_for_uid(int cmd, const char *appid, bundle *kb, uid case APP_START: case APP_START_RES: case APP_START_ASYNC: + case WIDGET_UPDATE: b = bundle_dup(kb); ret = __app_launch_local(b); break; diff --git a/src/widget.c b/src/widget.c new file mode 100644 index 0000000..4860ef1 --- /dev/null +++ b/src/widget.c @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define _GNU_SOURCE +#include +#include +#include +#include "aul.h" +#include "aul_util.h" +#include "aul_sock.h" +#include "aul_cmd.h" +#include "aul_error.h" +#include "launch.h" + +static const char *__to_appid(const char *widget_id) +{ + const char *appid; + appid = g_strstr_len(widget_id, strlen(widget_id), "@") + 1; + if (appid != (const char *)1) { + if (appid > widget_id + (sizeof(char) * strlen(widget_id))) + appid = (char *)widget_id; + } else { + appid = (char *)widget_id; + } + + return appid; +} + +API int aul_widget_instance_add(const char *widget_id, const char *instance_id) +{ + int ret; + bundle *kb; + + if (widget_id == NULL || instance_id == NULL) + return AUL_R_EINVAL; + + kb = bundle_create(); + if (kb == NULL) { + _E("out of memory"); + return AUL_R_ERROR; + } + + bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id); + bundle_add_str(kb, AUL_K_WIDGET_INSTANCE_ID, instance_id); + + ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), WIDGET_ADD, kb, + AUL_SOCK_NONE); + + bundle_free(kb); + if (ret < 0) + return aul_error_convert(ret); + + return AUL_R_OK; +} + +API int aul_widget_instance_del(const char *widget_id, const char *instance_id) +{ + int ret; + bundle *kb; + + if (widget_id == NULL || instance_id == NULL) + return AUL_R_EINVAL; + + kb = bundle_create(); + if (kb == NULL) { + _E("out of memory"); + return AUL_R_ERROR; + } + + bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id); + bundle_add_str(kb, AUL_K_WIDGET_INSTANCE_ID, instance_id); + + ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), WIDGET_DEL, kb, + AUL_SOCK_NONE); + + bundle_free(kb); + if (ret < 0) + return aul_error_convert(ret); + + return AUL_R_OK; +} + +struct __cb_data { + aul_widget_instance_foreach_cb cb; + void *data; +}; + +static void __foreach_cb(const char *key, const int type, + const bundle_keyval_t *kv, void *user_data) +{ + struct __cb_data *cb_data = (struct __cb_data *)user_data; + + cb_data->cb(key, cb_data->data); +} + +API int aul_widget_instance_foreach(const char *widget_id, + aul_widget_instance_foreach_cb cb, void *data) +{ + int ret; + int fd; + bundle *kb; + app_pkt_t *pkt = NULL; + bundle *list_kb = NULL; + struct __cb_data cb_data; + + if (widget_id == NULL) + return AUL_R_EINVAL; + + kb = bundle_create(); + if (kb == NULL) { + _E("out of memory"); + return AUL_R_ERROR; + } + + bundle_add_str(kb, AUL_K_APPID, __to_appid(widget_id)); + bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id); + + fd = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), WIDGET_LIST, kb, + AUL_SOCK_ASYNC); + + if (fd > 0) { + ret = aul_sock_recv_reply_pkt(fd, &pkt); + if (ret < 0 || pkt == NULL) { + _E("failed to get instance list of %s", widget_id); + } else { + list_kb = bundle_decode(pkt->data, pkt->len); + if (list_kb) { + cb_data.cb = cb; + cb_data.data = data; + bundle_foreach(list_kb, __foreach_cb, &cb_data); + } + } + } else { + ret = fd; + } + + if (pkt) + free(pkt); + + bundle_free(kb); + + if (ret < 0) + return aul_error_convert(ret); + + return AUL_R_OK; +} + +API int aul_widget_instance_update(const char *widget_id, + const char *instance_id, bundle *param) +{ + int ret; + bundle *kb = param; + const char *appid; + + if (widget_id == NULL) + return AUL_R_EINVAL; + + if (kb == NULL) + kb = bundle_create(); + + if (kb == NULL) { + _E("out of memory"); + return AUL_R_ERROR; + } + + appid = __to_appid(widget_id); + + bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id); + + if (instance_id) + bundle_add_str(kb, AUL_K_WIDGET_INSTANCE_ID, instance_id); + + ret = app_request_to_launchpad_for_uid(WIDGET_UPDATE, appid, kb, + getuid()); + + if (param == NULL) + bundle_free(kb); + + return ret; +} + -- 2.7.4