[VoiceControl] Refactoring/reformatting module 26/156426/3
authorSzymon Jastrzebski <s.jastrzebsk@partner.samsung.com>
Wed, 18 Oct 2017 09:48:32 +0000 (11:48 +0200)
committerSzymon Jastrzebski <s.jastrzebsk@partner.samsung.com>
Wed, 18 Oct 2017 09:48:32 +0000 (11:48 +0200)
+ refactor the code and replace static VoiceControlClient into member of
    VoiceControlInstace to prevent possible crashes
+ moving VcConvertCmdType function into the vc_utils

[Verification] Code compiles

Change-Id: Ibe76be9af93df3825917c7fb2115afb0d8826d76
Signed-off-by: Szymon Jastrzebski <s.jastrzebsk@partner.samsung.com>
src/voicecontrol/voicecontrol_client.cc [changed mode: 0755->0644]
src/voicecontrol/voicecontrol_client.h [changed mode: 0755->0644]
src/voicecontrol/voicecontrol_extension.cc [changed mode: 0755->0644]
src/voicecontrol/voicecontrol_extension.h [changed mode: 0755->0644]
src/voicecontrol/voicecontrol_instance.cc [changed mode: 0755->0644]
src/voicecontrol/voicecontrol_instance.h [changed mode: 0755->0644]
src/voicecontrol/voicecontrol_util.cc [changed mode: 0755->0644]
src/voicecontrol/voicecontrol_util.h [changed mode: 0755->0644]

old mode 100755 (executable)
new mode 100644 (file)
index bf42449..debba64
  *    limitations under the License.
  */
 
-#include "voicecontrol/voicecontrol_util.h"
 #include "voicecontrol/voicecontrol_client.h"
 #include <voice_control.h>
 #include <voice_control_internal.h>
+#include "voicecontrol/voicecontrol_util.h"
 
 #include <functional>
 
-#include "common/picojson.h"
 #include "common/logger.h"
