using common::ErrorCode;
using common::PlatformResult;
+using namespace attributes;
namespace privileges {
-const char* kPrivilegeMediaControllerClient =
- "http://tizen.org/privilege/mediacontroller.client";
-const char* kPrivilegeMediaControllerServer =
- "http://tizen.org/privilege/mediacontroller.server";
+const char* kPrivilegeMediaControllerClient = "http://tizen.org/privilege/mediacontroller.client";
+const char* kPrivilegeMediaControllerServer = "http://tizen.org/privilege/mediacontroller.server";
-} // privileges
+} // privileges
namespace attributes {
const char* kSupport = "support";
const char* kType = "type";
const char* kValue = "value";
-
-} // attributes
+const char* kSeason = "season";
+const char* kSeasonNumber = "seasonNumber";
+const char* kSeasonTitle = "seasonTitle";
+const char* kEpisode = "episode";
+const char* kEpisodeNumber = "episodeNumber";
+const char* kEpisodeTitle = "episodeTitle";
+const char* kResolution = "resolution";
+const char* kResolutionWidth = "resolutionWidth";
+const char* kResolutionHeight = "resolutionHeight";
+
+} // attributes
namespace types {
{"ROTATION_180", MC_DISPLAY_ROTATION_180},
{"ROTATION_270", MC_DISPLAY_ROTATION_270}};
-PlatformResult ConvertPlaybackState(mc_playback_h playback_h, std::string *state) {
+PlatformResult ConvertPlaybackState(mc_playback_h playback_h, std::string* state) {
ScopeLogger();
int ret;
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult ConvertContentAgeRating(mc_playback_h playback_h, std::string *rating) {
+PlatformResult ConvertContentAgeRating(mc_playback_h playback_h, std::string* rating) {
ScopeLogger();
mc_content_age_rating_e rating_e = MC_CONTENT_RATING_ALL;
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult ConvertContentType(mc_playback_h playback_h, std::string *contentType) {
+PlatformResult ConvertContentType(mc_playback_h playback_h, std::string* contentType) {
ScopeLogger();
mc_content_type_e content_type_e = MC_CONTENT_TYPE_UNDECIDED;
int ret = mc_client_get_playback_content_type(playback_h, &content_type_e);
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult ConvertPlaybackPosition(mc_playback_h playback_h, double *position) {
+PlatformResult ConvertPlaybackPosition(mc_playback_h playback_h, double* position) {
ScopeLogger();
int ret;
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult ConvertMetadata(mc_metadata_h metadata_h, picojson::object *metadata) {
+PlatformResult ConvertMetadata(mc_metadata_h metadata_h, picojson::object* metadata) {
ScopeLogger();
- char *value = nullptr;
+ char* value = nullptr;
SCOPE_EXIT {
free(value);
};
picojson::value to_decode = picojson::value(picojson::object());
- picojson::object &obj = to_decode.get<picojson::object>();
+ picojson::object& obj = to_decode.get<picojson::object>();
for (auto entry : MediaControllerMetadataAttributeEnum) {
int ret = mc_metadata_get(metadata_h, entry.second, &value);
ret, get_error_message(ret)));
}
- obj[entry.first] = picojson::value(value);
+ obj[entry.first] = value ? picojson::value(value) : picojson::value();
}
PlatformResult result = utils::DecodeMetadata(to_decode, metadata);
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult ConvertPlaybackAbility(mc_playback_ability_h ability_h, const std::string &action,
- std::string *ability_str) {
+PlatformResult ConvertPlaybackAbility(mc_playback_ability_h ability_h, const std::string& action,
+ std::string* ability_str) {
ScopeLogger();
mc_ability_support_e ability_e;
} // namespace types
-PlatformResult utils::GetAllPlaylists(const std::string &app_id, picojson::array *playlists) {
+PlatformResult utils::GetAllPlaylists(const std::string& app_id, picojson::array* playlists) {
ScopeLogger();
- auto OnPlaylists = [](mc_playlist_h playlist, void *user_data) -> bool {
- char *name = nullptr;
+ auto OnPlaylists = [](mc_playlist_h playlist, void* user_data) -> bool {
+ char* name = nullptr;
SCOPE_EXIT {
free(name);
return false;
}
- auto playlists = static_cast<picojson::array *>(user_data);
+ auto playlists = static_cast<picojson::array*>(user_data);
picojson::value value = picojson::value(picojson::object());
- picojson::object &obj = value.get<picojson::object>();
+ picojson::object& obj = value.get<picojson::object>();
- obj.insert(std::make_pair("name", picojson::value{name}));
+ obj.insert(std::make_pair(kName, picojson::value{name}));
playlists->push_back(value);
return true;
return error;
}
-bool utils::isEncodable(const std::string &name) {
- if (name == "season" || name == "episode" || name == "resolution") {
- return true;
- }
- return false;
+bool utils::isMetadataAttributeEncodable(const std::string& name) {
+ return name == kSeason || name == kEpisode || name == kResolution;
}
-PlatformResult utils::EncodeMetadata(const picojson::object &to_encode, picojson::object *encoded) {
+PlatformResult utils::EncodeMetadata(const picojson::object& to_encode, picojson::object* encoded) {
ScopeLogger();
int ret = 0;
- char *encoded_value = nullptr;
+ char* encoded_value = nullptr;
int number = 0;
SCOPE_EXIT {
// season
try {
- number = static_cast<int>(to_encode.at("seasonNumber").get<double>());
- const char *season_title = to_encode.at("seasonTitle").is<picojson::null>()
+ number = static_cast<int>(to_encode.at(kSeasonNumber).get<double>());
+ const char* season_title = to_encode.at(kSeasonTitle).is<picojson::null>()
? nullptr
- : to_encode.at("seasonTitle").get<std::string>().c_str();
+ : to_encode.at(kSeasonTitle).get<std::string>().c_str();
ret = mc_metadata_encode_season(number, season_title, &encoded_value);
if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
("mc_metadata_encode_season() error: %d, message: %s", ret, get_error_message(ret)));
}
- (*encoded).insert(std::make_pair("season", picojson::value(encoded_value)));
+ (*encoded).insert(std::make_pair(kSeason, picojson::value(encoded_value)));
} catch (...) {
LoggerE("Season formation missing! - This should never happened.");
}
// episode
try {
- number = static_cast<int>(to_encode.at("episodeNumber").get<double>());
- const char *episode_title = to_encode.at("episodeTitle").is<picojson::null>()
+ number = static_cast<int>(to_encode.at(kEpisodeNumber).get<double>());
+ const char* episode_title = to_encode.at(kEpisodeTitle).is<picojson::null>()
? nullptr
- : to_encode.at("episodeTitle").get<std::string>().c_str();
+ : to_encode.at(kEpisodeTitle).get<std::string>().c_str();
ret = mc_metadata_encode_episode(number, episode_title, &encoded_value);
if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
("mc_metadata_encode_episode() error: %d, message: %s", ret, get_error_message(ret)));
}
- (*encoded).insert(std::make_pair("episode", picojson::value(encoded_value)));
+ (*encoded).insert(std::make_pair(kEpisode, picojson::value(encoded_value)));
} catch (...) {
LoggerE("Episode formation missing! - This should never happened.");
}
// resolution
try {
- u_int width = static_cast<u_int>(to_encode.at("resolutionWidth").get<double>());
- u_int height = static_cast<u_int>(to_encode.at("resolutionHeight").get<double>());
+ u_int width = static_cast<u_int>(to_encode.at(kResolutionWidth).get<double>());
+ u_int height = static_cast<u_int>(to_encode.at(kResolutionHeight).get<double>());
ret = mc_metadata_encode_resolution(width, height, &encoded_value);
if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
("mc_metadata_encode_resolution() error: %d, message: %s", ret, get_error_message(ret)));
}
- (*encoded).insert(std::make_pair("resolution", picojson::value(encoded_value)));
+ (*encoded).insert(std::make_pair(kResolution, picojson::value(encoded_value)));
} catch (...) {
LoggerE("Resolution formation missing! - This should never happened.");
}
// other metadata attributes
for (auto entry : types::MediaControllerMetadataAttributeEnum) {
std::string name = entry.first;
- if (name != "season" && name != "episode" && name != "resolution") {
+ if (!isMetadataAttributeEncodable(name)) {
try {
- std::string value_str = to_encode.at(entry.first).get<std::string>();
- (*encoded).insert(std::make_pair(entry.first, picojson::value(value_str)));
+ std::string value_str = to_encode.at(name).get<std::string>();
+ (*encoded).insert(std::make_pair(name, picojson::value(value_str)));
} catch (...) {
LoggerE("%s formation missing! - This should never happened.", name.c_str());
}
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult utils::DecodeMetadata(const picojson::value &to_decode, picojson::object *decoded) {
+PlatformResult utils::DecodeMetadata(const picojson::value& to_decode, picojson::object* decoded) {
ScopeLogger();
int ret = 0;
int number = 0;
- char *season_title = nullptr;
- char *episode_title = nullptr;
+ char* season_title = nullptr;
+ char* episode_title = nullptr;
+ std::string val;
SCOPE_EXIT {
free(season_title);
};
// decode season
- std::string val = to_decode.get("season").get<std::string>();
+ if (!to_decode.get(kSeason).is<picojson::null>()) {
+ val = to_decode.get(kSeason).get<std::string>();
- ret = mc_metadata_decode_season(val.c_str(), &number, &season_title);
- if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
- return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Error while decoding season",
- ("mc_metadata_decode_season() error: %d, message: %s", ret, get_error_message(ret)));
- }
+ ret = mc_metadata_decode_season(val.c_str(), &number, &season_title);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error while decoding season",
+ ("mc_metadata_decode_season() error: %d, message: %s", ret, get_error_message(ret)));
+ }
- (*decoded)["seasonNumber"] = picojson::value((double)number);
- (*decoded)["episodeTitle"] =
- season_title ? picojson::value(std::string(season_title)) : picojson::value();
+ (*decoded)[kSeasonNumber] = picojson::value((double)number);
+ (*decoded)[kSeasonTitle] =
+ season_title ? picojson::value(std::string(season_title)) : picojson::value();
+ }
// decode episode
- val = to_decode.get("episode").get<std::string>();
+ if (!to_decode.get(kEpisode).is<picojson::null>()) {
+ val = to_decode.get(kEpisode).get<std::string>();
- ret = mc_metadata_decode_episode(val.c_str(), &number, &episode_title);
- if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
- return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Error while decoding episode",
- ("mc_metadata_decode_episode() error: %d, message: %s", ret, get_error_message(ret)));
- }
+ ret = mc_metadata_decode_episode(val.c_str(), &number, &episode_title);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error while decoding episode",
+ ("mc_metadata_decode_episode() error: %d, message: %s", ret, get_error_message(ret)));
+ }
- (*decoded)["episodeNumber"] = picojson::value((double)number);
- (*decoded)["episodeTitle"] =
- episode_title ? picojson::value(std::string(episode_title)) : picojson::value();
+ (*decoded)[kEpisodeNumber] = picojson::value((double)number);
+ (*decoded)[kEpisodeTitle] =
+ episode_title ? picojson::value(std::string(episode_title)) : picojson::value();
+ }
// decode resolution
- val = to_decode.get("resolution").get<std::string>();
- u_int width = 0;
- u_int height = 0;
+ if (!to_decode.get(kResolution).is<picojson::null>()) {
+ val = to_decode.get(kResolution).get<std::string>();
+ u_int width = 0;
+ u_int height = 0;
- ret = mc_metadata_decode_resolution(val.c_str(), &width, &height);
- if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
- return LogAndCreateResult(
- ErrorCode::UNKNOWN_ERR, "Error while decoding resolution",
- ("mc_metadata_decode_resolution() error: %d, message: %s", ret, get_error_message(ret)));
- }
+ ret = mc_metadata_decode_resolution(val.c_str(), &width, &height);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Error while decoding resolution",
+ ("mc_metadata_decode_resolution() error: %d, message: %s", ret, get_error_message(ret)));
+ }
- (*decoded)["resolutionWidth"] = picojson::value((double)width);
- (*decoded)["resolutionHeight"] = picojson::value((double)height);
+ (*decoded)[kResolutionWidth] = picojson::value((double)width);
+ (*decoded)[kResolutionHeight] = picojson::value((double)height);
+ }
// now rewrite not encoded attributes
for (auto entry : types::MediaControllerMetadataAttributeEnum) {
std::string name = entry.first;
- // to omit decoded attributes
- if (!isEncodable(name)) {
- (*decoded)[name] = to_decode.get(name);
+ if (!isMetadataAttributeEncodable(name)) {
+ (*decoded)[name] =
+ to_decode.get(name).is<picojson::null>() ? picojson::value("") : to_decode.get(name);
}
}