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],
value: new MediaControllerDisplayModeAbilities(),
enumerable: true
},
+ displayRotation: {
+ value: new MediaControllerDisplayRotationAbilities(),
+ enumerable: true
+ },
playbackPosition: {
get: function() {
return _playbackPosition;
});
};
+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: {
enumerable: true,
writable: false
},
+ displayRotation: {
+ value: new MediaControllerDisplayRotationAbilitiesInfo(serverName),
+ enumerable: true,
+ writable: false
+ },
playbackPosition: {
get: function() {
return getSimpleAbility(
});
};
+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
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) {
values: [
'onplaybackabilitychanged',
'ondisplaymodeabilitychanged',
+ 'ondisplayrotationabilitychanged',
'onsimpleabilitychanged'
]
}
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();
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) {
// 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.
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)));
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,
/**
* 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();
/**
* 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) {
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();
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);
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
// TODO displayRotation const
const char* kAbilityType = "abilityType";
+const char* kDisplayRotationAbility = "displayRotationAbility";
const char* kServerName = "serverName";
} // namespace
MediaControllerServerSavePlaybackAbilities);
REGISTER_SYNC("MediaControllerServer_setDisplayModeAbility",
MediaControllerServerSetDisplayModeAbility);
+ REGISTER_SYNC("MediaControllerServer_setDisplayRotationAbility",
+ MediaControllerServerSetDisplayRotationAbility);
REGISTER_SYNC("MediaControllerServer_setSimpleAbility", MediaControllerServerSetSimpleAbility);
// client
MediaControllerClientGetPlaybackAbility);
REGISTER_SYNC("MediaControllerClient_getDisplayModeAbility",
MediaControllerClientGetDisplayModeAbility);
+ REGISTER_SYNC("MediaControllerClient_getDisplayRotationAbility",
+ MediaControllerClientGetDisplayRotationAbility);
REGISTER_SYNC("MediaControllerClient_getSimpleAbility", MediaControllerClientGetSimpleAbility);
REGISTER_ASYNC("MediaControllerClient_findSubscribedServers",
MediaControllerClientFindSubscribedServers);
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();
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();
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
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);
namespace extension {
namespace mediacontroller {
-using common::PlatformResult;
-using common::ErrorCode;
using common::BundleJsonIterator;
+using common::ErrorCode;
+using common::PlatformResult;
MediaControllerServer::MediaControllerServer()
: handle_(nullptr),
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();
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
namespace extension {
namespace mediacontroller {
-using common::PlatformResult;
using common::ErrorCode;
+using common::PlatformResult;
namespace types {
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 {
namespace utils {
common::PlatformResult GetAllPlaylists(const std::string& app_id, picojson::array* playlists);
common::ErrorCode ConvertMediaControllerError(int e);
-}
+} // namespace utils
} // namespace mediacontroller
} // namespace extension