+#include "common/picojson.h"
 #include "common/platform_exception.h"
 #include "common/scope_exit.h"
 #include "common/tools.h"
 namespace extension {
 namespace voicecontrol {
 
-VoiceControlClient* VoiceControlClient::GetInstance() {
-  ScopeLogger();
-  static VoiceControlClient instance;
-
-  return &instance;
-}
-
 VoiceControlClient::VoiceControlClient() : is_result_cb_set(false), is_lang_cb_set(false) {
 }
 
 VoiceControlClient::~VoiceControlClient() {
 }
 
-int VcConvertCmdType(const std::string &type) {
-  // TODO add switch here when also other types of command will be also supported.
-  // For now, only foreground is supported, we are returning it as default value.
-  return VC_COMMAND_TYPE_FOREGROUND;
-}
-
-common::PlatformResult VoiceControlClient::GetCurrentLanguage(std::string *language) {
+common::PlatformResult VoiceControlClient::GetCurrentLanguage(std::string* language) {
   ScopeLogger();
 
-  char *lang = nullptr;
+  charlang = nullptr;
   int ret = VC_ERROR_NONE;
 
   ret = vc_get_current_language(&lang);
@@ -67,7 +54,8 @@ common::PlatformResult VoiceControlClient::GetCurrentLanguage(std::string *langu
   return MakeErrorObject(ret);
 }
 
-common::PlatformResult VoiceControlClient::SetCommandList(const std::vector<picojson::value>& list, const std::string& type) {
+common::PlatformResult VoiceControlClient::SetCommandList(const std::vector<picojson::value>& list,
+                                                          const std::string& type) {
   ScopeLogger();
 
   int ret = VC_ERROR_NONE;
@@ -90,7 +78,8 @@ common::PlatformResult VoiceControlClient::SetCommandList(const std::vector<pico
       return MakeErrorObject(ret);
     }
 
-    std::unique_ptr<std::remove_pointer<vc_cmd_h>::type, int (*)(vc_cmd_h)> ptr(vc_command, &vc_cmd_destroy);
+    std::unique_ptr<std::remove_pointer<vc_cmd_h>::type, int (*)(vc_cmd_h)> ptr(vc_command,
+                                                                                &vc_cmd_destroy);
 
     ret = vc_cmd_set_command(ptr.get(), (*it).get(COMMAND).get<std::string>().c_str());
     if (VC_ERROR_NONE != ret) {
@@ -151,7 +140,6 @@ common::PlatformResult VoiceControlClient::RemoveLanguageChangeListener() {
   return MakeErrorObject(VC_ERROR_NONE);
 }
 
-
 const bool VoiceControlClient::IsResultListenerSet() {
   ScopeLogger();
 
@@ -166,5 +154,5 @@ const bool VoiceControlClient::IsLanguageChangedListenerSet() {
 
 #undef CHECK_EXIST
 
-} // namespace voicecontrol
-} // namespace extension
+}  // namespace voicecontrol
+}  // namespace extension
old mode 100755 (executable)
new mode 100644 (file)
index 7f06730..117d99c
 #ifndef VOICECONTROL_VOICECONTROL_CLIENT_H_
 #define VOICECONTROL_VOICECONTROL_CLIENT_H_
 
-#include "common/extension.h"
 #include <voice_control.h>
+#include "common/extension.h"
 
 namespace extension {
 namespace voicecontrol {
 
 class VoiceControlClient {
- public:
-  static VoiceControlClient* GetInstance();
-
  public:
   VoiceControlClient();
   ~VoiceControlClient();
 
-  common::PlatformResult GetCurrentLanguage(std::string *language);
-  common::PlatformResult SetCommandList(const std::vector<picojson::value>& list, const std::string& type);
+  common::PlatformResult GetCurrentLanguage(std::string* language);
+  common::PlatformResult SetCommandList(const std::vector<picojson::value>& list,
+                                        const std::string& type);
   common::PlatformResult UnsetCommandList(const std::string& type);
   common::PlatformResult AddResultListener();
   common::PlatformResult RemoveResultListener();
@@ -47,7 +45,7 @@ class VoiceControlClient {
   bool is_lang_cb_set;
 };
 
-} // namespace voicecontrol
-} // namespace extension
+}  // namespace voicecontrol
+}  // namespace extension
 
-#endif // VOICECONTROL_VOICECONTROL_CLIENT_H_
\ No newline at end of file
+#endif  // VOICECONTROL_VOICECONTROL_CLIENT_H_
\ No newline at end of file
old mode 100755 (executable)
new mode 100644 (file)
index f3bd17a..66e1f8c
@@ -29,14 +29,12 @@ VoicecontrolExtension::VoicecontrolExtension() {
   SetExtensionName("tizen.voicecontrol");
   SetJavaScriptAPI(kSource_voicecontrol_api);
 
-  const char* entry_points[] = {
-      "tizen.VoiceControlCommand",
-      NULL
-    };
+  const char* entry_points[] = {"tizen.VoiceControlCommand", NULL};
   SetExtraJSEntryPoints(entry_points);
 }
 
-VoicecontrolExtension::~VoicecontrolExtension() {}
+VoicecontrolExtension::~VoicecontrolExtension() {
+}
 
 common::Instance* VoicecontrolExtension::CreateInstance() {
   return new extension::voicecontrol::VoiceControlInstance;
old mode 100755 (executable)
new mode 100644 (file)
index 5d98992..aab4fd3
@@ -28,4 +28,4 @@ class VoicecontrolExtension : public common::Extension {
   virtual common::Instance* CreateInstance();
 };
 
-#endif // VOICECONTROL_VOICECONTROL_EXTENSION_H_
+#endif  // VOICECONTROL_VOICECONTROL_EXTENSION_H_
old mode 100755 (executable)
new mode 100644 (file)
index 034b416..7a11ceb
  */
 
 #include "voicecontrol/voicecontrol_instance.h"
-#include "voicecontrol/voicecontrol_client.h"
-#include "voicecontrol/voicecontrol_util.h"
 #include <voice_control.h>
 #include <voice_control_internal.h>
+#include "voicecontrol/voicecontrol_client.h"
+#include "voicecontrol/voicecontrol_util.h"
 
 #include <functional>
 
-#include "common/picojson.h"
 #include "common/logger.h"
+#include "common/picojson.h"
 #include "common/platform_exception.h"
 #include "common/scope_exit.h"
 #include "common/tools.h"
@@ -34,96 +34,15 @@ namespace voicecontrol {
 namespace {
 // The privileges that are required in Voicecontrol API
 const std::string kPrivilegeVoiceControl = "http://tizen.org/privilege/recorder";
-
-void ReplyAsync(VoiceControlInstance* instance, const std::string& listenerId, bool isSuccess, picojson::object& param) {
-  ScopeLogger();
-  param["listenerId"] = picojson::value(listenerId);
-  param["status"] = picojson::value(isSuccess ? "success" : "error");
-
-  /* All callback functions are called by voice control framework */
-  /* Send result from callback to javascript */
-  picojson::value result = picojson::value(param);
-
-  instance->PostMessage(instance, result.serialize().c_str());
-}
-
-
-
-/* Define callback functions for voice control */
-void VcResultCb(vc_result_event_e event, vc_cmd_list_h cmd_list, const char* result, void *user_data) {
-  ScopeLogger();
-  VoiceControlInstance *instance = static_cast<VoiceControlInstance *>(user_data);
-
-  if (nullptr != instance && VoiceControlClient::GetInstance()->IsResultListenerSet()) {
-    LoggerD("VcResultCb");
-    picojson::object param = picojson::object();
-    param["event"] = picojson::value(std::string(((event == VC_RESULT_EVENT_RESULT_SUCCESS) ? "SUCCESS" : "FAILURE")));
-
-    int len = 0;
-    int ret = VC_ERROR_NONE;
-
-    ret = vc_cmd_list_get_count(cmd_list, &len);
-    if (VC_ERROR_NONE != ret) {
-      LoggerE("Fail to get the count of the result list");
-      return;
-    }
-
-    picojson::array& value_vector = param.insert(std::make_pair("list",
-      picojson::value(picojson::array(len)))).first->second.get<picojson::array>();
-
-    ret = vc_cmd_list_first(cmd_list);
-    for (auto i = 0; VC_ERROR_NONE == ret && i < len; i++) {
-      LoggerD("Current (%d), Count (%d)", i, len);
-      vc_cmd_h vc_command = nullptr;
-      char* command = nullptr;
-      SCOPE_EXIT {
-        free(command);
-      };
-
-      ret = vc_cmd_list_get_current(cmd_list, &vc_command);
-      if (VC_ERROR_NONE != ret) {
-        break;
-      }
-      ret = vc_cmd_get_command(vc_command, &command);
-      if (VC_ERROR_NONE != ret) {
-        break;
-      }
-
-      if (nullptr != command) {
-        LoggerD("Command (%s)", command);
-        value_vector[i] = picojson::value(command);
-      }
-
-      ret = vc_cmd_list_next(cmd_list);
-    }
-
-    param["results"] = picojson::value(std::string(result));
-
-    ReplyAsync(instance, ON_RESULT, true, param);
-  }
-}
-
-void VcLanguageChangedCb(const char* previous, const char* current, void* user_data) {
-  ScopeLogger();
-  VoiceControlInstance *instance = static_cast<VoiceControlInstance *>(user_data);
-  if (nullptr != instance && VoiceControlClient::GetInstance()->IsLanguageChangedListenerSet()) {
-    LoggerD("VcLanguageChangedCb");
-    picojson::object param = picojson::object();
-    param["previous"] = picojson::value(std::string(previous));
-    param["current"] = picojson::value(std::string(current));
-
-    ReplyAsync(instance, ON_LANG, true, param);
-  }
-}
-} // namespace
+}  // namespace
 
 using namespace common;
 using namespace extension::voicecontrol;
 
-VoiceControlInstance::VoiceControlInstance() {
+VoiceControlInstance::VoiceControlInstance() : voice_control_client() {
   using namespace std::placeholders;
-  #define REGISTER_SYNC(c,x) \
-    RegisterSyncHandler(c, std::bind(&VoiceControlInstance::x, this, _1, _2));
+#define REGISTER_SYNC(c, x) \
+  RegisterSyncHandler(c, std::bind(&VoiceControlInstance::x, this, _1, _2));
   REGISTER_SYNC("VoiceControlClient_getCurrentLanguage", GetCurrentLanguage);
   REGISTER_SYNC("VoiceControlClient_setCommandList", SetCommandList);
   REGISTER_SYNC("VoiceControlClient_unsetCommandList", UnsetCommandList);
@@ -133,7 +52,7 @@ VoiceControlInstance::VoiceControlInstance() {
   REGISTER_SYNC("VoiceControlClient_removeLanguageChangeListener", RemoveLanguageChangeListener);
   REGISTER_SYNC("VoiceControlClient_release", Release);
   REGISTER_SYNC("VoiceControlClientManager_getVoiceControlClient", GetVoiceControlClient);
-  #undef REGISTER_SYNC
+#undef REGISTER_SYNC
 }
 
 VoiceControlInstance::~VoiceControlInstance() {
@@ -144,13 +63,14 @@ VoiceControlInstance::~VoiceControlInstance() {
   }
 }
 
-#define CHECK_EXIST(args, name, out) \
-  if (!args.contains(name)) {\
-    ReportError(TypeMismatchException(name + " is required argument"), out);\
-    return;\
+#define CHECK_EXIST(args, name, out)                                         \
+  if (!args.contains(name)) {                                                \
+    ReportError(TypeMismatchException(name + " is required argument"), out); \
+    return;                                                                  \
   }
 
-void VoiceControlInstance::GetVoiceControlClient(const picojson::value& args, picojson::object& out) {
+void VoiceControlInstance::GetVoiceControlClient(const picojson::value& args,
+                                                 picojson::object& out) {
   ScopeLogger();
 
   CHECK_PRIVILEGE_ACCESS(kPrivilegeVoiceControl, &out);
@@ -188,7 +108,7 @@ void VoiceControlInstance::GetVoiceControlClient(const picojson::value& args, pi
   }
 
   ret = vc_prepare_sync();
-    if (VC_ERROR_NONE != ret) {
+  if (VC_ERROR_NONE != ret) {
     LogAndReportError(MakeErrorObject(ret), &out);
     return;
   }
@@ -196,7 +116,6 @@ void VoiceControlInstance::GetVoiceControlClient(const picojson::value& args, pi
   ReportSuccess(out);
 }
 
-
 void VoiceControlInstance::Release(const picojson::value& args, picojson::object& out) {
   ScopeLogger();
   int ret = VC_ERROR_NONE;
@@ -232,7 +151,7 @@ void VoiceControlInstance::GetCurrentLanguage(const picojson::value& args, picoj
   ScopeLogger();
 
   std::string language;
-  common::PlatformResult result = VoiceControlClient::GetInstance()->GetCurrentLanguage(&language);
+  common::PlatformResult result = voice_control_client.GetCurrentLanguage(&language);
 
   if (result.IsSuccess()) {
     ReportSuccess(picojson::value(language), out);
@@ -248,10 +167,10 @@ void VoiceControlInstance::SetCommandList(const picojson::value& args, picojson:
   CHECK_EXIST(args, TYPE, out)
   CHECK_EXIST(args, LIST, out)
 
-  std::string type = args.get(TYPE).get<std::string>();
+  const std::string& type = args.get(TYPE).get<std::string>();
   std::vector<picojson::value> list = args.get(LIST).get<picojson::array>();
 
-  common::PlatformResult result = VoiceControlClient::GetInstance()->SetCommandList(list, type);
+  common::PlatformResult result = voice_control_client.SetCommandList(list, type);
 
   if (result.IsSuccess()) {
     ReportSuccess(out);
@@ -266,9 +185,9 @@ void VoiceControlInstance::UnsetCommandList(const picojson::value& args, picojso
 
   CHECK_EXIST(args, TYPE, out)
 
-  std::string type = args.get(TYPE).get<std::string>();
+  const std::string& type = args.get(TYPE).get<std::string>();
 
-  common::PlatformResult result = VoiceControlClient::GetInstance()->UnsetCommandList(type);
+  common::PlatformResult result = voice_control_client.UnsetCommandList(type);
 
   if (result.IsSuccess()) {
     ReportSuccess(out);
@@ -280,7 +199,7 @@ void VoiceControlInstance::UnsetCommandList(const picojson::value& args, picojso
 void VoiceControlInstance::AddResultListener(const picojson::value& args, picojson::object& out) {
   ScopeLogger();
 
-  common::PlatformResult result = VoiceControlClient::GetInstance()->AddResultListener();
+  common::PlatformResult result = voice_control_client.AddResultListener();
 
   if (result.IsSuccess()) {
     ReportSuccess(out);
@@ -289,10 +208,11 @@ void VoiceControlInstance::AddResultListener(const picojson::value& args, picojs
   }
 }
 
-void VoiceControlInstance::RemoveResultListener(const picojson::value& args, picojson::object& out) {
+void VoiceControlInstance::RemoveResultListener(const picojson::value& args,
+                                                picojson::object& out) {
   ScopeLogger();
 
-  common::PlatformResult result = VoiceControlClient::GetInstance()->RemoveResultListener();
+  common::PlatformResult result = voice_control_client.RemoveResultListener();
 
   if (result.IsSuccess()) {
     ReportSuccess(out);
@@ -301,10 +221,11 @@ void VoiceControlInstance::RemoveResultListener(const picojson::value& args, pic
   }
 }
 
-void VoiceControlInstance::AddLanguageChangeListener(const picojson::value& args, picojson::object& out) {
+void VoiceControlInstance::AddLanguageChangeListener(const picojson::value& args,
+                                                     picojson::object& out) {
   ScopeLogger();
 
-  common::PlatformResult result = VoiceControlClient::GetInstance()->AddLanguageChangeListener();
+  common::PlatformResult result = voice_control_client.AddLanguageChangeListener();
 
   if (result.IsSuccess()) {
     ReportSuccess(out);
@@ -313,10 +234,11 @@ void VoiceControlInstance::AddLanguageChangeListener(const picojson::value& args
   }
 }
 
-void VoiceControlInstance::RemoveLanguageChangeListener(const picojson::value& args, picojson::object& out) {
+void VoiceControlInstance::RemoveLanguageChangeListener(const picojson::value& args,
+                                                        picojson::object& out) {
   ScopeLogger();
 
-  common::PlatformResult result = VoiceControlClient::GetInstance()->RemoveLanguageChangeListener();
+  common::PlatformResult result = voice_control_client.RemoveLanguageChangeListener();
 
   if (result.IsSuccess()) {
     ReportSuccess(out);
@@ -325,7 +247,95 @@ void VoiceControlInstance::RemoveLanguageChangeListener(const picojson::value& a
   }
 }
 
+void VoiceControlInstance::ReplyAsync(VoiceControlInstance* instance, const std::string& listenerId,
+                                      bool isSuccess, picojson::object& param) {
+  ScopeLogger();
+  param["listenerId"] = picojson::value(listenerId);
+  param["status"] = picojson::value(isSuccess ? "success" : "error");
+
+  /* All callback functions are called by voice control framework */
+  /* Send result from callback to javascript */
+  picojson::value result = picojson::value(param);
+
+  instance->PostMessage(instance, result.serialize().c_str());
+}
+
+/* Define callback functions for voice control */
+void VoiceControlInstance::VcResultCb(vc_result_event_e event, vc_cmd_list_h cmd_list,
+                                      const char* result, void* user_data) {
+  ScopeLogger();
+  VoiceControlInstance* instance = static_cast<VoiceControlInstance*>(user_data);
+
+  if (nullptr != instance && instance->voice_control_client.IsResultListenerSet()) {
+    LoggerD("VcResultCb");
+    picojson::object param = picojson::object();
+    param["event"] =
+        picojson::value(((event == VC_RESULT_EVENT_RESULT_SUCCESS) ? "SUCCESS" : "FAILURE"));
+
+    int len = 0;
+    int ret = VC_ERROR_NONE;
+
+    ret = vc_cmd_list_get_count(cmd_list, &len);
+    if (VC_ERROR_NONE != ret) {
+      LoggerE("Fail to get the count of the result list");
+      return;
+    }
+
+    ret = vc_cmd_list_first(cmd_list);
+    if (VC_ERROR_NONE != ret) {
+      LoggerE("Fail to get the first element of the result list");
+    }
+
+    picojson::array& value_vector =
+        param.insert(std::make_pair("list", picojson::value(picojson::array(len))))
+            .first->second.get<picojson::array>();
+    param["results"] = picojson::value(result);
+
+    for (int i = 0; VC_ERROR_NONE == ret && i < len; i++) {
+      LoggerD("Current (%d), Count (%d)", i, len);
+      vc_cmd_h vc_command = nullptr;
+      char* command = nullptr;
+      SCOPE_EXIT {
+        free(command);
+      };
+
+      ret = vc_cmd_list_get_current(cmd_list, &vc_command);
+      if (VC_ERROR_NONE != ret) {
+        break;
+      }
+
+      ret = vc_cmd_get_command(vc_command, &command);
+      if (VC_ERROR_NONE != ret) {
+        break;
+      }
+
+      if (nullptr != command) {
+        LoggerD("Command (%s)", command);
+        value_vector[i] = picojson::value(command);
+      }
+
+      ret = vc_cmd_list_next(cmd_list);
+    }
+
+    ReplyAsync(instance, ON_RESULT, true, param);
+  }
+}
+
+void VoiceControlInstance::VcLanguageChangedCb(const char* previous, const char* current,
+                                               void* user_data) {
+  ScopeLogger();
+  VoiceControlInstance* instance = static_cast<VoiceControlInstance*>(user_data);
+  if (nullptr != instance && instance->voice_control_client.IsLanguageChangedListenerSet()) {
+    LoggerD("VcLanguageChangedCb");
+    picojson::object param = picojson::object();
+    param["previous"] = picojson::value(previous);
+    param["current"] = picojson::value(current);
+
+    ReplyAsync(instance, ON_LANG, true, param);
+  }
+}
+
 #undef CHECK_EXIST
 
-} // namespace voicecontrol
-} // namespace extension
+}  // namespace voicecontrol
+}  // namespace extension
old mode 100755 (executable)
new mode 100644 (file)
index 633482e..03d2aac
 #ifndef VOICECONTROL_VOICECONTROL_INSTANCE_H_
 #define VOICECONTROL_VOICECONTROL_INSTANCE_H_
 
+#include <voice_control_common.h>
+
 #include "common/extension.h"
+#include "voicecontrol/voicecontrol_client.h"
 
 namespace extension {
 namespace voicecontrol {
@@ -38,9 +41,17 @@ class VoiceControlInstance : public common::ParsedInstance {
   void RemoveResultListener(const picojson::value& args, picojson::object& out);
   void AddLanguageChangeListener(const picojson::value& args, picojson::object& out);
   void RemoveLanguageChangeListener(const picojson::value& args, picojson::object& out);
+
+  static void VcLanguageChangedCb(const char* previous, const char* current, void* user_data);
+  static void VcResultCb(vc_result_event_e event, vc_cmd_list_h cmd_list, const char* result,
+                         void* user_data);
+  static void ReplyAsync(VoiceControlInstance* instance, const std::string& listenerId,
+                         bool isSuccess, picojson::object& param);
+
+  VoiceControlClient voice_control_client;
 };
 
-} // namespace voicecontrol
-} // namespace extension
+}  // namespace voicecontrol
+}  // namespace extension
 
-#endif // VOICECONTROL_VOICECONTROL_INSTANCE_H_
\ No newline at end of file
+#endif  // VOICECONTROL_VOICECONTROL_INSTANCE_H_
\ No newline at end of file
old mode 100755 (executable)
new mode 100644 (file)
index b51bbdc..f54c1da
@@ -56,5 +56,11 @@ common::PlatformResult MakeErrorObject(const int ret) {
   }
 }
 
-} // namespace voicecontrol
-} // namespace extension
+int VcConvertCmdType(const std::string& type) {
+  // TODO add switch here when also other types of command will be also supported.
+  // For now, only foreground is supported, we return it as the default value.
+  return VC_COMMAND_TYPE_FOREGROUND;
+}
+
+}  // namespace voicecontrol
+}  // namespace extension
old mode 100755 (executable)
new mode 100644 (file)
index 3071aa9..a8fff25
@@ -23,32 +23,33 @@ namespace extension {
 namespace voicecontrol {
 
 namespace {
-  /* Error message text */
-  const std::string NO_ERROR = "No error";
-  const std::string INVALID_PARAMETER = "Invalid parameter!";
-  const std::string OUT_OF_MEMORY = "Out of memory!";
-  const std::string OPERATION_FAILED = "Operation failed!";
-  const std::string PERMISSION_DENIED = "Permission denied!";
-  const std::string NOT_SUPPORTED = "Not supported!";
-
-  /* Parameter name */
-  const std::string CALLBACK_ID = "callbackId";
-  const std::string TYPE = "type";
-  const std::string LIST = "list";
-  const std::string COMMAND = "command";
-
-  /* Voice control command type */
-  const std::string FOREGROUND = "FOREGROUND";
-
-  /* Listener types on javascript */
-  const std::string ON_RESULT = "onresult";
-  const std::string ON_LANG = "onlanguagechanged";
+/* Error message text */
+const std::string NO_ERROR = "No error";
+const std::string INVALID_PARAMETER = "Invalid parameter!";
+const std::string OUT_OF_MEMORY = "Out of memory!";
+const std::string OPERATION_FAILED = "Operation failed!";
+const std::string PERMISSION_DENIED = "Permission denied!";
+const std::string NOT_SUPPORTED = "Not supported!";
+
+/* Parameter name */
+const std::string CALLBACK_ID = "callbackId";
+const std::string TYPE = "type";
+const std::string LIST = "list";
+const std::string COMMAND = "command";
+
+/* Voice control command type */
+const std::string FOREGROUND = "FOREGROUND";
+
+/* Listener types on javascript */
+const std::string ON_RESULT = "onresult";
+const std::string ON_LANG = "onlanguagechanged";
 }
 
-  const std::string& MakeErrorMessage(const int ret);
-  common::PlatformResult MakeErrorObject(const int ret);
+const std::string& MakeErrorMessage(const int ret);
+common::PlatformResult MakeErrorObject(const int ret);
+int VcConvertCmdType(const std::string& type);
 
-} // namespace voicecontrol
-} // namespace extension
+}  // namespace voicecontrol
+}  // namespace extension
 
-#endif // VOICECONTROL_VOICECONTROL_UTIL_H_
\ No newline at end of file
+#endif  // VOICECONTROL_VOICECONTROL_UTIL_H_
\ No newline at end of file