[mediacontroller][common] Use PlatformEnum in MediaController. 12/208812/1
authorMichal Michalski <m.michalski2@partner.samsung.com>
Tue, 7 May 2019 08:59:32 +0000 (10:59 +0200)
committerPiotr Kosko/Native/Web API (PLT) /SRPOL/Professional/삼성전자 <p.kosko@samsung.com>
Fri, 28 Jun 2019 13:51:04 +0000 (15:51 +0200)
Refactor enums in MediaController module using PlatformEnum
template class.

[Verification] Code compiles + MC TCT passed.

Signed-off-by: Michal Michalski <m.michalski2@partner.samsung.com>
Change-Id: Ie861d1c0aca7651a2f9ce45b966773082abf6045

src/mediacontroller/mediacontroller_client.cc
src/mediacontroller/mediacontroller_server.cc
src/mediacontroller/mediacontroller_types.cc
src/mediacontroller/mediacontroller_types.h

index 05d0bda..513dffe 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "common/logger.h"
 #include "common/scope_exit.h"
+#include "common/tools.h"
 
 #include "mediacontroller/mediacontroller_types.h"
 
@@ -153,10 +154,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;
   }
 
@@ -187,7 +187,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;
@@ -195,7 +195,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;
@@ -253,7 +253,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;
   }
@@ -295,10 +295,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;
   }
 
@@ -392,7 +391,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;
@@ -400,7 +399,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;
@@ -456,7 +455,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;
@@ -551,11 +550,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;
   }
