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 int dependency_resolver_initialize(mas_dependency_plugin_proxy_interface interface)
42 const int FILEPATH_LEN = 512;
43 char filepath[FILEPATH_LEN] = {'\0', };
44 char *vconf_str = vconf_get_str(MAS_DEPENDENCY_MODULE_PATH);
46 snprintf(filepath, FILEPATH_LEN - 1, "%s", vconf_str);
49 const char *default_path = MAS_DEPENDENCY_DEFAULT_PATH;
50 snprintf(filepath, FILEPATH_LEN - 1, "%s/%s", default_path, MAS_DEPENDENCY_DEFAULT_FILENAME);
52 filepath[FILEPATH_LEN - 1] = '\0';
56 g_handle = dlopen(filepath, RTLD_LAZY);
57 if (NULL != (error = dlerror())) {
58 MAS_LOGE("[ERROR] Fail to dlopen(%s), error(%s)", filepath, error);
59 return -1; //MAS_ERROR_OPERATION_FAILED;
62 g_mas_dependency.initialize =
63 (mas_dependency_initialize)dlsym(g_handle,
64 MAS_DEPENDENCY_FUNC_INITIALIZE);
65 g_mas_dependency.deinitialize =
66 (mas_dependency_deinitialize)dlsym(g_handle,
67 MAS_DEPENDENCY_FUNC_DEINITIALIZE);
68 g_mas_dependency.set_error_callback =
69 (mas_dependency_set_error_callback)dlsym(g_handle,
70 MAS_DEPENDENCY_FUNC_SET_ERROR_CALLBACK);
71 g_mas_dependency.start_recording =
72 (mas_dependency_start_recording)dlsym(g_handle,
73 MAS_DEPENDENCY_FUNC_START_RECORDING);
74 g_mas_dependency.stop_recording =
75 (mas_dependency_stop_recording)dlsym(g_handle,
76 MAS_DEPENDENCY_FUNC_STOP_RECORDING);
77 g_mas_dependency.set_recording_session =
78 (mas_dependency_set_recording_session)dlsym(g_handle,
79 MAS_DEPENDENCY_FUNC_SET_RECORDING_SESSION);
80 g_mas_dependency.set_background_volume =
81 (mas_dependency_set_background_volume)dlsym(g_handle,
82 MAS_DEPENDENCY_FUNC_SET_BACKGROUND_VOLUME);
83 g_mas_dependency.get_audio_format =
84 (mas_dependency_get_audio_format)dlsym(g_handle,
85 MAS_DEPENDENCY_FUNC_GET_AUDIO_FORMAT);
86 g_mas_dependency.get_audio_source_type =
87 (mas_dependency_get_audio_source_type)dlsym(g_handle,
88 MAS_DEPENDENCY_FUNC_GET_AUDIO_SOURCE_TYPE);
89 g_mas_dependency.process_wakeup_engine_command =
90 (mas_dependency_process_wakeup_engine_command)dlsym(g_handle,
91 MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_ENGINE_COMMAND);
94 int dependency_version = 0;
95 if (NULL != g_handle) {
96 mas_dependency_initialize func = g_mas_dependency.initialize;
99 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_INITIALIZE);
102 ret = func(interface, &dependency_version);
103 } catch (const std::exception& e) {
104 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
105 MAS_DEPENDENCY_FUNC_INITIALIZE, e.what());
108 MAS_LOGE("[ERROR] Fail to initialize, ret(%d)", ret);
112 MAS_LOGE("[ERROR] g_handle is not valid");
114 MAS_LOGD("g_handle : %p, dependency_version %d", g_handle, dependency_version);
118 int dependency_resolver_deinitialize(void)
120 MAS_LOGD("g_handle : %p", g_handle);
122 if (NULL != g_handle) {
123 mas_dependency_deinitialize func = g_mas_dependency.deinitialize;
125 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_DEINITIALIZE);
129 } catch (const std::exception& e) {
130 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
131 MAS_DEPENDENCY_FUNC_DEINITIALIZE, e.what());
134 MAS_LOGE("[ERROR] Fail to deinitialize, ret(%d)", ret);
141 MAS_LOGE("[ERROR] g_handle is not valid");
147 int dependency_resolver_set_error_callback(mas_error_cb callback, void* user_data)
150 if (NULL != g_handle) {
151 mas_dependency_set_error_callback func = g_mas_dependency.set_error_callback;
153 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_SET_ERROR_CALLBACK);
156 ret = func(callback, user_data);
157 } catch (const std::exception& e) {
158 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
159 MAS_DEPENDENCY_FUNC_SET_ERROR_CALLBACK, e.what());
162 MAS_LOGE("[ERROR] Fail to set error callback(%p, %p), ret(%d)", callback, user_data, ret);
166 MAS_LOGE("[ERROR] g_handle is not valid");
171 int dependency_resolver_start_recording(void)
174 MAS_LOGD("g_handle : %p", g_handle);
175 if (NULL != g_handle) {
176 mas_dependency_start_recording func = g_mas_dependency.start_recording;
178 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_START_RECORDING);
182 } catch (const std::exception& e) {
183 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
184 MAS_DEPENDENCY_FUNC_START_RECORDING, e.what());
187 MAS_LOGE("[ERROR] Fail to start recording, ret(%d)", ret);
191 MAS_LOGE("[ERROR] g_handle is not valid");
197 int dependency_resolver_stop_recording(void)
200 if (NULL != g_handle) {
201 mas_dependency_stop_recording func = g_mas_dependency.stop_recording;
203 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_STOP_RECORDING);
207 } catch (const std::exception& e) {
208 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
209 MAS_DEPENDENCY_FUNC_STOP_RECORDING, e.what());
212 MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
216 MAS_LOGE("[ERROR] g_handle is not valid");
222 int dependency_resolver_set_recording_session(unsigned int session)
225 MAS_LOGD("g_handle : %p", g_handle);
226 if (NULL != g_handle) {
227 mas_dependency_set_recording_session func = g_mas_dependency.set_recording_session;
229 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_SET_RECORDING_SESSION);
233 } catch (const std::exception& e) {
234 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
235 MAS_DEPENDENCY_FUNC_SET_RECORDING_SESSION, e.what());
238 MAS_LOGE("[ERROR] Fail to set recording session, ret(%d)", ret);
242 MAS_LOGE("[ERROR] g_handle is not valid");
248 int dependency_resolver_set_background_volume(double ratio)
251 if (NULL != g_handle) {
252 mas_dependency_set_background_volume func = g_mas_dependency.set_background_volume;
254 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_SET_BACKGROUND_VOLUME);
258 } catch (const std::exception& e) {
259 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
260 MAS_DEPENDENCY_FUNC_SET_BACKGROUND_VOLUME, e.what());
263 MAS_LOGE("[ERROR] Fail to set background volume to %f, ret(%d)", ratio, ret);
267 MAS_LOGE("[ERROR] g_handle is not valid");
273 int dependency_resolver_get_audio_format(int* rate, int* channel, int* audio_type)
276 if (NULL != g_handle) {
277 mas_dependency_get_audio_format func = g_mas_dependency.get_audio_format;
279 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_GET_AUDIO_FORMAT);
282 ret = func(rate, channel, audio_type);
283 } catch (const std::exception& e) {
284 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
285 MAS_DEPENDENCY_FUNC_GET_AUDIO_FORMAT, e.what());
288 MAS_LOGE("[ERROR] Fail to get audio format, ret(%d)", ret);
292 MAS_LOGE("[ERROR] g_handle is not valid");
298 int dependency_resolver_get_audio_source_type(char** type)
301 if (NULL != g_handle) {
302 mas_dependency_get_audio_source_type func = g_mas_dependency.get_audio_source_type;
304 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_GET_AUDIO_SOURCE_TYPE);
308 } catch (const std::exception& e) {
309 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
310 MAS_DEPENDENCY_FUNC_GET_AUDIO_SOURCE_TYPE, e.what());
313 MAS_LOGE("[ERROR] Fail to get audio source type, ret(%d)", ret);
317 MAS_LOGE("[ERROR] g_handle is not valid");
323 int dependency_resolver_process_wakeup_engine_command(const char* engine, const char* command)
326 if (NULL != g_handle) {
327 mas_dependency_process_wakeup_engine_command func = g_mas_dependency.process_wakeup_engine_command;
329 MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_ENGINE_COMMAND);
332 ret = func(engine, command);
333 } catch (const std::exception& e) {
334 MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
335 MAS_DEPENDENCY_FUNC_PROCESS_WAKEUP_ENGINE_COMMAND, e.what());
338 MAS_LOGE("[ERROR] Fail to process wakeup engine command, ret(%d)", ret);
342 MAS_LOGE("[ERROR] g_handle is not valid");