[mediacontroller][common] Use PlatformEnum in MediaController.
[platform/core/api/webapi-plugins.git] / src / mediacontroller / mediacontroller_client.cc
index 0899a3f..2db0e8d 100644 (file)
@@ -157,10 +157,9 @@ PlatformResult MediaControllerClient::GetLatestServerInfo(picojson::value* serve
   }
 
   std::string state_str;
-  PlatformResult result = Types::PlatformEnumToString(Types::kMediaControllerServerState,
-                                                      static_cast<int>(state), &state_str);
+  PlatformResult result = types::MediaControllerServerStateEnum.getName(state, &state_str);
   if (!result) {
-    LoggerE("PlatformEnumToString failed, error: %s", result.message().c_str());
+    LoggerE("MediaControllerServerStateEnum.getName() failed, error: %s", result.message().c_str());
     return result;
   }
 
@@ -195,7 +194,7 @@ PlatformResult MediaControllerClient::GetPlaybackInfo(const std::string& server_
 
   // playback state
   std::string state;
-  PlatformResult result = Types::ConvertPlaybackState(playback_h, &state);
+  PlatformResult result = types::ConvertPlaybackState(playback_h, &state);
   if (!result) {
     LoggerE("ConvertPlaybackState failed, error: %s", result.message().c_str());
     return result;
@@ -203,7 +202,7 @@ PlatformResult MediaControllerClient::GetPlaybackInfo(const std::string& server_
 
   // playback position
   double position;
-  result = Types::ConvertPlaybackPosition(playback_h, &position);
+  result = types::ConvertPlaybackPosition(playback_h, &position);
   if (!result) {
     LoggerE("ConvertPlaybackPosition failed, error: %s", result.message().c_str());
     return result;
@@ -211,7 +210,7 @@ PlatformResult MediaControllerClient::GetPlaybackInfo(const std::string& server_
 
   // content age rating
   std::string rating;
-  result = Types::ConvertContentAgeRating(playback_h, &rating);
+  result = types::ConvertContentAgeRating(playback_h, &rating);
   if (!result) {
     LoggerE("ConvertContentAgeRating failed, error: %s", result.message().c_str());
     return result;
@@ -259,7 +258,6 @@ PlatformResult MediaControllerClient::GetPlaybackInfo(const std::string& server_
   (*playback_info)["index"] = picojson::value(std::string(index ? index : ""));
   (*playback_info)["playlistName"] =
       picojson::value(std::string(playlist_name ? playlist_name : ""));
-  ;
 
   return PlatformResult(ErrorCode::NO_ERROR);
 }
@@ -281,7 +279,7 @@ PlatformResult MediaControllerClient::GetMetadata(const std::string& server_name
     mc_metadata_destroy(metadata_h);
   };
 
-  PlatformResult result = Types::ConvertMetadata(metadata_h, metadata);
+  PlatformResult result = types::ConvertMetadata(metadata_h, metadata);
   if (!result) {
     return result;
   }
@@ -323,10 +321,9 @@ void MediaControllerClient::OnServerStatusUpdate(const char* server_name, mc_ser
 
   // server state
   std::string state_str;
-  PlatformResult result = Types::PlatformEnumToString(Types::kMediaControllerServerState,
-                                                      static_cast<int>(state), &state_str);
+  PlatformResult result = types::MediaControllerServerStateEnum.getName(state, &state_str);
   if (!result) {
-    LoggerE("PlatformEnumToString failed, error: %s", result.message().c_str());
+    LoggerE("MediaControllerServerStateEnum.getName() failed, error: %s", result.message().c_str());
     return;
   }
 
@@ -420,7 +417,7 @@ void MediaControllerClient::OnPlaybackUpdate(const char* server_name, mc_playbac
 
   // playback state
   std::string state;
-  PlatformResult result = Types::ConvertPlaybackState(playback, &state);
+  PlatformResult result = types::ConvertPlaybackState(playback, &state);
   if (!result) {
     LoggerE("ConvertPlaybackState failed, error: %s", result.message().c_str());
     return;
@@ -428,7 +425,7 @@ void MediaControllerClient::OnPlaybackUpdate(const char* server_name, mc_playbac
 
   // playback position
   double position;
-  result = Types::ConvertPlaybackPosition(playback, &position);
+  result = types::ConvertPlaybackPosition(playback, &position);
   if (!result) {
     LoggerE("ConvertPlaybackPosition failed, error: %s", result.message().c_str());
     return;
@@ -477,11 +474,10 @@ void MediaControllerClient::OnRepeatModeUpdate(const char* server_name, mc_repea
     data_o["mode"] = picojson::value(mode == MC_REPEAT_MODE_ON);
     client->playback_info_listener_(&data);
   }
-  std::string state{};
-  PlatformResult result = Types::PlatformEnumToString(Types::kMediaControllerRepeatState,
-                                                      static_cast<int>(mode), &state);
+  std::string state;
+  PlatformResult result = types::MediaControllerRepeatModeEnum.getName(mode, &state);
   if (!result) {
-    LoggerE("PlatformEnumToString failed, error: %s", result.message().c_str());
+    LoggerE("MediaControllerRepeatModeEnum.getName() failed, error: %s", result.message().c_str());
     return;
   }
   data_o["action"] = picojson::value(std::string("onrepeatstatechanged"));
@@ -499,7 +495,7 @@ void MediaControllerClient::OnMetadataUpdate(const char* server_name, mc_metadat
   picojson::object& data_o = data.get<picojson::object>();
 
   picojson::value metadata = picojson::value(picojson::object());
-  PlatformResult result = Types::ConvertMetadata(metadata_h, &metadata.get<picojson::object>());
+  PlatformResult result = types::ConvertMetadata(metadata_h, &metadata.get<picojson::object>());
   if (!result) {
     LoggerE("ConvertMetadata failed, error: %s", result.message().c_str());
     return;
@@ -594,11 +590,10 @@ void MediaControllerClient::OnCommandReply(const char* server_name, const char*
 PlatformResult MediaControllerClient::SendPlaybackState(const std::string& server_name,
                                                         const std::string& state) {
   ScopeLogger();
-  int state_e;
   // In Native API, since Tizen 5.0 an action instead of a state is sent to change the state of a
   // server. In Web API the names were not refactored.
-  PlatformResult result =
-      Types::StringToPlatformEnum(Types::kMediaControllerPlaybackAction, state, &state_e);
+  mc_playback_action_e action_e;
+  PlatformResult result = types::MediaControllerPlaybackActionEnum.getValue(state, &action_e);
   if (!result) {
     return result;
   }
@@ -608,10 +603,7 @@ PlatformResult MediaControllerClient::SendPlaybackState(const std::string& serve
   SCOPE_EXIT {
     free(request_id);
   };*/
-  int ret;
-  ret = mc_client_send_playback_action_cmd(handle_, server_name.c_str(),
-                                           static_cast<mc_playback_action_e>(state_e),
-                                           /*&request_id*/ nullptr);
+  int ret = mc_client_send_playback_action_cmd(handle_, server_name.c_str(), action_e, nullptr);
   if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error sending playback state",
                               ("mc_client_send_playback_action_cmd() error: %d, message: %s", ret,
@@ -687,15 +679,13 @@ PlatformResult MediaControllerClient::SendRepeatState(const std::string& server_
   SCOPE_EXIT {
     free(request_id);
   };*/
-  int state_e;
-  PlatformResult result =
-      Types::StringToPlatformEnum(Types::kMediaControllerRepeatState, state, &state_e);
+  mc_repeat_mode_e state_e;
+  PlatformResult result = types::MediaControllerRepeatModeEnum.getValue(state, &state_e);
   if (!result) {
     return result;
   }
-  int ret = mc_client_send_repeat_mode_cmd(handle_, server_name.c_str(),
-                                           static_cast<mc_repeat_mode_e>(state_e),
-                                           /*&request_id*/ nullptr);
+
+  int ret = mc_client_send_repeat_mode_cmd(handle_, server_name.c_str(), state_e, nullptr);
   if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
     return LogAndCreateResult(
         ErrorCode::UNKNOWN_ERR, "Error sending repeat state",
@@ -711,19 +701,17 @@ PlatformResult MediaControllerClient::SendPlaybackItem(const std::string& name,
                                                        const std::string& state, double position) {
   ScopeLogger();
 
-  int state_e;
   // In Native API, since Tizen 5.0 an action instead of a state is sent to change the state of a
   // server. In Web API the names were not refactored.
-  PlatformResult result =
-      Types::StringToPlatformEnum(Types::kMediaControllerPlaybackAction, state, &state_e);
-
+  mc_playback_action_e action_e;
+  PlatformResult result = types::MediaControllerPlaybackActionEnum.getValue(state, &action_e);
   if (!result) {
     return result;
   }
 
+  auto position_ull = static_cast<unsigned long long>(position);
   int ret = mc_client_send_playlist_cmd(handle_, name.c_str(), playlist_name.c_str(), index.c_str(),
-                                        static_cast<mc_playback_action_e>(state_e),
-                                        static_cast<unsigned long long>(position), nullptr);
+                                        action_e, position_ull, nullptr);
 
   if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
     return LogAndCreateResult(