var nativeData = {
clientName: msg.clientName,
replyId: msg.replyId,
+ requestId: msg.requestId,
data: data
};
MediaControllerClient::~MediaControllerClient() {
ScopeLogger();
+ int ret = mc_client_unset_cmd_reply_received_cb(handle_);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ LoggerE("Failed to unset cmd reply callback. Error code: %d; Error message: %s",
+ ret, get_error_message(ret));
+ }
+
if (nullptr != server_status_listener_ && !UnsetServerStatusChangeListener()) {
LoggerE("Failed to unset server status change listener");
}
("mc_client_create() error: %d, message: %s", ret, get_error_message(ret)));
}
+ ret = mc_client_set_cmd_reply_received_cb(handle_, OnCommandReply, this);
+ if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+ return LogAndCreateResult(
+ ErrorCode::UNKNOWN_ERR, "Unable to register cmd reply received callback",
+ ("mc_client_set_cmd_reply_received_cb() error: %d, message: %s", ret, get_error_message(ret)));
+ }
+
return PlatformResult(ErrorCode::NO_ERROR);
}
const JsonCallback& reply_cb) {
ScopeLogger();
bundle* bundle = bundle_create();
+ char* request_id = nullptr;
SCOPE_EXIT {
bundle_free(bundle);
+ free(request_id);
};
int ret;
("bundle_add(data) error: %d, message: %s", ret, get_error_message(ret)));
}
- ret = mc_client_send_custom_command(handle_, server_name.c_str(), command.c_str(), bundle,
- OnCommandReply, this);
+ ret = mc_client_send_custom_cmd(handle_, server_name.c_str(), command.c_str(), bundle, &request_id);
if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
return LogAndCreateResult(
ErrorCode::UNKNOWN_ERR, "Error sending custom command",
- ("mc_client_send_custom_command() error: %d, message: %s", ret, get_error_message(ret)));
+ ("mc_client_send_custom_cmd() error: %d, message: %s", ret, get_error_message(ret)));
}
command_reply_callback_ = reply_cb;
return PlatformResult(ErrorCode::NO_ERROR);
}
-void MediaControllerClient::OnCommandReply(const char* server_name, int result_code, bundle* bundle,
- void* user_data) {
+void MediaControllerClient::OnCommandReply(const char* server_name, const char* request_id,
+ int result_code, bundle* bundle, void* user_data) {
ScopeLogger();
MediaControllerClient* client = static_cast<MediaControllerClient*>(user_data);
static void OnServerStatusUpdate(const char* server_name, mc_server_state_e state,
void* user_data);
- static void OnCommandReply(const char* server_name, int result_code, bundle* bundle,
- void* user_data);
+ static void OnCommandReply(const char* server_name, const char* request_id,
+ int result_code, bundle* bundle, void* user_data);
static void OnPlaybackUpdate(const char* server_name, mc_playback_h playback, void* user_data);
static void OnShuffleModeUpdate(const char* server_name, mc_shuffle_mode_e mode, void* user_data);
static void OnRepeatModeUpdate(const char* server_name, mc_repeat_mode_e mode, void* user_data);
CHECK_EXIST(args, "clientName", out)
CHECK_EXIST(args, "replyId", out)
+ CHECK_EXIST(args, "requestId", out)
CHECK_EXIST(args, "data", out)
- server_->CommandReply(args.get("clientName").get<std::string>(), args.get("replyId").to_str(),
- args.get("data"));
+ server_->CommandReply(args.get("clientName").get<std::string>(), args.get("requestId").to_str(),
+ args.get("replyId").to_str(), args.get("data"));
ReportSuccess(out);
}
return PlatformResult(ErrorCode::NO_ERROR);
}
-void MediaControllerServer::OnCommandReceived(const char* client_name, const char* command,
- bundle* bundle, void* user_data) {
+void MediaControllerServer::OnCommandReceived(const char* client_name, const char* request_id,
+ const char* command, bundle* bundle, void* user_data) {
ScopeLogger();
MediaControllerServer* server = static_cast<MediaControllerServer*>(user_data);
request_o["clientName"] = picojson::value(std::string(client_name));
request_o["command"] = picojson::value(std::string(command));
request_o["replyId"] = picojson::value(std::string(reply_id_str));
+ request_o["requestId"] = picojson::value(std::string(request_id));
request_o["data"] = data;
server->command_listener_(&request);
}
PlatformResult MediaControllerServer::CommandReply(const std::string& client_name,
+ const std::string& request_id,
const std::string& reply_id,
const picojson::value& data) {
ScopeLogger();
("bundle_add(data) error: %d, message: %s", ret, get_error_message(ret)));
}
- ret = mc_server_send_command_reply(handle_, client_name.c_str(), 0, bundle);
+ ret = mc_server_send_cmd_reply(handle_, client_name.c_str(), request_id.c_str(), 0, bundle);
if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
return LogAndCreateResult(
ErrorCode::UNKNOWN_ERR, "Error sending command reply",
PlatformResult MediaControllerServer::SetCommandListener(const JsonCallback& callback) {
ScopeLogger();
- int ret = mc_server_set_custom_command_received_cb(handle_, OnCommandReceived, this);
+ int ret = mc_server_set_custom_cmd_received_cb(handle_, OnCommandReceived, this);
if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to set command callback",
- ("mc_server_set_custom_command_received_cb() error: %d, message: %s",
+ ("mc_server_set_custom_cmd_received_cb() error: %d, message: %s",
ret, get_error_message(ret)));
}
command_listener_ = callback;
PlatformResult MediaControllerServer::UnsetCommandListener() {
ScopeLogger();
- int ret = mc_server_unset_custom_command_received_cb(handle_);
+ int ret = mc_server_unset_custom_cmd_received_cb(handle_);
if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to unset command callback",
- ("mc_server_set_custom_command_received_cb() error: %d, message: %s",
+ ("mc_server_unset_custom_cmd_received_cb() error: %d, message: %s",
ret, get_error_message(ret)));
}
command_listener_ = nullptr;
common::PlatformResult SetChangeRequestPlaybackInfoListener(const JsonCallback& callback);
common::PlatformResult UnsetChangeRequestPlaybackInfoListener();
- common::PlatformResult CommandReply(const std::string& client_name, const std::string& reply_id,
- const picojson::value& data);
+ common::PlatformResult CommandReply(const std::string& client_name, const std::string& request_id,
+ const std::string& reply_id, const picojson::value& data);
common::PlatformResult SetCommandListener(const JsonCallback& callback);
common::PlatformResult UnsetCommandListener();
static void OnRepeatModeCommand(const char* client_name, const char* request_id,
mc_repeat_mode_e mode, void* user_data);
- static void OnCommandReceived(const char* client_name, const char* command, bundle* data,
- void* user_data);
+ static void OnCommandReceived(const char* client_name, const char* request_id,
+ const char* command, bundle* data, void* user_data);
};
} // namespace mediacontroller