}
};
-var ServerCommandListener = new ListenerManager(
- native_,
- '_ServerCommandListener',
- function(msg, listener) {
- var data = undefined;
- data = listener(msg.clientName, msg.command, msg.data);
+var ServerCommandListener = new ListenerManager(native_, '_ServerCommandListener', function(msg, listener) {
+ // passing raw msg.data object instead of tizen.Bundle
+ // due to backward compatibility issue.
+ var reply = listener(msg.clientName, msg.command, msg.data);
- if (type_.isUndefined(data)) {
- data = null;
- }
+ if (!(reply instanceof RequestReply)) {
+ reply = new RequestReply(xwalk.utils.type.isNullOrUndefined(reply) ? null : reply, 0);
+ }
- var bundle;
- if (data instanceof tizen.Bundle) {
- bundle = data;
- } else {
- bundle = new tizen.Bundle(data);
- }
+ var nativeData = {
+ clientName: msg.clientName,
+ requestId: msg.requestId,
+ reply: reply
+ };
- var nativeData = {
- clientName: msg.clientName,
- requestId: msg.requestId,
- data: bundle
- };
+ var result = native_.callSync('MediaControllerServer_replyCommand', nativeData);
+ if (native_.isFailure(result)) {
+ throw native_.getErrorObject(result);
+ }
+});
- var result = native_.callSync('MediaControllerServer_replyCommand', nativeData);
- if (native_.isFailure(result)) {
- throw native_.getErrorObject(result);
- }
- }
-);
+var ReplyCommandListener = new ListenerManager(native_, '_ReplyCommandListener', function(msg, listener, watchId) {
+ if (this.requestIdToListenerId[watchId] === msg.requestId) {
-var ReplyCommandListener = new ListenerManager(native_, '_ReplyCommandListener', function(
- msg,
- listener,
- watchId
-) {
- if (this.requestIdToListenerId[watchId] === msg.requestId) {
- listener(msg);
- this.removeListener(watchId);
- delete this.requestIdToListenerId[watchId];
- return true;
- }
- return false;
+ // this listener is a wrapper around user callback which is neccessary
+ // due to difference between sendCommand() and new API methods.
+ listener(msg);
+
+ this.removeListener(watchId);
+ delete this.requestIdToListenerId[watchId];
+
+ return true;
+ }
+ return false;
});
var ServerPlaybackInfoListener = new ListenerManager(
function RequestReply(data, code) {
xwalk.utils.validator.isConstructorCall(this, RequestReply);
this.code = xwalk.utils.converter.toLong(code);
- if (xwalk.utils.type.isUndefined(data)) {
- this.data = null;
- }
- else if (!(data instanceof tizen.Bundle)) {
- this.data = new tizen.Bundle(data);
- }
- else {
- this.data = data;
- }
+ this.data = xwalk.utils.type.isNullOrUndefined(data) ? null : new tizen.Bundle(data);
}
MediaControllerServer.prototype.setSearchRequestListener = function(listener) {
var reply = args.listener(msg.clientName, request);
if (type_.isUndefined(reply)) {
- reply = null;
+ reply = new RequestReply(null, 0);
}
var nativeData = {
clientName: msg.clientName,
requestId: msg.requestId,
- reply: reply,
- replyType: "RequestReply"
+ reply: reply
};
var result = native_.callSync('MediaControllerServer_replyCommand', nativeData);
native_.call('MediaControllerServerInfo_sendRepeatState', data, callback);
};
-MediaControllerServerInfo.prototype.sendCommand = function(
- command,
- data,
- successCallback,
- errorCallback
-) {
- var args = validator_.validateArgs(arguments, [
- { name: 'command', type: types_.STRING },
- { name: 'data', type: types_.DICTIONARY },
- { name: 'successCallback', type: types_.FUNCTION },
- { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
- ]);
-
- var callback = function(result) {
- if (native_.isFailure(result)) {
- native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
- return;
- }
- native_.callIfPossible(
- args.successCallback,
- native_.getResultObject(result).data
- );
- };
+MediaControllerServerInfo.prototype.sendCommand = function(command, data, successCallback, errorCallback) {
+ var args = validator_.validateArgs(arguments, [
+ {name: 'command', type: types_.STRING},
+ {name: 'data', type: types_.DICTIONARY, nullable: true},
+ {name: 'successCallback', type: types_.FUNCTION},
+ {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true}
+ ]);
- var bundle;
- if (args.data instanceof tizen.Bundle) {
- bundle = args.data;
- } else {
- bundle = new tizen.Bundle(args.data);
+ var callback = function(result) {
+ if (native_.isFailure(result)) {
+ native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+ return;
}
+ native_.callIfPossible(args.successCallback, native_.getResultObject(result).data,
+ native_.getResultObject(result).code);
+ };
- var nativeData = {
- command: args.command,
- data: bundle,
- name: this.name,
- listenerId: ReplyCommandListener.listenerName
- };
+ var nativeData = {
+ command: args.command,
+ data: args.data === null ? null : new tizen.Bundle(args.data),
+ name: this.name,
+ listenerId: ReplyCommandListener.listenerName
+ };
- var replyListenerId = ReplyCommandListener.addListener(callback);
- var result = native_.callSync('MediaControllerServerInfo_sendCommand', nativeData);
+ var replyListenerId = ReplyCommandListener.addListener(callback);
+ var result = native_.callSync('MediaControllerServerInfo_sendCommand', nativeData);
- ReplyCommandListener.requestIdToListenerId[replyListenerId] = result.requestId;
+ ReplyCommandListener.requestIdToListenerId[replyListenerId] = result.requestId;
};
MediaControllerServerInfo.prototype.sendSearchRequest = function(request, successCallback, errorCallback) {
const picojson::value& data,
const JsonCallback& reply_cb, char** request_id) {
ScopeLogger();
- bundle* bundle = nullptr;
- int ret;
+ bundle* bundle_data = nullptr;
SCOPE_EXIT {
- bundle_free(bundle);
+ bundle_free(bundle_data);
};
- if (!data.is<picojson::null>()) {
- PlatformResult result = common::JsonToBundle(data, &bundle);
- if (!result) {
- LoggerE("JsonToBundle() failed.");
- return result;
- }
+ PlatformResult result = common::JsonToBundle(data, &bundle_data);
+ if (!result) {
+ LoggerE("JsonToBundle() failed.");
+ return result;
}
- ret =
- mc_client_send_custom_cmd(handle_, server_name.c_str(), command.c_str(), bundle, request_id);
+ if (nullptr == bundle_data) {
+ LoggerD("bundle is null");
+ }
+ int ret = mc_client_send_custom_cmd(handle_, server_name.c_str(),
+ command.c_str(), bundle_data, request_id);
if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
return LogAndCreateResult(
ErrorCode::UNKNOWN_ERR, "Error sending custom command",
}
command_reply_callback_ = reply_cb;
-
return PlatformResult(ErrorCode::NO_ERROR);
}
CHECK_EXIST(args, "clientName", out);
CHECK_EXIST(args, "requestId", out);
CHECK_EXIST(args, "reply", out);
- CHECK_EXIST(args, "replyType", out);
- int code = 0;
- picojson::value data;
+ auto client_name = args.get("clientName").get<std::string>();
+ auto request_id = args.get("requestId").get<std::string>();
- if (args.get("replyType").get<std::string>() == "RequestReply") {
- CHECK_EXIST(args.get("reply"), "code", out);
- CHECK_EXIST(args.get("reply"), "data", out);
- code = static_cast<int>(args.get("reply").get("code").get<double>());
- data = args.get("reply").get<picojson::object>().at("data");
- }
- else {
- data = args.get("reply");
- }
+ auto reply = args.get("reply");
+ CHECK_EXIST(reply, "code", out);
+ CHECK_EXIST(reply, "data", out);
- auto result = server_->CommandReply(args.get("clientName").get<std::string>(),
- args.get("requestId").get<std::string>(),
- code, data);
+ LoggerD("reply json: %s", reply.serialize().c_str());
+ int code = static_cast<int>(reply.get("code").get<double>());
+ auto data = reply.get("data");
+ auto result = server_->CommandReply(client_name, request_id, code, data);
if (!result) {
LogAndReportError(result, &out);
return;