Bug 1220121: Convert IPDL of Bluetooth AVRCP API to |ControlPlayStatus|, r=shuang

This commit is contained in:
Thomas Zimmermann 2015-11-12 11:23:35 +01:00
parent 62d409ef30
commit 9ec12aea49
11 changed files with 58 additions and 72 deletions

View File

@ -70,32 +70,6 @@ USING_BLUETOOTH_NAMESPACE
static BluetoothInterface* sBtInterface;
static nsTArray<RefPtr<BluetoothProfileController> > sControllerArray;
/*
* Static methods
*/
ControlPlayStatus
BluetoothServiceBluedroid::PlayStatusStringToControlPlayStatus(
const nsAString& aPlayStatus)
{
ControlPlayStatus playStatus = ControlPlayStatus::PLAYSTATUS_UNKNOWN;
if (aPlayStatus.EqualsLiteral("STOPPED")) {
playStatus = ControlPlayStatus::PLAYSTATUS_STOPPED;
} else if (aPlayStatus.EqualsLiteral("PLAYING")) {
playStatus = ControlPlayStatus::PLAYSTATUS_PLAYING;
} else if (aPlayStatus.EqualsLiteral("PAUSED")) {
playStatus = ControlPlayStatus::PLAYSTATUS_PAUSED;
} else if (aPlayStatus.EqualsLiteral("FWD_SEEK")) {
playStatus = ControlPlayStatus::PLAYSTATUS_FWD_SEEK;
} else if (aPlayStatus.EqualsLiteral("REV_SEEK")) {
playStatus = ControlPlayStatus::PLAYSTATUS_REV_SEEK;
} else if (aPlayStatus.EqualsLiteral("ERROR")) {
playStatus = ControlPlayStatus::PLAYSTATUS_ERROR;
}
return playStatus;
}
class BluetoothServiceBluedroid::EnableResultHandler final
: public BluetoothResultHandler
{
@ -1952,15 +1926,12 @@ BluetoothServiceBluedroid::SendMetaData(const nsAString& aTitle,
void
BluetoothServiceBluedroid::SendPlayStatus(
int64_t aDuration, int64_t aPosition,
const nsAString& aPlayStatus,
int64_t aDuration, int64_t aPosition, ControlPlayStatus aPlayStatus,
BluetoothReplyRunnable* aRunnable)
{
BluetoothAvrcpManager* avrcp = BluetoothAvrcpManager::Get();
if (avrcp) {
ControlPlayStatus playStatus =
PlayStatusStringToControlPlayStatus(aPlayStatus);
avrcp->UpdatePlayStatus(aDuration, aPosition, playStatus);
avrcp->UpdatePlayStatus(aDuration, aPosition, aPlayStatus);
}
DispatchReplySuccess(aRunnable);
}

View File

@ -255,7 +255,7 @@ public:
virtual void
SendPlayStatus(int64_t aDuration,
int64_t aPosition,
const nsAString& aPlayStatus,
ControlPlayStatus aPlayStatus,
BluetoothReplyRunnable* aRunnable) override;
virtual void
@ -486,9 +486,6 @@ protected:
static nsresult StartGonkBluetooth();
static nsresult StopGonkBluetooth();
static ControlPlayStatus PlayStatusStringToControlPlayStatus(
const nsAString& aPlayStatus);
static void ConnectDisconnect(bool aConnect,
const BluetoothAddress& aDeviceAddress,
BluetoothReplyRunnable* aRunnable,

View File

@ -4044,27 +4044,6 @@ BluetoothDBusService::SendMetaData(const nsAString& aTitle,
aMediaNumber, aTotalMediaCount, aDuration);
}
static ControlPlayStatus
PlayStatusStringToControlPlayStatus(const nsAString& aPlayStatus)
{
ControlPlayStatus playStatus = ControlPlayStatus::PLAYSTATUS_UNKNOWN;
if (aPlayStatus.EqualsLiteral("STOPPED")) {
playStatus = ControlPlayStatus::PLAYSTATUS_STOPPED;
} else if (aPlayStatus.EqualsLiteral("PLAYING")) {
playStatus = ControlPlayStatus::PLAYSTATUS_PLAYING;
} else if (aPlayStatus.EqualsLiteral("PAUSED")) {
playStatus = ControlPlayStatus::PLAYSTATUS_PAUSED;
} else if (aPlayStatus.EqualsLiteral("FWD_SEEK")) {
playStatus = ControlPlayStatus::PLAYSTATUS_FWD_SEEK;
} else if (aPlayStatus.EqualsLiteral("REV_SEEK")) {
playStatus = ControlPlayStatus::PLAYSTATUS_REV_SEEK;
} else if (aPlayStatus.EqualsLiteral("ERROR")) {
playStatus = ControlPlayStatus::PLAYSTATUS_ERROR;
}
return playStatus;
}
class SendPlayStatusTask : public Task
{
public:
@ -4119,7 +4098,7 @@ private:
void
BluetoothDBusService::SendPlayStatus(int64_t aDuration,
int64_t aPosition,
const nsAString& aPlayStatus,
ControlPlayStatus aPlayStatus,
BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
@ -4130,9 +4109,7 @@ BluetoothDBusService::SendPlayStatus(int64_t aDuration,
return;
}
ControlPlayStatus playStatus =
PlayStatusStringToControlPlayStatus(aPlayStatus);
if (playStatus == ControlPlayStatus::PLAYSTATUS_UNKNOWN) {
if (aPlayStatus == ControlPlayStatus::PLAYSTATUS_UNKNOWN) {
DispatchBluetoothReply(aRunnable, BluetoothValue(),
NS_LITERAL_STRING("Invalid play status"));
return;
@ -4155,9 +4132,9 @@ BluetoothDBusService::SendPlayStatus(int64_t aDuration,
return;
}
if (playStatus != avrcp->GetPlayStatus()) {
if (aPlayStatus != avrcp->GetPlayStatus()) {
UpdateNotification(ControlEventId::EVENT_PLAYBACK_STATUS_CHANGED,
playStatus);
aPlayStatus);
} else if (aPosition != avrcp->GetPosition()) {
UpdateNotification(ControlEventId::EVENT_PLAYBACK_POS_CHANGED, aPosition);
}
@ -4168,11 +4145,11 @@ BluetoothDBusService::SendPlayStatus(int64_t aDuration,
Task* task = new SendPlayStatusTask(deviceAddress,
aDuration,
aPosition,
playStatus,
aPlayStatus,
aRunnable);
DispatchToDBusThread(task);
avrcp->UpdatePlayStatus(aDuration, aPosition, playStatus);
avrcp->UpdatePlayStatus(aDuration, aPosition, aPlayStatus);
}
static void

View File

@ -268,7 +268,7 @@ public:
virtual void
SendPlayStatus(int64_t aDuration,
int64_t aPosition,
const nsAString& aPlayStatus,
ControlPlayStatus aPlayStatus,
BluetoothReplyRunnable* aRunnable) override;
virtual void

View File

@ -421,7 +421,7 @@ public:
virtual void
SendPlayStatus(int64_t aDuration,
int64_t aPosition,
const nsAString& aPlayStatus,
ControlPlayStatus aPlayStatus,
BluetoothReplyRunnable* aRunnable) = 0;
virtual void

View File

@ -97,6 +97,31 @@ StringToPinCode(const nsAString& aString, BluetoothPinCode& aPinCode)
return NS_OK;
}
nsresult
StringToControlPlayStatus(const nsAString& aString,
ControlPlayStatus& aPlayStatus)
{
if (aString.EqualsLiteral("STOPPED")) {
aPlayStatus = ControlPlayStatus::PLAYSTATUS_STOPPED;
} else if (aString.EqualsLiteral("PLAYING")) {
aPlayStatus = ControlPlayStatus::PLAYSTATUS_PLAYING;
} else if (aString.EqualsLiteral("PAUSED")) {
aPlayStatus = ControlPlayStatus::PLAYSTATUS_PAUSED;
} else if (aString.EqualsLiteral("FWD_SEEK")) {
aPlayStatus = ControlPlayStatus::PLAYSTATUS_FWD_SEEK;
} else if (aString.EqualsLiteral("REV_SEEK")) {
aPlayStatus = ControlPlayStatus::PLAYSTATUS_REV_SEEK;
} else if (aString.EqualsLiteral("ERROR")) {
aPlayStatus = ControlPlayStatus::PLAYSTATUS_ERROR;
} else {
BT_LOGR("Invalid play status: %s", NS_ConvertUTF16toUTF8(aString).get());
aPlayStatus = ControlPlayStatus::PLAYSTATUS_UNKNOWN;
return NS_ERROR_ILLEGAL_VALUE;
}
return NS_OK;
}
nsresult
StringToPropertyType(const nsAString& aString, BluetoothPropertyType& aType)
{

View File

@ -43,6 +43,14 @@ PinCodeToString(const BluetoothPinCode& aPinCode, nsAString& aString);
nsresult
StringToPinCode(const nsAString& aString, BluetoothPinCode& aPinCode);
//
// Play status/string conversion
//
nsresult
StringToControlPlayStatus(const nsAString& aString,
ControlPlayStatus& aPlayStatus);
//
// Property type/string conversion
//

View File

@ -2038,6 +2038,13 @@ BluetoothAdapter::SendMediaPlayStatus(
return nullptr;
}
ControlPlayStatus playStatus;
auto rv = StringToControlPlayStatus(aMediaPlayStatus.mPlayStatus, playStatus);
if (NS_FAILED(rv)) {
aRv.Throw(rv);
return nullptr;
}
RefPtr<DOMRequest> request = new DOMRequest(win);
RefPtr<BluetoothReplyRunnable> results =
new BluetoothVoidReplyRunnable(request);
@ -2049,7 +2056,7 @@ BluetoothAdapter::SendMediaPlayStatus(
}
bs->SendPlayStatus(aMediaPlayStatus.mDuration,
aMediaPlayStatus.mPosition,
aMediaPlayStatus.mPlayStatus,
playStatus,
results);
return request.forget();

View File

@ -541,12 +541,11 @@ BluetoothServiceChildProcess::SendMetaData(const nsAString& aTitle,
void
BluetoothServiceChildProcess::SendPlayStatus(int64_t aDuration,
int64_t aPosition,
const nsAString& aPlayStatus,
ControlPlayStatus aPlayStatus,
BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable,
SendPlayStatusRequest(aDuration, aPosition,
nsString(aPlayStatus)));
SendPlayStatusRequest(aDuration, aPosition, aPlayStatus));
}
void

View File

@ -267,7 +267,7 @@ public:
virtual void
SendPlayStatus(int64_t aDuration,
int64_t aPosition,
const nsAString& aPlayStatus,
ControlPlayStatus aPlayStatus,
BluetoothReplyRunnable* aRunnable) override;
virtual void

View File

@ -18,6 +18,8 @@ using mozilla::dom::bluetooth::BluetoothObjectType
from "mozilla/dom/bluetooth/BluetoothCommon.h";
using mozilla::dom::bluetooth::BluetoothPinCode
from "mozilla/dom/bluetooth/BluetoothCommon.h";
using mozilla::dom::bluetooth::ControlPlayStatus
from "mozilla/dom/bluetooth/BluetoothCommon.h";
namespace mozilla {
namespace dom {
@ -268,7 +270,7 @@ struct SendPlayStatusRequest
{
int64_t duration;
int64_t position;
nsString playStatus;
ControlPlayStatus playStatus;
};
struct ConnectGattClientRequest