[mediacontroller] Add display rotation abilities 48/214148/4
authorLukasz Bardeli <l.bardeli@samsung.com>
Wed, 18 Sep 2019 10:17:51 +0000 (12:17 +0200)
committerPiotr Kosko/Native/Web API (PLT) /SRPOL/Engineer/삼성전자 <p.kosko@samsung.com>
Thu, 19 Sep 2019 12:27:35 +0000 (14:27 +0200)
[ACR] http://suprem.sec.samsung.net/jira/browse/TWDAPI-234

[Verification]
tested manually on chrome console

Change-Id: I226a84bcb17757e900bfce64058180dec812af95
Signed-off-by: Lukasz Bardeli <l.bardeli@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
src/mediacontroller/mediacontroller_server.h
src/mediacontroller/mediacontroller_utils.cc
src/mediacontroller/mediacontroller_utils.h

index f0732f4..71bfaf6 100755 (executable)
@@ -266,6 +266,13 @@ var ClientAbilityChangeListener = new ListenerManager(
                 new MediaControllerDisplayModeAbilitiesInfo(msg.name)
             );
         }
+        if (msg.action === 'ondisplayrotationabilitychanged') {
+            native_.callIfPossible(
+                listener[msg.action],
+                new MediaControllerServerInfo(msg),
+                new MediaControllerDisplayRotationAbilitiesInfo(msg.name)
+            );
+        }
         if (msg.action === 'onsimpleabilitychanged') {
             native_.callIfPossible(
                 listener[msg.action],
@@ -661,6 +668,10 @@ var MediaControllerAbilities = function() {
             value: new MediaControllerDisplayModeAbilities(),
             enumerable: true
         },
+        displayRotation: {
+            value: new MediaControllerDisplayRotationAbilities(),
+            enumerable: true
+        },
         playbackPosition: {
             get: function() {
                 return _playbackPosition;
@@ -942,6 +953,76 @@ var MediaControllerDisplayModeAbilities = function() {
     });
 };
 
+var MediaControllerDisplayRotationAbilities = function() {
+    var _rotationNone = MediaControllerAbilitySupport.NO,
+        _rotation90 = MediaControllerAbilitySupport.NO,
+        _rotation180 = MediaControllerAbilitySupport.NO,
+        _rotation270 = MediaControllerAbilitySupport.NO;
+
+    Object.defineProperties(this, {
+        rotationNone: {
+            get: function() {
+                return _rotationNone;
+            },
+            set: function(val) {
+                if (val !== _rotationNone) {
+                    setDisplayRotationAbility(
+                        MediaControllerDisplayRotationType.ROTATION_NONE,
+                        val
+                    );
+                    _rotationNone = val;
+                }
+            },
+            enumerable: true
+        },
+        rotation90: {
+            get: function() {
+                return _rotation90;
+            },
+            set: function(val) {
+                if (val !== _rotation90) {
+                    setDisplayRotationAbility(
+                        MediaControllerDisplayRotationType.ROTATION_90,
+                        val
+                    );
+                    _rotation90 = val;
+                }
+            },
+            enumerable: true
+        },
+        rotation180: {
+            get: function() {
+                return _rotation180;
+            },
+            set: function(val) {
+                if (val !== _rotation180) {
+                    setDisplayRotationAbility(
+                        MediaControllerDisplayRotationType.ROTATION_180,
+                        val
+                    );
+                    _rotation180 = val;
+                }
+            },
+            enumerable: true
+        },
+        rotation270: {
+            get: function() {
+                return _rotation270;
+            },
+            set: function(val) {
+                if (val !== _rotation270) {
+                    setDisplayRotationAbility(
+                        MediaControllerDisplayRotationType.ROTATION_270,
+                        val
+                    );
+                    _rotation270 = val;
+                }
+            },
+            enumerable: true
+        }
+    });
+};
+
 var MediaControllerAbilitiesInfo = function(serverName) {
     Object.defineProperties(this, {
         playback: {
@@ -954,6 +1035,11 @@ var MediaControllerAbilitiesInfo = function(serverName) {
             enumerable: true,
             writable: false
         },
+        displayRotation: {
+            value: new MediaControllerDisplayRotationAbilitiesInfo(serverName),
+            enumerable: true,
+            writable: false
+        },
         playbackPosition: {
             get: function() {
                 return getSimpleAbility(
@@ -1160,6 +1246,51 @@ var MediaControllerDisplayModeAbilitiesInfo = function(serverName) {
     });
 };
 
+var MediaControllerDisplayRotationAbilitiesInfo = function(serverName) {
+    Object.defineProperties(this, {
+        rotationNone: {
+            get: function() {
+                return getDisplayRotationAbility(
+                    serverName,
+                    MediaControllerDisplayRotationType.ROTATION_NONE
+                );
+            },
+            set: function() {},
+            enumerable: true
+        },
+        rotation90: {
+            get: function() {
+                return getDisplayRotationAbility(
+                    serverName,
+                    MediaControllerDisplayRotationType.ROTATION_90
+                );
+            },
+            set: function() {},
+            enumerable: true
+        },
+        rotation180: {
+            get: function() {
+                return getDisplayRotationAbility(
+                    serverName,
+                    MediaControllerDisplayRotationType.ROTATION_180
+                );
+            },
+            set: function() {},
+            enumerable: true
+        },
+        rotation270: {
+            get: function() {
+                return getDisplayRotationAbility(
+                    serverName,
+                    MediaControllerDisplayRotationType.ROTATION_270
+                );
+            },
+            set: function() {},
+            enumerable: true
+        }
+    });
+};
+
 // subtitles
 var MediaControllerSubtitles = function() {
     // the default value is false
@@ -2600,6 +2731,40 @@ var getDisplayModeAbility = function(serverName, mode) {
     return native_.getResultObject(result);
 };
 
+var getDisplayRotationAbility = function(serverName, displayRotation) {
+    var data = {
+        serverName: serverName,
+        displayRotationAbility: displayRotation
+    };
+    var result = native_.callSync(
+        'MediaControllerClient_getDisplayRotationAbility',
+        data
+    );
+    if (native_.isFailure(result)) {
+        throw new native_.getErrorObject(result);
+    }
+
+    return native_.getResultObject(result);
+};
+
+var setDisplayRotationAbility = function(displayRotationAbility, support) {
+    checkSupportValue(support);
+
+    var data = {
+        displayRotationAbility: displayRotationAbility,
+        support: support
+    };
+
+    var result = native_.callSync(
+        'MediaControllerServer_setDisplayRotationAbility',
+        data
+    );
+
+    if (native_.isFailure(result)) {
+        throw native_.getErrorObject(result);
+    }
+};
+
 function MediaControllerClient() {}
 
 MediaControllerClient.prototype.findServers = function(successCallback, errorCallback) {
@@ -2775,6 +2940,7 @@ MediaControllerClient.prototype.addAbilityChangeListener = function(callback) {
             values: [
                 'onplaybackabilitychanged',
                 'ondisplaymodeabilitychanged',
+                'ondisplayrotationabilitychanged',
                 'onsimpleabilitychanged'
             ]
         }
index 90564aa..9f77350 100644 (file)
 namespace extension {
 namespace mediacontroller {
 
-using common::PlatformResult;
 using common::ErrorCode;
+using common::JsonToBundle;
+using common::PlatformResult;
 using common::tools::ReportError;
 using common::tools::ReportSuccess;
-using common::JsonToBundle;
 
 MediaControllerClient::MediaControllerClient() : handle_(nullptr), subscribed_servers{} {
   ScopeLogger();
@@ -251,6 +251,35 @@ PlatformResult MediaControllerClient::GetDisplayModeAbility(const std::string& s
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
+PlatformResult MediaControllerClient::GetDisplayRotationAbility(
+    const std::string& server_name, const std::string& display_rotation_ability,
+    std::string* abilities) {
+  ScopeLogger();
+
+  mc_display_rotation_e display_rotation_e = MC_DISPLAY_ROTATION_NONE;
+
+  PlatformResult result = types::MediaControllerDisplayRotationEnum.getValue(
+      display_rotation_ability, &display_rotation_e);
+  if (!result) {
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting value of display rotation",
+                              ("MediaControllerDisplayRotationEnum.getValue() failed, error: %s",
+                               result.message().c_str()));
+  }
+
+  u_int supported_items = 0;
+  int ret =
+      mc_client_get_server_display_rotation_ability(handle_, server_name.c_str(), &supported_items);
+  if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+    return LogAndCreateResult(
+        ErrorCode::UNKNOWN_ERR, "Error getting ability",
+        ("mc_client_get_ability_support() error: %d, message: %s", ret, get_error_message(ret)));
+  }
+
+  *abilities = (supported_items & display_rotation_e) != 0 ? "YES" : "NO";
+
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
 PlatformResult MediaControllerClient::GetSimpleAbility(const std::string& server_name,
                                                        const std::string& ability_type,
                                                        picojson::value* ability_val) {
@@ -566,6 +595,7 @@ PlatformResult MediaControllerClient::SetAbilityChangeListener(const JsonCallbac
     // The purpose of this lambda is to unset as many setters as we can in case of failure.
     int (*unsetters[])(mc_client_h) = {mc_client_unset_playback_ability_updated_cb,
                                        mc_client_unset_display_mode_ability_updated_cb,
+                                       mc_client_unset_display_rotation_ability_updated_cb,
                                        mc_client_unset_ability_support_updated_cb};
 
     // This loop is no-op in case of success.
@@ -594,9 +624,19 @@ PlatformResult MediaControllerClient::SetAbilityChangeListener(const JsonCallbac
          get_error_message(ret)));
   }
 
-  ret = mc_client_set_ability_support_updated_cb(handle_, OnSimpleAbilityUpdate, this);
+  ret = mc_client_set_display_rotation_ability_updated_cb(handle_, OnDisplayRotationAbilityUpdate,
+                                                          this);
   if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
     failed_setters = 2;
+    return LogAndCreateResult(
+        ErrorCode::UNKNOWN_ERR, "Unable to register display rotation ability listener",
+        ("mc_client_set_display_rotation_ability_updated_cb() error: %d, message: %s", ret,
+         get_error_message(ret)));
+  }
+
+  ret = mc_client_set_ability_support_updated_cb(handle_, OnSimpleAbilityUpdate, this);
+  if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+    failed_setters = 3;
     return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unable to register simple ability listener",
                               ("mc_client_set_ability_support_updated_cb() error: %d, message: %s",
                                ret, get_error_message(ret)));
@@ -639,6 +679,13 @@ PlatformResult MediaControllerClient::UnsetAbilityChangeListener() {
             ret, get_error_message(ret));
   }
 
+  ret = mc_client_unset_display_rotation_ability_updated_cb(handle_);
+  if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+    LoggerE(
+        "mc_client_unset_display_rotation_ability_updated_cb() failed with error %d, message: %s",
+        ret, get_error_message(ret));
+  }
+
   ret = mc_client_unset_ability_support_updated_cb(handle_);
   if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
     LoggerW("mc_client_unset_ability_support_updated_cb() failed with error %d, message: %s", ret,
@@ -697,7 +744,7 @@ PlatformResult MediaControllerClient::UnsubscribeServer(const std::string& serve
   /**
    * After unsubscribing last media controller server, unsetting and setting callback
    * is needed to receive again callbacks from all media controller servers.
-  */
+   */
   if (subscribed_servers.size() <= 0 && nullptr != ability_listener_) {
     JsonCallback callback = ability_listener_;
     UnsetAbilityChangeListener();
@@ -715,7 +762,7 @@ PlatformResult MediaControllerClient::FindSubscribedServers(picojson::array* ser
   /**
    * If subscription is successful, then servers are subscribed to every subscription type,
    * so we can check only the one type of subscription to receive all subscribed servers.
-  */
+   */
   int ret = mc_client_foreach_server_subscribed(handle_, MC_SUBSCRIPTION_TYPE_ABILITY_SUPPORT,
                                                 FindServersCallback, servers);
   if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
@@ -791,6 +838,22 @@ void MediaControllerClient::OnDisplayModeAbilityUpdate(const char* server_name,
   client->ability_listener_(&data);
 }
 
+void MediaControllerClient::OnDisplayRotationAbilityUpdate(const char* server_name,
+                                                           u_int supported_items, void* user_data) {
+  ScopeLogger();
+  MediaControllerClient* client = static_cast<MediaControllerClient*>(user_data);
+
+  picojson::value data = picojson::value(picojson::object());
+  picojson::object& data_o = data.get<picojson::object>();
+
+  data_o["action"] = picojson::value(std::string("ondisplayrotationabilitychanged"));
+  data_o["name"] = picojson::value(std::string(server_name));
+  // only active servers can trigger listener, thus state is always "ACTIVE"
+  data_o["state"] = picojson::value(std::string("ACTIVE"));
+
+  client->ability_listener_(&data);
+}
+
 void MediaControllerClient::OnShuffleModeUpdate(const char* server_name, mc_shuffle_mode_e mode,
                                                 void* user_data) {
   ScopeLogger();
index 3adacc0..f460e12 100644 (file)
@@ -72,6 +72,9 @@ class MediaControllerClient {
   common::PlatformResult GetSimpleAbility(const std::string& server_name,
                                           const std::string& ability_type,
                                           picojson::value* ability_val);
+  common::PlatformResult GetDisplayRotationAbility(const std::string& server_name,
+                                                   const std::string& display_rotation_ability,
+                                                   std::string* ability_val);
   common::PlatformResult SubscribeServer(const std::string& server_name);
   common::PlatformResult UnsubscribeServer(const std::string& server_name);
   common::PlatformResult FindSubscribedServers(picojson::array* servers);
@@ -136,6 +139,8 @@ class MediaControllerClient {
   static void OnPlaybackAbilityUpdate(const char* server_name, mc_playback_ability_h ability,
                                       void* user_data);
   static void OnDisplayModeAbilityUpdate(const char* server_name, u_int mode, void* user_data);
+  static void OnDisplayRotationAbilityUpdate(const char* server_name, u_int supported_items,
+                                             void* user_data);
   static void OnSimpleAbilityUpdate(const char* server_name, mc_ability_e type,
                                     mc_ability_support_e mode, void* user_data);
   // subtitles
index 88ac2f9..c6d355e 100644 (file)
@@ -41,6 +41,7 @@ const std::string kPrivilegeMediaControllerServer =
 // TODO displayRotation const
 
 const char* kAbilityType = "abilityType";
+const char* kDisplayRotationAbility = "displayRotationAbility";
 const char* kServerName = "serverName";
 }  // namespace
 
@@ -95,6 +96,8 @@ MediaControllerInstance::MediaControllerInstance() {
                 MediaControllerServerSavePlaybackAbilities);
   REGISTER_SYNC("MediaControllerServer_setDisplayModeAbility",
                 MediaControllerServerSetDisplayModeAbility);
+  REGISTER_SYNC("MediaControllerServer_setDisplayRotationAbility",
+                MediaControllerServerSetDisplayRotationAbility);
   REGISTER_SYNC("MediaControllerServer_setSimpleAbility", MediaControllerServerSetSimpleAbility);
 
   // client
@@ -107,6 +110,8 @@ MediaControllerInstance::MediaControllerInstance() {
                 MediaControllerClientGetPlaybackAbility);
   REGISTER_SYNC("MediaControllerClient_getDisplayModeAbility",
                 MediaControllerClientGetDisplayModeAbility);
+  REGISTER_SYNC("MediaControllerClient_getDisplayRotationAbility",
+                MediaControllerClientGetDisplayRotationAbility);
   REGISTER_SYNC("MediaControllerClient_getSimpleAbility", MediaControllerClientGetSimpleAbility);
   REGISTER_ASYNC("MediaControllerClient_findSubscribedServers",
                  MediaControllerClientFindSubscribedServers);
@@ -825,6 +830,31 @@ void MediaControllerInstance::MediaControllerServerSetDisplayModeAbility(
   ReportSuccess(out);
 }
 
+void MediaControllerInstance::MediaControllerServerSetDisplayRotationAbility(
+    const picojson::value& args, picojson::object& out) {
+  ScopeLogger();
+
+  if (!server_) {
+    LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
+                      ("Failed: server_"));
+    return;
+  }
+
+  CHECK_ARGS(args, kDisplayRotationAbility, std::string, out)
+  CHECK_ARGS(args, "support", std::string, out)
+
+  std::string display_rotation_ability = args.get(kDisplayRotationAbility).get<std::string>();
+  std::string support = args.get("support").get<std::string>();
+  const PlatformResult& result =
+      server_->SetDisplayRotationAbility(display_rotation_ability, support);
+  if (!result) {
+    LogAndReportError(result, &out, ("Failed server_->SetDisplayRotationAbility()"));
+    return;
+  }
+
+  ReportSuccess(out);
+}
+
 void MediaControllerInstance::MediaControllerServerSetSimpleAbility(const picojson::value& args,
                                                                     picojson::object& out) {
   ScopeLogger();
@@ -994,6 +1024,33 @@ void MediaControllerInstance::MediaControllerClientGetDisplayModeAbility(
   ReportSuccess(picojson::value(ability), out);
 }
 
+void MediaControllerInstance::MediaControllerClientGetDisplayRotationAbility(
+    const picojson::value& args, picojson::object& out) {
+  ScopeLogger();
+
+  if (!client_) {
+    LogAndReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Unknown error occured."), &out,
+                      ("Failed: client_"));
+    return;
+  }
+
+  CHECK_ARGS(args, kServerName, std::string, out)
+  CHECK_ARGS(args, kDisplayRotationAbility, std::string, out)
+
+  std::string server_name = args.get(kServerName).get<std::string>();
+  std::string display_rotation_ability = args.get(kDisplayRotationAbility).get<std::string>();
+  std::string ability;
+
+  PlatformResult result =
+      client_->GetDisplayRotationAbility(server_name, display_rotation_ability, &ability);
+  if (!result) {
+    LogAndReportError(result, &out, ("Failed: client_->GetDisplayRotationAbility"));
+    return;
+  }
+
+  ReportSuccess(picojson::value(ability), out);
+}
+
 void MediaControllerInstance::MediaControllerClientGetSimpleAbility(const picojson::value& args,
                                                                     picojson::object& out) {
   ScopeLogger();
index edeb472..3681ad5 100644 (file)
@@ -69,6 +69,8 @@ class MediaControllerInstance : public common::ParsedInstance {
                                                   picojson::object& out);
   void MediaControllerServerSetDisplayModeAbility(const picojson::value& args,
                                                   picojson::object& out);
+  void MediaControllerServerSetDisplayRotationAbility(const picojson::value& args,
+                                                      picojson::object& out);
   void MediaControllerServerSetSimpleAbility(const picojson::value& args, picojson::object& out);
 
   // client
@@ -79,6 +81,8 @@ class MediaControllerInstance : public common::ParsedInstance {
   void MediaControllerClientGetPlaybackAbility(const picojson::value& args, picojson::object& out);
   void MediaControllerClientGetDisplayModeAbility(const picojson::value& args,
                                                   picojson::object& out);
+  void MediaControllerClientGetDisplayRotationAbility(const picojson::value& args,
+                                                      picojson::object& out);
   void MediaControllerClientGetSimpleAbility(const picojson::value& args, picojson::object& out);
   void MediaControllerClientAddAbilityChangeListener(const picojson::value& args,
                                                      picojson::object& out);
index c2223d7..1d86a52 100644 (file)
@@ -27,9 +27,9 @@
 namespace extension {
 namespace mediacontroller {
 
-using common::PlatformResult;
-using common::ErrorCode;
 using common::BundleJsonIterator;
+using common::ErrorCode;
+using common::PlatformResult;
 
 MediaControllerServer::MediaControllerServer()
     : handle_(nullptr),
@@ -787,6 +787,37 @@ PlatformResult MediaControllerServer::SetDisplayModeAbility(const std::string& m
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
+PlatformResult MediaControllerServer::SetDisplayRotationAbility(
+    std::string& display_rotation_ability, const std::string& support_str) {
+  ScopeLogger();
+
+  mc_display_rotation_e display_rotation_e;
+  PlatformResult result = types::MediaControllerDisplayRotationEnum.getValue(
+      display_rotation_ability, &display_rotation_e);
+  if (!result) {
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting value of display rotation",
+                              ("MediaControllerDisplayRotationEnum.getValue() failed, error: %s",
+                               result.message().c_str()));
+  }
+
+  mc_ability_support_e support_e;
+  result = types::MediaControllerAbilitySupportEnum.getValue(support_str, &support_e);
+  if (!result) {
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error getting value of ability",
+                              ("MediaControllerAbilitySupportEnum.getValue() failed, error: %s",
+                               result.message().c_str()));
+  }
+
+  int ret = mc_server_set_display_rotation_ability(handle_, display_rotation_e, support_e);
+  if (MEDIA_CONTROLLER_ERROR_NONE != ret) {
+    return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Error setting ability",
+                              ("mc_server_set_display_rotation_ability() error: %d, message: %s",
+                               ret, get_error_message(ret)));
+  }
+
+  return PlatformResult(ErrorCode::NO_ERROR);
+}
+
 PlatformResult MediaControllerServer::SetSimpleAbility(const std::string& ability_type,
                                                        const std::string& support_str) {
   ScopeLogger();
index b85ac27..04c0365 100644 (file)
@@ -69,6 +69,8 @@ class MediaControllerServer {
   common::PlatformResult SavePlaybackAbilities(const picojson::value& abilities);
   common::PlatformResult SetDisplayModeAbility(const std::string& mode,
                                                const std::string& support_str);
+  common::PlatformResult SetDisplayRotationAbility(std::string& display_rotation_ability,
+                                                   const std::string& support_str);
   common::PlatformResult SetSimpleAbility(const std::string& ability_type,
                                           const std::string& support_str);
   // subtitles
index 7841491..28fd445 100644 (file)
@@ -25,8 +25,8 @@
 namespace extension {
 namespace mediacontroller {
 
-using common::PlatformResult;
 using common::ErrorCode;
+using common::PlatformResult;
 
 namespace types {
 
@@ -266,13 +266,12 @@ PlatformResult ConvertPlaybackAbility(mc_playback_ability_h ability_h, const std
   return PlatformResult(ErrorCode::NO_ERROR);
 }
 
-}  // types
+}  // namespace types
 
 PlatformResult utils::GetAllPlaylists(const std::string& app_id, picojson::array* playlists) {
   ScopeLogger();
 
   auto OnPlaylists = [](mc_playlist_h playlist, void* user_data) -> bool {
-
     char* name = nullptr;
 
     SCOPE_EXIT {
index 2338982..9655659 100644 (file)
@@ -59,7 +59,7 @@ extern const common::PlatformEnum<mc_display_rotation_e> MediaControllerDisplayR
 namespace utils {
 common::PlatformResult GetAllPlaylists(const std::string& app_id, picojson::array* playlists);
 common::ErrorCode ConvertMediaControllerError(int e);
-}
+}  // namespace utils
 
 }  // namespace mediacontroller
 }  // namespace extension