2 * Copyright © 2021 Samsung Electronics co., Ltd. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 #include "mmi-provider-iface.h"
25 #include "mmi-manager-dbg.h"
26 #include "mmi-common.h"
27 #include "mmi-provider.h"
35 Eina_List *_provider_list = NULL;
36 Ecore_Event_Handler *_provider_event_handlers[5];
39 _key_provider_event_cb(void *data EINA_UNUSED, int type, void *event)
41 mmi_provider_event_key *ev = (mmi_provider_event_key *)event;
43 LOGI("[MMI_PROVIDER_EVENT_KEY] type:%d, timestamp:%d, duration:%d, confidence=%.2f\n",
44 ev->type, ev->timestamp, ev->duration, ev->confidence);
45 LOGI("... keycode:%d, key_down:%d, keyname=%s, source=%s\n",
46 ev->keycode, ev->key_down, ev->keyname, ev->source);
48 return ECORE_CALLBACK_PASS_ON;
52 _gesture_provider_event_cb(void *data EINA_UNUSED, int type, void *event)
54 mmi_provider_event_gesture *ev = (mmi_provider_event_gesture *)event;
56 LOGI("[MMI_PROVIDER_EVENT_GESTURE] type:%d, timestamp:%d, duration:%d, confidence=%.2f\n",
57 ev->type, ev->timestamp, ev->duration, ev->confidence);
58 LOGI("... source=%s\n", ev->source);
60 return ECORE_CALLBACK_PASS_ON;
64 _voice_provider_event_cb(void *data EINA_UNUSED, int type, void *event)
66 mmi_provider_event_voice *ev = (mmi_provider_event_voice *)event;
68 LOGI("[MMI_PROVIDER_EVENT_VOICE] type:%d, timestamp:%d, duration:%d, confidence=%.2f\n",
69 ev->type, ev->timestamp, ev->duration, ev->confidence);
70 LOGI("... cmd:%s, nargs:%d, source:%s\n", ev->cmd, ev->nargs, ev->source);
72 return ECORE_CALLBACK_PASS_ON;
76 _vision_provider_event_cb(void *data EINA_UNUSED, int type, void *event)
78 mmi_provider_event_vision *ev = (mmi_provider_event_vision *)event;
80 LOGI("[MMI_PROVIDER_EVENT_VISION] type:%d, timestamp:%d, duration:%d, confidence=%.2f\n",
81 ev->type, ev->timestamp, ev->duration, ev->confidence);
82 LOGI("... cmd:%s, nargs:%d, source:%s\n", ev->cmd, ev->nargs, ev->source);
84 mmi_vision_state state = ev->type;
85 LOGI("[MMI_PROVIDER_EVENT_VISION] state = %d", state);
97 LOGI("type : %d, confidence : %f\n", ev->type, ev->confidence);
100 return ECORE_CALLBACK_PASS_ON;
104 _screen_analyzer_provider_event_cb(void *data EINA_UNUSED, int type, void *event)
107 return ECORE_CALLBACK_PASS_ON;
111 mmi_provider_set_op_mode_on_caps(unsigned long long caps, mmi_provider_op_mode mode)
114 mmi_provider_handle *provider = NULL;
118 LOGE("Given caps in empty !\n");
122 EINA_LIST_FOREACH(_provider_list, l, provider)
124 if (provider->capabilities & caps)
126 LOGD("Set op_mode(%d) on provider(%s) !\n", mode, provider->module_info->name);
127 provider->module_data->set_mode(mode);
135 mmi_provider_register_caps(mmi_provider_handle *provider, unsigned long long caps)
139 LOGE("Given provider is invalid !\n");
145 LOGE("Given caps is invalid ! (caps=%lld)\n", caps);
149 /* Right now, we add the given caps to the existing caps. */
150 provider->capabilities |= caps;
155 mmi_provider_alloc_event(int ev_type)
163 _provider_load_module(const char *provider_name)
165 mmi_provider_handle *provider = (mmi_provider_handle *)calloc(1, sizeof(mmi_provider_handle));
169 LOGE("Failed to alloc provider handle");
173 void *provider_info = NULL;
174 mmi_provider_module *mmi_provider_module_info = NULL;
175 mmi_provider_module_data *provider_module_data = NULL;
177 provider_info = dlopen(provider_name, RTLD_LAZY);
181 LOGE("Failed to dlopen(error :%s, path :%s)!\n", dlerror(), provider_name);
185 mmi_provider_module_info = dlsym(provider_info, "mmi_provider_module_info");
187 if(!mmi_provider_module_info)
189 LOGE("Module(%s) dosen't have mmi_provider_module_info \n", provider_name);
193 if(!mmi_provider_module_info->provider_init || !mmi_provider_module_info->provider_deinit)
195 LOGE("Module(%s) doesn't have init/deinit function\n", provider_name);
199 provider_module_data = mmi_provider_module_info->provider_init();
201 if(!provider_module_data)
203 LOGE("Failed to init module (%s) !\n", provider_name);
207 LOGI("moudle info name = %s\n", mmi_provider_module_info->name);
208 provider->provider_info = provider_info;
209 provider->module_info = mmi_provider_module_info;
210 provider->module_data = provider_module_data;
211 provider->capabilities = mmi_provider_module_info->capabilities;
212 provider->op_mode = provider_module_data->get_mode();
214 _provider_list = eina_list_append(_provider_list, provider);
218 if(mmi_provider_module_info && mmi_provider_module_info->provider_deinit)
219 mmi_provider_module_info->provider_deinit(provider_module_data);
222 dlclose(provider_info);
230 _modality_providers_lookup(void)
233 struct dirent *entry;
235 dir = opendir(PROVIDER_PATH);
243 while((entry = readdir(dir)) != NULL)
245 char provider_name[512];
246 if(strstr(entry->d_name, "libmmi_modality") != NULL)
248 snprintf(provider_name, sizeof(provider_name), "%s%s", PROVIDER_PATH, entry->d_name);
249 LOGD("Provider full path = %s\n", provider_name);
250 _provider_load_module(provider_name);
258 _event_handler_init()
260 MMI_PROVIDER_EVENT_KEY = ecore_event_type_new();
261 MMI_PROVIDER_EVENT_GESTURE = ecore_event_type_new();
262 MMI_PROVIDER_EVENT_VOICE = ecore_event_type_new();
263 MMI_PROVIDER_EVENT_VISION = ecore_event_type_new();
264 MMI_PROVIDER_EVENT_SCREEN_ANALYZER = ecore_event_type_new();
265 MMI_VISION_EVENT_PROPAGATE = ecore_event_type_new();
266 MMI_VISION_EVENT_DROP = ecore_event_type_new();
267 MMI_VISION_EVENT_FINISH = ecore_event_type_new();
268 MMI_EVENT_REFRESH_SCREEN_INFORM = ecore_event_type_new();
270 LOGD("MMI_PROVIDER_EVENT_KEY=%d\n", MMI_PROVIDER_EVENT_KEY);
271 LOGD("MMI_PROVIDER_EVENT_GESTURE=%d\n", MMI_PROVIDER_EVENT_GESTURE);
272 LOGD("MMI_PROVIDER_EVENT_VOICE=%d\n", MMI_PROVIDER_EVENT_VOICE);
273 LOGD("MMI_PROVIDER_EVENT_VISION=%d\n", MMI_PROVIDER_EVENT_VISION);
274 LOGD("MMI_PROVIDER_EVENT_SCREEN_ANALYZER=%d\n", MMI_PROVIDER_EVENT_SCREEN_ANALYZER);
277 _provider_event_handlers[0] = ecore_event_handler_add(MMI_PROVIDER_EVENT_KEY,
278 _key_provider_event_cb, NULL);
279 _provider_event_handlers[1] = ecore_event_handler_add(MMI_PROVIDER_EVENT_GESTURE,
280 _gesture_provider_event_cb, NULL);
281 _provider_event_handlers[2] = ecore_event_handler_add(MMI_PROVIDER_EVENT_VOICE,
282 _voice_provider_event_cb, NULL);
283 _provider_event_handlers[3] = ecore_event_handler_add(MMI_PROVIDER_EVENT_VISION,
284 _vision_provider_event_cb, NULL);
285 _provider_event_handlers[4] = ecore_event_handler_add(MMI_PROVIDER_EVENT_SCREEN_ANALYZER,
286 _screen_analyzer_provider_event_cb, NULL);
290 _event_handler_shutdown()
293 ecore_event_handler_del(_provider_event_handlers[0]);
294 ecore_event_handler_del(_provider_event_handlers[1]);
295 ecore_event_handler_del(_provider_event_handlers[2]);
296 ecore_event_handler_del(_provider_event_handlers[3]);
297 ecore_event_handler_del(_provider_event_handlers[4]);
298 _provider_event_handlers[0] = NULL;
299 _provider_event_handlers[1] = NULL;
300 _provider_event_handlers[2] = NULL;
301 _provider_event_handlers[3] = NULL;
302 _provider_event_handlers[4] = NULL;
304 MMI_PROVIDER_EVENT_KEY = -1;
305 MMI_PROVIDER_EVENT_GESTURE = -1;
306 MMI_PROVIDER_EVENT_VOICE = -1;
307 MMI_PROVIDER_EVENT_VISION = -1;
308 MMI_PROVIDER_EVENT_SCREEN_ANALYZER = -1;
310 LOGD("MMI_PROVIDER_EVENT_KEY=%d\n", MMI_PROVIDER_EVENT_KEY);
311 LOGD("MMI_PROVIDER_EVENT_GESTURE=%d\n", MMI_PROVIDER_EVENT_GESTURE);
312 LOGD("MMI_PROVIDER_EVENT_VOICE=%d\n", MMI_PROVIDER_EVENT_VOICE);
313 LOGD("MMI_PROVIDER_EVENT_VISION=%d\n", MMI_PROVIDER_EVENT_VISION);
314 LOGD("MMI_PROVIDER_EVENT_SCREEN_ANALYZER=%d\n", MMI_PROVIDER_EVENT_SCREEN_ANALYZER);
318 modality_providers_init(void)
320 LOGD("PROVIDER_PATH=%s\n", PROVIDER_PATH);
322 //Lookup and init modality providers
323 _event_handler_init();
324 _modality_providers_lookup();
328 modality_providers_shutdown(void)
330 _event_handler_shutdown();
332 //Do shutdown for intialized providers
337 mmi_provider_handle *provider = NULL;
338 EINA_LIST_FOREACH(_provider_list, l, provider)
340 if(provider->module_info)
342 if(provider->module_data)
343 provider->module_info->provider_deinit(provider->module_data);
344 provider->module_data = NULL;
345 provider->module_info = NULL;
347 if(provider->provider_info)
348 dlclose(provider->provider_info);
351 _provider_list = eina_list_free(_provider_list);
352 _provider_list = NULL;