3 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the License);
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
21 #include <sync_agent.h>
24 #include "common/dm_common.h"
25 #include "common/util/util.h"
26 #include "framework/ui-event-handler/user-interaction/user_interaction.h"
27 #include "serviceadapter/sa_util.h"
28 #include "ipc_agent.h"
30 #ifndef OMADM_AGENT_LOG
32 #define LOG_TAG "OMA_DM_UI"
35 #define TIMEOUT_MIN_VAL 10
36 #define TIMEOUT_MAX_VAL 60
39 void free_uic_value(uic_data ** uic_value)
43 if (uic_value != NULL) {
44 if (*uic_value != NULL) {
45 str_free(&((*uic_value)->display));
46 if ((*uic_value)->multi_data != NULL) {
49 for (iter = (*uic_value)->multi_data; iter != NULL; iter = g_list_next(iter)) {
50 data = (char *)(iter->data);
55 if ((*uic_value)->pUic_option != NULL) {
56 str_free(&((*uic_value)->pUic_option->default_data));
57 str_free(&((*uic_value)->pUic_option->echo_type));
58 str_free(&((*uic_value)->pUic_option->input_type));
59 str_free(&((*uic_value)->pUic_option->max_t));
60 str_free(&((*uic_value)->pUic_option->maxlen));
61 str_free(&((*uic_value)->pUic_option->min_t));
62 free((*uic_value)->pUic_option);
63 (*uic_value)->pUic_option = NULL;
65 if ((*uic_value)->res_data != NULL) {
66 free_res_data((*uic_value)->res_data);
67 (*uic_value)->res_data = NULL;
77 void free_res_data(uic_res_data * res_data)
81 retm_if((res_data) == NULL, "res data is NULL!!");
84 res_data->type = UIC_NONE_TYPE;
86 str_free(&(res_data->input_text));
88 if (res_data->res_multi_data != NULL) {
91 for (iter = res_data->res_multi_data; iter != NULL; iter = g_list_next(iter)) {
92 data = (char *)(iter->data);
101 DM_ERROR exec_userinteration_option(char *data, uic_option ** uic_value)
105 DM_ERROR ret = DM_OK;
106 char *findValue = NULL;
109 _DEBUG_INFO("uic_data null");
110 (*uic_value)->min_t = strdup("0");
111 (*uic_value)->max_t = g_strdup_printf("%d", TIMEOUT_MAX_VAL);
112 (*uic_value)->default_data = strdup("0");
113 (*uic_value)->maxlen = strdup("0");
114 (*uic_value)->input_type = strdup("0");
115 (*uic_value)->echo_type = strdup("0");
119 ret = findStgringValue(data, UI_OP_MINDT, UI_OP_EQUAL, &findValue);
120 if (findValue != NULL) {
121 if (!strncmp(findValue, TIEM_ZERO, strlen(TIEM_ZERO))) {
122 (*uic_value)->min_t = g_strdup_printf("%d", TIMEOUT_MIN_VAL);
124 (*uic_value)->min_t = strdup(findValue);
126 str_free(&findValue);
128 (*uic_value)->min_t = g_strdup_printf("%d", TIMEOUT_MIN_VAL);
130 _DEBUG_INFO("min time : %s", (*uic_value)->min_t);
131 /*UI value setting */
132 ret = findStgringValue(data, UI_OP_MAXDT, UI_OP_EQUAL, &findValue);
133 if (findValue != NULL) {
134 _DEBUG_INFO("max time : %s", findValue);
135 if (!strncmp(findValue, TIEM_ZERO, strlen(TIEM_ZERO))) {
136 (*uic_value)->max_t = g_strdup_printf("%d", TIMEOUT_MAX_VAL);
138 (*uic_value)->max_t = strdup(findValue);
140 str_free(&findValue);
142 (*uic_value)->max_t = g_strdup_printf("%d", TIMEOUT_MAX_VAL);
144 _DEBUG_INFO("max time : %s", (*uic_value)->max_t);
145 /*UI value setting */
146 ret = findStgringValue(data, UI_OP_DR, UI_OP_EQUAL, &findValue);
147 if (findValue != NULL) {
148 _DEBUG_INFO("default data: %s", findValue);
149 (*uic_value)->default_data = strdup(findValue);
150 str_free(&findValue);
152 (*uic_value)->default_data = strdup("0");
154 /*UI value setting */
155 ret = findStgringValue(data, UI_OP_MAXLEN, UI_OP_EQUAL, &findValue);
156 if (findValue != NULL) {
157 _DEBUG_INFO("max len : %s", findValue);
158 (*uic_value)->maxlen = strdup(findValue);
159 str_free(&findValue);
161 (*uic_value)->maxlen = strdup("0");
163 /*UI value setting */
164 ret = findStgringValue(data, UI_OP_IT, UI_OP_EQUAL, &findValue);
165 if (findValue != NULL) {
166 _DEBUG_INFO("input type : %s", findValue);
167 (*uic_value)->input_type = strdup(findValue);
168 str_free(&findValue);
170 (*uic_value)->input_type = strdup("0");
173 /*UI value setting */
174 ret = findStgringValue(data, UI_OP_ET, UI_OP_EQUAL, &findValue);
175 if (findValue != NULL) {
176 _DEBUG_INFO("echo_type : %s", findValue);
177 (*uic_value)->echo_type = strdup(findValue);
178 str_free(&findValue);
180 (*uic_value)->echo_type = strdup("0");
187 DM_ERROR ui_display(uic_data * uic_value)
191 DM_ERROR ret = DM_OK;
193 retvm_if((uic_value) == NULL, COMMON_ERR_IS_NULL, "uic_value is NULL!!");
197 /* ui_ret = launch_om_dm_fumo_alert_ui();
199 ret = DM_ALERT_UI_LAUNCH_ERROR;
204 ui_ret = alert_uic_display(uic_value);
206 uic_value->res_data->status = DM_ERR_NOT_EXECUTED;
207 _DEBUG_INFO("display alert fail : %d", DM_ERR_NOT_EXECUTED);
209 uic_value->res_data->status = DM_OK;
210 _DEBUG_INFO("display alert success : %d", uic_value->res_data->status);
221 DM_ERROR ui_confirm_or_reject(uic_data * uic_value)
225 DM_ERROR ret = DM_OK;
227 retvm_if((uic_value) == NULL, COMMON_ERR_IS_NULL, "uic_value is NULL!!");
229 /* cancel -> atomic, sequence */
231 /* ui_ret = launch_om_dm_fumo_alert_ui();
233 ret = DM_ALERT_UI_LAUNCH_ERROR;
238 ui_ret = alert_uic_confirmation(uic_value);
242 uic_value->res_data->status = DM_OK;
243 _DEBUG_INFO("display alert success : %d", DM_OK);
245 /*calcel or app launch fail or timeout */
246 uic_value->res_data->status = DM_ERR_NOT_MODIFIED;
247 _DEBUG_INFO("confirm alert fail : %d", DM_ERR_NOT_MODIFIED);
258 DM_ERROR ui_text_input(uic_data * uic_value, char **result_data)
262 DM_ERROR ret = DM_OK;
264 retvm_if((uic_value) == NULL, COMMON_ERR_IS_NULL, "uic_value is NULL!!");
267 /* ui_ret = launch_om_dm_fumo_alert_ui();
269 ret = DM_ALERT_UI_LAUNCH_ERROR;
274 ui_ret = alert_uic_inputText(uic_value);
278 if (uic_value->res_data->input_text != NULL) {
279 (*result_data) = strdup(uic_value->res_data->input_text);
280 uic_value->res_data->status = DM_OK;
281 _DEBUG_INFO("test input alert success : %d", DM_OK);
283 (*result_data) = strdup("NULL");
284 uic_value->res_data->status = DM_ERR_NOT_EXECUTED;
285 _DEBUG_INFO("input alert fail : %d", DM_ERR_NOT_EXECUTED);
288 /*calcel or app launch fail */
289 (*result_data) = strdup("NULL");
290 uic_value->res_data->status = DM_ERR_NOT_EXECUTED;
291 _DEBUG_INFO("input alert fail : %d", DM_ERR_NOT_EXECUTED);
302 DM_ERROR ui_single_choice(uic_data * uic_value, GList ** responseItems)
306 DM_ERROR ret = DM_OK;
308 retvm_if((uic_value) == NULL, COMMON_ERR_IS_NULL, "uic_value is NULL!!");
311 /* ui_ret = launch_om_dm_fumo_alert_ui();
313 ret = DM_ALERT_UI_LAUNCH_ERROR;
318 ui_ret = alert_uic_single_choice(uic_value);
320 if (uic_value->res_data->res_multi_data != NULL) {
322 for (iter = uic_value->res_data->res_multi_data; iter != NULL; iter = g_list_next(iter)) {
324 _DEBUG_INFO("choice data : %s", (char *)(iter->data));
325 data = strdup((char *)(iter->data));
326 (*responseItems) = g_list_append((*responseItems), data);
328 uic_value->res_data->status = DM_OK;
329 _DEBUG_INFO("single choice alert success : %d", DM_OK);
331 /*calcel or app launch fail */
333 data = strdup("NULL");
334 (*responseItems) = g_list_append((*responseItems), data);
335 uic_value->res_data->status = DM_ERR_NOT_EXECUTED;
336 _DEBUG_INFO("single choice alert fail : %d", DM_ERR_NOT_EXECUTED);
339 /*calcel or app launch fail or timeout */
341 data = strdup("NULL");
342 (*responseItems) = g_list_append((*responseItems), data);
343 uic_value->res_data->status = DM_ERR_NOT_EXECUTED;
344 _DEBUG_INFO("single choice alert fail : %d", DM_ERR_NOT_EXECUTED);
355 DM_ERROR ui_multiple_choice(uic_data * uic_value, GList ** responseItems)
359 DM_ERROR ret = DM_OK;
361 retvm_if((uic_value) == NULL, COMMON_ERR_IS_NULL, "uic_value is NULL!!");
364 /* ui_ret = launch_om_dm_fumo_alert_ui();
366 ret = DM_ALERT_UI_LAUNCH_ERROR;
370 ui_ret = alert_uic_multiple_choice(uic_value);
372 if (uic_value->res_data->res_multi_data != NULL) {
374 for (iter = uic_value->res_data->res_multi_data; iter != NULL; iter = g_list_next(iter)) {
376 _DEBUG_INFO("choice data : %s", (char *)(iter->data));
377 data = strdup((char *)(iter->data));
378 (*responseItems) = g_list_append((*responseItems), data);
380 uic_value->res_data->status = DM_OK;
381 _DEBUG_INFO("multiple choice alert success : %d", DM_OK);
383 /*calcel or app launch fail */
385 data = strdup("NULL");
386 (*responseItems) = g_list_append((*responseItems), data);
387 uic_value->res_data->status = DM_ERR_NOT_EXECUTED;
388 _DEBUG_INFO("multiple choice alert fail : %d", DM_ERR_NOT_EXECUTED);
392 /*calcel or app launch fail */
394 data = strdup("NULL");
395 (*responseItems) = g_list_append((*responseItems), data);
396 uic_value->res_data->status = DM_ERR_NOT_EXECUTED;
397 _DEBUG_INFO("multiple choice alert fail : %d", DM_ERR_NOT_EXECUTED);