[mediacontroller][bundle] fixing custom command 64/209964/5
authorDawid Juszczak <d.juszczak@samsung.com>
Fri, 12 Jul 2019 13:45:22 +0000 (15:45 +0200)
committerDawid Juszczak <d.juszczak@samsung.com>
Mon, 15 Jul 2019 11:28:19 +0000 (13:28 +0200)
Refactored some functions to use tizen.Bundle
and formated code with format script

Changed implementation of functions:
+ MediaControllerInstance::MediaControllerServerReplyCommand
+ MediaControllerInstance::MediaControllerServerInfoSendCommand

+ MediaControllerServer::OnCommandReceived
+ MediaControllerServer::CommandReply

+ MediaControllerClient::OnCommandReply
+ MediaControllerClient::SendCommand

[Verified]
tct-mediacontroller-tizen-tests - 100% passed
also tested manually on chrome console

Change-Id: I9d072d10a5fc272c54d17731f33ae9b733009412
Signed-off-by: Dawid Juszczak <d.juszczak@samsung.com>
src/mediacontroller/mediacontroller_api.js
src/mediacontroller/mediacontroller_client.cc
src/mediacontroller/mediacontroller_client.h
src/mediacontroller/mediacontroller_instance.cc
src/mediacontroller/mediacontroller_instance.h
src/mediacontroller/mediacontroller_server.cc
src/mediacontroller/mediacontroller_utils.cc
src/mediacontroller/mediacontroller_utils.h

index ade8ca5..7ad023c 100755 (executable)
@@ -114,10 +114,17 @@ var ServerCommandListener = new ListenerManager(native_, '_ServerCommandListener
    data = null;
   }
 
+  var bundle;
+  if (data instanceof tizen.Bundle) {
+    bundle = data;
+  } else {
+    bundle = new tizen.Bundle(data);
+  }
+
   var nativeData = {
     clientName: msg.clientName,
     requestId: msg.requestId,
-    data: data
+    data: bundle.toString()
   };
 
   var result = native_.callSync('MediaControllerServer_replyCommand', nativeData);
@@ -1084,9 +1091,16 @@ MediaControllerServerInfo.prototype.sendCommand = function(command, data, succes
     native_.callIfPossible(args.successCallback, native_.getResultObject(result).data);
   };
 
+  var bundle;
+  if (args.data instanceof tizen.Bundle) {
+    bundle = args.data;
+  } else {
+    bundle = new tizen.Bundle(args.data);
+  }
+
   var nativeData = {
     command: args.command,
-    data: args.data,
+    data: bundle.toString(),
     name: this.name,
     listenerId: ReplyCommandListener.listenerName
   };
index 4b12af4..089202a 100644 (file)
@@ -20,6 +20,7 @@
 #include <bundle_internal.h>
 #include <memory>
 
+#include "common/json-utils.h"
 #include "common/logger.h"
 #include "common/scope_exit.h"
 #include "common/tools.h"