@@ -565,10 +563,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,
index 9c089cc..df43313 100644 (file)
@@ -74,27 +74,25 @@ PlatformResult MediaControllerServer::Init() {
 PlatformResult MediaControllerServer::SetPlaybackState(const std::string& state) {
   ScopeLogger();
 
-  int state_int;
-  PlatformResult result =
-      Types::StringToPlatformEnum(Types::kMediaControllerPlaybackState, state, &state_int);
-
+  mc_playback_states_e state_e;
+  PlatformResult result = types::MediaControllerPlaybackStateEnum.getValue(state, &state_e);
   if (!result) {
     return result;
   }
 
-  if (static_cast<mc_playback_states_e>(state_int) == playback_state_) {
+  if (state_e == playback_state_) {
     LoggerD("No change in playback state requested, skipping");
     return PlatformResult(ErrorCode::NO_ERROR);
   }
 
-  int ret = mc_server_set_playback_state(handle_, static_cast<mc_playback_states_e>(state_int));
+  int ret = mc_server_set_playback_state(handle_, state_e);
   if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
     return LogAndCreateResult(
         ErrorCode::UNKNOWN_ERR, "Error setting playback state",
         ("mc_server_set_playback_state() error: %d, message: %s", ret, get_error_message(ret)));
   }
 
-  playback_state_ = static_cast<mc_playback_states_e>(state_int);
+  playback_state_ = state_e;
 
   ret = mc_server_update_playback_info(handle_);
   if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
@@ -180,16 +178,14 @@ PlatformResult MediaControllerServer::SetRepeatMode(bool mode) {
 PlatformResult MediaControllerServer::SetMetadata(const picojson::object& metadata) {
   ScopeLogger();
 
-  int attribute_int, ret;
   for (picojson::object::const_iterator i = metadata.begin(); i != metadata.end(); ++i) {
-    PlatformResult result = Types::StringToPlatformEnum(Types::kMediaControllerMetadataAttribute,
-                                                        i->first, &attribute_int);
+    mc_meta_e attr_e;
+    PlatformResult result = types::MediaControllerMetadataAttributeEnum.getValue(i->first, &attr_e);
     if (!result) {
       return result;
     }
 
-    ret = mc_server_set_metadata(handle_, static_cast<mc_meta_e>(attribute_int),
-                                 i->second.to_str().c_str());
+    int ret = mc_server_set_metadata(handle_, attr_e, i->second.to_str().c_str());
     if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
       return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error setting metadata",
                                 ("mc_server_set_metadata(%s) error: %d, message: %s",
@@ -197,7 +193,7 @@ PlatformResult MediaControllerServer::SetMetadata(const picojson::object& metada
     }
   }
 
-  ret = mc_server_update_metadata(handle_);
+  int ret = mc_server_update_metadata(handle_);
   if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
     return LogAndCreateResult(
         ErrorCode::UNKNOWN_ERR, "Error updating metadata",
@@ -413,17 +409,17 @@ void MediaControllerServer::OnPlaybackActionCommand(const char* client_name, con
   MediaControllerServer* server = static_cast<MediaControllerServer*>(user_data);
 
   // Here, we need to convert mc_playback_action_e enum to mc_playback_states_e enum.
-  std::string state;
-  PlatformResult result = Types::PlatformEnumToString(Types::kMediaControllerPlaybackAction,
-                                                      static_cast<int>(action), &state);
+  std::string action_str;
+  PlatformResult result = types::MediaControllerPlaybackActionEnum.getName(action, &action_str);
   if (!result) {
-    LoggerW("PlatformEnumToString failed, error: %s", result.message().c_str());
+    LoggerW("MediaControllerPlaybackActionEnum.getName() failed, error: %s", result.message().c_str());
     return;
   }
-  int state_e = 0;
-  result = Types::StringToPlatformEnum(Types::kMediaControllerPlaybackState, state, &state_e);
+
+  mc_playback_states_e state_e;
+  result = types::MediaControllerPlaybackStateEnum.getValue(action_str, &state_e);
   if (!result) {
-    LoggerE("PlatformEnumToString failed, error: %s", result.message().c_str());
+    LoggerE("MediaControllerPlaybackStateEnum.getValue() failed, error: %s", result.message().c_str());
     return;
   }
 
@@ -436,7 +432,7 @@ void MediaControllerServer::OnPlaybackActionCommand(const char* client_name, con
   picojson::object& data_o = data.get<picojson::object>();
 
   data_o["action"] = picojson::value(std::string("onplaybackstaterequest"));
-  data_o["state"] = picojson::value(state);
+  data_o["state"] = picojson::value(action_str);
 
   server->change_request_playback_info_listener_(&data);
 }
index 6c92df8..78a32ed 100644 (file)
@@ -28,113 +28,69 @@ namespace mediacontroller {
 using common::PlatformResult;
 using common::ErrorCode;
 
-const std::string Types::kMediaControllerServerState = "MediaControllerServerState";
-const std::string Types::kMediaControllerPlaybackState = "MediaControllerPlaybackState";
-const std::string Types::kMediaControllerPlaybackAction = "MediaControllerPlaybackAction";
-const std::string Types::kMediaControllerMetadataAttribute = "MediaControllerMetadataAttribute";
-
-const PlatformEnumMap Types::platform_enum_map_ = {{kMediaControllerServerState,
-                                                    {{"NONE", MC_SERVER_STATE_NONE},
-                                                     {"ACTIVE", MC_SERVER_STATE_ACTIVATE},
-                                                     {"INACTIVE", MC_SERVER_STATE_DEACTIVATE}}},
-                                                   {kMediaControllerPlaybackState,
-                                                    {{"PLAY", MC_PLAYBACK_STATE_PLAYING},
-                                                     {"PAUSE", MC_PLAYBACK_STATE_PAUSED},
-                                                     {"STOP", MC_PLAYBACK_STATE_STOPPED},
-                                                     {"NEXT", MC_PLAYBACK_STATE_MOVING_TO_NEXT},
-                                                     {"PREV", MC_PLAYBACK_STATE_MOVING_TO_PREVIOUS},
-                                                     {"FORWARD", MC_PLAYBACK_STATE_FAST_FORWARDING},
-                                                     {"REWIND", MC_PLAYBACK_STATE_REWINDING}}},
-                                                   {kMediaControllerPlaybackAction,
-                                                    {{"PLAY", MC_PLAYBACK_ACTION_PLAY},
-                                                     {"PAUSE", MC_PLAYBACK_ACTION_PAUSE},
-                                                     {"STOP", MC_PLAYBACK_ACTION_STOP},
-                                                     {"NEXT", MC_PLAYBACK_ACTION_NEXT},
-                                                     {"PREV", MC_PLAYBACK_ACTION_PREV},
-                                                     {"FORWARD", MC_PLAYBACK_ACTION_FAST_FORWARD},
-                                                     {"REWIND", MC_PLAYBACK_ACTION_REWIND}}},
-                                                   {kMediaControllerMetadataAttribute,
-                                                    {{"title", MC_META_MEDIA_TITLE},
-                                                     {"artist", MC_META_MEDIA_ARTIST},
-                                                     {"album", MC_META_MEDIA_ALBUM},
-                                                     {"author", MC_META_MEDIA_AUTHOR},
-                                                     {"genre", MC_META_MEDIA_GENRE},
-                                                     {"duration", MC_META_MEDIA_DURATION},
-                                                     {"date", MC_META_MEDIA_DATE},
-                                                     {"copyright", MC_META_MEDIA_COPYRIGHT},
-                                                     {"description", MC_META_MEDIA_DESCRIPTION},
-                                                     {"trackNum", MC_META_MEDIA_TRACK_NUM},
-                                                     {"picture", MC_META_MEDIA_PICTURE}}}};
-
-PlatformEnumReverseMap Types::platform_enum_reverse_map_ = {};
-
-PlatformResult Types::GetPlatformEnumMap(const std::string& type,
-                                         std::map<std::string, int> const** enum_map) {
-  ScopeLogger();
-
-  auto iter = platform_enum_map_.find(type);
-  if (iter == platform_enum_map_.end()) {
-    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                              std::string("Undefined platform enum type ") + type);
-  }
-
-  *enum_map = &iter->second;
-
-  return PlatformResult(ErrorCode::NO_ERROR);
-}
-
-PlatformResult Types::StringToPlatformEnum(const std::string& type, const std::string& value,
-                                           int* platform_enum) {
-  ScopeLogger();
-
-  std::map<std::string, int> const* def = nullptr;
-  PlatformResult result = GetPlatformEnumMap(type, &def);
-  if (!result) {
-    return result;
-  }
-
-  auto def_iter = def->find(value);
-  if (def_iter != def->end()) {
-    *platform_enum = def_iter->second;
-    return PlatformResult(ErrorCode::NO_ERROR);
-  }
-
-  std::string message = "Platform enum value " + value + " not found for " + type;
-  return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, message);
-}
-
-PlatformResult Types::PlatformEnumToString(const std::string& type, int value,
-                                           std::string* platform_str) {
-  ScopeLogger();
-
-  if (platform_enum_reverse_map_.empty()) {
-    for (auto& def : platform_enum_map_) {
-      platform_enum_reverse_map_[def.first] = {};
-
-      for (auto& key : def.second) {
-        platform_enum_reverse_map_[def.first][key.second] = key.first;
-      }
-    }
-  }
-
-  auto it = platform_enum_reverse_map_.find(type);
-  if (it == platform_enum_reverse_map_.end()) {
-    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR,
-                              std::string("Undefined platform enum type ") + type);
-  }
-
-  auto def = platform_enum_reverse_map_.at(type);
-  auto def_it = def.find(value);
-  if (def_it != def.end()) {
-    *platform_str = def_it->second;
-    return PlatformResult(ErrorCode::NO_ERROR);
-  }
-
-  std::string message = "Platform enum value " + std::to_string(value) + " not found for " + type;
-  return LogAndCreateResult(ErrorCode::INVALID_VALUES_ERR, message);
-}
-
-PlatformResult Types::ConvertPlaybackState(mc_playback_h playback_h, std::string* state) {
+namespace types {
+
+const common::PlatformEnum<mc_server_state_e> MediaControllerServerStateEnum {
+    {"NONE", MC_SERVER_STATE_NONE},
+    {"ACTIVE", MC_SERVER_STATE_ACTIVATE},
+    {"INACTIVE", MC_SERVER_STATE_DEACTIVATE}
+};
+
+const common::PlatformEnum<mc_playback_states_e> MediaControllerPlaybackStateEnum {
+    {"PLAY", MC_PLAYBACK_STATE_PLAYING},
+    {"PAUSE", MC_PLAYBACK_STATE_PAUSED},
+    {"STOP", MC_PLAYBACK_STATE_STOPPED},
+    {"NEXT", MC_PLAYBACK_STATE_MOVING_TO_NEXT},
+    {"PREV", MC_PLAYBACK_STATE_MOVING_TO_PREVIOUS},
+    {"FORWARD", MC_PLAYBACK_STATE_FAST_FORWARDING},
+    {"REWIND", MC_PLAYBACK_STATE_REWINDING}
+};
+
+const common::PlatformEnum<mc_playback_action_e> MediaControllerPlaybackActionEnum {
+    {"PLAY", MC_PLAYBACK_ACTION_PLAY},
+    {"PAUSE", MC_PLAYBACK_ACTION_PAUSE},
+    {"STOP", MC_PLAYBACK_ACTION_STOP},
+    {"NEXT", MC_PLAYBACK_ACTION_NEXT},
+    {"PREV", MC_PLAYBACK_ACTION_PREV},
+    {"FORWARD", MC_PLAYBACK_ACTION_FAST_FORWARD},
+    {"REWIND", MC_PLAYBACK_ACTION_REWIND}
+};
+
+const common::PlatformEnum<mc_meta_e> MediaControllerMetadataAttributeEnum {
+    {"title", MC_META_MEDIA_TITLE},
+    {"artist", MC_META_MEDIA_ARTIST},
+    {"album", MC_META_MEDIA_ALBUM},
+    {"author", MC_META_MEDIA_AUTHOR},
+    {"genre", MC_META_MEDIA_GENRE},
+    {"duration", MC_META_MEDIA_DURATION},
+    {"date", MC_META_MEDIA_DATE},
+    {"copyright", MC_META_MEDIA_COPYRIGHT},
+    {"description", MC_META_MEDIA_DESCRIPTION},
+    {"trackNum", MC_META_MEDIA_TRACK_NUM},
+    {"picture", MC_META_MEDIA_PICTURE}
+};
+
+const common::PlatformEnum<mc_repeat_mode_e> MediaControllerRepeatModeEnum {
+    {"REPEAT_OFF", MC_REPEAT_MODE_OFF},
+    {"REPEAT_ONE", MC_REPEAT_MODE_ONE_MEDIA},
+    {"REPEAT_ALL", MC_REPEAT_MODE_ON}
+};
+
+const common::PlatformEnum<mc_content_age_rating_e> MediaControllerContentAgeRatingEnum {
+     {"ALL", MC_CONTENT_RATING_ALL},    {"1", MC_CONTENT_RATING_1_PLUS},
+     {"2", MC_CONTENT_RATING_2_PLUS},   {"3", MC_CONTENT_RATING_3_PLUS},
+     {"4", MC_CONTENT_RATING_4_PLUS},   {"5", MC_CONTENT_RATING_5_PLUS},
+     {"6", MC_CONTENT_RATING_6_PLUS},   {"7", MC_CONTENT_RATING_7_PLUS},
+     {"8", MC_CONTENT_RATING_8_PLUS},   {"9", MC_CONTENT_RATING_9_PLUS},
+     {"10", MC_CONTENT_RATING_10_PLUS}, {"11", MC_CONTENT_RATING_11_PLUS},
+     {"12", MC_CONTENT_RATING_12_PLUS}, {"13", MC_CONTENT_RATING_13_PLUS},
+     {"14", MC_CONTENT_RATING_14_PLUS}, {"15", MC_CONTENT_RATING_15_PLUS},
+     {"16", MC_CONTENT_RATING_16_PLUS}, {"17", MC_CONTENT_RATING_17_PLUS},
+     {"18", MC_CONTENT_RATING_18_PLUS}, {"19", MC_CONTENT_RATING_19_PLUS}
+};
+
+
+PlatformResult ConvertPlaybackState(mc_playback_h playback_h, std::string* state) {
   ScopeLogger();
 
   int ret;
@@ -149,17 +105,16 @@ PlatformResult Types::ConvertPlaybackState(mc_playback_h playback_h, std::string
     state_e = MC_PLAYBACK_STATE_STOPPED;
   }
 
-  PlatformResult result = Types::PlatformEnumToString(Types::kMediaControllerPlaybackState,
-                                                      static_cast<int>(state_e), state);
+  PlatformResult result = MediaControllerPlaybackStateEnum.getName(state_e, state);
   if (!result) {
-    LoggerE("PlatformEnumToString failed, error: %s", result.message().c_str());
+    LoggerE("MediaControllerPlaybackStateEnum.getName() failed, error: %s", result.message().c_str());
     return result;
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-PlatformResult Types::ConvertPlaybackPosition(mc_playback_h playback_h, double* position) {
+PlatformResult ConvertPlaybackPosition(mc_playback_h playback_h, double* position) {
   ScopeLogger();
 
   int ret;
@@ -177,35 +132,30 @@ PlatformResult Types::ConvertPlaybackPosition(mc_playback_h playback_h, double*
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-PlatformResult Types::ConvertMetadata(mc_metadata_h metadata_h, picojson::object* metadata) {
+PlatformResult ConvertMetadata(mc_metadata_h metadata_h, picojson::object* metadata) {
   ScopeLogger();
 
-  std::map<std::string, int> const* metadata_fields = nullptr;
-  PlatformResult result =
-      GetPlatformEnumMap(Types::kMediaControllerMetadataAttribute, &metadata_fields);
-  if (!result) {
-    LoggerE("GetPlatformEnumMap failed, error: %s", result.message().c_str());
-    return result;
-  }
-
   char* value = nullptr;
   SCOPE_EXIT {
     free(value);
   };
 
-  for (auto& field : *metadata_fields) {
-    int ret = mc_metadata_get(metadata_h, static_cast<mc_meta_e>(field.second), &value);
+  for (auto entry: MediaControllerMetadataAttributeEnum) {
+    int ret = mc_metadata_get(metadata_h, entry.second, &value);
     if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
       return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting metadata",
-                                ("mc_metadata_get(%s) error: %d, message: %s", field.first.c_str(),
+                                ("mc_metadata_get(%s) error: %d, message: %s", entry.first.c_str(),
                                  ret, get_error_message(ret)));
     }
 
-    (*metadata)[field.first] = picojson::value(std::string(value ? value : ""));
+    (*metadata)[entry.first] = picojson::value(std::string(value ? value : ""));
   }
 
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
+} // types
+
+
 }  // namespace mediacontroller
 }  // namespace extension
index 8aaa0f8..b012cdc 100644 (file)
 #include <string>
 
 #include "common/platform_result.h"
+#include "common/platform_enum.h"
+
 
 namespace extension {
 namespace mediacontroller {
 
-typedef std::map<std::string, std::map<std::string, int>> PlatformEnumMap;
-typedef std::map<std::string, std::map<int, std::string>> PlatformEnumReverseMap;
 typedef std::function<void(picojson::value*)> JsonCallback;
 
-class Types {
- public:
-  static const std::string kMediaControllerServerState;
-  static const std::string kMediaControllerPlaybackState;
-  static const std::string kMediaControllerPlaybackAction;
-  static const std::string kMediaControllerMetadataAttribute;
 
-  static common::PlatformResult GetPlatformEnumMap(
-      const std::string& type, std::map<std::string, int> const** platform_str);
+namespace types {
 
-  static common::PlatformResult StringToPlatformEnum(const std::string& type,
-                                                     const std::string& value, int* platform_enum);
+common::PlatformResult ConvertPlaybackState(mc_playback_h playback_h, std::string* state);
+common::PlatformResult ConvertContentAgeRating(mc_playback_h playback_h, std::string* state);
+common::PlatformResult ConvertPlaybackPosition(mc_playback_h playback_h, double* position);
+common::PlatformResult ConvertMetadata(mc_metadata_h metadata_h, picojson::object* metadata);
 
-  static common::PlatformResult PlatformEnumToString(const std::string& type, int value,
-                                                     std::string* platform_str);
+extern const common::PlatformEnum<mc_server_state_e> MediaControllerServerStateEnum;
+extern const common::PlatformEnum<mc_playback_states_e> MediaControllerPlaybackStateEnum;
+extern const common::PlatformEnum<mc_playback_action_e> MediaControllerPlaybackActionEnum;
+extern const common::PlatformEnum<mc_meta_e> MediaControllerMetadataAttributeEnum;
+extern const common::PlatformEnum<mc_repeat_mode_e> MediaControllerRepeatModeEnum;
+extern const common::PlatformEnum<mc_content_age_rating_e> MediaControllerContentAgeRatingEnum;
 
-  static common::PlatformResult ConvertPlaybackState(mc_playback_h playback_h, std::string* state);
-  static common::PlatformResult ConvertPlaybackPosition(mc_playback_h playback_h, double* position);
-  static common::PlatformResult ConvertMetadata(mc_metadata_h metadata_h,
-                                                picojson::object* metadata);
+} // namespace types
 
- private:
-  static const PlatformEnumMap platform_enum_map_;
-  static PlatformEnumReverseMap platform_enum_reverse_map_;
-};
 
 }  // namespace mediacontroller
 }  // namespace extension