[6.0][mediacontroller] add new playback interfaces 12/217012/10
authorDawid Juszczak <d.juszczak@samsung.com>
Wed, 30 Oct 2019 15:39:36 +0000 (16:39 +0100)
committerDawid Juszczak <d.juszczak@samsung.com>
Thu, 14 Nov 2019 10:18:07 +0000 (11:18 +0100)
[acr]
http://suprem.sec.samsung.net/jira/browse/TWDAPI-249

[description]
>> refactor_01 <<
add new interfaces:
+ MediaControllerServerPlaybackInfo
+ MediaControllerServerInfoPlaybackInfo

[verification]
tct-mediacontroller-tizen-tests 100% PASS
tested manually in chrome console

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

index 2f53dd2..87d84f3 100755 (executable)
@@ -602,6 +602,18 @@ var MediaControllerMetadata = function(data) {
     }
 };
 
+MediaControllerMetadata.prototype.save = function() {
+    var data = {
+        metadata: this
+    };
+
+    var result = native_.callSync('MediaControllerServerUpdateMetadata', data);
+
+    if (native_.isFailure(result)) {
+        throw native_.getErrorObject(result);
+    }
+};
+
 var MediaControllerPlaybackInfo = function(data) {
     var _state = 'STOP';
     var _position = 0;
@@ -944,10 +956,7 @@ var MediaControllerPlaybackAbilities = function() {
             TOGGLE_PLAY_PAUSE: _togglePlayPause
         };
 
-        var result = native_.callSync(
-            'MediaControllerServerSavePlaybackAbilities',
-            data
-        );
+        var result = native_.callSync('MediaControllerServerSavePlaybackAbilities', data);
         if (native_.isFailure(result)) {
             throw new native_.getErrorObject(result);
         }
@@ -2058,12 +2067,9 @@ var MediaControllerDisplayRotationInfo = function(name) {
     Object.defineProperties(this, {
         displayRotation: {
             get: function() {
-                var result = native_.callSync(
-                    'MediaControllerDisplayRotationInfoGet',
-                    {
-                        name: _serverName
-                    }
-                );
+                var result = native_.callSync('MediaControllerDisplayRotationInfoGet', {
+                    name: _serverName
+                });
                 if (native_.isFailure(result)) {
                     throw new native_.getErrorObject(result);
                 }
@@ -2158,11 +2164,22 @@ var MediaControllerDisplayRotationInfo = function(name) {
 
 function MediaControllerServer(data) {
     var _iconURI = null;
+    var _playbackInfo = new MediaControllerPlaybackInfo(data);
+    var _playback = new MediaControllerServerPlaybackInfo(data, _playbackInfo);
 
     Object.defineProperties(this, {
         playbackInfo: {
-            value: new MediaControllerPlaybackInfo(data),
-            writable: false,
+            get: function() {
+                return _playbackInfo;
+            },
+            set: function() {},
+            enumerable: true
+        },
+        playback: {
+            get: function() {
+                return _playback;
+            },
+            set: function() {},
             enumerable: true
         },
         iconURI: {
@@ -2198,6 +2215,12 @@ function MediaControllerServer(data) {
 }
 
 MediaControllerServer.prototype.updatePlaybackState = function(state) {
+    utils_.printDeprecationWarningFor('updatePlaybackState()');
+
+    this.playback.state = state;
+};
+
+var updatePlaybackState = function(state) {
     var args = validator_.validateArgs(arguments, [
         {
             name: 'state',
@@ -2215,10 +2238,6 @@ MediaControllerServer.prototype.updatePlaybackState = function(state) {
     if (native_.isFailure(result)) {
         throw native_.getErrorObject(result);
     }
-
-    edit_.allow();
-    this.playbackInfo.state = args.state;
-    edit_.disallow();
 };
 
 MediaControllerServer.prototype.updateIconURI = function(iconURI) {
@@ -2244,6 +2263,21 @@ MediaControllerServer.prototype.updateIconURI = function(iconURI) {
 };
 
 MediaControllerServer.prototype.updatePlaybackPosition = function(position) {
+    utils_.printDeprecationWarningFor('updatePlaybackPosition()');
+    var args = validator_.validateArgs(arguments, [
+        { name: 'position', type: types_.UNSIGNED_LONG_LONG }
+    ]);
+    this.playback.position = args.position;
+};
+
+var updatePlaybackPosition = function(position) {
+    if (position < 0) {
+        throw new WebAPIException(
+            WebAPIException.INVALID_VALUES_ERR,
+            'Cannot set playback position to ' + position
+        );
+    }
+
     var args = validator_.validateArgs(arguments, [
         { name: 'position', type: types_.UNSIGNED_LONG_LONG }
     ]);
@@ -2257,13 +2291,14 @@ MediaControllerServer.prototype.updatePlaybackPosition = function(position) {
     if (native_.isFailure(result)) {
         throw native_.getErrorObject(result);
     }
-
-    edit_.allow();
-    this.playbackInfo.position = args.position;
-    edit_.disallow();
 };
 
 MediaControllerServer.prototype.updatePlaybackAgeRating = function(rating) {
+    utils_.printDeprecationWarningFor('updatePlaybackAgeRating()');
+    this.playback.ageRating = rating;
+};
+
+var updatePlaybackAgeRating = function(rating) {
     var args = validator_.validateArgs(arguments, [
         {
             name: 'rating',
@@ -2280,13 +2315,14 @@ MediaControllerServer.prototype.updatePlaybackAgeRating = function(rating) {
     if (native_.isFailure(result)) {
         throw native_.getErrorObject(result);
     }
-
-    edit_.allow();
-    this.playbackInfo.ageRating = args.rating;
-    edit_.disallow();
 };
 
 MediaControllerServer.prototype.updatePlaybackContentType = function(contentType) {
+    utils_.printDeprecationWarningFor('updatePlaybackContentType()');
+    this.playback.contentType = contentType;
+};
+
+var updatePlaybackContentType = function(contentType) {
     var args = validator_.validateArgs(arguments, [
         {
             name: 'contentType',
@@ -2299,20 +2335,18 @@ MediaControllerServer.prototype.updatePlaybackContentType = function(contentType
         contentType: args.contentType
     };
 
-    var result = native_.callSync(
-        'MediaControllerServerUpdatePlaybackContentType',
-        data
-    );
+    var result = native_.callSync('MediaControllerServerUpdatePlaybackContentType', data);
     if (native_.isFailure(result)) {
         throw native_.getErrorObject(result);
     }
-
-    edit_.allow();
-    this.playbackInfo.contentType = args.contentType;
-    edit_.disallow();
 };
 
 MediaControllerServer.prototype.updateShuffleMode = function(mode) {
+    utils_.printDeprecationWarningFor('updateShuffleMode()');
+    this.playback.shuffleMode = mode;
+};
+
+var updateShuffleMode = function() {
     var args = validator_.validateArgs(arguments, [
         { name: 'mode', type: types_.BOOLEAN }
     ]);
@@ -2326,10 +2360,6 @@ MediaControllerServer.prototype.updateShuffleMode = function(mode) {
     if (native_.isFailure(result)) {
         throw native_.getErrorObject(result);
     }
-
-    edit_.allow();
-    this.playbackInfo.shuffleMode = args.mode;
-    edit_.disallow();
 };
 
 MediaControllerServer.prototype.updateRepeatMode = function(mode) {
@@ -2356,7 +2386,12 @@ MediaControllerServer.prototype.updateRepeatMode = function(mode) {
     edit_.disallow();
 };
 
-MediaControllerServer.prototype.updateRepeatState = function() {
+MediaControllerServer.prototype.updateRepeatState = function(state) {
+    utils_.printDeprecationWarningFor('updateRepeatState()');
+    this.playback.repeatState = state;
+};
+
+var updateRepeatState = function(state) {
     var args = validator_.validateArgs(arguments, [
         {
             name: 'state',
@@ -2374,17 +2409,13 @@ MediaControllerServer.prototype.updateRepeatState = function() {
     if (native_.isFailure(result)) {
         throw native_.getErrorObject(result);
     }
-
-    edit_.allow();
-    this.playbackInfo.repeatState = args.state;
-    if (MediaControllerRepeatState.REPEAT_ONE !== args.state) {
-        this.playbackInfo.repeatMode =
-            args.state === MediaControllerRepeatState.REPEAT_ALL;
-    }
-    edit_.disallow();
 };
 
 MediaControllerServer.prototype.updateMetadata = function(metadata) {
+    utils_.printDeprecationWarningFor(
+        'updateMetadata()',
+        'MediaControllerMetadata.save()'
+    );
     var args = validator_.validateArgs(arguments, [
         {
             name: 'metadata',
@@ -2392,20 +2423,10 @@ MediaControllerServer.prototype.updateMetadata = function(metadata) {
             values: MediaControllerMetadata
         }
     ]);
-
-    var data = {
-        metadata: args.metadata
-    };
-
-    var result = native_.callSync('MediaControllerServerUpdateMetadata', data);
-
-    if (native_.isFailure(result)) {
-        throw native_.getErrorObject(result);
+    for (var elem in args.metadata) {
+        this.playback.metadata[elem] = args.metadata[elem];
     }
-
-    edit_.allow();
-    this.playbackInfo.metadata = args.metadata;
-    edit_.disallow();
+    this.playback.metadata.save();
 };
 
 MediaControllerServer.prototype.addChangeRequestPlaybackInfoListener = function(
@@ -2577,6 +2598,18 @@ MediaControllerServer.prototype.deletePlaylist = function(
 };
 
 MediaControllerServer.prototype.updatePlaybackItem = function(playlistName, index) {
+    utils_.printDeprecationWarningFor(
+        'MediaControllerServer.updatePlaybackItem()',
+        'MediaControllerServerPlaybackInfo.updatePlaybackItem()'
+    );
+    updatePlaybackItem(playlistName, index);
+    edit_.allow();
+    this.playback.playlistName = playlistName;
+    this.playback.index = index;
+    edit_.disallow();
+};
+
+var updatePlaybackItem = function(playlistName, index) {
     var args = validator_.validateArgs(arguments, [
         { name: 'playlistName', type: types_.STRING },
         { name: 'index', type: types_.STRING }
@@ -2592,11 +2625,6 @@ MediaControllerServer.prototype.updatePlaybackItem = function(playlistName, inde
     if (native_.isFailure(result)) {
         throw native_.getErrorObject(result);
     }
-
-    edit_.allow();
-    this.playbackInfo.index = args.index;
-    this.playbackInfo.playlistName = args.playlistName;
-    edit_.disallow();
 };
 
 MediaControllerServer.prototype.getAllPlaylists = function(
@@ -2804,10 +2832,7 @@ var getDisplayRotationAbility = function(serverName, displayRotation) {
         serverName: serverName,
         displayRotationAbility: displayRotation
     };
-    var result = native_.callSync(
-        'MediaControllerClientGetDisplayRotationAbility',
-        data
-    );
+    var result = native_.callSync('MediaControllerClientGetDisplayRotationAbility', data);
     if (native_.isFailure(result)) {
         throw new native_.getErrorObject(result);
     }
@@ -2823,10 +2848,7 @@ var setDisplayRotationAbility = function(displayRotationAbility, support) {
         support: support
     };
 
-    var result = native_.callSync(
-        'MediaControllerServerSetDisplayRotationAbility',
-        data
-    );
+    var result = native_.callSync('MediaControllerServerSetDisplayRotationAbility', data);
 
     if (native_.isFailure(result)) {
         throw native_.getErrorObject(result);
@@ -3157,9 +3179,7 @@ MediaControllerClient.prototype.removeAbilityChangeListener = function(callbackI
     ClientAbilityChangeListener.removeListener(args.callbackId);
 
     if (type_.isEmptyObject(ClientAbilityChangeListener.listeners)) {
-        var result = native_.callSync(
-            'MediaControllerClientRemoveAbilityChangeListener'
-        );
+        var result = native_.callSync('MediaControllerClientRemoveAbilityChangeListener');
         if (native_.isFailure(result)) {
             throw native_.getErrorObject(result);
         }
@@ -3219,12 +3239,25 @@ function MediaControllerServerInfo(data) {
                 if (native_.isFailure(result)) {
                     throw new native_.getErrorObject(result);
                 }
+                var retData = native_.getResultObject(result);
                 edit_.allow();
-                var data = native_.getResultObject(result);
-                var playbackInfo = new MediaControllerPlaybackInfo(data);
+                var ret = new MediaControllerPlaybackInfo(retData);
                 edit_.disallow();
-
-                return playbackInfo;
+                return ret;
+            }.bind(this),
+            set: function() {},
+            enumerable: true
+        },
+        playback: {
+            get: function() {
+                var result = native_.callSync('MediaControllerClientGetPlaybackInfo', {
+                    name: this.name
+                });
+                if (native_.isFailure(result)) {
+                    throw new native_.getErrorObject(result);
+                }
+                var playbackData = native_.getResultObject(result);
+                return new MediaControllerServerInfoPlaybackInfo(this.name, playbackData);
             }.bind(this),
             set: function() {},
             enumerable: true
@@ -3827,6 +3860,207 @@ MediaControllerPlaylist.prototype.getItems = function(successCallback, errorCall
     }
 };
 
+function MediaControllerServerPlaybackInfo(data, oldPlaybackInfo) {
+    var _state = 'STOP';
+    var _position = 0;
+    var _shuffleMode = false;
+    var _contentType = MediaControllerContentType.UNDECIDED;
+    var _repeatState = MediaControllerRepeatState.REPEAT_ALL;
+    var _ageRating = MediaControllerContentAgeRating.ALL;
+    var _metadata = new MediaControllerMetadata();
+    var _index = null;
+    var _playlistName = null;
+    // it is needed to keep consistency in both old and new type of PlaybackInfo
+    var _oldPlaybackInfo = oldPlaybackInfo;
+
+    Object.defineProperties(this, {
+        state: {
+            get: function() {
+                return _state;
+            },
+            set: function(v) {
+                updatePlaybackState(v);
+                _state = v;
+                edit_.allow();
+                _oldPlaybackInfo.state = v;
+                edit_.disallow();
+            },
+            enumerable: true
+        },
+        position: {
+            get: function() {
+                return _position;
+            },
+            set: function(v) {
+                updatePlaybackPosition(v);
+                _position = v;
+                edit_.allow();
+                _oldPlaybackInfo.position = v;
+                edit_.disallow();
+            },
+            enumerable: true
+        },
+        ageRating: {
+            get: function() {
+                return _ageRating;
+            },
+            set: function(v) {
+                updatePlaybackAgeRating(v);
+                _ageRating = v;
+                edit_.allow();
+                _oldPlaybackInfo.ageRating = v;
+                edit_.disallow();
+            },
+            enumerable: true
+        },
+        shuffleMode: {
+            get: function() {
+                return _shuffleMode;
+            },
+            set: function(v) {
+                updateShuffleMode(v);
+                _shuffleMode = v;
+                edit_.allow();
+                _oldPlaybackInfo.shuffleMode = v;
+                edit_.disallow();
+            },
+            enumerable: true
+        },
+        repeatState: {
+            get: function() {
+                return _repeatState;
+            },
+            set: function(v) {
+                updateRepeatState(v);
+                _repeatState = v;
+                edit_.allow();
+                _oldPlaybackInfo.repeatState = v;
+                if (MediaControllerRepeatState.REPEAT_ONE !== v) {
+                    _oldPlaybackInfo.repeatMode =
+                        v === MediaControllerRepeatState.REPEAT_ALL;
+                }
+                edit_.disallow();
+            },
+            enumerable: true
+        },
+        contentType: {
+            get: function() {
+                return _contentType;
+            },
+            set: function(v) {
+                updatePlaybackContentType(v);
+                _contentType = v;
+                edit_.allow();
+                _oldPlaybackInfo.contentType = v;
+                edit_.disallow();
+            },
+            enumerable: true
+        },
+        metadata: {
+            get: function() {
+                return _metadata;
+            },
+            set: function() {},
+            enumerable: true
+        },
+        index: {
+            get: function() {
+                return _index;
+            },
+            set: function(v) {
+                if (edit_.isAllowed && v) {
+                    _index = v;
+                    _oldPlaybackInfo.index = v;
+                }
+            },
+            enumerable: true
+        },
+        playlistName: {
+            get: function() {
+                return _playlistName;
+            },
+            set: function(v) {
+                if (edit_.isAllowed && v) {
+                    _playlistName = v;
+                    _oldPlaybackInfo.playlistName = v;
+                }
+            },
+            enumerable: true
+        }
+    });
+
+    if (data instanceof _global.Object) {
+        for (var prop in data) {
+            if (data.hasOwnProperty(prop) && this.hasOwnProperty(prop)) {
+                this[prop] = data[prop];
+            }
+        }
+    }
+}
+
+MediaControllerServerPlaybackInfo.prototype.updatePlaybackItem = function(
+    playlistName,
+    index
+) {
+    updatePlaybackItem(playlistName, index);
+    edit_.allow();
+    this.playlistName = playlistName;
+    this.index = index;
+    edit_.disallow();
+};
+
+function MediaControllerServerInfoPlaybackInfo(serverName, data) {
+    var _serverName = serverName; // this variable will be used in the future
+
+    Object.defineProperties(this, {
+        state: {
+            value: data.state,
+            enumerable: true,
+            writable: false
+        },
+        position: {
+            value: data.position,
+            enumerable: true,
+            writable: false
+        },
+        ageRating: {
+            value: data.ageRating,
+            enumerable: true,
+            writable: false
+        },
+        shuffleMode: {
+            value: data.shuffleMode,
+            enumerable: true,
+            writable: false
+        },
+        repeatState: {
+            value: data.repeatState,
+            enumerable: true,
+            writable: false
+        },
+        contentType: {
+            value: data.contentType,
+            enumerable: true,
+            writable: false
+        },
+        metadata: {
+            value: new MediaControllerMetadata(data.metadata),
+            enumerable: true,
+            writable: false
+        },
+        index: {
+            value: data.index,
+            enumerable: true,
+            writable: false
+        },
+        playlistName: {
+            value: data.playlistName,
+            enumerable: true,
+            writable: false
+        }
+    });
+}
+
 exports = new MediaControllerManager();
 exports.SearchFilter = SearchFilter;
 exports.RequestReply = RequestReply;
index 3aed68c..ed9cacd 100644 (file)
@@ -45,7 +45,7 @@ MediaControllerInstance::MediaControllerInstance() {
   using namespace std::placeholders;
 
 #define REGISTER_METHOD(M) \
-    RegisterSyncHandler(#M, std::bind(&MediaControllerInstance::M, this, _1, _2))
+  RegisterSyncHandler(#M, std::bind(&MediaControllerInstance::M, this, _1, _2))
 
   // server
   REGISTER_METHOD(MediaControllerManagerCreateServer);