@@ -296,7 +297,8 @@ PlatformResult MediaControllerClient::GetMetadata(const std::string& server_name
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-PlatformResult MediaControllerClient::GetServerIconURI(const std::string& name, common::optional<std::string>* icon_uri) {
+PlatformResult MediaControllerClient::GetServerIconURI(const std::string& name,
+                                                       common::optional<std::string>* icon_uri) {
   ScopeLogger();
 
   char* icon_uri_str = nullptr;
@@ -543,17 +545,21 @@ PlatformResult MediaControllerClient::SendCommand(const std::string& server_name
                                                   const picojson::value& data,
                                                   const JsonCallback& reply_cb, char** request_id) {
   ScopeLogger();
-  bundle* bundle = bundle_create();
+  bundle* bundle = nullptr;
+  int ret;
   SCOPE_EXIT {
     bundle_free(bundle);
   };
 
-  int ret;
-  ret = bundle_add(bundle, "data", data.serialize().c_str());
-  if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
-    return LogAndCreateResult(
-        ErrorCode::UNKNOWN_ERR, "Unable to add data to bundle",
-        ("bundle_add(data) error: %d, message: %s", ret, get_error_message(ret)));
+  if (!data.is<picojson::null>()) {
+    bundle = bundle_create();
+
+    const picojson::object& json = data.get<picojson::object>();
+    PlatformResult result = common::JsonToBundle(json, bundle);
+    if (!result) {
+      LoggerE("JsonToBundle() failed.");
+      return result;
+    }
   }
 
   ret =
@@ -579,25 +585,14 @@ void MediaControllerClient::OnCommandReply(const char* server_name, const char*
   picojson::value reply = picojson::value(picojson::object());
   picojson::object& reply_o = reply.get<picojson::object>();
 
-  int ret;
-  char* data_str = nullptr;
-  SCOPE_EXIT {
-    free(data_str);
-  };
-  picojson::value data;
-
-  ret = bundle_get_str(bundle, "data", &data_str);
-  if (BUNDLE_ERROR_NONE != ret || nullptr == data_str) {
-    LoggerE("bundle_get_str(data) failed, error: %d", ret);
-  } else {
-    std::string err;
-    picojson::parse(data, data_str, data_str + strlen(data_str), &err);
-    if (!err.empty()) {
-      LoggerE("Failed to parse bundle data: %s", err.c_str());
-      ReportError(out_o);
-      client->command_reply_callback_(&out);
-      return;
-    }
+  picojson::value data = picojson::value(picojson::object());
+  picojson::object& data_obj = data.get<picojson::object>();
+  PlatformResult result = common::BundleToJson(bundle, &data_obj);
+  if (!result) {
+    LoggerE("BundleToJson() failed.");
+    ReportError(out_o);
+    client->command_reply_callback_(&out);
+    return;
   }
 
   reply_o["data"] = data;
index c11c389..a07f533 100644 (file)
@@ -20,8 +20,8 @@
 #include <media_controller_client.h>
 #include <string>
 
-#include "common/platform_result.h"
 #include "common/optional.h"
+#include "common/platform_result.h"
 
 #include "mediacontroller/mediacontroller_utils.h"
 
@@ -61,7 +61,8 @@ class MediaControllerClient {
                                           double position);
   common::PlatformResult SetPlaylistUpdateListener(const JsonCallback& callback);
   common::PlatformResult UnsetPlaylistUpdateListener();
-  common::PlatformResult GetServerIconURI(const std::string& name, common::optional<std::string>* icon_uri);
+  common::PlatformResult GetServerIconURI(const std::string& name,
+                                          common::optional<std::string>* icon_uri);
 
  private:
   mc_client_h handle_;
index 8e94bd2..2d0696f 100644 (file)
@@ -62,7 +62,8 @@ MediaControllerInstance::MediaControllerInstance() {
   REGISTER_SYNC("MediaControllerServer_updateRepeatMode", MediaControllerServerUpdateRepeatMode);
   REGISTER_SYNC("MediaControllerServer_updateRepeatState", MediaControllerServerUpdateRepeatState);
   REGISTER_SYNC("MediaControllerServer_updateShuffleMode", MediaControllerServerUpdateShuffleMode);
-  REGISTER_SYNC("MediaControllerServer_updatePlaybackContentType", MediaControllerServerUpdatePlaybackContentType);
+  REGISTER_SYNC("MediaControllerServer_updatePlaybackContentType",
+                MediaControllerServerUpdatePlaybackContentType);
   REGISTER_SYNC("MediaControllerServer_updateMetadata", MediaControllerServerUpdateMetadata);
   REGISTER_SYNC("MediaControllerServer_addChangeRequestPlaybackInfoListener",
                 MediaControllerServerAddChangeRequestPlaybackInfoListener);
@@ -114,8 +115,7 @@ MediaControllerInstance::MediaControllerInstance() {
                 MediaControllerServerInfoRemovePlaylistUpdateListener);
   REGISTER_ASYNC("MediaControllerServerInfo_getAllPlaylists",
                  MediaControllerServerInfoGetAllPlaylists);
-  REGISTER_SYNC("MediaControllerServerInfo_getIconURI",
-                 MediaControllerServerInfoGetIconURI);
+  REGISTER_SYNC("MediaControllerServerInfo_getIconURI", MediaControllerServerInfoGetIconURI);
 
   // playlist
   REGISTER_SYNC("MediaControllerPlaylist_addItem", MediaControllerPlaylistAddItem);
@@ -203,12 +203,10 @@ void MediaControllerInstance::MediaControllerServerUpdateIconURI(const picojson:
   const char* icon_uri = nullptr;
   if (args.get("iconURI").is<std::string>()) {
     icon_uri = args.get("iconURI").get<std::string>().c_str();
-  }
-  else if (!args.get("iconURI").is<picojson::null>()) {
-    LogAndReportError(PlatformResult(ErrorCode::INVALID_VALUES_ERR,
-                      "Icon URI must be a string or null."),
-                      &out,
-                      ("Icon URI is not a string or null."));
+  } else if (!args.get("iconURI").is<picojson::null>()) {
+    LogAndReportError(
+        PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Icon URI must be a string or null."), &out,
+        ("Icon URI is not a string or null."));
     return;
   }
 
@@ -285,13 +283,13 @@ void MediaControllerInstance::MediaControllerServerUpdateShuffleMode(const picoj
   ReportSuccess(out);
 }
 
-void MediaControllerInstance::MediaControllerServerUpdatePlaybackContentType(const picojson::value& args,
-                                                                     picojson::object& out) {
+void MediaControllerInstance::MediaControllerServerUpdatePlaybackContentType(
+    const picojson::value& args, picojson::object& out) {
   ScopeLogger();
   if (!server_) {
-     LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
+    LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
                       ("Failed: server_"));
-     return;
+    return;
   }
 
   CHECK_ARGS(args, "contentType", std::string, out);
@@ -451,10 +449,16 @@ void MediaControllerInstance::MediaControllerServerReplyCommand(const picojson::
   CHECK_EXIST(args, "requestId", out)
   CHECK_EXIST(args, "data", out)
 
-  auto result = server_->CommandReply(
-    args.get("clientName").get<std::string>(),
-    args.get("requestId").get<std::string>(),
-    args.get("data"));
+  auto serialized_data = args.get("data").get<std::string>();
+  picojson::value json;
+  std::string err = picojson::parse(json, serialized_data);
+  if (!err.empty()) {
+    LoggerE("json parse error: %s", err.c_str());
+    return;
+  }
+
+  auto result = server_->CommandReply(args.get("clientName").get<std::string>(),
+                                      args.get("requestId").get<std::string>(), json);
 
   if (!result) {
     LogAndReportError(result, &out);
@@ -918,9 +922,17 @@ void MediaControllerInstance::MediaControllerServerInfoSendCommand(const picojso
     free(request_id);
   };
 
-  PlatformResult result = client_->SendCommand(args.get("name").get<std::string>(),
-                                               args.get("command").get<std::string>(),
-                                               args.get("data"), reply_cb, &request_id);
+  auto serialized_data = args.get("data").get<std::string>();
+  picojson::value json;
+  std::string err = picojson::parse(json, serialized_data);
+  if (!err.empty()) {
+    LoggerE("json parse error: %s", err.c_str());
+    return;
+  }
+
+  PlatformResult result =
+      client_->SendCommand(args.get("name").get<std::string>(),
+                           args.get("command").get<std::string>(), json, reply_cb, &request_id);
 
   if (result) {
     ReportSuccess(out);
@@ -1154,15 +1166,13 @@ void MediaControllerInstance::MediaControllerServerInfoGetIconURI(const picojson
   picojson::object result;
   if (icon_uri) {
     result["iconURI"] = picojson::value(*icon_uri);
-  }
-  else {
+  } else {
     result["iconURI"] = picojson::value();
   }
 
   ReportSuccess(picojson::value(result), out);
 }
 
-
 void MediaControllerInstance::MediaControllerPlaylistAddItem(const picojson::value& args,
                                                              picojson::object& out) {
   ScopeLogger();
index c005c6b..20a7e1d 100644 (file)
@@ -42,7 +42,8 @@ class MediaControllerInstance : public common::ParsedInstance {
   void MediaControllerServerUpdateRepeatMode(const picojson::value& args, picojson::object& out);
   void MediaControllerServerUpdateRepeatState(const picojson::value& args, picojson::object& out);
   void MediaControllerServerUpdateShuffleMode(const picojson::value& args, picojson::object& out);
-  void MediaControllerServerUpdatePlaybackContentType(const picojson::value& args, picojson::object& out);
+  void MediaControllerServerUpdatePlaybackContentType(const picojson::value& args,
+                                                      picojson::object& out);
   void MediaControllerServerUpdateMetadata(const picojson::value& args, picojson::object& out);
   void MediaControllerServerAddChangeRequestPlaybackInfoListener(const picojson::value& args,
                                                                  picojson::object& out);
index a32d75b..26f6464 100644 (file)
@@ -19,6 +19,7 @@
 #include <bundle.h>
 #include <bundle_internal.h>
 
+#include "common/json-utils.h"
 #include "common/logger.h"
 #include "common/scope_exit.h"
 #include "common/tools.h"
@@ -170,17 +171,19 @@ PlatformResult MediaControllerServer::SetContentType(const std::string& content_
   ScopeLogger();
 
   mc_content_type_e content_type_e;
-  PlatformResult result = types::MediaControllerContentTypeEnum.getValue(content_type, &content_type_e);
+  PlatformResult result =
+      types::MediaControllerContentTypeEnum.getValue(content_type, &content_type_e);
   if (!result) {
-    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Converting string to platform enum failed",
-      ("MediaControllerContentTypeEnum.getValue() error message: %s", result.message().c_str()));
+    return LogAndCreateResult(
+        ErrorCode::UNKNOWN_ERR, "Converting string to platform enum failed",
+        ("MediaControllerContentTypeEnum.getValue() error message: %s", result.message().c_str()));
   }
 
   int ret = mc_server_set_playback_content_type(handle_, content_type_e);
   if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
-     return LogAndCreateResult(
-        ErrorCode::UNKNOWN_ERR, "Error updating playback content type",
-        ("mc_server_set_playback_content_type() error: %d, message: %s", ret, get_error_message(ret)));
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error updating playback content type",
+                              ("mc_server_set_playback_content_type() error: %d, message: %s", ret,
+                               get_error_message(ret)));
   }
 
   content_type_ = content_type_e;
@@ -298,26 +301,14 @@ void MediaControllerServer::OnCommandReceived(const char* client_name, const cha
                                               const char* command, bundle* bundle,
                                               void* user_data) {
   ScopeLogger();
-
   MediaControllerServer* server = static_cast<MediaControllerServer*>(user_data);
 
-  int ret;
-  char* data_str = nullptr;
-  SCOPE_EXIT {
-    free(data_str);
-  };
-  picojson::value data;
-
-  ret = bundle_get_str(bundle, "data", &data_str);
-  if (BUNDLE_ERROR_NONE != ret || nullptr == data_str) {
-    LoggerE("bundle_get_str(data) failed, error: %d", ret);
-  } else {
-    std::string err;
-    picojson::parse(data, data_str, data_str + strlen(data_str), &err);
-    if (!err.empty()) {
-      LoggerE("Failed to parse bundle data: %s", err.c_str());
-      return;
-    }
+  picojson::value data = picojson::value(picojson::object());
+  picojson::object& data_obj = data.get<picojson::object>();
+  PlatformResult result = common::BundleToJson(bundle, &data_obj);
+  if (!result) {
+    LoggerE("BundleToJson() failed.");
+    return;
   }
 
   picojson::value request = picojson::value(picojson::object());
@@ -337,17 +328,21 @@ PlatformResult MediaControllerServer::CommandReply(const std::string& client_nam
   ScopeLogger();
 
   int ret;
-
-  bundle* bundle = bundle_create();
+  bundle* bundle = nullptr;
   SCOPE_EXIT {
     bundle_free(bundle);
   };
 
-  ret = bundle_add(bundle, "data", data.serialize().c_str());
-  if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
-    return LogAndCreateResult(
-        ErrorCode::UNKNOWN_ERR, "Unable to add data to bundle",
-        ("bundle_add(data) error: %d, message: %s", ret, get_error_message(ret)));
+  if (!data.is<picojson::null>()) {
+    ScopeLogger("data is not null");
+    bundle = bundle_create();
+    const picojson::object& json = data.get<picojson::object>();
+    PlatformResult result = common::JsonToBundle(json, bundle);
+
+    if (!result) {
+      LoggerE("JsonToBundle() failed.");
+      return result;
+    }
   }
 
   ret = mc_server_send_cmd_reply(handle_, client_name.c_str(), request_id.c_str(), 0, bundle);
@@ -517,7 +512,7 @@ PlatformResult MediaControllerServer::MediaControllerPlaylistAddItem(
     }
 
     int ret = mc_server_add_item_to_playlist(handle_, playlist_handle_map_[name], index.c_str(),
-                                         attr_e, v.second.to_str().c_str());
+                                             attr_e, v.second.to_str().c_str());
     if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
       return LogAndCreateResult(
           ErrorCode::UNKNOWN_ERR, "Error adding playlist item",
@@ -704,14 +699,16 @@ void MediaControllerServer::OnPlaybackActionCommand(const char* client_name, con
   std::string action_str;
   PlatformResult result = types::MediaControllerPlaybackActionEnum.getName(action, &action_str);
   if (!result) {
-    LoggerW("MediaControllerPlaybackActionEnum.getName() failed, error: %s", result.message().c_str());
+    LoggerW("MediaControllerPlaybackActionEnum.getName() failed, error: %s",
+            result.message().c_str());
     return;
   }
 
   mc_playback_states_e state_e;
   result = types::MediaControllerPlaybackStateEnum.getValue(action_str, &state_e);
   if (!result) {
-    LoggerE("MediaControllerPlaybackStateEnum.getValue() failed, error: %s", result.message().c_str());
+    LoggerE("MediaControllerPlaybackStateEnum.getValue() failed, error: %s",
+            result.message().c_str());
     return;
   }
 
@@ -821,7 +818,8 @@ void MediaControllerServer::OnPlaybackItemCommand(const char* client_name, const
   std::string action_str;
   PlatformResult result = types::MediaControllerPlaybackActionEnum.getName(action, &action_str);
   if (!result) {
-    LoggerE("MediaControllerPlaybackActionEnum.getName() failed, error: %s", result.message().c_str());
+    LoggerE("MediaControllerPlaybackActionEnum.getName() failed, error: %s",
+            result.message().c_str());
     return;
   }
 
index 8776699..0814bc8 100644 (file)
@@ -30,33 +30,27 @@ using common::ErrorCode;
 
 namespace types {
 
-const common::PlatformEnum<mc_server_state_e> MediaControllerServerStateEnum {
+const common::PlatformEnum<mc_server_state_e> MediaControllerServerStateEnum{
     {"NONE", MC_SERVER_STATE_NONE},
     {"ACTIVE", MC_SERVER_STATE_ACTIVATE},
-    {"INACTIVE", MC_SERVER_STATE_DEACTIVATE}
-};
+    {"INACTIVE", MC_SERVER_STATE_DEACTIVATE}};
 
-const common::PlatformEnum<mc_playback_states_e> MediaControllerPlaybackStateEnum {
+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 {
+    {"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},
@@ -67,36 +61,31 @@ const common::PlatformEnum<mc_meta_e> MediaControllerMetadataAttributeEnum {
     {"copyright", MC_META_MEDIA_COPYRIGHT},
     {"description", MC_META_MEDIA_DESCRIPTION},
     {"trackNum", MC_META_MEDIA_TRACK_NUM},
-    {"picture", MC_META_MEDIA_PICTURE}
-};
+    {"picture", MC_META_MEDIA_PICTURE}};
 
-const common::PlatformEnum<mc_repeat_mode_e> MediaControllerRepeatModeEnum {
+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}
-};
-
-const common::PlatformEnum<mc_content_type_e> MediaControllerContentTypeEnum {
+    {"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}};
+
+const common::PlatformEnum<mc_content_type_e> MediaControllerContentTypeEnum{
     {"IMAGE", MC_CONTENT_TYPE_IMAGE},
     {"MUSIC", MC_CONTENT_TYPE_MUSIC},
     {"VIDEO", MC_CONTENT_TYPE_VIDEO},
     {"OTHER", MC_CONTENT_TYPE_OTHER},
-    {"UNDECIDED", MC_CONTENT_TYPE_UNDECIDED}
-};
-
+    {"UNDECIDED", MC_CONTENT_TYPE_UNDECIDED}};
 
 PlatformResult ConvertPlaybackState(mc_playback_h playback_h, std::string* state) {
   ScopeLogger();
@@ -115,7 +104,8 @@ PlatformResult ConvertPlaybackState(mc_playback_h playback_h, std::string* state
 
   PlatformResult result = MediaControllerPlaybackStateEnum.getName(state_e, state);
   if (!result) {
-    LoggerE("MediaControllerPlaybackStateEnum.getName() failed, error: %s", result.message().c_str());
+    LoggerE("MediaControllerPlaybackStateEnum.getName() failed, error: %s",
+            result.message().c_str());
     return result;
   }
 
@@ -135,7 +125,8 @@ PlatformResult ConvertContentAgeRating(mc_playback_h playback_h, std::string* ra
 
   PlatformResult result = MediaControllerContentAgeRatingEnum.getName(rating_e, rating);
   if (!result) {
-    LoggerE("MediaControllerContentAgeRatingEnum.getName() failed, error: %s", result.message().c_str());
+    LoggerE("MediaControllerContentAgeRatingEnum.getName() failed, error: %s",
+            result.message().c_str());
     return result;
   }
 
@@ -148,7 +139,8 @@ PlatformResult ConvertContentType(mc_playback_h playback_h, std::string* content
   int ret = mc_client_get_playback_content_type(playback_h, &content_type_e);
   if (ret != MEDIA_CONTROLLER_ERROR_NONE) {
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting content type",
-      ("mc_client_get_playback_content_type() error: %d, message: %s", ret, get_error_message(ret)));
+                              ("mc_client_get_playback_content_type() error: %d, message: %s", ret,
+                               get_error_message(ret)));
   }
 
   PlatformResult result = MediaControllerContentTypeEnum.getName(content_type_e, contentType);
@@ -186,7 +178,7 @@ PlatformResult ConvertMetadata(mc_metadata_h metadata_h, picojson::object* metad
     free(value);
   };
 
-  for (auto entry: MediaControllerMetadataAttributeEnum) {
+  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",
@@ -200,8 +192,7 @@ PlatformResult ConvertMetadata(mc_metadata_h metadata_h, picojson::object* metad
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-} // types
-
+}  // types
 
 PlatformResult utils::GetAllPlaylists(const std::string& app_id, picojson::array* playlists) {
   ScopeLogger();
index 0f26b44..80947a5 100644 (file)
@@ -22,9 +22,8 @@
 #include <map>
 #include <string>
 
-#include "common/platform_result.h"
 #include "common/platform_enum.h"
-
+#include "common/platform_result.h"
 
 namespace extension {
 namespace mediacontroller {
@@ -47,8 +46,7 @@ extern const common::PlatformEnum<mc_repeat_mode_e> MediaControllerRepeatModeEnu
 extern const common::PlatformEnum<mc_content_age_rating_e> MediaControllerContentAgeRatingEnum;
 extern const common::PlatformEnum<mc_content_type_e> MediaControllerContentTypeEnum;
 
-} // namespace types
-
+}  // namespace types
 
 namespace utils {
 common::PlatformResult GetAllPlaylists(const std::string& app_id, picojson::array* playlists);