mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1203092: Remove void pointers from Bluetooth's daemon backend, r=shuang
This commit is contained in:
parent
c8d051a615
commit
5a41c2f71a
@ -28,25 +28,14 @@ BluetoothDaemonA2dpModule::SetNotificationHandler(
|
||||
sNotificationHandler = aNotificationHandler;
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothDaemonA2dpModule::Send(DaemonSocketPDU* aPDU,
|
||||
BluetoothA2dpResultHandler* aRes)
|
||||
{
|
||||
nsRefPtr<BluetoothA2dpResultHandler> res(aRes);
|
||||
nsresult rv = Send(aPDU, static_cast<void*>(res.get()));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
unused << res.forget(); // Keep reference for response
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonA2dpModule::HandleSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData)
|
||||
DaemonSocketPDU& aPDU,
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
static void (BluetoothDaemonA2dpModule::* const HandleOp[])(
|
||||
const DaemonSocketPDUHeader&, DaemonSocketPDU&, void*) = {
|
||||
const DaemonSocketPDUHeader&, DaemonSocketPDU&,
|
||||
DaemonSocketResultHandler*) = {
|
||||
[0] = &BluetoothDaemonA2dpModule::HandleRsp,
|
||||
[1] = &BluetoothDaemonA2dpModule::HandleNtf
|
||||
};
|
||||
@ -56,7 +45,7 @@ BluetoothDaemonA2dpModule::HandleSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
// negate twice to map bit to 0/1
|
||||
unsigned int isNtf = !!(aHeader.mOpcode & 0x80);
|
||||
|
||||
(this->*(HandleOp[isNtf]))(aHeader, aPDU, aUserData);
|
||||
(this->*(HandleOp[isNtf]))(aHeader, aPDU, aRes);
|
||||
}
|
||||
|
||||
// Commands
|
||||
@ -139,7 +128,7 @@ BluetoothDaemonA2dpModule::DisconnectRsp(
|
||||
void
|
||||
BluetoothDaemonA2dpModule::HandleRsp(
|
||||
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
|
||||
void* aUserData)
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
static void (BluetoothDaemonA2dpModule::* const HandleRsp[])(
|
||||
const DaemonSocketPDUHeader&,
|
||||
@ -158,8 +147,7 @@ BluetoothDaemonA2dpModule::HandleRsp(
|
||||
}
|
||||
|
||||
nsRefPtr<BluetoothA2dpResultHandler> res =
|
||||
already_AddRefed<BluetoothA2dpResultHandler>(
|
||||
static_cast<BluetoothA2dpResultHandler*>(aUserData));
|
||||
static_cast<BluetoothA2dpResultHandler*>(aRes);
|
||||
|
||||
if (!res) {
|
||||
return; // Return early if no result handler has been set for response
|
||||
@ -315,7 +303,7 @@ BluetoothDaemonA2dpModule::AudioConfigNtf(
|
||||
void
|
||||
BluetoothDaemonA2dpModule::HandleNtf(
|
||||
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
|
||||
void* aUserData)
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
static void (BluetoothDaemonA2dpModule::* const HandleNtf[])(
|
||||
const DaemonSocketPDUHeader&, DaemonSocketPDU&) = {
|
||||
|
@ -15,6 +15,7 @@ BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
using mozilla::ipc::DaemonSocketPDU;
|
||||
using mozilla::ipc::DaemonSocketPDUHeader;
|
||||
using mozilla::ipc::DaemonSocketResultHandler;
|
||||
|
||||
class BluetoothSetupResultHandler;
|
||||
|
||||
@ -33,7 +34,8 @@ public:
|
||||
|
||||
static const int MAX_NUM_CLIENTS;
|
||||
|
||||
virtual nsresult Send(DaemonSocketPDU* aPDU, void* aUserData) = 0;
|
||||
virtual nsresult Send(DaemonSocketPDU* aPDU,
|
||||
DaemonSocketResultHandler* aRes) = 0;
|
||||
|
||||
virtual nsresult RegisterModule(uint8_t aId, uint8_t aMode,
|
||||
uint32_t aMaxNumClients,
|
||||
@ -55,11 +57,8 @@ public:
|
||||
BluetoothA2dpResultHandler* aRes);
|
||||
|
||||
protected:
|
||||
nsresult Send(DaemonSocketPDU* aPDU,
|
||||
BluetoothA2dpResultHandler* aRes);
|
||||
|
||||
void HandleSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData);
|
||||
DaemonSocketPDU& aPDU, DaemonSocketResultHandler* aRes);
|
||||
|
||||
//
|
||||
// Responses
|
||||
@ -87,7 +86,7 @@ protected:
|
||||
|
||||
void HandleRsp(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU,
|
||||
void* aUserData);
|
||||
DaemonSocketResultHandler* aRes);
|
||||
|
||||
//
|
||||
// Notifications
|
||||
@ -125,7 +124,7 @@ protected:
|
||||
|
||||
void HandleNtf(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU,
|
||||
void* aUserData);
|
||||
DaemonSocketResultHandler* aRes);
|
||||
|
||||
static BluetoothA2dpNotificationHandler* sNotificationHandler;
|
||||
};
|
||||
|
@ -28,25 +28,14 @@ BluetoothDaemonAvrcpModule::SetNotificationHandler(
|
||||
sNotificationHandler = aNotificationHandler;
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothDaemonAvrcpModule::Send(DaemonSocketPDU* aPDU,
|
||||
BluetoothAvrcpResultHandler* aRes)
|
||||
{
|
||||
nsRefPtr<BluetoothAvrcpResultHandler> res(aRes);
|
||||
nsresult rv = Send(aPDU, static_cast<void*>(res.get()));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
unused << res.forget(); // Keep reference for response
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonAvrcpModule::HandleSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData)
|
||||
DaemonSocketPDU& aPDU,
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
static void (BluetoothDaemonAvrcpModule::* const HandleOp[])(
|
||||
const DaemonSocketPDUHeader&, DaemonSocketPDU&, void*) = {
|
||||
const DaemonSocketPDUHeader&, DaemonSocketPDU&,
|
||||
DaemonSocketResultHandler*) = {
|
||||
[0] = &BluetoothDaemonAvrcpModule::HandleRsp,
|
||||
[1] = &BluetoothDaemonAvrcpModule::HandleNtf
|
||||
};
|
||||
@ -55,7 +44,7 @@ BluetoothDaemonAvrcpModule::HandleSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
|
||||
unsigned int isNtf = !!(aHeader.mOpcode & 0x80);
|
||||
|
||||
(this->*(HandleOp[isNtf]))(aHeader, aPDU, aUserData);
|
||||
(this->*(HandleOp[isNtf]))(aHeader, aPDU, aRes);
|
||||
}
|
||||
|
||||
// Commands
|
||||
@ -421,7 +410,7 @@ BluetoothDaemonAvrcpModule::SetVolumeRsp(
|
||||
void
|
||||
BluetoothDaemonAvrcpModule::HandleRsp(
|
||||
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
|
||||
void* aUserData)
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
static void (BluetoothDaemonAvrcpModule::* const HandleRsp[])(
|
||||
const DaemonSocketPDUHeader&,
|
||||
@ -459,8 +448,7 @@ BluetoothDaemonAvrcpModule::HandleRsp(
|
||||
}
|
||||
|
||||
nsRefPtr<BluetoothAvrcpResultHandler> res =
|
||||
already_AddRefed<BluetoothAvrcpResultHandler>(
|
||||
static_cast<BluetoothAvrcpResultHandler*>(aUserData));
|
||||
static_cast<BluetoothAvrcpResultHandler*>(aRes);
|
||||
|
||||
if (!res) {
|
||||
return; // Return early if no result handler has been set for response
|
||||
@ -792,7 +780,7 @@ BluetoothDaemonAvrcpModule::PassthroughCmdNtf(
|
||||
void
|
||||
BluetoothDaemonAvrcpModule::HandleNtf(
|
||||
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
|
||||
void* aUserData)
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
static void (BluetoothDaemonAvrcpModule::* const HandleNtf[])(
|
||||
const DaemonSocketPDUHeader&, DaemonSocketPDU&) = {
|
||||
|
@ -15,6 +15,7 @@ BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
using mozilla::ipc::DaemonSocketPDU;
|
||||
using mozilla::ipc::DaemonSocketPDUHeader;
|
||||
using mozilla::ipc::DaemonSocketResultHandler;
|
||||
|
||||
class BluetoothSetupResultHandler;
|
||||
|
||||
@ -65,7 +66,8 @@ public:
|
||||
|
||||
static const int MAX_NUM_CLIENTS;
|
||||
|
||||
virtual nsresult Send(DaemonSocketPDU* aPDU, void* aUserData) = 0;
|
||||
virtual nsresult Send(DaemonSocketPDU* aPDU,
|
||||
DaemonSocketResultHandler* aRes) = 0;
|
||||
|
||||
virtual nsresult RegisterModule(uint8_t aId, uint8_t aMode,
|
||||
uint32_t aMaxNumClients,
|
||||
@ -119,11 +121,8 @@ public:
|
||||
nsresult SetVolumeCmd(uint8_t aVolume, BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
protected:
|
||||
nsresult Send(DaemonSocketPDU* aPDU,
|
||||
BluetoothAvrcpResultHandler* aRes);
|
||||
|
||||
void HandleSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData);
|
||||
DaemonSocketPDU& aPDU, DaemonSocketResultHandler* aRes);
|
||||
|
||||
//
|
||||
// Responses
|
||||
@ -183,7 +182,7 @@ protected:
|
||||
|
||||
void HandleRsp(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU,
|
||||
void* aUserData);
|
||||
DaemonSocketResultHandler* aRes);
|
||||
|
||||
//
|
||||
// Notifications
|
||||
@ -293,7 +292,7 @@ protected:
|
||||
|
||||
void HandleNtf(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU,
|
||||
void* aUserData);
|
||||
DaemonSocketResultHandler* aRes);
|
||||
|
||||
static BluetoothAvrcpNotificationHandler* sNotificationHandler;
|
||||
};
|
||||
|
@ -28,25 +28,14 @@ BluetoothDaemonGattModule::SetNotificationHandler(
|
||||
sNotificationHandler = aNotificationHandler;
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothDaemonGattModule::Send(DaemonSocketPDU* aPDU,
|
||||
BluetoothGattResultHandler* aRes)
|
||||
{
|
||||
nsRefPtr<BluetoothGattResultHandler> res(aRes);
|
||||
nsresult rv = Send(aPDU, static_cast<void*>(res.get()));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
unused << res.forget(); // Keep reference for response
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonGattModule::HandleSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData)
|
||||
DaemonSocketPDU& aPDU,
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
static void (BluetoothDaemonGattModule::* const HandleOp[])(
|
||||
const DaemonSocketPDUHeader&, DaemonSocketPDU&, void*) = {
|
||||
const DaemonSocketPDUHeader&, DaemonSocketPDU&,
|
||||
DaemonSocketResultHandler*) = {
|
||||
[0] = &BluetoothDaemonGattModule::HandleRsp,
|
||||
[1] = &BluetoothDaemonGattModule::HandleNtf
|
||||
};
|
||||
@ -56,7 +45,7 @@ BluetoothDaemonGattModule::HandleSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
// Negate twice to map bit to 0/1
|
||||
unsigned long isNtf = !!(aHeader.mOpcode & 0x80);
|
||||
|
||||
(this->*(HandleOp[isNtf]))(aHeader, aPDU, aUserData);
|
||||
(this->*(HandleOp[isNtf]))(aHeader, aPDU, aRes);
|
||||
}
|
||||
|
||||
// Commands
|
||||
@ -1405,7 +1394,7 @@ BluetoothDaemonGattModule::ServerSendResponseRsp(
|
||||
void
|
||||
BluetoothDaemonGattModule::HandleRsp(
|
||||
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
|
||||
void* aUserData)
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
static void (BluetoothDaemonGattModule::* const HandleRsp[])(
|
||||
const DaemonSocketPDUHeader&,
|
||||
@ -1493,8 +1482,7 @@ BluetoothDaemonGattModule::HandleRsp(
|
||||
}
|
||||
|
||||
nsRefPtr<BluetoothGattResultHandler> res =
|
||||
already_AddRefed<BluetoothGattResultHandler>(
|
||||
static_cast<BluetoothGattResultHandler*>(aUserData));
|
||||
static_cast<BluetoothGattResultHandler*>(aRes);
|
||||
|
||||
if (!res) {
|
||||
return;
|
||||
@ -2152,7 +2140,7 @@ BluetoothDaemonGattModule::ServerResponseConfirmationNtf(
|
||||
void
|
||||
BluetoothDaemonGattModule::HandleNtf(
|
||||
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
|
||||
void* aUserData)
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
static void (BluetoothDaemonGattModule::* const HandleNtf[])(
|
||||
const DaemonSocketPDUHeader&, DaemonSocketPDU&) = {
|
||||
|
@ -15,6 +15,7 @@ BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
using mozilla::ipc::DaemonSocketPDU;
|
||||
using mozilla::ipc::DaemonSocketPDUHeader;
|
||||
using mozilla::ipc::DaemonSocketResultHandler;
|
||||
|
||||
class BluetoothSetupResultHandler;
|
||||
|
||||
@ -67,7 +68,8 @@ public:
|
||||
|
||||
static const int MAX_NUM_CLIENTS;
|
||||
|
||||
virtual nsresult Send(DaemonSocketPDU* aPDU, void* aUserData) = 0;
|
||||
virtual nsresult Send(DaemonSocketPDU* aPDU,
|
||||
DaemonSocketResultHandler* aRes) = 0;
|
||||
|
||||
virtual nsresult RegisterModule(uint8_t aId, uint8_t aMode,
|
||||
uint32_t aMaxNumClients,
|
||||
@ -300,11 +302,8 @@ public:
|
||||
// TODO: Add L support
|
||||
|
||||
protected:
|
||||
nsresult Send(DaemonSocketPDU* aPDU,
|
||||
BluetoothGattResultHandler* aRes);
|
||||
|
||||
void HandleSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData);
|
||||
DaemonSocketPDU& aPDU, DaemonSocketResultHandler* aRes);
|
||||
|
||||
//
|
||||
// Responses
|
||||
@ -471,7 +470,7 @@ protected:
|
||||
|
||||
void HandleRsp(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU,
|
||||
void* aUserData);
|
||||
DaemonSocketResultHandler* aRes);
|
||||
|
||||
//
|
||||
// Notifications
|
||||
@ -770,7 +769,7 @@ protected:
|
||||
|
||||
void HandleNtf(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU,
|
||||
void* aUserData);
|
||||
DaemonSocketResultHandler* aRes);
|
||||
|
||||
static BluetoothGattNotificationHandler* sNotificationHandler;
|
||||
};
|
||||
|
@ -31,25 +31,14 @@ BluetoothDaemonHandsfreeModule::SetNotificationHandler(
|
||||
sNotificationHandler = aNotificationHandler;
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothDaemonHandsfreeModule::Send(DaemonSocketPDU* aPDU,
|
||||
BluetoothHandsfreeResultHandler* aRes)
|
||||
{
|
||||
nsRefPtr<BluetoothHandsfreeResultHandler> res(aRes);
|
||||
nsresult rv = Send(aPDU, static_cast<void*>(res.get()));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
unused << res.forget(); // Keep reference for response
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonHandsfreeModule::HandleSvc(
|
||||
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU, void* aUserData)
|
||||
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
static void (BluetoothDaemonHandsfreeModule::* const HandleOp[])(
|
||||
const DaemonSocketPDUHeader&, DaemonSocketPDU&, void*) = {
|
||||
const DaemonSocketPDUHeader&, DaemonSocketPDU&,
|
||||
DaemonSocketResultHandler*) = {
|
||||
[0] = &BluetoothDaemonHandsfreeModule::HandleRsp,
|
||||
[1] = &BluetoothDaemonHandsfreeModule::HandleNtf
|
||||
};
|
||||
@ -59,7 +48,7 @@ BluetoothDaemonHandsfreeModule::HandleSvc(
|
||||
// Negate twice to map bit to 0/1
|
||||
unsigned long isNtf = !!(aHeader.mOpcode & 0x80);
|
||||
|
||||
(this->*(HandleOp[isNtf]))(aHeader, aPDU, aUserData);
|
||||
(this->*(HandleOp[isNtf]))(aHeader, aPDU, aRes);
|
||||
}
|
||||
|
||||
// Commands
|
||||
@ -679,7 +668,7 @@ BluetoothDaemonHandsfreeModule::ConfigureWbsRsp(
|
||||
void
|
||||
BluetoothDaemonHandsfreeModule::HandleRsp(
|
||||
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
|
||||
void* aUserData)
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
static void (BluetoothDaemonHandsfreeModule::* const HandleRsp[])(
|
||||
const DaemonSocketPDUHeader&,
|
||||
@ -727,8 +716,7 @@ BluetoothDaemonHandsfreeModule::HandleRsp(
|
||||
}
|
||||
|
||||
nsRefPtr<BluetoothHandsfreeResultHandler> res =
|
||||
already_AddRefed<BluetoothHandsfreeResultHandler>(
|
||||
static_cast<BluetoothHandsfreeResultHandler*>(aUserData));
|
||||
static_cast<BluetoothHandsfreeResultHandler*>(aRes);
|
||||
|
||||
if (!res) {
|
||||
return; // Return early if no result handler has been set for response
|
||||
@ -1463,7 +1451,7 @@ BluetoothDaemonHandsfreeModule::WbsNtf(
|
||||
void
|
||||
BluetoothDaemonHandsfreeModule::HandleNtf(
|
||||
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
|
||||
void* aUserData)
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
static void (BluetoothDaemonHandsfreeModule::* const HandleNtf[])(
|
||||
const DaemonSocketPDUHeader&, DaemonSocketPDU&) = {
|
||||
|
@ -15,6 +15,7 @@ BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
using mozilla::ipc::DaemonSocketPDU;
|
||||
using mozilla::ipc::DaemonSocketPDUHeader;
|
||||
using mozilla::ipc::DaemonSocketResultHandler;
|
||||
|
||||
class BluetoothSetupResultHandler;
|
||||
|
||||
@ -44,7 +45,8 @@ public:
|
||||
OPCODE_CONFIGURE_WBS = 0x0f
|
||||
};
|
||||
|
||||
virtual nsresult Send(DaemonSocketPDU* aPDU, void* aUserData) = 0;
|
||||
virtual nsresult Send(DaemonSocketPDU* aPDU,
|
||||
DaemonSocketResultHandler* aRes) = 0;
|
||||
|
||||
virtual nsresult RegisterModule(uint8_t aId, uint8_t aMode,
|
||||
uint32_t aMaxNumClients,
|
||||
@ -128,11 +130,9 @@ public:
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
protected:
|
||||
nsresult Send(DaemonSocketPDU* aPDU,
|
||||
BluetoothHandsfreeResultHandler* aRes);
|
||||
|
||||
void HandleSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData);
|
||||
DaemonSocketPDU& aPDU,
|
||||
DaemonSocketResultHandler* aRes);
|
||||
|
||||
//
|
||||
// Responses
|
||||
@ -212,7 +212,7 @@ protected:
|
||||
|
||||
void HandleRsp(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU,
|
||||
void* aUserData);
|
||||
DaemonSocketResultHandler* aRes);
|
||||
|
||||
//
|
||||
// Notifications
|
||||
@ -369,7 +369,7 @@ protected:
|
||||
|
||||
void HandleNtf(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU,
|
||||
void* aUserData);
|
||||
DaemonSocketResultHandler* aRes);
|
||||
|
||||
static BluetoothHandsfreeNotificationHandler* sNotificationHandler;
|
||||
#if ANDROID_VERSION < 21
|
||||
|
@ -34,7 +34,8 @@ static const int sRetryInterval = 100; // ms
|
||||
class BluetoothDaemonSetupModule
|
||||
{
|
||||
public:
|
||||
virtual nsresult Send(DaemonSocketPDU* aPDU, void* aUserData) = 0;
|
||||
virtual nsresult Send(DaemonSocketPDU* aPDU,
|
||||
DaemonSocketResultHandler* aRes) = 0;
|
||||
|
||||
// Commands
|
||||
//
|
||||
@ -107,7 +108,7 @@ protected:
|
||||
// Called to handle PDUs with Service field equal to 0x00, which
|
||||
// contains internal operations for setup and configuration.
|
||||
void HandleSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData)
|
||||
DaemonSocketPDU& aPDU, DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
static void (BluetoothDaemonSetupModule::* const HandleRsp[])(
|
||||
const DaemonSocketPDUHeader&,
|
||||
@ -125,27 +126,15 @@ protected:
|
||||
}
|
||||
|
||||
nsRefPtr<BluetoothSetupResultHandler> res =
|
||||
already_AddRefed<BluetoothSetupResultHandler>(
|
||||
static_cast<BluetoothSetupResultHandler*>(aUserData));
|
||||
static_cast<BluetoothSetupResultHandler*>(aRes);
|
||||
|
||||
if (!res) {
|
||||
if (!aRes) {
|
||||
return; // Return early if no result handler has been set
|
||||
}
|
||||
|
||||
(this->*(HandleRsp[aHeader.mOpcode]))(aHeader, aPDU, res);
|
||||
}
|
||||
|
||||
nsresult Send(DaemonSocketPDU* aPDU, BluetoothSetupResultHandler* aRes)
|
||||
{
|
||||
nsRefPtr<BluetoothSetupResultHandler> res(aRes);
|
||||
nsresult rv = Send(aPDU, static_cast<void*>(res.get()));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
unused << res.forget(); // Keep reference for response
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
// Responses
|
||||
@ -211,7 +200,8 @@ public:
|
||||
|
||||
static const int MAX_NUM_CLIENTS;
|
||||
|
||||
virtual nsresult Send(DaemonSocketPDU* aPDU, void* aUserData) = 0;
|
||||
virtual nsresult Send(DaemonSocketPDU* aPDU,
|
||||
DaemonSocketResultHandler* aRes) = 0;
|
||||
|
||||
nsresult EnableCmd(BluetoothResultHandler* aRes)
|
||||
{
|
||||
@ -600,28 +590,18 @@ public:
|
||||
protected:
|
||||
|
||||
void HandleSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData)
|
||||
DaemonSocketPDU& aPDU, DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
static void (BluetoothDaemonCoreModule::* const HandleOp[])(
|
||||
const DaemonSocketPDUHeader&, DaemonSocketPDU&, void*) = {
|
||||
const DaemonSocketPDUHeader&, DaemonSocketPDU&,
|
||||
DaemonSocketResultHandler*) = {
|
||||
[0] = &BluetoothDaemonCoreModule::HandleRsp,
|
||||
[1] = &BluetoothDaemonCoreModule::HandleNtf
|
||||
};
|
||||
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
(this->*(HandleOp[!!(aHeader.mOpcode & 0x80)]))(aHeader, aPDU, aUserData);
|
||||
}
|
||||
|
||||
nsresult Send(DaemonSocketPDU* aPDU, BluetoothResultHandler* aRes)
|
||||
{
|
||||
nsRefPtr<BluetoothResultHandler> res(aRes);
|
||||
nsresult rv = Send(aPDU, static_cast<void*>(res.get()));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
unused << res.forget(); // Keep reference for response
|
||||
return NS_OK;
|
||||
(this->*(HandleOp[!!(aHeader.mOpcode & 0x80)]))(aHeader, aPDU, aRes);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -825,7 +805,7 @@ private:
|
||||
}
|
||||
|
||||
void HandleRsp(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData)
|
||||
DaemonSocketPDU& aPDU, DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
static void (BluetoothDaemonCoreModule::* const HandleRsp[])(
|
||||
const DaemonSocketPDUHeader&,
|
||||
@ -862,8 +842,7 @@ private:
|
||||
}
|
||||
|
||||
nsRefPtr<BluetoothResultHandler> res =
|
||||
already_AddRefed<BluetoothResultHandler>(
|
||||
static_cast<BluetoothResultHandler*>(aUserData));
|
||||
static_cast<BluetoothResultHandler*>(aRes);
|
||||
|
||||
if (!res) {
|
||||
return; // Return early if no result handler has been set for response
|
||||
@ -1345,7 +1324,7 @@ private:
|
||||
}
|
||||
|
||||
void HandleNtf(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData)
|
||||
DaemonSocketPDU& aPDU, DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
static void (BluetoothDaemonCoreModule::* const HandleNtf[])(
|
||||
const DaemonSocketPDUHeader&, DaemonSocketPDU&) = {
|
||||
@ -1453,35 +1432,44 @@ public:
|
||||
// Outgoing PDUs
|
||||
//
|
||||
|
||||
nsresult Send(DaemonSocketPDU* aPDU, void* aUserData) override;
|
||||
nsresult Send(DaemonSocketPDU* aPDU,
|
||||
DaemonSocketResultHandler* aRes) override;
|
||||
|
||||
void StoreUserData(const DaemonSocketPDU& aPDU) override;
|
||||
void StoreResultHandler(const DaemonSocketPDU& aPDU) override;
|
||||
|
||||
// Incoming PUDs
|
||||
//
|
||||
|
||||
void Handle(DaemonSocketPDU& aPDU) override;
|
||||
|
||||
void* FetchUserData(const DaemonSocketPDUHeader& aHeader);
|
||||
already_AddRefed<DaemonSocketResultHandler> FetchResultHandler(
|
||||
const DaemonSocketPDUHeader& aHeader);
|
||||
|
||||
private:
|
||||
void HandleSetupSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData);
|
||||
DaemonSocketPDU& aPDU,
|
||||
DaemonSocketResultHandler* aRes);
|
||||
void HandleCoreSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData);
|
||||
DaemonSocketPDU& aPDU,
|
||||
DaemonSocketResultHandler* aRes);
|
||||
void HandleSocketSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData);
|
||||
DaemonSocketPDU& aPDU,
|
||||
DaemonSocketResultHandler* aRes);
|
||||
void HandleHandsfreeSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData);
|
||||
DaemonSocketPDU& aPDU,
|
||||
DaemonSocketResultHandler* aRes);
|
||||
void HandleA2dpSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData);
|
||||
DaemonSocketPDU& aPDU,
|
||||
DaemonSocketResultHandler* aUserData);
|
||||
void HandleAvrcpSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData);
|
||||
DaemonSocketPDU& aPDU,
|
||||
DaemonSocketResultHandler* aRes);
|
||||
void HandleGattSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData);
|
||||
DaemonSocketPDU& aPDU,
|
||||
DaemonSocketResultHandler* aRes);
|
||||
|
||||
DaemonSocket* mConnection;
|
||||
nsTArray<void*> mUserDataQ;
|
||||
nsTArray<nsRefPtr<DaemonSocketResultHandler>> mResQ;
|
||||
};
|
||||
|
||||
BluetoothDaemonProtocol::BluetoothDaemonProtocol()
|
||||
@ -1510,13 +1498,14 @@ BluetoothDaemonProtocol::UnregisterModule(uint8_t aId,
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothDaemonProtocol::Send(DaemonSocketPDU* aPDU, void* aUserData)
|
||||
BluetoothDaemonProtocol::Send(DaemonSocketPDU* aPDU,
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mConnection);
|
||||
MOZ_ASSERT(aPDU);
|
||||
|
||||
aPDU->SetConsumer(this);
|
||||
aPDU->SetUserData(aUserData);
|
||||
aPDU->SetResultHandler(aRes);
|
||||
aPDU->UpdateHeader();
|
||||
|
||||
if (mConnection->GetConnectionStatus() == SOCKET_DISCONNECTED) {
|
||||
@ -1532,64 +1521,65 @@ BluetoothDaemonProtocol::Send(DaemonSocketPDU* aPDU, void* aUserData)
|
||||
void
|
||||
BluetoothDaemonProtocol::HandleSetupSvc(
|
||||
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
|
||||
void* aUserData)
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
BluetoothDaemonSetupModule::HandleSvc(aHeader, aPDU, aUserData);
|
||||
BluetoothDaemonSetupModule::HandleSvc(aHeader, aPDU, aRes);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonProtocol::HandleCoreSvc(
|
||||
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
|
||||
void* aUserData)
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
BluetoothDaemonCoreModule::HandleSvc(aHeader, aPDU, aUserData);
|
||||
BluetoothDaemonCoreModule::HandleSvc(aHeader, aPDU, aRes);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonProtocol::HandleSocketSvc(
|
||||
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
|
||||
void* aUserData)
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
BluetoothDaemonSocketModule::HandleSvc(aHeader, aPDU, aUserData);
|
||||
BluetoothDaemonSocketModule::HandleSvc(aHeader, aPDU, aRes);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonProtocol::HandleHandsfreeSvc(
|
||||
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
|
||||
void* aUserData)
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
BluetoothDaemonHandsfreeModule::HandleSvc(aHeader, aPDU, aUserData);
|
||||
BluetoothDaemonHandsfreeModule::HandleSvc(aHeader, aPDU, aRes);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonProtocol::HandleA2dpSvc(
|
||||
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
|
||||
void* aUserData)
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
BluetoothDaemonA2dpModule::HandleSvc(aHeader, aPDU, aUserData);
|
||||
BluetoothDaemonA2dpModule::HandleSvc(aHeader, aPDU, aRes);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonProtocol::HandleAvrcpSvc(
|
||||
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
|
||||
void* aUserData)
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
BluetoothDaemonAvrcpModule::HandleSvc(aHeader, aPDU, aUserData);
|
||||
BluetoothDaemonAvrcpModule::HandleSvc(aHeader, aPDU, aRes);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonProtocol::HandleGattSvc(
|
||||
const DaemonSocketPDUHeader& aHeader, DaemonSocketPDU& aPDU,
|
||||
void* aUserData)
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
BluetoothDaemonGattModule::HandleSvc(aHeader, aPDU, aUserData);
|
||||
BluetoothDaemonGattModule::HandleSvc(aHeader, aPDU, aRes);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonProtocol::Handle(DaemonSocketPDU& aPDU)
|
||||
{
|
||||
static void (BluetoothDaemonProtocol::* const HandleSvc[])(
|
||||
const DaemonSocketPDUHeader&, DaemonSocketPDU&, void*) = {
|
||||
const DaemonSocketPDUHeader&, DaemonSocketPDU&,
|
||||
DaemonSocketResultHandler*) = {
|
||||
[0x00] = &BluetoothDaemonProtocol::HandleSetupSvc,
|
||||
[0x01] = &BluetoothDaemonProtocol::HandleCoreSvc,
|
||||
[0x02] = &BluetoothDaemonProtocol::HandleSocketSvc,
|
||||
@ -1614,19 +1604,22 @@ BluetoothDaemonProtocol::Handle(DaemonSocketPDU& aPDU)
|
||||
return;
|
||||
}
|
||||
|
||||
(this->*(HandleSvc[header.mService]))(header, aPDU, FetchUserData(header));
|
||||
nsRefPtr<DaemonSocketResultHandler> res = FetchResultHandler(header);
|
||||
|
||||
(this->*(HandleSvc[header.mService]))(header, aPDU, res);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonProtocol::StoreUserData(const DaemonSocketPDU& aPDU)
|
||||
BluetoothDaemonProtocol::StoreResultHandler(const DaemonSocketPDU& aPDU)
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
mUserDataQ.AppendElement(aPDU.GetUserData());
|
||||
mResQ.AppendElement(aPDU.GetResultHandler());
|
||||
}
|
||||
|
||||
void*
|
||||
BluetoothDaemonProtocol::FetchUserData(const DaemonSocketPDUHeader& aHeader)
|
||||
already_AddRefed<DaemonSocketResultHandler>
|
||||
BluetoothDaemonProtocol::FetchResultHandler(
|
||||
const DaemonSocketPDUHeader& aHeader)
|
||||
{
|
||||
MOZ_ASSERT(!NS_IsMainThread());
|
||||
|
||||
@ -1634,10 +1627,10 @@ BluetoothDaemonProtocol::FetchUserData(const DaemonSocketPDUHeader& aHeader)
|
||||
return nullptr; // Ignore notifications
|
||||
}
|
||||
|
||||
void* userData = mUserDataQ.ElementAt(0);
|
||||
mUserDataQ.RemoveElementAt(0);
|
||||
nsRefPtr<DaemonSocketResultHandler> userData = mResQ.ElementAt(0);
|
||||
mResQ.RemoveElementAt(0);
|
||||
|
||||
return userData;
|
||||
return userData.forget();
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -160,7 +160,7 @@ BluetoothDaemonSocketModule::CloseCmd(BluetoothSocketResultHandler* aRes)
|
||||
void
|
||||
BluetoothDaemonSocketModule::HandleSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU,
|
||||
void* aUserData)
|
||||
DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
static void (BluetoothDaemonSocketModule::* const HandleRsp[])(
|
||||
const DaemonSocketPDUHeader&,
|
||||
@ -177,8 +177,7 @@ BluetoothDaemonSocketModule::HandleSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
}
|
||||
|
||||
nsRefPtr<BluetoothSocketResultHandler> res =
|
||||
already_AddRefed<BluetoothSocketResultHandler>(
|
||||
static_cast<BluetoothSocketResultHandler*>(aUserData));
|
||||
static_cast<BluetoothSocketResultHandler*>(aRes);
|
||||
|
||||
if (!res) {
|
||||
return; // Return early if no result handler has been set
|
||||
@ -187,19 +186,6 @@ BluetoothDaemonSocketModule::HandleSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
(this->*(HandleRsp[aHeader.mOpcode]))(aHeader, aPDU, res);
|
||||
}
|
||||
|
||||
nsresult
|
||||
BluetoothDaemonSocketModule::Send(DaemonSocketPDU* aPDU,
|
||||
BluetoothSocketResultHandler* aRes)
|
||||
{
|
||||
nsRefPtr<BluetoothSocketResultHandler> res(aRes);
|
||||
nsresult rv = Send(aPDU, static_cast<void*>(res.get()));
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
unused << res.forget(); // Keep reference for response
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
BluetoothDaemonSocketModule::SocketFlags(bool aEncrypt, bool aAuth)
|
||||
{
|
||||
|
@ -15,13 +15,15 @@ BEGIN_BLUETOOTH_NAMESPACE
|
||||
|
||||
using mozilla::ipc::DaemonSocketPDU;
|
||||
using mozilla::ipc::DaemonSocketPDUHeader;
|
||||
using mozilla::ipc::DaemonSocketResultHandler;
|
||||
|
||||
class BluetoothDaemonSocketModule
|
||||
{
|
||||
public:
|
||||
static const int MAX_NUM_CLIENTS;
|
||||
|
||||
virtual nsresult Send(DaemonSocketPDU* aPDU, void* aUserData) = 0;
|
||||
virtual nsresult Send(DaemonSocketPDU* aPDU,
|
||||
DaemonSocketResultHandler* aRes) = 0;
|
||||
|
||||
// Commands
|
||||
//
|
||||
@ -45,9 +47,7 @@ public:
|
||||
protected:
|
||||
|
||||
void HandleSvc(const DaemonSocketPDUHeader& aHeader,
|
||||
DaemonSocketPDU& aPDU, void* aUserData);
|
||||
|
||||
nsresult Send(DaemonSocketPDU* aPDU, BluetoothSocketResultHandler* aRes);
|
||||
DaemonSocketPDU& aPDU, DaemonSocketResultHandler* aRes);
|
||||
|
||||
private:
|
||||
class AcceptWatcher;
|
||||
|
@ -23,7 +23,7 @@ public:
|
||||
virtual ~DaemonSocketIOConsumer();
|
||||
|
||||
virtual void Handle(DaemonSocketPDU& aPDU) = 0;
|
||||
virtual void StoreUserData(const DaemonSocketPDU& aPDU) = 0;
|
||||
virtual void StoreResultHandler(const DaemonSocketPDU& aPDU) = 0;
|
||||
|
||||
protected:
|
||||
DaemonSocketIOConsumer();
|
||||
|
@ -29,9 +29,8 @@ namespace ipc {
|
||||
//
|
||||
|
||||
DaemonSocketPDU::DaemonSocketPDU(uint8_t aService, uint8_t aOpcode,
|
||||
uint16_t aPayloadSize)
|
||||
uint16_t aPayloadSize)
|
||||
: mConsumer(nullptr)
|
||||
, mUserData(nullptr)
|
||||
{
|
||||
MOZ_COUNT_CTOR_INHERITED(DaemonSocketPDU, UnixSocketIOBuffer);
|
||||
|
||||
@ -51,7 +50,6 @@ DaemonSocketPDU::DaemonSocketPDU(uint8_t aService, uint8_t aOpcode,
|
||||
|
||||
DaemonSocketPDU::DaemonSocketPDU(size_t aPayloadSize)
|
||||
: mConsumer(nullptr)
|
||||
, mUserData(nullptr)
|
||||
{
|
||||
MOZ_COUNT_CTOR_INHERITED(DaemonSocketPDU, UnixSocketIOBuffer);
|
||||
|
||||
@ -102,8 +100,8 @@ DaemonSocketPDU::Send(int aFd)
|
||||
|
||||
if (mConsumer) {
|
||||
// We successfully sent a PDU, now store the
|
||||
// result runnable in the consumer.
|
||||
mConsumer->StoreUserData(*this);
|
||||
// result handler in the consumer.
|
||||
mConsumer->StoreResultHandler(*this);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -9,6 +9,7 @@
|
||||
|
||||
#include "mozilla/FileUtils.h"
|
||||
#include "mozilla/ipc/SocketBase.h"
|
||||
#include "mozilla/ipc/DaemonSocketMessageHandlers.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace ipc {
|
||||
@ -55,14 +56,14 @@ public:
|
||||
mConsumer = aConsumer;
|
||||
}
|
||||
|
||||
void SetUserData(void* aUserData)
|
||||
void SetResultHandler(DaemonSocketResultHandler* aRes)
|
||||
{
|
||||
mUserData = aUserData;
|
||||
mRes = aRes;
|
||||
}
|
||||
|
||||
void* GetUserData() const
|
||||
DaemonSocketResultHandler* GetResultHandler() const
|
||||
{
|
||||
return mUserData;
|
||||
return mRes;
|
||||
}
|
||||
|
||||
void GetHeader(uint8_t& aService, uint8_t& aOpcode,
|
||||
@ -80,7 +81,7 @@ private:
|
||||
void OnError(const char* aFunction, int aErrno);
|
||||
|
||||
DaemonSocketIOConsumer* mConsumer;
|
||||
void* mUserData;
|
||||
nsRefPtr<DaemonSocketResultHandler> mRes;
|
||||
ScopedClose mReceivedFd;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user