add null check about object id of output modality
[platform/core/uifw/mmi-manager.git] / src / mmimgr / output_modality / mmi_output_modality.cpp
1 /*
2  * Copyright (c) 2022 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
18
19 #include <string>
20
21 #include "mmi-common.h"
22 #include "TouchModule.h"
23 #include "mmi-manager-dbg.h"
24 #include "mmi_output_modality.h"
25 #include <Ecore.h>
26
27 static TouchModule *g_touch_module = nullptr;
28
29 static void __refresh_screen_inform_event_free(void *data EINA_UNUSED, void *event)
30 {
31         mmi_event_refresh_screen_inform *ev = (mmi_event_refresh_screen_inform *)event;
32         free(ev);
33 }
34
35 static tizen_profile_e __get_tizen_profile()
36 {
37         tizen_profile_e profile;
38         char *profileName = NULL;
39
40         system_info_get_platform_string("http://tizen.org/feature/profile", &profileName);
41         switch (*profileName) {
42         case 't':
43         case 'T':
44                 profile = _PROFILE_TV;
45                 break;
46         case 'm':
47         case 'M':
48                 profile = _PROFILE_MOBILE;
49                 break;
50         default:
51                 profile = _PROFILE_COMMON;
52         }
53
54         free(profileName);
55         return profile;
56 }
57
58 EXPORT_API void output_modality_initialize()
59 {
60         LOGD("initialize output modality");
61         g_touch_module = new TouchModule();
62 }
63
64 EXPORT_API void output_modality_shutdown()
65 {
66         LOGD("shutdown output modality");
67         if (g_touch_module) {
68                 delete g_touch_module;
69                 g_touch_module = NULL;
70         }
71 }
72
73 EXPORT_API int output_modality_voice_touch(mmi_output_modality_voice_touch modality)
74 {
75         mmi_voice_touch_mode mode = (mmi_voice_touch_mode)modality.mode;
76         int ret = 0;
77
78         if (MMI_VOICE_TOUCH_MODE_TOOLTIP == mode) {
79                 if (TIZEN_PROFILE_TV) {
80                         LOGD("voice touch by tooltip in TV");
81                         if (modality.object_id == NULL) {
82                                 LOGE("mmi_output_modality_voice_touch modality's object id is NULL");
83                                 return -1;
84                         }
85                         std::string objID = std::string(modality.object_id, strlen(modality.object_id));
86                         ret = g_touch_module->ClickByObjectId(objID);
87                 }
88                 else {
89                         LOGD("voice touch by tooltip in others");
90                         ret = g_touch_module->ClickByCoordinate(modality.coord_x, modality.coord_y);
91                 }
92         } else if (MMI_VOICE_TOUCH_MODE_GRID == mode) {
93                 LOGD("voice touch by grid");
94                 ret = g_touch_module->ClickByCoordinate(modality.coord_x, modality.coord_y);
95         } else {
96                 LOGE("mode(%d) is not supported", mode);
97                 return 0;
98         }
99         LOGD("voice touch done");
100
101         mmi_event_refresh_screen_inform *ev = (mmi_event_refresh_screen_inform *)calloc(1, sizeof(mmi_event_refresh_screen_inform));
102         if (ev == NULL) {
103                 LOGE("mmi_event_refresh_screen_inform malloc failed");
104                 return -1;
105         }
106
107         ev->seconds = 2.0;
108         ecore_event_add(MMI_EVENT_REFRESH_SCREEN_INFORM, ev, __refresh_screen_inform_event_free, NULL);
109
110         return ret;
111 }