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);
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
};
#include <bundle_internal.h>
#include <memory>
+#include "common/json-utils.h"
#include "common/logger.h"
#include "common/scope_exit.h"
#include "common/tools.h"
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;
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 =
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;
#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"
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_;
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);
MediaControllerServerInfoRemovePlaylistUpdateListener);
REGISTER_ASYNC("MediaControllerServerInfo_getAllPlaylists",
MediaControllerServerInfoGetAllPlaylists);
- REGISTER_SYNC("MediaControllerServerInfo_getIconURI",
- MediaControllerServerInfoGetIconURI);
+ REGISTER_SYNC("MediaControllerServerInfo_getIconURI", MediaControllerServerInfoGetIconURI);
// playlist
REGISTER_SYNC("MediaControllerPlaylist_addItem", MediaControllerPlaylistAddItem);
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;
}
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);
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);
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);
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();
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);
#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"
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;
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());
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);
}
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",
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;
}
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;
}
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},
{"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();
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;
}
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;
}
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);
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",
return PlatformResult(ErrorCode::NO_ERROR);
}
-} // types
-
+} // types
PlatformResult utils::GetAllPlaylists(const std::string& app_id, picojson::array* playlists) {
ScopeLogger();
#include <map>
#include <string>
-#include "common/platform_result.h"
#include "common/platform_enum.h"
-
+#include "common/platform_result.h"
namespace extension {
namespace mediacontroller {
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);