2 * Copyright 2018-2019 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
27 #include "multi_assistant_main.h"
28 #include "dependency_resolver.h"
33 #define LOG_TAG "dependency-resolver"
35 static void *g_handle = NULL;
36 static mas_dependency_module_interface g_mas_dependency = { NULL, };
38 mas_dependency_module_interface* dependency_resolver_get_interface()
40 return &g_mas_dependency;
43 int dependency_resolver_initialize(mas_dependency_plugin_proxy_interface interface)
47 const int FILEPATH_LEN = 512;
48 char filepath[FILEPATH_LEN] = {'\0', };
49 char *vconf_str = vconf_get_str(MAS_DEPENDENCY_MODULE_PATH);
51 snprintf(filepath, FILEPATH_LEN - 1, "%s", vconf_str);
54 const char *default_path = MAS_DEPENDENCY_DEFAULT_PATH;
55 snprintf(filepath, FILEPATH_LEN - 1, "%s/%s", default_path, MAS_DEPENDENCY_DEFAULT_FILENAME);
57 filepath[FILEPATH_LEN - 1] = '\0';
61 g_handle = dlopen(filepath, RTLD_LAZY);
62 if (NULL != (error = dlerror())) {
63 MAS_LOGE("[ERROR] Fail to dlopen(%s), error(%s)", filepath, error);
64 return -1; //MAS_ERROR_OPERATION_FAILED;
67 g_mas_dependency.initialize =
68 (mas_dependency_initialize)dlsym(g_handle,
69 MAS_DEPENDENCY_FUNC_INITIALIZE);
70 g_mas_dependency.deinitialize =
71 (mas_dependency_deinitialize)dlsym(g_handle,
72 MAS_DEPENDENCY_FUNC_DEINITIALIZE);
73 g_mas_dependency.set_error_callback =
74 (mas_dependency_set_error_callback)dlsym(g_handle,
75 MAS_DEPENDENCY_FUNC_SET_ERROR_CALLBACK);
76 g_mas_dependency.start_recording =
77 (mas_dependency_start_recording)dlsym(g_handle,
78 MAS_DEPENDENCY_FUNC_START_RECORDING);
79 g_mas_dependency.stop_recording =
80 (mas_dependency_stop_recording)dlsym(g_handle,
81 MAS_DEPENDENCY_FUNC_STOP_RECORDING);
82 g_mas_dependency.set_recording_session =
83 (mas_dependency_set_recording_session)dlsym(g_handle,
84 MAS_DEPENDENCY_FUNC_SET_RECORDING_SESSION);
85 g_mas_dependency.set_background_volume =
86 (mas_dependency_set_background_volume)dlsym(g_handle,
87 MAS_DEPENDENCY_FUNC_SET_BACKGROUND_VOLUME);
88 g_mas_dependency.get_audio_format =
89 (mas_dependency_get_audio_format)dlsym(g_handle,
90 MAS_DEPENDENCY_FUNC_GET_AUDIO_FORMAT);
91 g_mas_dependency.get_audio_source_type =
92 (mas_dependency_get_audio_source_type)dlsym(g_handle,
93 MAS_DEPENDENCY_FUNC_GET_AUDIO_SOURCE_TYPE);
94 g_mas_dependency.process_wakeup_engine_command =
95 (mas_dependency_process_wakeup_engine_command)dlsym(g_handle,
96 MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_ENGINE_COMMAND);
97 g_mas_dependency.process_wakeup_candidate =
98 (mas_dependency_process_wakeup_candidate)dlsym(g_handle,
99 MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_CANDIDATE);
102 int dependency_version = 0;
103 if (NULL != g_handle) {
104 mas_dependency_initialize func = g_mas_dependency.initialize;
107 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_INITIALIZE);
110 ret = func(interface, &dependency_version);
111 } catch (const std::exception& e) {
112 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
113 MAS_DEPENDENCY_FUNC_INITIALIZE, e.what());
116 MAS_LOGE("[ERROR] Fail to initialize, ret(%d)", ret);
120 MAS_LOGE("[ERROR] g_handle is not valid");
122 MAS_LOGD("g_handle : %p, dependency_version %d", g_handle, dependency_version);
126 int dependency_resolver_deinitialize(void)
128 MAS_LOGD("g_handle : %p", g_handle);
130 if (NULL != g_handle) {
131 mas_dependency_deinitialize func = g_mas_dependency.deinitialize;
133 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_DEINITIALIZE);
137 } catch (const std::exception& e) {
138 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
139 MAS_DEPENDENCY_FUNC_DEINITIALIZE, e.what());
142 MAS_LOGE("[ERROR] Fail to deinitialize, ret(%d)", ret);
149 MAS_LOGE("[ERROR] g_handle is not valid");
155 int dependency_resolver_set_error_callback(mas_error_cb callback, void* user_data)
158 if (NULL != g_handle) {
159 mas_dependency_set_error_callback func = g_mas_dependency.set_error_callback;
161 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_SET_ERROR_CALLBACK);
164 ret = func(callback, user_data);
165 } catch (const std::exception& e) {
166 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
167 MAS_DEPENDENCY_FUNC_SET_ERROR_CALLBACK, e.what());
170 MAS_LOGE("[ERROR] Fail to set error callback(%p, %p), ret(%d)", callback, user_data, ret);
174 MAS_LOGE("[ERROR] g_handle is not valid");
179 int dependency_resolver_start_recording(void)
182 MAS_LOGD("g_handle : %p", g_handle);
183 if (NULL != g_handle) {
184 mas_dependency_start_recording func = g_mas_dependency.start_recording;
186 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_START_RECORDING);
190 } catch (const std::exception& e) {
191 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
192 MAS_DEPENDENCY_FUNC_START_RECORDING, e.what());
195 MAS_LOGE("[ERROR] Fail to start recording, ret(%d)", ret);
199 MAS_LOGE("[ERROR] g_handle is not valid");
205 int dependency_resolver_stop_recording(void)
208 if (NULL != g_handle) {
209 mas_dependency_stop_recording func = g_mas_dependency.stop_recording;
211 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_STOP_RECORDING);
215 } catch (const std::exception& e) {
216 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
217 MAS_DEPENDENCY_FUNC_STOP_RECORDING, e.what());
220 MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
224 MAS_LOGE("[ERROR] g_handle is not valid");
230 int dependency_resolver_set_recording_session(unsigned int session)
233 MAS_LOGD("g_handle : %p", g_handle);
234 if (NULL != g_handle) {
235 mas_dependency_set_recording_session func = g_mas_dependency.set_recording_session;
237 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_SET_RECORDING_SESSION);
241 } catch (const std::exception& e) {
242 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
243 MAS_DEPENDENCY_FUNC_SET_RECORDING_SESSION, e.what());
246 MAS_LOGE("[ERROR] Fail to set recording session, ret(%d)", ret);
250 MAS_LOGE("[ERROR] g_handle is not valid");
256 int dependency_resolver_set_background_volume(double ratio)
259 if (NULL != g_handle) {
260 mas_dependency_set_background_volume func = g_mas_dependency.set_background_volume;
262 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_SET_BACKGROUND_VOLUME);
266 } catch (const std::exception& e) {
267 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
268 MAS_DEPENDENCY_FUNC_SET_BACKGROUND_VOLUME, e.what());
271 MAS_LOGE("[ERROR] Fail to set background volume to %f, ret(%d)", ratio, ret);
275 MAS_LOGE("[ERROR] g_handle is not valid");
281 int dependency_resolver_get_audio_format(int* rate, int* channel, int* audio_type)
284 if (NULL != g_handle) {
285 mas_dependency_get_audio_format func = g_mas_dependency.get_audio_format;
287 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_GET_AUDIO_FORMAT);
290 ret = func(rate, channel, audio_type);
291 } catch (const std::exception& e) {
292 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
293 MAS_DEPENDENCY_FUNC_GET_AUDIO_FORMAT, e.what());
296 MAS_LOGE("[ERROR] Fail to get audio format, ret(%d)", ret);
300 MAS_LOGE("[ERROR] g_handle is not valid");
306 int dependency_resolver_get_audio_source_type(char** type)
309 if (NULL != g_handle) {
310 mas_dependency_get_audio_source_type func = g_mas_dependency.get_audio_source_type;
312 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_GET_AUDIO_SOURCE_TYPE);
316 } catch (const std::exception& e) {
317 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
318 MAS_DEPENDENCY_FUNC_GET_AUDIO_SOURCE_TYPE, e.what());
321 MAS_LOGE("[ERROR] Fail to get audio source type, ret(%d)", ret);
325 MAS_LOGE("[ERROR] g_handle is not valid");
331 int dependency_resolver_process_wakeup_engine_command(const char* engine, const char* command)
334 if (NULL != g_handle) {
335 mas_dependency_process_wakeup_engine_command func = g_mas_dependency.process_wakeup_engine_command;
337 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_ENGINE_COMMAND);
340 ret = func(engine, command);
341 } catch (const std::exception& e) {
342 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
343 MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_ENGINE_COMMAND, e.what());
346 MAS_LOGE("[ERROR] Fail to process wakeup engine command, ret(%d)", ret);
350 MAS_LOGE("[ERROR] g_handle is not valid");
356 int dependency_resolver_process_wakeup_candidate(mas_wakeup_event_info* info)
359 if (NULL != g_handle) {
360 mas_dependency_process_wakeup_candidate func = g_mas_dependency.process_wakeup_candidate;
362 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_CANDIDATE);
366 } catch (const std::exception& e) {
367 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
368 MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_CANDIDATE, e.what());
371 MAS_LOGE("[ERROR] Fail to process wakeup candidate, ret(%d)", ret);
375 MAS_LOGE("[ERROR] g_handle is not valid");