Bug 830213 - Patch 1: Add ConnectSco, DisconnectSco, IsScoConnected in nsIDOMBluetoothAdapter, r=echou, sr=mrbkap

This commit is contained in:
Gina Yeh 2013-05-10 18:58:59 +08:00
parent 240cb7e823
commit bccf590a6b
10 changed files with 240 additions and 1 deletions

View File

@ -124,6 +124,37 @@ private:
nsRefPtr<BluetoothAdapter> mAdapterPtr;
};
class GetScoConnectionStatusTask : public BluetoothReplyRunnable
{
public:
GetScoConnectionStatusTask(nsIDOMDOMRequest* aReq) :
BluetoothReplyRunnable(aReq)
{
MOZ_ASSERT(aReq);
}
virtual bool ParseSuccessfulReply(JS::Value* aValue)
{
*aValue = JSVAL_VOID;
const BluetoothValue& v = mReply->get_BluetoothReplySuccess().value();
if (v.type() != BluetoothValue::Tbool) {
NS_WARNING("Not a boolean!");
SetError(NS_LITERAL_STRING("BluetoothReplyTypeError"));
return false;
}
aValue->setBoolean(v.get_bool());
return true;
}
void
ReleaseMembers()
{
BluetoothReplyRunnable::ReleaseMembers();
}
};
static int kCreatePairedDeviceTimeout = 50000; // unit: msec
nsresult
@ -743,4 +774,58 @@ BluetoothAdapter::ConfirmReceivingFile(const nsAString& aDeviceAddress,
return NS_OK;
}
NS_IMETHODIMP
BluetoothAdapter::ConnectSco(nsIDOMDOMRequest** aRequest)
{
nsCOMPtr<nsIDOMDOMRequest> req;
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
nsRefPtr<BluetoothVoidReplyRunnable> results =
new BluetoothVoidReplyRunnable(req);
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
bs->ConnectSco(results);
req.forget(aRequest);
return NS_OK;
}
NS_IMETHODIMP
BluetoothAdapter::DisconnectSco(nsIDOMDOMRequest** aRequest)
{
nsCOMPtr<nsIDOMDOMRequest> req;
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
nsRefPtr<BluetoothVoidReplyRunnable> results =
new BluetoothVoidReplyRunnable(req);
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
bs->DisconnectSco(results);
req.forget(aRequest);
return NS_OK;
}
NS_IMETHODIMP
BluetoothAdapter::IsScoConnected(nsIDOMDOMRequest** aRequest)
{
nsCOMPtr<nsIDOMDOMRequest> req;
nsresult rv = PrepareDOMRequest(GetOwner(), getter_AddRefs(req));
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
nsRefPtr<BluetoothReplyRunnable> results =
new GetScoConnectionStatusTask(req);
BluetoothService* bs = BluetoothService::Get();
NS_ENSURE_TRUE(bs, NS_ERROR_FAILURE);
bs->IsScoConnected(results);
req.forget(aRequest);
return NS_OK;
}
NS_IMPL_EVENT_HANDLER(BluetoothAdapter, devicefound)

View File

@ -270,6 +270,15 @@ public:
ConfirmReceivingFile(const nsAString& aDeviceAddress, bool aConfirm,
BluetoothReplyRunnable* aRunnable) = 0;
virtual void
ConnectSco(BluetoothReplyRunnable* aRunnable) = 0;
virtual void
DisconnectSco(BluetoothReplyRunnable* aRunnable) = 0;
virtual void
IsScoConnected(BluetoothReplyRunnable* aRunnable) = 0;
bool
IsEnabled() const
{

View File

@ -225,6 +225,12 @@ BluetoothParent::RecvPBluetoothRequestConstructor(
return actor->DoRequest(aRequest.get_ConfirmReceivingFileRequest());
case Request::TDenyReceivingFileRequest:
return actor->DoRequest(aRequest.get_DenyReceivingFileRequest());
case Request::TConnectScoRequest:
return actor->DoRequest(aRequest.get_ConnectScoRequest());
case Request::TDisconnectScoRequest:
return actor->DoRequest(aRequest.get_DisconnectScoRequest());
case Request::TIsScoConnectedRequest:
return actor->DoRequest(aRequest.get_IsScoConnectedRequest());
default:
MOZ_NOT_REACHED("Unknown type!");
return false;
@ -570,3 +576,33 @@ BluetoothRequestParent::DoRequest(const DenyReceivingFileRequest& aRequest)
mReplyRunnable.get());
return true;
}
bool
BluetoothRequestParent::DoRequest(const ConnectScoRequest& aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TConnectScoRequest);
mService->ConnectSco(mReplyRunnable.get());
return true;
}
bool
BluetoothRequestParent::DoRequest(const DisconnectScoRequest& aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TDisconnectScoRequest);
mService->DisconnectSco(mReplyRunnable.get());
return true;
}
bool
BluetoothRequestParent::DoRequest(const IsScoConnectedRequest& aRequest)
{
MOZ_ASSERT(mService);
MOZ_ASSERT(mRequestType == Request::TIsScoConnectedRequest);
mService->IsScoConnected(mReplyRunnable.get());
return true;
}

