Remove check type code.
[platform/core/uifw/voice-control-elm.git] / src / vc_elm.c
1 /*
2  * Copyright (c) 2011-2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <cynara-client.h>
18 #include <cynara-error.h>
19 #include <cynara-session.h>
20 #include <system_info.h>
21 #include "vc_elm_main.h"
22 #include <voice_control_elm.h>
23 #include <voice_control_elm_private.h>
24 #include <vconf.h>
25
26 #include "vc_elm.h"
27 #include "vc_elm_core.h"
28 #include "vc_elm_tools.h"
29 #include "vc_elm_tooltip.h"
30 #include "vc_elm_widget_wrapper.h"
31
32 //#define VC_VOICE_TOUCH_AUTOMODE               VCONFKEY_VC_VOICE_TOUCH_AUTOMODE
33 #define VC_VOICE_TOUCH_AUTOMODE         "db/voice/vc/voice_touch/automode"
34
35 #define VC_ELM_MODE_MANUAL              0
36
37 #define VC_ELM_MODE_AUTO_APP    1
38
39 #define VC_ELM_MODE_AUTO_APPFW  2
40
41 /**
42 * @brief Internal variable. It can check whether voice control elm is initialized or not.
43 */
44 static unsigned is_vc_elm_initialized = false;
45
46 /**
47 * @brief An internal variable for checking whether voice touch's auto mode is ON or not.
48 */
49 static int g_is_vt_automode = 0;
50
51 /**
52  * @brief App domain name of the current app.
53  */
54 static char *g_app_domain = NULL;
55 static Eina_List *g_handlers_list = NULL;
56
57 typedef enum {
58         VC_ELM_TYPE_EVAS_OBJECT = 0, VC_ELM_TYPE_ITEM = 1
59 } vc_elm_type_e;
60
61 struct __vc_elm_s {
62         vc_elm_type_e type;
63         intptr_t *data;
64 };
65
66 typedef struct __vc_elm_s vc_elm_s;
67
68 struct __vc_elm_widget_cb_data_s {
69         vc_elm_widget_cb callback;
70         void *data;
71 };
72
73 typedef struct __vc_elm_widget_cb_data_s vc_elm_widget_cb_data_s;
74
75 static int g_feature_enabled = -1;
76
77 static int g_privilege_allowed = -1;
78 static cynara *p_cynara = NULL;
79
80 static int g_auto_mode = 0;
81 static int g_click_method = 0;
82
83 static int __vc_elm_get_feature_enabled()
84 {
85         if (0 == g_feature_enabled) {
86                 VC_ELM_LOG_DBG("[ERROR] Voice control feature NOT supported"); //LCOV_EXCL_LINE
87                 return VC_ELM_ERROR_NOT_SUPPORTED;
88         } else if (-1 == g_feature_enabled) {
89                 bool vc_supported = false;
90                 bool mic_supported = false;
91                 if (0 == system_info_get_platform_bool(VC_ELM_FEATURE_PATH, &vc_supported)) {
92                         if (0 == system_info_get_platform_bool(VC_ELM_MIC_FEATURE_PATH, &mic_supported)) {
93                                 if (false == vc_supported || false == mic_supported) {
94                                         VC_ELM_LOG_DBG("[ERROR] Voice control feature NOT supported"); //LCOV_EXCL_LINE
95                                         g_feature_enabled = 0;
96                                         return VC_ELM_ERROR_NOT_SUPPORTED;
97                                 }
98
99                                 g_feature_enabled = 1;
100                         } else {
101                                 VC_ELM_LOG_DBG("[ERROR] Fail to get feature value"); //LCOV_EXCL_LINE
102                                 return VC_ELM_ERROR_NOT_SUPPORTED;
103                         }
104                 } else {
105                         VC_ELM_LOG_DBG("[ERROR] Fail to get feature value"); //LCOV_EXCL_LINE
106                         return VC_ELM_ERROR_NOT_SUPPORTED;
107                 }
108         }
109         return 0;
110 }
111
112 static int __check_privilege_initialize()
113 {
114         int ret = cynara_initialize(&p_cynara, NULL);
115         if (CYNARA_API_SUCCESS != ret)
116                 VC_ELM_LOG_ERR("[ERROR] fail to initialize"); //LCOV_EXCL_LINE
117
118         return ret == CYNARA_API_SUCCESS;
119 }
120
121 static int __check_privilege(const char* uid, const char * privilege)
122 {
123         FILE *fp = NULL;
124         char label_path[1024] = "/proc/self/attr/current";
125         char smack_label[1024] = {'\0',};
126
127         if (!p_cynara) {
128                 return false;
129         }
130
131         fp = fopen(label_path, "r");
132         if (fp != NULL) {
133                 if (0 >= fread(smack_label, 1, sizeof(smack_label), fp))
134                         VC_ELM_LOG_ERR("[ERROR] fail to fread"); //LCOV_EXCL_LINE
135
136                 fclose(fp);
137         }
138
139         pid_t pid = getpid();
140         char *session = cynara_session_from_pid(pid);
141         int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
142         VC_ELM_LOG_DBG("[Client]cynara_check returned %d(%s)", ret, (CYNARA_API_ACCESS_ALLOWED == ret) ? "Allowed" : "Denied");
143         if (session)
144                 free(session);
145
146         if (ret != CYNARA_API_ACCESS_ALLOWED)
147                 return false;
148         return true;
149 }
150
151 static void __check_privilege_deinitialize()
152 {
153         if (p_cynara)
154                 cynara_finish(p_cynara);
155         p_cynara = NULL;
156 }
157
158 static int __vc_elm_check_privilege()
159 {
160         char uid[16];
161
162         if (0 == g_privilege_allowed) {
163                 VC_ELM_LOG_ERR("[ERROR] Permission is denied"); //LCOV_EXCL_LINE
164                 return VC_ELM_ERROR_PERMISSION_DENIED;
165         } else if (-1 == g_privilege_allowed) {
166                 if (false == __check_privilege_initialize()) {
167                         VC_ELM_LOG_ERR("[ERROR] privilege initialize is failed"); //LCOV_EXCL_LINE
168                         return VC_ELM_ERROR_PERMISSION_DENIED;
169                 }
170                 snprintf(uid, 16, "%d", getuid());
171                 if (false == __check_privilege(uid, VC_ELM_PRIVILEGE)) {
172                         VC_ELM_LOG_ERR("[ERROR] Permission is denied"); //LCOV_EXCL_LINE
173                         g_privilege_allowed = 0;
174                         __check_privilege_deinitialize();
175                         return VC_ELM_ERROR_PERMISSION_DENIED;
176                 }
177                 __check_privilege_deinitialize();
178         }
179
180         g_privilege_allowed = 1;
181         return VC_ELM_ERROR_NONE;
182 }
183
184 void __vc_config_vtauto_changed_cb(keynode_t *key, void *data)
185 {
186         (void)data; //unused parameter
187         int ret = vconf_get_bool(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE, &g_is_vt_automode);
188         if (0 != ret) {
189                 VC_ELM_LOG_ERR("Fail to get vconfkey(%s), current voice touch mode(%d)", key, g_is_vt_automode); //LCOV_EXCL_LINE
190         }
191
192         return;
193 }
194
195 int vc_elm_initialize()
196 {
197         if (0 != __vc_elm_get_feature_enabled()) {
198                 return VC_ELM_ERROR_NOT_SUPPORTED;
199         }
200
201         if (true == is_vc_elm_initialized) {
202                 VC_ELM_LOG_DBG("vc elm is already initialized"); //LCOV_EXCL_LINE
203                 return VC_ELM_ERROR_INVALID_STATE;
204         }
205
206         eina_log_level_set(EINA_LOG_LEVEL_DBG);
207
208         _vc_elm_core_enable_name_autogen(EINA_FALSE);
209         _vc_elm_core_init();
210
211         g_handlers_list = NULL;
212         _vc_elm_core_load();
213
214         is_vc_elm_initialized = true;
215
216         /* Initialize voice touch's automode and Register to detect voice touch automode change */
217         vconf_get_bool(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE, &g_is_vt_automode);
218
219         vconf_notify_key_changed(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE, __vc_config_vtauto_changed_cb, NULL);
220
221         VC_ELM_LOG_DBG("vc elm is initialized");
222         return VC_ELM_ERROR_NONE;
223 }
224
225 int vc_elm_deinitialize()
226 {
227         Eina_List *l;
228         vc_elm_h handler = NULL;
229
230         if (0 != __vc_elm_get_feature_enabled()) {
231                 return VC_ELM_ERROR_NOT_SUPPORTED;
232         }
233
234         if (false == is_vc_elm_initialized) {
235                 VC_ELM_LOG_DBG("vc elm is already deinitialized"); //LCOV_EXCL_LINE
236                 return VC_ELM_ERROR_INVALID_STATE;
237         }
238
239         if (NULL != g_handlers_list) {
240                 EINA_LIST_FOREACH(g_handlers_list, l, handler) {
241                         vc_elm_unset_command(handler);
242                         vc_elm_unset_command_hint(handler);
243                         vc_elm_destroy(handler);
244                 }
245                 eina_list_free(g_handlers_list);
246         }
247
248         vconf_ignore_key_changed(VCONFKEY_VC_VOICE_TOUCH_AUTOMODE, __vc_config_vtauto_changed_cb);
249
250         _vc_elm_core_fini();
251
252         if (NULL != g_app_domain) {
253                 free(g_app_domain);
254                 g_app_domain = NULL;
255         }
256
257         is_vc_elm_initialized = false;
258         VC_ELM_LOG_DBG("shutting down vc_elm");
259         return VC_ELM_ERROR_NONE;
260 }
261
262 int vc_elm_foreach_supported_languages(vc_elm_supported_language_cb callback, void *user_data)
263 {
264         int ret = 0;
265         if (0 != __vc_elm_get_feature_enabled()) {
266                 return VC_ELM_ERROR_NOT_SUPPORTED;
267         }
268         if (0 != __vc_elm_check_privilege()) {
269                 return VC_ELM_ERROR_PERMISSION_DENIED;
270         }
271
272         ret = _vc_elm_widget_wrapper_foreach_supported_languages(callback, user_data);
273         return ret;
274 }
275
276 int vc_elm_get_current_language(char **language)
277 {
278         int ret = 0;
279         if (0 != __vc_elm_get_feature_enabled()) {
280                 return VC_ELM_ERROR_NOT_SUPPORTED;
281         }
282         if (0 != __vc_elm_check_privilege()) {
283                 return VC_ELM_ERROR_PERMISSION_DENIED;
284         }
285
286         ret = _vc_elm_widget_wrapper_get_current_language(language);
287         return ret;
288 }
289
290 static Eina_Bool __hash_fn(const Eina_Hash *hash, const void *key, void *kdata, void *fdata)
291 {
292         vc_elm_widget_cb_data_s *data;
293         vc_elm_widget_cb callback;
294         (void)hash;
295         (void)kdata;
296         data = (vc_elm_widget_cb_data_s *)fdata;
297         callback = data->callback;
298         callback(key, data->data);
299         return EINA_TRUE;
300 }
301
302 int vc_elm_foreach_supported_widgets(vc_elm_widget_cb callback, void *user_data)
303 {
304         vc_elm_widget_cb_data_s data;
305         const Eina_Hash  *hash = NULL;
306
307         if (0 != __vc_elm_get_feature_enabled()) {
308                 return VC_ELM_ERROR_NOT_SUPPORTED;
309         }
310         if (0 != __vc_elm_check_privilege()) {
311                 return VC_ELM_ERROR_PERMISSION_DENIED;
312         }
313
314         if (NULL == callback) {
315                 VC_ELM_LOG_ERR("Invalid parameters detected!"); //LCOV_EXCL_LINE
316                 return VC_ELM_ERROR_INVALID_PARAMETER;
317         }
318         if (false == is_vc_elm_initialized) {
319                 VC_ELM_LOG_ERR("Invalid state detected! Library not initialized!"); //LCOV_EXCL_LINE
320                 return VC_ELM_ERROR_INVALID_STATE;
321         }
322         data.callback = callback;
323         data.data = user_data;
324         hash = _vc_elm_core_get_config_widget_map();
325         if (NULL == hash) {
326                 VC_ELM_LOG_ERR("Config widget map is NULL!"); //LCOV_EXCL_LINE
327                 return VC_ELM_ERROR_OPERATION_FAILED;
328         }
329         eina_hash_foreach(hash, __hash_fn, &data);
330         return VC_ELM_ERROR_NONE;
331 }
332
333 int vc_elm_foreach_supported_actions(const char *widget, vc_elm_action_cb callback, void *user_data)
334 {
335         const Eina_Hash *hash = NULL;
336         Eina_List *actions_list = NULL;
337         Eina_List *l = NULL;
338         const char *action_tag = NULL;
339
340         if (0 != __vc_elm_get_feature_enabled()) {
341                 return VC_ELM_ERROR_NOT_SUPPORTED;
342         }
343         if (0 != __vc_elm_check_privilege()) {
344                 return VC_ELM_ERROR_PERMISSION_DENIED;
345         }
346
347         if ((NULL == widget) || (NULL == callback)) {
348                 VC_ELM_LOG_ERR("Invalid parameters detected!"); //LCOV_EXCL_LINE
349                 return VC_ELM_ERROR_INVALID_PARAMETER;
350         }
351         if (false == is_vc_elm_initialized) {
352                 VC_ELM_LOG_ERR("Invalid state detected! Library not initialized!"); //LCOV_EXCL_LINE
353                 return VC_ELM_ERROR_INVALID_STATE;
354         }
355         hash = _vc_elm_core_get_config_widget_map();
356         if (NULL == hash) {
357                 VC_ELM_LOG_ERR("Config widget map is NULL!"); //LCOV_EXCL_LINE
358                 return VC_ELM_ERROR_OPERATION_FAILED;
359         }
360         actions_list = (Eina_List *)eina_hash_find(hash, widget);
361         if (NULL == actions_list) {
362                 VC_ELM_LOG_ERR("Action list is NULL!"); //LCOV_EXCL_LINE
363                 return VC_ELM_ERROR_OPERATION_FAILED;
364         }
365         EINA_LIST_FOREACH(actions_list, l, action_tag) {
366                 if (NULL != action_tag) {
367                         callback(action_tag, user_data);
368                 }
369         }
370         return VC_ELM_ERROR_NONE;
371 }
372
373 int vc_elm_get_action_command(const char *action, char **command)
374 {
375         const Eina_Hash *hash = NULL;
376         const char *command_name = NULL;
377         size_t len = 0;
378
379         if (0 != __vc_elm_get_feature_enabled()) {
380                 return VC_ELM_ERROR_NOT_SUPPORTED;
381         }
382         if (0 != __vc_elm_check_privilege()) {
383                 return VC_ELM_ERROR_PERMISSION_DENIED;
384         }
385
386         if ((NULL == action) || (NULL == command)) {
387                 VC_ELM_LOG_ERR("Invalid parameters detected!"); //LCOV_EXCL_LINE
388                 return VC_ELM_ERROR_INVALID_PARAMETER;
389         }
390         if (false == is_vc_elm_initialized) {
391                 VC_ELM_LOG_ERR("Invalid state detected! Library not initialized!"); //LCOV_EXCL_LINE
392                 return VC_ELM_ERROR_INVALID_STATE;
393         }
394         hash = _vc_elm_core_get_config_action_map();
395         if (NULL == hash) {
396                 VC_ELM_LOG_ERR("Config action map is NULL!"); //LCOV_EXCL_LINE
397                 return VC_ELM_ERROR_OPERATION_FAILED;
398         }
399         command_name = eina_hash_find(_vc_elm_core_get_config_action_map(), action);
400         if (NULL == command_name) {
401                 VC_ELM_LOG_ERR("No command for given action name!"); //LCOV_EXCL_LINE
402                 return VC_ELM_ERROR_OPERATION_FAILED;
403         }
404         len = strlen(command_name) + 1;
405         *command = (char *)calloc(len, sizeof(char));
406         if (NULL == *command) {
407                 VC_ELM_LOG_ERR("Can not allocate memory!"); //LCOV_EXCL_LINE
408                 return VC_ELM_ERROR_OPERATION_FAILED;
409         }
410         memcpy(*command, command_name, len);
411
412         VC_ELM_LOG_INFO("[SUCCESS] get action command, action(%s), command(%s)", action, *command);
413         return VC_ELM_ERROR_NONE;
414 }
415
416 int vc_elm_create_object(Evas_Object *object, vc_elm_h *vc_elm)
417 {
418         vc_elm_s *handler = NULL;
419         if (0 != __vc_elm_get_feature_enabled()) {
420                 return VC_ELM_ERROR_NOT_SUPPORTED;
421         }
422         if (0 != __vc_elm_check_privilege()) {
423                 return VC_ELM_ERROR_PERMISSION_DENIED;
424         }
425
426         if (NULL == vc_elm) {
427                 VC_ELM_LOG_ERR("Invalid parameters detected! (vc_elm_h *) pointer is NULL"); //LCOV_EXCL_LINE
428                 return VC_ELM_ERROR_INVALID_PARAMETER;
429         }
430         if ((NULL == object) || (!elm_object_widget_check(object))) {
431                 VC_ELM_LOG_ERR("Invalid parameters detected! Incorrect (Evas_Object *)"); //LCOV_EXCL_LINE
432                 *vc_elm = NULL;
433                 return VC_ELM_ERROR_INVALID_PARAMETER;
434         }
435         if (false == is_vc_elm_initialized) {
436                 VC_ELM_LOG_ERR("Invalid state detected! Library not initialized!"); //LCOV_EXCL_LINE
437                 return VC_ELM_ERROR_INVALID_STATE;
438         }
439         if (!_vc_elm_core_register_default_widget(_get_ui_object_name(object), EINA_FALSE, NULL) || (NULL == eina_hash_find(_vc_elm_core_get_config_widget_map(), elm_widget_type_get(object)))) {
440                 VC_ELM_LOG_ERR("Not supported widget"); //LCOV_EXCL_LINE
441                 *vc_elm = NULL;
442                 return VC_ELM_ERROR_NOT_SUPPORTED;
443         }
444         handler = (vc_elm_s *)calloc(1, sizeof(vc_elm_s));
445         if (NULL == handler) {
446                 VC_ELM_LOG_ERR("Calloc function returned NULL"); //LCOV_EXCL_LINE
447                 return VC_ELM_ERROR_OUT_OF_MEMORY;
448         }
449         handler->type = VC_ELM_TYPE_EVAS_OBJECT;
450         handler->data = (void *)object;
451         g_handlers_list = eina_list_append(g_handlers_list, handler);
452         *vc_elm = (vc_elm_h)handler;
453
454         VC_ELM_LOG_INFO("[SUCCESS] create object(%s)", _get_ui_object_name(object));
455         _vc_elm_core_set_view_changed();
456         return VC_ELM_ERROR_NONE;
457 }
458
459 int vc_elm_create_item(Elm_Object_Item *item, vc_elm_h *vc_elm)
460 {
461         vc_elm_s *handler = NULL;
462         if (0 != __vc_elm_get_feature_enabled()) {
463                 return VC_ELM_ERROR_NOT_SUPPORTED;
464         }
465         if (0 != __vc_elm_check_privilege()) {
466                 return VC_ELM_ERROR_PERMISSION_DENIED;
467         }
468
469         if (NULL == vc_elm) {
470                 VC_ELM_LOG_ERR("Invalid parameters detected! (vc_elm_h *) pointer is NULL"); //LCOV_EXCL_LINE
471                 return VC_ELM_ERROR_INVALID_PARAMETER;
472         }
473         if (NULL == item) {
474                 VC_ELM_LOG_ERR("Invalid parameters detected! (Elm_Object_Item *) pointer is NULL"); //LCOV_EXCL_LINE
475                 *vc_elm = NULL;
476                 return VC_ELM_ERROR_INVALID_PARAMETER;
477         }
478         if (false == is_vc_elm_initialized) {
479                 VC_ELM_LOG_ERR("Invalid state detected! Library not initialized!"); //LCOV_EXCL_LINE
480                 return VC_ELM_ERROR_INVALID_STATE;
481         }
482         handler = (vc_elm_s *)calloc(1, sizeof(vc_elm_s));
483         if (NULL == handler) {
484                 VC_ELM_LOG_ERR("Calloc function returned NULL"); //LCOV_EXCL_LINE
485                 *vc_elm = NULL;
486                 return VC_ELM_ERROR_OUT_OF_MEMORY;
487         }
488         handler->type = VC_ELM_TYPE_ITEM;
489         handler->data = (void *)item;
490         g_handlers_list = eina_list_append(g_handlers_list, handler);
491         *vc_elm = (vc_elm_h)handler;
492
493         VC_ELM_LOG_INFO("[SUCCESS] create item object)");
494         _vc_elm_core_set_view_changed();
495         return VC_ELM_ERROR_NONE;
496 }
497
498 int vc_elm_destroy(vc_elm_h vc_elm)
499 {
500         vc_elm_s *handler = NULL;
501         Eina_List *list = NULL;
502         if (0 != __vc_elm_get_feature_enabled()) {
503                 return VC_ELM_ERROR_NOT_SUPPORTED;
504         }
505         if (0 != __vc_elm_check_privilege()) {
506                 return VC_ELM_ERROR_PERMISSION_DENIED;
507         }
508
509         if (NULL == vc_elm) {
510                 VC_ELM_LOG_ERR("Invalid vc_elm parameter detected!"); //LCOV_EXCL_LINE
511                 return VC_ELM_ERROR_INVALID_PARAMETER;
512         }
513         handler = (vc_elm_s *)vc_elm;
514         list = eina_list_data_find_list(g_handlers_list, handler);
515         if (NULL == list) {
516                 VC_ELM_LOG_ERR("Bad handler pointer detected!"); //LCOV_EXCL_LINE
517                 return VC_ELM_ERROR_INVALID_PARAMETER;
518         }
519         g_handlers_list = eina_list_remove_list(g_handlers_list, list);
520         free(handler);
521         handler = NULL;
522
523         VC_ELM_LOG_INFO("[SUCCESS] destroy");
524         _vc_elm_core_set_view_changed();
525         return VC_ELM_ERROR_NONE;
526 }
527
528 int vc_elm_set_command(vc_elm_h vc_elm, const char *command)
529 {
530         vc_elm_s *handler = (vc_elm_s *)vc_elm;
531         int type = 0;
532         if (0 != __vc_elm_get_feature_enabled()) {
533                 return VC_ELM_ERROR_NOT_SUPPORTED;
534         }
535         if (0 != __vc_elm_check_privilege()) {
536                 return VC_ELM_ERROR_PERMISSION_DENIED;
537         }
538
539         if (NULL == vc_elm) {
540                 VC_ELM_LOG_ERR("Invalid vc_elm parameter detected!"); //LCOV_EXCL_LINE
541                 return VC_ELM_ERROR_INVALID_PARAMETER;
542         }
543         type = handler->type;
544         if (VC_ELM_TYPE_EVAS_OBJECT == type) {
545                 Evas_Object *obj = (Evas_Object *)handler->data;
546                 return _vc_elm_set_object_command(obj, command);
547         } else if (VC_ELM_TYPE_ITEM == type) {
548                 Elm_Object_Item *it = (Elm_Object_Item *)handler->data;
549                 return _vc_elm_set_item_object_command(it, command);
550         }
551
552         VC_ELM_LOG_INFO("[SUCCESS] set command(%s)", command);
553         _vc_elm_core_set_view_changed();
554         return VC_ELM_ERROR_INVALID_PARAMETER;
555 }
556
557 int vc_elm_unset_command(vc_elm_h vc_elm)
558 {
559         vc_elm_s *handler = (vc_elm_s *)vc_elm;
560         int type = 0;
561         if (0 != __vc_elm_get_feature_enabled()) {
562                 return VC_ELM_ERROR_NOT_SUPPORTED;
563         }
564         if (0 != __vc_elm_check_privilege()) {
565                 return VC_ELM_ERROR_PERMISSION_DENIED;
566         }
567
568         if (NULL == vc_elm) {
569                 VC_ELM_LOG_ERR("Invalid vc_elm parameter detected!"); //LCOV_EXCL_LINE
570                 return VC_ELM_ERROR_INVALID_PARAMETER;
571         }
572         type = handler->type;
573         if (VC_ELM_TYPE_EVAS_OBJECT == type) {
574                 Evas_Object *obj = (Evas_Object *)handler->data;
575                 return _vc_elm_unset_object_command(obj);
576         } else if (VC_ELM_TYPE_ITEM == type) {
577                 Elm_Object_Item *it = (Elm_Object_Item *)handler->data;
578                 return _vc_elm_unset_item_object_command(it);
579         }
580
581         VC_ELM_LOG_INFO("[SUCCESS] unset command");
582         _vc_elm_core_set_view_changed();
583         return VC_ELM_ERROR_INVALID_PARAMETER;
584 }
585
586 int vc_elm_set_command_hint(vc_elm_h vc_elm, const char* hint)
587 {
588         vc_elm_s *handler = (vc_elm_s *)vc_elm;
589         int type = 0;
590         if (0 != __vc_elm_get_feature_enabled()) {
591                 return VC_ELM_ERROR_NOT_SUPPORTED;
592         }
593         if (0 != __vc_elm_check_privilege()) {
594                 return VC_ELM_ERROR_PERMISSION_DENIED;
595         }
596
597         if (NULL == vc_elm) {
598                 VC_ELM_LOG_ERR("Invalid vc_elm parameter detected!"); //LCOV_EXCL_LINE
599                 return VC_ELM_ERROR_INVALID_PARAMETER;
600         }
601         type = handler->type;
602         if (VC_ELM_TYPE_EVAS_OBJECT == type) {
603                 Evas_Object *obj = (Evas_Object *)handler->data;
604                 return _vc_elm_set_object_hint(obj, hint);
605         } else if (VC_ELM_TYPE_ITEM == type) {
606                 Elm_Object_Item *it = (Elm_Object_Item *)handler->data;
607                 return _vc_elm_set_item_object_hint(it, hint);
608         }
609
610         VC_ELM_LOG_INFO("[SUCCESS] set hint(%s)", hint);
611         _vc_elm_core_set_view_changed();
612         return VC_ELM_ERROR_INVALID_PARAMETER;
613 }
614
615 int vc_elm_unset_command_hint(vc_elm_h vc_elm)
616 {
617         vc_elm_s *handler = (vc_elm_s *)vc_elm;
618         int type = 0;
619         if (0 != __vc_elm_get_feature_enabled()) {
620                 return VC_ELM_ERROR_NOT_SUPPORTED;
621         }
622         if (0 != __vc_elm_check_privilege()) {
623                 return VC_ELM_ERROR_PERMISSION_DENIED;
624         }
625
626         if (NULL == vc_elm) {
627                 VC_ELM_LOG_ERR("Invalid vc_elm parameter detected!"); //LCOV_EXCL_LINE
628                 return VC_ELM_ERROR_INVALID_PARAMETER;
629         }
630         type = handler->type;
631         if (VC_ELM_TYPE_EVAS_OBJECT == type) {
632                 Evas_Object *obj = (Evas_Object *)handler->data;
633                 return _vc_elm_unset_object_hint(obj);
634         } else if (VC_ELM_TYPE_ITEM == type) {
635                 Elm_Object_Item *it = (Elm_Object_Item *)handler->data;
636                 return _vc_elm_unset_item_object_hint(it);
637         }
638
639         VC_ELM_LOG_INFO("[SUCCESS] unset hint");
640         _vc_elm_core_set_view_changed();
641         return VC_ELM_ERROR_INVALID_PARAMETER;
642 }
643
644 int vc_elm_set_command_hint_direction(vc_elm_h vc_elm, vc_elm_direction_e direction)
645 {
646         vc_elm_s *handler = (vc_elm_s *)vc_elm;
647         int type = 0;
648         if (0 != __vc_elm_get_feature_enabled()) {
649                 return VC_ELM_ERROR_NOT_SUPPORTED;
650         }
651         if (0 != __vc_elm_check_privilege()) {
652                 return VC_ELM_ERROR_PERMISSION_DENIED;
653         }
654
655         if (NULL == vc_elm) {
656                 VC_ELM_LOG_ERR("Invalid vc_elm parameter detected!"); //LCOV_EXCL_LINE
657                 return VC_ELM_ERROR_INVALID_PARAMETER;
658         }
659         type = handler->type;
660         if (VC_ELM_TYPE_EVAS_OBJECT == type) {
661                 Evas_Object *obj = (Evas_Object *)handler->data;
662                 return _vc_elm_set_object_hint_direction(obj, direction);
663         } else if (VC_ELM_TYPE_ITEM == type) {
664                 Elm_Object_Item *it = (Elm_Object_Item *)handler->data;
665                 Evas_Object *parent = elm_object_item_widget_get(it);
666                 return _vc_elm_set_sub_item_hint_direction(parent, direction);
667         }
668
669         VC_ELM_LOG_INFO("[SUCCESS] set hint direction(%d)", direction);
670         _vc_elm_core_set_view_changed();
671         return VC_ELM_ERROR_INVALID_PARAMETER;
672 }
673
674 int vc_elm_get_command_hint_direction(vc_elm_h vc_elm, vc_elm_direction_e *direction)
675 {
676         vc_elm_s *handler = (vc_elm_s *)vc_elm;
677         int type = 0;
678         if (0 != __vc_elm_get_feature_enabled()) {
679                 return VC_ELM_ERROR_NOT_SUPPORTED;
680         }
681         if (0 != __vc_elm_check_privilege()) {
682                 return VC_ELM_ERROR_PERMISSION_DENIED;
683         }
684
685         if (NULL == vc_elm) {
686                 VC_ELM_LOG_ERR("Invalid vc_elm parameter detected!"); //LCOV_EXCL_LINE
687                 return VC_ELM_ERROR_INVALID_PARAMETER;
688         }
689         type = handler->type;
690         if (VC_ELM_TYPE_EVAS_OBJECT == type) {
691                 Evas_Object *obj = (Evas_Object *)handler->data;
692                 return _vc_elm_get_object_hint_direction(obj, direction);
693         } else if (VC_ELM_TYPE_ITEM == type) {
694                 Elm_Object_Item *it = (Elm_Object_Item *)handler->data;
695                 Evas_Object *parent = elm_object_item_widget_get(it);
696                 return _vc_elm_get_sub_item_hint_direction(parent, direction);
697         }
698
699         VC_ELM_LOG_INFO("[SUCCESS] get hint direction(%d)", *direction);
700         return VC_ELM_ERROR_INVALID_PARAMETER;
701 }
702
703 int vc_elm_set_command_hint_offset(vc_elm_h vc_elm, int pos_x, int pos_y)
704 {
705         vc_elm_s *handler = (vc_elm_s *)vc_elm;
706         int type = 0;
707         if (0 != __vc_elm_get_feature_enabled()) {
708                 return VC_ELM_ERROR_NOT_SUPPORTED;
709         }
710         if (0 != __vc_elm_check_privilege()) {
711                 return VC_ELM_ERROR_PERMISSION_DENIED;
712         }
713
714         if (NULL == vc_elm) {
715                 VC_ELM_LOG_ERR("Invalid vc_elm parameter detected!"); //LCOV_EXCL_LINE
716                 return VC_ELM_ERROR_INVALID_PARAMETER;
717         }
718         type = handler->type;
719         if (VC_ELM_TYPE_EVAS_OBJECT == type) {
720                 Evas_Object *obj = (Evas_Object *)handler->data;
721                 return _vc_elm_set_object_custom_hint(obj, NULL, pos_x, pos_y);
722         } else if (VC_ELM_TYPE_ITEM == type) {
723                 Elm_Object_Item *it = (Elm_Object_Item *)handler->data;
724                 return _vc_elm_set_item_object_custom_hint(it, NULL, pos_x, pos_y);
725         }
726
727         VC_ELM_LOG_INFO("[SUCCESS] set hint offset, x(%d), y(%d)", pos_x, pos_y);
728         _vc_elm_core_set_view_changed();
729         return VC_ELM_ERROR_INVALID_PARAMETER;
730 }
731
732 int vc_elm_get_command_hint_offset(vc_elm_h vc_elm, int *pos_x, int *pos_y)
733 {
734         vc_elm_s *handler = (vc_elm_s *)vc_elm;
735         const char *path = NULL;
736         int type = 0;
737         if (0 != __vc_elm_get_feature_enabled()) {
738                 return VC_ELM_ERROR_NOT_SUPPORTED;
739         }
740         if (0 != __vc_elm_check_privilege()) {
741                 return VC_ELM_ERROR_PERMISSION_DENIED;
742         }
743
744         if (NULL == vc_elm) {
745                 VC_ELM_LOG_ERR("Invalid vc_elm parameter detected!"); //LCOV_EXCL_LINE
746                 return VC_ELM_ERROR_INVALID_PARAMETER;
747         }
748         if ((NULL == pos_x) || (NULL == pos_y)) {
749                 VC_ELM_LOG_ERR("Invalid position pointers detected!"); //LCOV_EXCL_LINE
750                 return VC_ELM_ERROR_INVALID_PARAMETER;
751         }
752         type = handler->type;
753         if (VC_ELM_TYPE_EVAS_OBJECT == type) {
754                 Evas_Object *obj = (Evas_Object *)handler->data;
755                 return _vc_elm_get_object_custom_hint(obj, &path, pos_x, pos_y);
756         } else if (VC_ELM_TYPE_ITEM == type) {
757                 Elm_Object_Item *it = (Elm_Object_Item *)handler->data;
758                 return _vc_elm_get_item_object_custom_hint(it, &path, pos_x, pos_y);
759         }
760         return VC_ELM_ERROR_INVALID_PARAMETER;
761 }
762
763 int vc_elm_set_current_language_changed_cb(vc_elm_current_language_changed_cb callback, void *user_data)
764 {
765         int ret = VC_ELM_ERROR_NONE;
766
767         if (0 != __vc_elm_get_feature_enabled()) {
768                 return VC_ELM_ERROR_NOT_SUPPORTED;
769         }
770         if (0 != __vc_elm_check_privilege()) {
771                 return VC_ELM_ERROR_PERMISSION_DENIED;
772         }
773
774         if (false == is_vc_elm_initialized) {
775                 VC_ELM_LOG_ERR("Invalid state detected! Library not initialized!"); //LCOV_EXCL_LINE
776                 return VC_ELM_ERROR_INVALID_STATE;
777         }
778
779         ret = _vc_elm_widget_wrapper_set_current_language_changed_callback(callback, user_data);
780         if (0 != ret) {
781                 return VC_ELM_ERROR_OPERATION_FAILED;
782         }
783         return VC_ELM_ERROR_NONE;
784 }
785
786 int vc_elm_unset_current_language_changed_cb(void)
787 {
788         int ret = VC_ELM_ERROR_NONE;
789
790         if (0 != __vc_elm_get_feature_enabled()) {
791                 return VC_ELM_ERROR_NOT_SUPPORTED;
792         }
793         if (0 != __vc_elm_check_privilege()) {
794                 return VC_ELM_ERROR_PERMISSION_DENIED;
795         }
796
797         if (false == is_vc_elm_initialized) {
798                 VC_ELM_LOG_ERR("Invalid state detected! Library not initialized!"); //LCOV_EXCL_LINE
799                 return VC_ELM_ERROR_INVALID_STATE;
800         }
801
802         ret = _vc_elm_widget_wrapper_unset_current_language_changed_callback();
803         if (0 != ret) {
804                 return VC_ELM_ERROR_OPERATION_FAILED;
805         }
806         return VC_ELM_ERROR_NONE;
807 }
808
809 int _vc_elm_set_object_command(Evas_Object *obj, const char *command)
810 {
811         if (_vc_elm_core_set_object_command(obj, command))
812                 return VC_ELM_ERROR_NONE;
813         else
814                 return VC_ELM_ERROR_OPERATION_FAILED;
815 }
816
817 int _vc_elm_unset_object_command(Evas_Object *obj)
818 {
819         if (_vc_elm_core_unset_object_command(obj))
820                 return VC_ELM_ERROR_NONE;
821         else
822                 return VC_ELM_ERROR_OPERATION_FAILED;
823 }
824
825 int _vc_elm_set_object_hint(Evas_Object *obj, const char *hint)
826 {
827         if (_vc_elm_core_set_object_hint(obj, hint))
828                 return VC_ELM_ERROR_NONE;
829         else
830                 return VC_ELM_ERROR_OPERATION_FAILED;
831 }
832
833 int _vc_elm_unset_object_hint(Evas_Object *obj)
834 {
835         if (_vc_elm_core_unset_object_hint(obj))
836                 return VC_ELM_ERROR_NONE;
837         else
838                 return VC_ELM_ERROR_OPERATION_FAILED;
839 }
840
841 int _vc_elm_set_object_custom_hint(Evas_Object *obj, const char *image_path, int pos_x, int pos_y)
842 {
843         if (_vc_elm_core_set_object_custom_hint(obj, image_path, pos_x, pos_y))
844                 return VC_ELM_ERROR_NONE;
845         else
846                 return VC_ELM_ERROR_OPERATION_FAILED;
847 }
848
849 int _vc_elm_get_object_custom_hint(Evas_Object *obj, const char **image_path, int *pos_x, int *pos_y)
850 {
851         if (_vc_elm_core_get_object_custom_hint(obj, image_path, pos_x, pos_y))
852                 return VC_ELM_ERROR_NONE;
853         else
854                 return VC_ELM_ERROR_OPERATION_FAILED;
855 }
856
857 int _vc_elm_set_item_object_custom_hint(Elm_Object_Item *obj, const char *image_path, int pos_x, int pos_y)
858 {
859         if (_vc_elm_core_set_item_object_custom_hint(obj, image_path, pos_x, pos_y))
860                 return VC_ELM_ERROR_NONE;
861         else
862                 return VC_ELM_ERROR_OPERATION_FAILED;
863 }
864
865 int _vc_elm_get_item_object_custom_hint(Elm_Object_Item *obj, const char **image_path, int *pos_x, int *pos_y)
866 {
867         if (_vc_elm_core_get_item_object_custom_hint(obj, image_path, pos_x, pos_y))
868                 return VC_ELM_ERROR_NONE;
869         else
870                 return VC_ELM_ERROR_OPERATION_FAILED;
871 }
872
873 int _vc_elm_set_item_object_command(Elm_Object_Item *obj, const char *command)
874 {
875         if (_vc_elm_core_set_item_object_command(obj, command))
876                 return VC_ELM_ERROR_NONE;
877         else
878                 return VC_ELM_ERROR_OPERATION_FAILED;
879 }
880
881 int _vc_elm_unset_item_object_command(Elm_Object_Item *obj)
882 {
883         if (_vc_elm_core_unset_item_object_command(obj))
884                 return VC_ELM_ERROR_NONE;
885         else
886                 return VC_ELM_ERROR_OPERATION_FAILED;
887 }
888
889 int _vc_elm_set_item_object_hint(Elm_Object_Item *obj, const char *hint)
890 {
891         if (_vc_elm_core_set_item_object_hint(obj, hint))
892                 return VC_ELM_ERROR_NONE;
893         else
894                 return VC_ELM_ERROR_OPERATION_FAILED;
895 }
896
897 int _vc_elm_unset_item_object_hint(Elm_Object_Item *obj)
898 {
899         if (_vc_elm_core_unset_item_object_hint(obj))
900                 return VC_ELM_ERROR_NONE;
901         else
902                 return VC_ELM_ERROR_OPERATION_FAILED;
903 }
904
905 int _vc_elm_enable_name_autogen_enable(Eina_Bool autogen)
906 {
907         if (_vc_elm_core_enable_name_autogen(autogen))
908                 return VC_ELM_ERROR_NONE;
909         else
910                 return VC_ELM_ERROR_OPERATION_FAILED;
911 }
912
913 vc_elm_widget_info*
914 _vc_elm_register_widget(const char *widget_name, vc_elm_get_subobjects_cb get_subobjects_func, vc_elm_command_filter_cb is_feltered_func, void *user_data)
915 {
916         return _vc_elm_core_register_widget(widget_name, get_subobjects_func, is_feltered_func, user_data);
917 }
918
919 void _vc_elm_register_action(vc_elm_widget_info *info, const char *action_name, void *data, vc_elm_action_activator_cb func)
920 {
921         _vc_elm_core_register_action(info, action_name, data, func);
922 }
923
924 int _vc_elm_set_object_hint_direction(Evas_Object *obj, vc_elm_direction_e direction)
925 {
926         if (_vc_elm_core_set_object_hint_direction(obj, direction))
927                 return VC_ELM_ERROR_NONE;
928         else
929                 return VC_ELM_ERROR_OPERATION_FAILED;
930 }
931
932 int _vc_elm_get_object_hint_direction(Evas_Object *obj, vc_elm_direction_e *direction)
933 {
934         if (_vc_elm_core_get_object_hint_direction(obj, direction))
935                 return VC_ELM_ERROR_NONE;
936         else
937                 return VC_ELM_ERROR_OPERATION_FAILED;
938 }
939
940 int _vc_elm_set_sub_item_hint_direction(Evas_Object *obj, vc_elm_direction_e direction)
941 {
942         if (_vc_elm_core_set_sub_item_hint_direction(obj, direction))
943                 return VC_ELM_ERROR_NONE;
944         else
945                 return VC_ELM_ERROR_OPERATION_FAILED;
946 }
947
948 int _vc_elm_get_sub_item_hint_direction(Evas_Object *obj, vc_elm_direction_e *direction)
949 {
950         if (_vc_elm_core_get_sub_item_hint_direction(obj, direction))
951                 return VC_ELM_ERROR_NONE;
952         else
953                 return VC_ELM_ERROR_OPERATION_FAILED;
954 }
955 //LCOV_EXCL_START
956 int _vc_elm_set_text_domain(const char *domain, const char *locale_dir)
957 {
958
959         if (NULL == domain)
960                 return VC_ELM_ERROR_OPERATION_FAILED;
961
962         if (NULL != g_app_domain)
963                 free(g_app_domain);
964
965         g_app_domain = strdup(domain);
966         bindtextdomain(g_app_domain, locale_dir);
967
968         return VC_ELM_ERROR_NONE;
969 }
970
971 int _vc_elm_get_text_domain(char **domain)
972 {
973         if (NULL == g_app_domain) {
974                 *domain = NULL;
975                 return VC_ELM_ERROR_OPERATION_FAILED;
976         }
977
978         *domain = strdup(g_app_domain);
979         return VC_ELM_ERROR_NONE;
980 }
981
982 int vc_elm_is_supported_vt_auto(int* is_vt_automode)
983 {
984         if (0 != __vc_elm_get_feature_enabled()) {
985                 return VC_ELM_ERROR_NOT_SUPPORTED;
986         }
987
988         *is_vt_automode = g_is_vt_automode;
989         VC_ELM_LOG_DBG("Success to get vconfkey(%d)", *is_vt_automode);
990
991         return VC_ELM_ERROR_NONE;
992 }
993
994 int _vc_elm_set_auto_register_mode(int mode, int click_method)
995 {
996         g_auto_mode = mode;
997         g_click_method = click_method;
998
999         VC_ELM_LOG_DBG("g_auto_mode: %d, g_click_method: %d", g_auto_mode, g_click_method);
1000
1001         return 0;
1002 }
1003
1004 int _vc_elm_get_auto_register_mode(int* mode, int* click_method)
1005 {
1006         if (0 == g_is_vt_automode) {
1007                 VC_ELM_LOG_DBG("vt_automode is FALSE");
1008                 *mode = g_auto_mode;
1009                 *click_method = g_click_method;
1010         } else {
1011                 VC_ELM_LOG_DBG("vt_automode is TRUE");
1012                 *mode = (int)VC_ELM_MODE_AUTO_APPFW;
1013                 *click_method = g_click_method;
1014         }
1015
1016         *click_method = 1;
1017         VC_ELM_LOG_DBG("mode: %d, click_method: %d", *mode, *click_method);
1018
1019         return 0;
1020 }
1021
1022 int vc_elm_set_auto_register_mode(int mode, int click_method)
1023 {
1024         if (0 != __vc_elm_get_feature_enabled()) {
1025                 return VC_ELM_ERROR_NOT_SUPPORTED;
1026         }
1027
1028         if (0 == g_is_vt_automode) {
1029                 VC_ELM_LOG_DBG("vt_automode is FALSE");
1030                 return _vc_elm_set_auto_register_mode(mode, click_method);
1031         }
1032
1033         VC_ELM_LOG_DBG("vt_automode is TRUE");
1034         return _vc_elm_set_auto_register_mode((int)VC_ELM_MODE_AUTO_APPFW, click_method);
1035 }
1036
1037 int vc_elm_get_auto_register_mode(int* mode, int* click_method)
1038 {
1039         if (0 != __vc_elm_get_feature_enabled()) {
1040                 return VC_ELM_ERROR_NOT_SUPPORTED;
1041         }
1042
1043         return _vc_elm_get_auto_register_mode(mode, click_method);
1044 }
1045
1046 int vc_elm_add_allowed_text_part(const char* text_part)
1047 {
1048         if (0 != __vc_elm_get_feature_enabled()) {
1049                 return VC_ELM_ERROR_NOT_SUPPORTED;
1050         }
1051
1052         if (NULL == text_part) {
1053                 VC_ELM_LOG_ERR("Invalid parameter");
1054                 return VC_ELM_ERROR_INVALID_PARAMETER;
1055         }
1056
1057         if (0 != _vc_elm_core_add_allowed_text_part(text_part)) {
1058                 return VC_ELM_ERROR_OPERATION_FAILED;
1059         }
1060
1061         return VC_ELM_ERROR_NONE;
1062 }
1063
1064 int vc_elm_remove_allowed_text_part(void)
1065 {
1066         if (0 != __vc_elm_get_feature_enabled()) {
1067                 return VC_ELM_ERROR_NOT_SUPPORTED;
1068         }
1069
1070         if (0 != _vc_elm_core_remove_allowed_text_part()) {
1071                 return VC_ELM_ERROR_OPERATION_FAILED;
1072         }
1073
1074         return VC_ELM_ERROR_NONE;
1075 }
1076
1077 int vc_elm_set_geometry_info(int x, int y, int w, int h)
1078 {
1079         if (0 != __vc_elm_get_feature_enabled()) {
1080                 return VC_ELM_ERROR_NOT_SUPPORTED;
1081         }
1082
1083         if (0 != _vc_elm_core_set_geometry_info(x, y, w, h)) {
1084                 return VC_ELM_ERROR_OPERATION_FAILED;
1085         }
1086
1087         return VC_ELM_ERROR_NONE;
1088 }
1089
1090 int vc_elm_unset_geometry_info()
1091 {
1092         if (0 != __vc_elm_get_feature_enabled()) {
1093                 return VC_ELM_ERROR_NOT_SUPPORTED;
1094         }
1095
1096         if (0 != _vc_elm_core_unset_geometry_info()) {
1097                 return VC_ELM_ERROR_OPERATION_FAILED;
1098         }
1099
1100         return VC_ELM_ERROR_NONE;
1101 }
1102
1103 int vc_elm_set_click_time(float time)
1104 {
1105         if (0 != __vc_elm_get_feature_enabled()) {
1106                 return VC_ELM_ERROR_NOT_SUPPORTED;
1107         }
1108
1109         if (0 != _vc_elm_core_set_click_time(time)) {
1110                 return VC_ELM_ERROR_OPERATION_FAILED;
1111         }
1112
1113         return VC_ELM_ERROR_NONE;
1114 }
1115
1116 int vc_elm_unset_click_time()
1117 {
1118         if (0 != __vc_elm_get_feature_enabled()) {
1119                 return VC_ELM_ERROR_NOT_SUPPORTED;
1120         }
1121
1122         if (0 != _vc_elm_core_unset_click_time()) {
1123                 return VC_ELM_ERROR_OPERATION_FAILED;
1124         }
1125
1126         return VC_ELM_ERROR_NONE;
1127 }
1128 //LCOV_EXCL_STOP
1129 #ifdef SRPOL_DEBUG
1130 /**
1131  * @brief Wrapper for making internal function public - for automated test purposes
1132  */
1133 void show_tooltip()
1134 {
1135         _show_tooltips();
1136 }
1137
1138 /**
1139  * @brief Wrapper for making internal function public - for automated test purposes
1140  */
1141 void hide_tooltip()
1142 {
1143         _hide_tooltips();
1144 }
1145 #endif