Add exception handlers for the functions in external modules
[platform/core/uifw/multi-assistant-service.git] / plugins / wakeup-manager / src / dependency_resolver.cpp
index 551290e..43b080d 100644 (file)
@@ -22,6 +22,8 @@
 #include <unistd.h>
 #include <vconf.h>
 
+#include <stdexcept>
+
 #include "multi_assistant_main.h"
 #include "dependency_resolver.h"
 
@@ -93,7 +95,12 @@ int dependency_resolver_initialize(mas_proxy_interface interface)
                if (NULL == func) {
                        MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_INITIALIZE);
                } else {
-                       ret = func(interface, &dependency_version);
+                       try {
+                               ret = func(interface, &dependency_version);
+                       } catch (const std::exception& e) {
+                               MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+                                       MAS_DEPENDENCY_FUNC_INITIALIZE, e.what());
+                       }
                        if (0 != ret) {
                                MAS_LOGE("[ERROR] Fail to initialize, ret(%d)", ret);
                        }
@@ -114,7 +121,12 @@ int dependency_resolver_deinitialize(void)
                if (NULL == func) {
                        MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_DEINITIALIZE);
                } else {
-                       ret = func();
+                       try {
+                               ret = func();
+                       } catch (const std::exception& e) {
+                               MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+                                       MAS_DEPENDENCY_FUNC_DEINITIALIZE, e.what());
+                       }
                        if (0 != ret) {
                                MAS_LOGE("[ERROR] Fail to deinitialize, ret(%d)", ret);
                        }
@@ -137,7 +149,12 @@ int dependency_resolver_set_error_callback(mas_dependency_error_cb callback, voi
                if (NULL == func) {
                        MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_SET_ERROR_CALLBACK);
                } else {
-                       ret = func(callback, user_data);
+                       try {
+                               ret = func(callback, user_data);
+                       } catch (const std::exception& e) {
+                               MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+                                       MAS_DEPENDENCY_FUNC_DEINITIALIZE, e.what());
+                       }
                        if (0 != ret) {
                                MAS_LOGE("[ERROR] Fail to set error callback(%p, %p), ret(%d)", callback, user_data, ret);
                        }
@@ -157,7 +174,12 @@ int dependency_resolver_start_recording(void)
                if (NULL == func) {
                        MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_START_RECORDING);
                } else {
-                       ret = func();
+                       try {
+                               ret = func();
+                       } catch (const std::exception& e) {
+                               MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+                                       MAS_DEPENDENCY_FUNC_DEINITIALIZE, e.what());
+                       }
                        if (0 != ret) {
                                MAS_LOGE("[ERROR] Fail to start recording, ret(%d)", ret);
                        }
@@ -177,7 +199,12 @@ int dependency_resolver_stop_recording(void)
                if (NULL == func) {
                        MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_STOP_RECORDING);
                } else {
-                       ret = func();
+                       try {
+                               ret = func();
+                       } catch (const std::exception& e) {
+                               MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+                                       MAS_DEPENDENCY_FUNC_DEINITIALIZE, e.what());
+                       }
                        if (0 != ret) {
                                MAS_LOGE("[ERROR] Fail to stop recording, ret(%d)", ret);
                        }
@@ -198,7 +225,12 @@ int dependency_resolver_set_recording_session(unsigned int session)
                if (NULL == func) {
                        MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_SET_RECORDING_SESSION);
                } else {
-                       ret = func(session);
+                       try {
+                               ret = func(session);
+                       } catch (const std::exception& e) {
+                               MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+                                       MAS_DEPENDENCY_FUNC_DEINITIALIZE, e.what());
+                       }
                        if (0 != ret) {
                                MAS_LOGE("[ERROR] Fail to set recording session, ret(%d)", ret);
                        }
@@ -218,7 +250,12 @@ int dependency_resolver_set_background_volume(double ratio)
                if (NULL == func) {
                        MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_SET_BACKGROUND_VOLUME);
                } else {
-                       ret = func(ratio);
+                       try {
+                               ret = func(ratio);
+                       } catch (const std::exception& e) {
+                               MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+                                       MAS_DEPENDENCY_FUNC_DEINITIALIZE, e.what());
+                       }
                        if (0 != ret) {
                                MAS_LOGE("[ERROR] Fail to set background volume to %f, ret(%d)", ratio, ret);
                        }
@@ -238,7 +275,12 @@ int dependency_resolver_get_audio_format(int* rate, int* channel, int* audio_typ
                if (NULL == func) {
                        MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_GET_AUDIO_FORMAT);
                } else {
-                       ret = func(rate, channel, audio_type);
+                       try {
+                               ret = func(rate, channel, audio_type);
+                       } catch (const std::exception& e) {
+                               MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+                                       MAS_DEPENDENCY_FUNC_DEINITIALIZE, e.what());
+                       }
                        if (0 != ret) {
                                MAS_LOGE("[ERROR] Fail to get audio format, ret(%d)", ret);
                        }
@@ -258,7 +300,12 @@ int dependency_resolver_get_audio_source_type(char** type)
                if (NULL == func) {
                        MAS_LOGE("[ERROR] symbol lookup failed : %s", MAS_DEPENDENCY_FUNC_GET_AUDIO_SOURCE_TYPE);
                } else {
-                       ret = func(type);
+                       try {
+                               ret = func(type);
+                       } catch (const std::exception& e) {
+                               MAS_LOGE("[ERROR] %s of dependency module threw exception : %s",
+                                       MAS_DEPENDENCY_FUNC_DEINITIALIZE, e.what());
+                       }
                        if (0 != ret) {
                                MAS_LOGE("[ERROR] Fail to get audio source type, ret(%d)", ret);
                        }