From: Michal Michalski Date: Wed, 24 Oct 2018 11:54:58 +0000 (+0200) Subject: [MediaController] Replaced deprecated functions. X-Git-Tag: submit/tizen_5.0/20181102.061247~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=698483330989eb945ca55da13e2d4e56a80e879b;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [MediaController] Replaced deprecated functions. + mc_client_send_custom_command --> mc_client_send_custom_cmd [Verification] tct-mediacontroller-tizen-tests all passed. Change-Id: Ib39b5aa971fcdb1c8984f432945863af08ddbe80 Signed-off-by: Michal Michalski --- diff --git a/src/mediacontroller/mediacontroller_api.js b/src/mediacontroller/mediacontroller_api.js index fa7160bf..2b3dbf1a 100755 --- a/src/mediacontroller/mediacontroller_api.js +++ b/src/mediacontroller/mediacontroller_api.js @@ -116,6 +116,7 @@ var ServerCommandListener = new ListenerManager(native_, '_ServerCommandListener var nativeData = { clientName: msg.clientName, replyId: msg.replyId, + requestId: msg.requestId, data: data }; diff --git a/src/mediacontroller/mediacontroller_client.cc b/src/mediacontroller/mediacontroller_client.cc index f684dd7a..99c2ebbb 100644 --- a/src/mediacontroller/mediacontroller_client.cc +++ b/src/mediacontroller/mediacontroller_client.cc @@ -38,6 +38,12 @@ MediaControllerClient::MediaControllerClient() : handle_(nullptr) { 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"); } @@ -60,6 +66,13 @@ PlatformResult MediaControllerClient::Init() { ("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); } @@ -461,8 +474,10 @@ PlatformResult MediaControllerClient::SendCommand(const std::string& server_name const JsonCallback& reply_cb) { ScopeLogger(); bundle* bundle = bundle_create(); + char* request_id = nullptr; SCOPE_EXIT { bundle_free(bundle); + free(request_id); }; int ret; @@ -480,12 +495,11 @@ PlatformResult MediaControllerClient::SendCommand(const std::string& server_name ("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; @@ -493,8 +507,8 @@ PlatformResult MediaControllerClient::SendCommand(const std::string& server_name 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(user_data); diff --git a/src/mediacontroller/mediacontroller_client.h b/src/mediacontroller/mediacontroller_client.h index bb7cb8a1..6108eb52 100644 --- a/src/mediacontroller/mediacontroller_client.h +++ b/src/mediacontroller/mediacontroller_client.h @@ -66,8 +66,8 @@ class MediaControllerClient { 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); diff --git a/src/mediacontroller/mediacontroller_instance.cc b/src/mediacontroller/mediacontroller_instance.cc index 350c4d69..6a7a79f9 100644 --- a/src/mediacontroller/mediacontroller_instance.cc +++ b/src/mediacontroller/mediacontroller_instance.cc @@ -318,10 +318,11 @@ void MediaControllerInstance::MediaControllerServerReplyCommand(const picojson:: 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(), args.get("replyId").to_str(), - args.get("data")); + server_->CommandReply(args.get("clientName").get(), args.get("requestId").to_str(), + args.get("replyId").to_str(), args.get("data")); ReportSuccess(out); } diff --git a/src/mediacontroller/mediacontroller_server.cc b/src/mediacontroller/mediacontroller_server.cc index 123297c7..c1615541 100644 --- a/src/mediacontroller/mediacontroller_server.cc +++ b/src/mediacontroller/mediacontroller_server.cc @@ -207,8 +207,8 @@ PlatformResult MediaControllerServer::SetMetadata(const picojson::object& metada 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(user_data); @@ -247,12 +247,14 @@ void MediaControllerServer::OnCommandReceived(const char* client_name, const cha 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(); @@ -278,7 +280,7 @@ PlatformResult MediaControllerServer::CommandReply(const std::string& client_nam ("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", @@ -291,10 +293,10 @@ PlatformResult MediaControllerServer::CommandReply(const std::string& client_nam 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; @@ -305,10 +307,10 @@ PlatformResult MediaControllerServer::SetCommandListener(const JsonCallback& cal 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; diff --git a/src/mediacontroller/mediacontroller_server.h b/src/mediacontroller/mediacontroller_server.h index 9ffa5f28..19405e9f 100644 --- a/src/mediacontroller/mediacontroller_server.h +++ b/src/mediacontroller/mediacontroller_server.h @@ -41,8 +41,8 @@ class MediaControllerServer { 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(); @@ -69,8 +69,8 @@ class MediaControllerServer { 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