[6.0][mediacontroller] add MediaControllerPlaylistsInfo interface 16/217016/10
authorDawid Juszczak <d.juszczak@samsung.com>
Tue, 5 Nov 2019 10:32:52 +0000 (11:32 +0100)
committerDawid Juszczak <d.juszczak@samsung.com>
Mon, 9 Dec 2019 16:02:56 +0000 (17:02 +0100)
[acr]
http://suprem.sec.samsung.net/jira/browse/TWDAPI-248

[description]
>> refactor_05 <<
add MediaControllerPlaylistsInfo interface to MediaControllerServerInfo.
Methods added to MediaControllerPlaylistsInfo interface:
+ getAllPlaylists
+ sendPlaybackItem
+ addPlaylistUpdatedListener
+ removePlaylistUpdatedListener

[verification]
tested manually in chrome console
tct-mediacontroller-tizen-tests fails with 2 TC:
- MediaControllerServer_iconURI_attribute.html <- has to be modified,
  because attribute iconURI is no longer readonly
- MediaControllerServerInfo_iconURI_attribute.html <- has to be modified,
  because attribute iconURI is no longer readonly

Change-Id: I761bd30eb7988a0d874f1569cdf2e7f147012ee8
Signed-off-by: Dawid Juszczak <d.juszczak@samsung.com>
src/mediacontroller/mediacontroller_api.js
src/mediacontroller/mediacontroller_client.cc
src/mediacontroller/mediacontroller_client.h
src/mediacontroller/mediacontroller_instance.cc
src/mediacontroller/mediacontroller_instance.h
src/mediacontroller/mediacontroller_server.cc

index 77e594e..fcefe3f 100755 (executable)
@@ -280,9 +280,9 @@ var ServerInfoPlaybackInfoListener = new ListenerManager(
     }
 );
 
-var ServerInfoPlaylistUpdatedListener = new ListenerManager(
+var ServerInfoPlaylistUpdateListener = new ListenerManager(
     native_,
-    '_ServerInfoPlaylistUpdatedListener',
+    '_ServerInfoPlaylistUpdateListener',
     function(msg, listener) {
         if (msg.action === 'onplaylistupdated') {
             native_.callIfPossible(
@@ -3368,6 +3368,10 @@ function MediaControllerServerInfo(data) {
             set: function() {},
             enumerable: true
         },
+        playlists: {
+            value: new MediaControllerPlaylistsInfo(data.name),
+            enumerable: true
+        },
         iconURI: {
             get: function() {
                 var result = native_.callSync('MediaControllerServerInfoGetIconURI', {
@@ -3785,8 +3789,21 @@ MediaControllerServerInfo.prototype.getAllPlaylists = function(
     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,
@@ -3812,7 +3829,7 @@ MediaControllerServerInfo.prototype.getAllPlaylists = function(
 
     var result = native_.call(
         'MediaControllerServerInfoGetAllPlaylists',
-        { name: this.name },
+        { name: args.serverName },
         callback
     );
 
@@ -3827,6 +3844,10 @@ MediaControllerServerInfo.prototype.sendPlaybackItem = function(
     state,
     position
 ) {
+    utils_.printDeprecationWarningFor(
+        'MediaControllerServerInfo.sendPlaybackItem()',
+        'MediaControllerPlaylistsInfo.sendPlaybackItem()'
+    );
     var args = validator_.validateArgs(arguments, [
         { name: 'playlistName', type: types_.STRING },
         { name: 'index', type: types_.STRING },
@@ -3839,7 +3860,7 @@ MediaControllerServerInfo.prototype.sendPlaybackItem = function(
     ]);
 
     var data = {
-        name: this.name,
+        serverName: this.name,
         playlistName: args.playlistName,
         index: args.index,
         state: args.state,
@@ -3854,19 +3875,32 @@ MediaControllerServerInfo.prototype.sendPlaybackItem = function(
 };
 
 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)) {
@@ -3874,17 +3908,25 @@ MediaControllerServerInfo.prototype.addPlaylistUpdatedListener = function(listen
         }
     }
 
-    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'
         );
@@ -4389,6 +4431,78 @@ MediaControllerPlaylists.prototype.getAllPlaylists = function(
     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;
index 78f7032..b41510e 100644 (file)
@@ -1321,23 +1321,20 @@ PlatformResult MediaControllerClient::SendRepeatState(const std::string& server_
   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(
@@ -1345,6 +1342,7 @@ PlatformResult MediaControllerClient::SendPlaybackItem(const std::string& name,
         ("mc_client_send_playlist_cmd() error: %d, message: %s", ret, get_error_message(ret)));
   }
 
+  command_reply_callback_ = callback;
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
index 93cf61d..d48fffa 100644 (file)
@@ -66,9 +66,12 @@ class MediaControllerClient {
   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,
index f5ac474..2b97ad4 100644 (file)
@@ -167,6 +167,9 @@ MediaControllerInstance::MediaControllerInstance() {
   REGISTER_METHOD(MediaControllerDisplayRotationInfoAddChangeListener);
   REGISTER_METHOD(MediaControllerDisplayRotationInfoRemoveChangeListener);
 
+  // playlists_info
+  REGISTER_METHOD(MediaControllerPlaylistsInfoSendPlaybackItem);
+
 #undef REGISTER_METHOD
 }
 
@@ -1541,16 +1544,19 @@ void MediaControllerInstance::MediaControllerServerInfoSendPlaybackItem(const pi
     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;
@@ -2729,6 +2735,53 @@ void MediaControllerInstance::MediaControllerDisplayRotationInfoRemoveChangeList
   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
index 2065c6e..56385e8 100644 (file)
@@ -196,6 +196,10 @@ class MediaControllerInstance : public common::ParsedInstance {
   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_;
 };
index 4a297c7..50ef65c 100644 (file)
@@ -1151,6 +1151,7 @@ void MediaControllerServer::OnPlaybackItemCommand(const char* client_name, const
   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);
 }