}
);
-var ServerInfoPlaylistUpdatedListener = new ListenerManager(
+var ServerInfoPlaylistUpdateListener = new ListenerManager(
native_,
- '_ServerInfoPlaylistUpdatedListener',
+ '_ServerInfoPlaylistUpdateListener',
function(msg, listener) {
if (msg.action === 'onplaylistupdated') {
native_.callIfPossible(
set: function() {},
enumerable: true
},
+ playlists: {
+ value: new MediaControllerPlaylistsInfo(data.name),
+ enumerable: true
+ },
iconURI: {
get: function() {
var result = native_.callSync('MediaControllerServerInfoGetIconURI', {
successCallback,
errorCallback
) {
+ utils_.printDeprecationWarningFor(
+ 'MediaControllerServerInfo.getAllPlaylists',
+ 'MediaControllerPlaylistsInfo.getAllPlaylists'
+ );
+ var args = [this.name].concat(Array.prototype.slice.call(arguments));
+ serverInfoGetAllPlaylists.apply(this, args);
+};
+
+var serverInfoGetAllPlaylists = function(serverName, successCallback, errorCallback) {
var args = validator_.validateArgs(arguments, [
{
+ name: 'serverName',
+ type: types_.STRING
+ },
+ {
name: 'successCallback',
type: types_.FUNCTION,
optional: false,
var result = native_.call(
'MediaControllerServerInfoGetAllPlaylists',
- { name: this.name },
+ { name: args.serverName },
callback
);
state,
position
) {
+ utils_.printDeprecationWarningFor(
+ 'MediaControllerServerInfo.sendPlaybackItem()',
+ 'MediaControllerPlaylistsInfo.sendPlaybackItem()'
+ );
var args = validator_.validateArgs(arguments, [
{ name: 'playlistName', type: types_.STRING },
{ name: 'index', type: types_.STRING },
]);
var data = {
- name: this.name,
+ serverName: this.name,
playlistName: args.playlistName,
index: args.index,
state: args.state,
};
MediaControllerServerInfo.prototype.addPlaylistUpdatedListener = function(listener) {
+ utils_.printDeprecationWarningFor(
+ 'MediaControllerServerInfo.addPlaylistUpdatedListener()',
+ 'MediaControllerPlaylistsInfo.addPlaylistUpdateListener()'
+ );
+ var args = [this.name].concat(Array.prototype.slice.call(arguments));
+ return addPlaylistUpdateListener.apply(this, args);
+};
+
+var addPlaylistUpdateListener = function(serverName, listener) {
var args = validator_.validateArgs(arguments, [
{
+ name: 'serverName',
+ type: types_.STRING
+ },
+ {
name: 'listener',
type: types_.LISTENER,
values: ['onplaylistupdated', 'onplaylistdeleted']
}
]);
- if (type_.isEmptyObject(ServerInfoPlaylistUpdatedListener.listeners)) {
+ if (type_.isEmptyObject(ServerInfoPlaylistUpdateListener.listeners)) {
var result = native_.callSync(
'MediaControllerServerInfoAddPlaylistUpdateListener',
{
- listenerId: ServerInfoPlaylistUpdatedListener.listenerName
+ listenerId: ServerInfoPlaylistUpdateListener.listenerName
}
);
if (native_.isFailure(result)) {
}
}
- return ServerInfoPlaylistUpdatedListener.addListener(args.listener, this.name);
+ return ServerInfoPlaylistUpdateListener.addListener(args.listener, args.serverName);
};
MediaControllerServerInfo.prototype.removePlaylistUpdatedListener = function(watchId) {
+ utils_.printDeprecationWarningFor(
+ 'MediaControllerServerInfo.removePlaylistUpdatedListener()',
+ 'MediaControllerPlaylistsInfo.removePlaylistUpdateListener()'
+ );
+ removePlaylistUpdateListener(watchId);
+};
+
+var removePlaylistUpdateListener = function(watchId) {
var args = validator_.validateArgs(arguments, [
{ name: 'watchId', type: types_.LONG }
]);
- ServerInfoPlaylistUpdatedListener.removeListener(args.watchId);
+ ServerInfoPlaylistUpdateListener.removeListener(args.watchId);
- if (type_.isEmptyObject(ServerInfoPlaylistUpdatedListener.listeners)) {
+ if (type_.isEmptyObject(ServerInfoPlaylistUpdateListener.listeners)) {
var result = native_.callSync(
'MediaControllerServerInfoRemovePlaylistUpdateListener'
);
serverGetAllPlaylists.apply(this, arguments);
};
+var MediaControllerPlaylistsInfo = function(serverName) {
+ var _serverName = serverName;
+
+ this.getAllPlaylists = function(successCallback, errorCallback) {
+ var args = [_serverName].concat(Array.prototype.slice.call(arguments));
+ serverInfoGetAllPlaylists.apply(this, args);
+ };
+
+ this.sendPlaybackItem = function(
+ playlistName,
+ index,
+ action,
+ position,
+ replyCallback
+ ) {
+ var args = validator_.validateArgs(arguments, [
+ { name: 'playlistName', type: types_.STRING },
+ { name: 'index', type: types_.STRING },
+ {
+ name: 'action',
+ type: types_.ENUM,
+ values: Object.keys(MediaControllerPlaybackAction)
+ },
+ { name: 'position', type: types_.UNSIGNED_LONG_LONG },
+ {
+ name: 'replyCallback',
+ type: types_.FUNCTION,
+ optional: true,
+ nullable: true
+ }
+ ]);
+
+ var data = {
+ serverName: _serverName,
+ playlistName: args.playlistName,
+ index: args.index,
+ action: args.action,
+ position: args.position,
+ listenerId: ReplyCommandListener.listenerName
+ };
+
+ var callback = function(result) {
+ native_.callIfPossible(
+ args.replyCallback,
+ native_.getResultObject(result).data,
+ native_.getResultObject(result).code
+ );
+ };
+
+ var result = native_.callSync(
+ 'MediaControllerPlaylistsInfoSendPlaybackItem',
+ data
+ );
+
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+
+ var replyListenerId = ReplyCommandListener.addListener(callback);
+ ReplyCommandListener.requestIdToListenerId[replyListenerId] = result.requestId;
+ };
+
+ this.addPlaylistUpdateListener = function(listener) {
+ var args = [_serverName].concat(Array.prototype.slice.call(arguments));
+ return addPlaylistUpdateListener.apply(this, args);
+ };
+
+ this.removePlaylistUpdateListener = function(watchId) {
+ removePlaylistUpdateListener(watchId);
+ };
+};
+
exports = new MediaControllerManager();
exports.SearchFilter = SearchFilter;
exports.RequestReply = RequestReply;
return PlatformResult(ErrorCode::NO_ERROR);
}
-PlatformResult MediaControllerClient::SendPlaybackItem(const std::string& name,
- const std::string& playlist_name,
- const std::string& index,
- const std::string& state, double position) {
+PlatformResult MediaControllerClient::SendPlaybackItem(
+ const std::string& server_name, const std::string& playlist_name, const std::string& index,
+ const std::string& action, const unsigned long long position, const JsonCallback& callback,
+ char** request_id) {
ScopeLogger();
- // 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.
mc_playback_action_e action_e;
- PlatformResult result = types::MediaControllerPlaybackActionEnum.getValue(state, &action_e);
+ PlatformResult result = types::MediaControllerPlaybackActionEnum.getValue(action, &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(),
- action_e, position_ull, nullptr);
+ int ret = mc_client_send_playlist_cmd(handle_, server_name.c_str(), playlist_name.c_str(),
+ index.c_str(), action_e, position, request_id);
if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
return LogAndCreateResult(
("mc_client_send_playlist_cmd() error: %d, message: %s", ret, get_error_message(ret)));
}
+ command_reply_callback_ = callback;
return PlatformResult(ErrorCode::NO_ERROR);
}
common::PlatformResult UnsetServerStatusChangeListener();
common::PlatformResult SetPlaybackInfoListener(const JsonCallback& callback);
common::PlatformResult UnsetPlaybackInfoListener();
- common::PlatformResult SendPlaybackItem(const std::string& name, const std::string& playlist_name,
- const std::string& index, const std::string& state,
- double position);
+ common::PlatformResult SendPlaybackItem(const std::string& server_name,
+ const std::string& playlist_name,
+ const std::string& index, const std::string& action,
+ unsigned long long position,
+ const JsonCallback& callback = nullptr,
+ char** request_id = nullptr);
common::PlatformResult SetPlaylistUpdateListener(const JsonCallback& callback);
common::PlatformResult UnsetPlaylistUpdateListener();
common::PlatformResult GetServerIconURI(const std::string& name,
REGISTER_METHOD(MediaControllerDisplayRotationInfoAddChangeListener);
REGISTER_METHOD(MediaControllerDisplayRotationInfoRemoveChangeListener);
+ // playlists_info
+ REGISTER_METHOD(MediaControllerPlaylistsInfoSendPlaybackItem);
+
#undef REGISTER_METHOD
}
return;
}
- CHECK_ARGS(args, kName, std::string, out)
+ CHECK_ARGS(args, kServerName, std::string, out)
CHECK_ARGS(args, kPlaylistName, std::string, out)
CHECK_ARGS(args, kIndex, std::string, out)
CHECK_ARGS(args, kState, std::string, out)
CHECK_ARGS(args, kPosition, double, out)
- auto result = client_->SendPlaybackItem(
- args.get(kName).get<std::string>(), args.get(kPlaylistName).get<std::string>(),
- args.get(kIndex).get<std::string>(), args.get(kState).get<std::string>(),
- args.get(kPosition).get<double>());
+ const std::string& server_name = args.get(kServerName).get<std::string>();
+ const std::string& playlist_name = args.get(kPlaylistName).get<std::string>();
+ const std::string& index = args.get(kIndex).get<std::string>();
+ const std::string& state = args.get(kState).get<std::string>();
+ const int position = static_cast<unsigned long long>(args.get(kPosition).get<double>());
+
+ auto result = client_->SendPlaybackItem(server_name, playlist_name, index, state, position);
if (!result) {
LogAndReportError(result, &out);
return;
ReportSuccess(out);
}
+void MediaControllerInstance::MediaControllerPlaylistsInfoSendPlaybackItem(
+ const picojson::value& args, picojson::object& out) {
+ ScopeLogger();
+ if (!client_) {
+ LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, MediaControllerUnknownErrorMsg), &out,
+ (MediaControllerClientUnknownErrorMsg));
+ return;
+ }
+
+ CHECK_ARGS(args, kServerName, std::string, out)
+ CHECK_ARGS(args, kPlaylistName, std::string, out)
+ CHECK_ARGS(args, kIndex, std::string, out)
+ CHECK_ARGS(args, kAction, std::string, out)
+ CHECK_ARGS(args, kPosition, double, out)
+
+ JsonCallback reply_cb = [this, args](picojson::value* reply) -> void {
+ if (reply) {
+ picojson::object& reply_obj = reply->get<picojson::object>();
+ reply_obj[kListenerId] = args.get(kListenerId);
+ Instance::PostMessage(this, reply->serialize().c_str());
+ } else {
+ LoggerW("No reply passed to json callback, ignoring");
+ }
+ };
+
+ char* request_id = nullptr;
+ SCOPE_EXIT {
+ free(request_id);
+ };
+
+ const std::string& server_name = args.get(kServerName).get<std::string>();
+ const std::string& playlist_name = args.get(kPlaylistName).get<std::string>();
+ const std::string& index = args.get(kIndex).get<std::string>();
+ const std::string& action = args.get(kAction).get<std::string>();
+ const int position = static_cast<unsigned long long>(args.get(kPosition).get<double>());
+
+ PlatformResult result = client_->SendPlaybackItem(server_name, playlist_name, index, action,
+ position, reply_cb, &request_id);
+
+ if (result) {
+ out[kRequestId] = picojson::value(std::string(request_id));
+ ReportSuccess(out);
+ } else {
+ LogAndReportError(result, &out, ("Failed to send playback position."));
+ }
+}
+
#undef CHECK_EXIST
} // namespace mediacontroller
void MediaControllerDisplayRotationInfoRemoveChangeListener(const picojson::value& args,
picojson::object& out);
+ // playlists_info
+ void MediaControllerPlaylistsInfoSendPlaybackItem(const picojson::value& args,
+ picojson::object& out);
+
std::shared_ptr<MediaControllerClient> client_;
std::shared_ptr<MediaControllerServer> server_;
};
data_o[kState] = picojson::value(action_str);
data_o[kPosition] = picojson::value(static_cast<double>(position));
data_o[kClientName] = picojson::value(client_name);
+ data_o[kRequestId] = request_id ? picojson::value(std::string(request_id)) : picojson::value();
server->change_request_playback_info_listener_(&data);
}