View File

@ -185,6 +185,15 @@ protected:
bool
DoRequest(const DenyReceivingFileRequest& aRequest);
bool
DoRequest(const ConnectScoRequest& aRequest);
bool
DoRequest(const DisconnectScoRequest& aRequest);
bool
DoRequest(const IsScoConnectedRequest& aRequest);
};
END_BLUETOOTH_NAMESPACE

View File

@ -331,6 +331,24 @@ BluetoothServiceChildProcess::ConfirmReceivingFile(
DenyReceivingFileRequest(nsString(aDeviceAddress)));
}
void
BluetoothServiceChildProcess::ConnectSco(BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, ConnectScoRequest());
}
void
BluetoothServiceChildProcess::DisconnectSco(BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, DisconnectScoRequest());
}
void
BluetoothServiceChildProcess::IsScoConnected(BluetoothReplyRunnable* aRunnable)
{
SendRequest(aRunnable, IsScoConnectedRequest());
}
nsresult
BluetoothServiceChildProcess::HandleStartup()
{

View File

@ -138,6 +138,16 @@ public:
ConfirmReceivingFile(const nsAString& aDeviceAddress,
bool aConfirm,
BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual void
ConnectSco(BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual void
DisconnectSco(BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
virtual void
IsScoConnected(BluetoothReplyRunnable* aRunnable) MOZ_OVERRIDE;
protected:
BluetoothServiceChildProcess();
virtual ~BluetoothServiceChildProcess();

View File

@ -129,6 +129,18 @@ struct DenyReceivingFileRequest
nsString devicePath;
};
struct ConnectScoRequest
{
};
struct DisconnectScoRequest
{
};
struct IsScoConnectedRequest
{
};
union Request
{
DefaultAdapterPathRequest;
@ -152,6 +164,9 @@ union Request
StopSendingFileRequest;
ConfirmReceivingFileRequest;
DenyReceivingFileRequest;
ConnectScoRequest;
DisconnectScoRequest;
IsScoConnectedRequest;
};
protocol PBluetooth

View File

@ -2824,3 +2824,46 @@ BluetoothDBusService::ConfirmReceivingFile(const nsAString& aDeviceAddress,
DispatchBluetoothReply(aRunnable, v, errorStr);
}
void
BluetoothDBusService::ConnectSco(BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
NS_ENSURE_TRUE_VOID(hfp);
if(!hfp->ConnectSco(aRunnable)) {
NS_NAMED_LITERAL_STRING(replyError,
"SCO socket exists or HFP is not connected");
DispatchBluetoothReply(aRunnable, BluetoothValue(), replyError);
}
}
void
BluetoothDBusService::DisconnectSco(BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
NS_ENSURE_TRUE_VOID(hfp);
if (hfp->DisconnectSco()) {
DispatchBluetoothReply(aRunnable,
BluetoothValue(true), NS_LITERAL_STRING(""));
return;
}
NS_NAMED_LITERAL_STRING(replyError,
"SCO socket doesn't exist or HFP is not connected");
DispatchBluetoothReply(aRunnable, BluetoothValue(), replyError);
}
void
BluetoothDBusService::IsScoConnected(BluetoothReplyRunnable* aRunnable)
{
MOZ_ASSERT(NS_IsMainThread());
BluetoothHfpManager* hfp = BluetoothHfpManager::Get();
NS_ENSURE_TRUE_VOID(hfp);
DispatchBluetoothReply(aRunnable,
hfp->IsScoConnected(), EmptyString());
}

View File

@ -142,6 +142,15 @@ public:
ConfirmReceivingFile(const nsAString& aDeviceAddress, bool aConfirm,
BluetoothReplyRunnable* aRunnable);
virtual void
ConnectSco(BluetoothReplyRunnable* aRunnable);
virtual void
DisconnectSco(BluetoothReplyRunnable* aRunnable);
virtual void
IsScoConnected(BluetoothReplyRunnable* aRunnable);
private:
nsresult SendGetPropertyMessage(const nsAString& aPath,
const char* aInterface,

View File

@ -10,7 +10,7 @@ interface nsIDOMDOMRequest;
interface nsIDOMBlob;
interface nsIDOMBluetoothDevice;
[scriptable, builtinclass, uuid(88a5638f-f55a-4d67-8437-392d0a9a87c7)]
[scriptable, builtinclass, uuid(7058d214-3575-4913-99ad-0980296f617a)]
interface nsIDOMBluetoothAdapter : nsIDOMEventTarget
{
readonly attribute DOMString address;
@ -58,6 +58,11 @@ interface nsIDOMBluetoothAdapter : nsIDOMEventTarget
nsIDOMDOMRequest stopSendingFile(in DOMString aDeviceAddress);
nsIDOMDOMRequest confirmReceivingFile(in DOMString aDeviceAddress, in bool aConfirmation);
// Connect/Disconnect SCO (audio) connection
nsIDOMDOMRequest connectSco();
nsIDOMDOMRequest disconnectSco();
nsIDOMDOMRequest isScoConnected();
// Fired when discoverying and any device is discovered.
[implicit_jscontext] attribute jsval ondevicefound;
};