2 * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
25 #include "aul_error.h"
28 static const char *__to_appid(const char *widget_id)
31 appid = g_strstr_len(widget_id, strlen(widget_id), "@") + 1;
32 if (appid != (const char *)1) {
33 if (appid > widget_id + (sizeof(char) * strlen(widget_id)))
34 appid = (char *)widget_id;
36 appid = (char *)widget_id;
42 API int aul_widget_instance_add(const char *widget_id, const char *instance_id)
47 if (widget_id == NULL || instance_id == NULL)
56 bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
57 bundle_add_str(kb, AUL_K_WIDGET_INSTANCE_ID, instance_id);
59 ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), WIDGET_ADD, kb,
64 return aul_error_convert(ret);
69 API int aul_widget_instance_del(const char *widget_id, const char *instance_id)
74 if (widget_id == NULL || instance_id == NULL)
83 bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
84 bundle_add_str(kb, AUL_K_WIDGET_INSTANCE_ID, instance_id);
86 ret = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), WIDGET_DEL, kb,
91 return aul_error_convert(ret);
97 aul_widget_instance_foreach_cb cb;
101 static void __foreach_cb(const char *key, const int type,
102 const bundle_keyval_t *kv, void *user_data)
104 struct __cb_data *cb_data = (struct __cb_data *)user_data;
106 cb_data->cb(key, cb_data->data);
109 API int aul_widget_instance_foreach(const char *widget_id,
110 aul_widget_instance_foreach_cb cb, void *data)
115 app_pkt_t *pkt = NULL;
116 bundle *list_kb = NULL;
117 struct __cb_data cb_data;
119 if (widget_id == NULL)
122 kb = bundle_create();
128 bundle_add_str(kb, AUL_K_APPID, __to_appid(widget_id));
129 bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
131 fd = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), WIDGET_LIST, kb,
135 ret = aul_sock_recv_reply_pkt(fd, &pkt);
136 if (ret < 0 || pkt == NULL) {
137 _E("failed to get instance list of %s", widget_id);
139 list_kb = bundle_decode(pkt->data, pkt->len);
143 bundle_foreach(list_kb, __foreach_cb, &cb_data);
156 return aul_error_convert(ret);
161 API int aul_widget_instance_update(const char *widget_id,
162 const char *instance_id, bundle *param)
168 if (widget_id == NULL)
172 kb = bundle_create();
179 appid = __to_appid(widget_id);
181 bundle_add_str(kb, AUL_K_WIDGET_ID, widget_id);
184 bundle_add_str(kb, AUL_K_WIDGET_INSTANCE_ID, instance_id);
186 ret = app_request_to_launchpad_for_uid(WIDGET_UPDATE, appid, kb,