mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1170071 - Part 4: Add Gatt server interfaces for Bluetooth daemon. r=shuang
CLOSED TREE
This commit is contained in:
parent
0293af1415
commit
b7ed1e5a94
@ -107,6 +107,12 @@ BluetoothGattClientInterface::BluetoothGattClientInterface()
|
||||
BluetoothGattClientInterface::~BluetoothGattClientInterface()
|
||||
{ }
|
||||
|
||||
BluetoothGattServerInterface::BluetoothGattServerInterface()
|
||||
{ }
|
||||
|
||||
BluetoothGattServerInterface::~BluetoothGattServerInterface()
|
||||
{ }
|
||||
|
||||
BluetoothGattInterface::BluetoothGattInterface()
|
||||
{ }
|
||||
|
||||
|
@ -1044,6 +1044,7 @@ public:
|
||||
virtual void Cleanup(BluetoothGattResultHandler* aRes) = 0;
|
||||
|
||||
virtual BluetoothGattClientInterface* GetBluetoothGattClientInterface() = 0;
|
||||
virtual BluetoothGattServerInterface* GetBluetoothGattServerInterface() = 0;
|
||||
|
||||
protected:
|
||||
BluetoothGattInterface();
|
||||
|
@ -2315,6 +2315,11 @@ BluetoothDaemonGattClientInterface::BluetoothDaemonGattClientInterface(
|
||||
: mModule(aModule)
|
||||
{ }
|
||||
|
||||
BluetoothDaemonGattServerInterface::BluetoothDaemonGattServerInterface(
|
||||
BluetoothDaemonGattModule* aModule)
|
||||
: mModule(aModule)
|
||||
{ }
|
||||
|
||||
BluetoothDaemonGattInterface::BluetoothDaemonGattInterface(
|
||||
BluetoothDaemonGattModule* aModule)
|
||||
: mModule(aModule)
|
||||
@ -2758,6 +2763,203 @@ BluetoothDaemonGattClientInterface::TestCommand(
|
||||
}
|
||||
}
|
||||
|
||||
/* Register / Unregister */
|
||||
void
|
||||
BluetoothDaemonGattServerInterface::RegisterServer(
|
||||
const BluetoothUuid& aUuid, BluetoothGattServerResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
nsresult rv = mModule->ServerRegisterCmd(aUuid, aRes);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
DispatchError(aRes, rv);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonGattServerInterface::UnregisterServer(
|
||||
int aServerIf, BluetoothGattServerResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
nsresult rv = mModule->ServerUnregisterCmd(aServerIf, aRes);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
DispatchError(aRes, rv);
|
||||
}
|
||||
}
|
||||
|
||||
/* Connect / Disconnect */
|
||||
void
|
||||
BluetoothDaemonGattServerInterface::ConnectPeripheral(
|
||||
int aServerIf, const nsAString& aBdAddr, bool aIsDirect, /* auto connect */
|
||||
BluetoothTransport aTransport, BluetoothGattServerResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
nsresult rv = mModule->ServerConnectPeripheralCmd(
|
||||
aServerIf, aBdAddr, aIsDirect, aTransport, aRes);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
DispatchError(aRes, rv);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonGattServerInterface::DisconnectPeripheral(
|
||||
int aServerIf, const nsAString& aBdAddr, int aConnId,
|
||||
BluetoothGattServerResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
nsresult rv = mModule->ServerDisconnectPeripheralCmd(
|
||||
aServerIf, aBdAddr, aConnId, aRes);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
DispatchError(aRes, rv);
|
||||
}
|
||||
}
|
||||
|
||||
/* Add a services / a characteristic / a descriptor */
|
||||
void
|
||||
BluetoothDaemonGattServerInterface::AddService(
|
||||
int aServerIf, const BluetoothGattServiceId& aServiceId, int aNumHandles,
|
||||
BluetoothGattServerResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
nsresult rv = mModule->ServerAddServiceCmd(
|
||||
aServerIf, aServiceId, aNumHandles, aRes);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
DispatchError(aRes, rv);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonGattServerInterface::AddIncludedService(
|
||||
int aServerIf, int aServiceHandle, int aIncludedServiceHandle,
|
||||
BluetoothGattServerResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
nsresult rv = mModule->ServerAddIncludedServiceCmd(
|
||||
aServerIf, aServiceHandle, aIncludedServiceHandle, aRes);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
DispatchError(aRes, rv);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonGattServerInterface::AddCharacteristic(
|
||||
int aServerIf, int aServiceHandle, const BluetoothUuid& aUuid,
|
||||
BluetoothGattCharProp aProperties, BluetoothGattAttrPerm aPermissions,
|
||||
BluetoothGattServerResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
nsresult rv = mModule->ServerAddCharacteristicCmd(
|
||||
aServerIf, aServiceHandle, aUuid, aProperties, aPermissions, aRes);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
DispatchError(aRes, rv);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonGattServerInterface::AddDescriptor(
|
||||
int aServerIf, int aServiceHandle, const BluetoothUuid& aUuid,
|
||||
BluetoothGattAttrPerm aPermissions, BluetoothGattServerResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
nsresult rv = mModule->ServerAddDescriptorCmd(
|
||||
aServerIf, aServiceHandle, aUuid, aPermissions, aRes);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
DispatchError(aRes, rv);
|
||||
}
|
||||
}
|
||||
|
||||
/* Start / Stop / Delete a service */
|
||||
void
|
||||
BluetoothDaemonGattServerInterface::StartService(
|
||||
int aServerIf, int aServiceHandle, BluetoothTransport aTransport,
|
||||
BluetoothGattServerResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
nsresult rv = mModule->ServerStartServiceCmd(
|
||||
aServerIf, aServiceHandle, aTransport, aRes);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
DispatchError(aRes, rv);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonGattServerInterface::StopService(
|
||||
int aServerIf, int aServiceHandle, BluetoothGattServerResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
nsresult rv = mModule->ServerStopServiceCmd(aServerIf, aServiceHandle, aRes);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
DispatchError(aRes, rv);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonGattServerInterface::DeleteService(
|
||||
int aServerIf, int aServiceHandle, BluetoothGattServerResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
nsresult rv = mModule->ServerDeleteServiceCmd(
|
||||
aServerIf, aServiceHandle, aRes);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
DispatchError(aRes, rv);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonGattServerInterface::SendIndication(
|
||||
int aServerIf, int aAttributeHandle, int aConnId,
|
||||
const nsTArray<uint8_t>& aValue, bool aConfirm,
|
||||
BluetoothGattServerResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
nsresult rv = mModule->ServerSendIndicationCmd(
|
||||
aServerIf, aAttributeHandle, aConnId,
|
||||
aValue.Length() * sizeof(uint8_t), aConfirm,
|
||||
const_cast<uint8_t*>(aValue.Elements()), aRes);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
DispatchError(aRes, rv);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonGattServerInterface::SendResponse(
|
||||
int aConnId, int aTransId, BluetoothGattStatus aStatus,
|
||||
const BluetoothGattResponse& aResponse,
|
||||
BluetoothGattServerResultHandler* aRes)
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
nsresult rv = mModule->ServerSendResponseCmd(
|
||||
aConnId, aTransId, aStatus, aResponse, aRes);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
DispatchError(aRes, rv);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonGattClientInterface::DispatchError(
|
||||
BluetoothGattClientResultHandler* aRes, BluetoothStatus aStatus)
|
||||
@ -2780,6 +2982,28 @@ BluetoothDaemonGattClientInterface::DispatchError(
|
||||
DispatchError(aRes, status);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonGattServerInterface::DispatchError(
|
||||
BluetoothGattServerResultHandler* aRes, BluetoothStatus aStatus)
|
||||
{
|
||||
BluetoothResultRunnable1<BluetoothGattServerResultHandler, void,
|
||||
BluetoothStatus, BluetoothStatus>::Dispatch(
|
||||
aRes, &BluetoothGattResultHandler::OnError,
|
||||
ConstantInitOp1<BluetoothStatus>(aStatus));
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonGattServerInterface::DispatchError(
|
||||
BluetoothGattServerResultHandler* aRes, nsresult aRv)
|
||||
{
|
||||
BluetoothStatus status;
|
||||
|
||||
if (NS_WARN_IF(NS_FAILED(Convert(aRv, status)))) {
|
||||
status = STATUS_FAIL;
|
||||
}
|
||||
DispatchError(aRes, status);
|
||||
}
|
||||
|
||||
void
|
||||
BluetoothDaemonGattInterface::DispatchError(
|
||||
BluetoothGattResultHandler* aRes, BluetoothStatus aStatus)
|
||||
@ -2813,4 +3037,15 @@ BluetoothDaemonGattInterface::GetBluetoothGattClientInterface()
|
||||
return gattClientInterface;
|
||||
}
|
||||
|
||||
BluetoothGattServerInterface*
|
||||
BluetoothDaemonGattInterface::GetBluetoothGattServerInterface()
|
||||
{
|
||||
MOZ_ASSERT(mModule);
|
||||
|
||||
BluetoothDaemonGattServerInterface* gattServerInterface =
|
||||
new BluetoothDaemonGattServerInterface(mModule);
|
||||
|
||||
return gattServerInterface;
|
||||
}
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
@ -800,6 +800,7 @@ public:
|
||||
void Cleanup(BluetoothGattResultHandler* aRes);
|
||||
|
||||
BluetoothGattClientInterface* GetBluetoothGattClientInterface();
|
||||
BluetoothGattServerInterface* GetBluetoothGattServerInterface();
|
||||
|
||||
private:
|
||||
void DispatchError(BluetoothGattResultHandler* aRes,
|
||||
@ -945,7 +946,86 @@ private:
|
||||
BluetoothDaemonGattModule* mModule;
|
||||
};
|
||||
|
||||
// TODO: Add GattServerInterface
|
||||
class BluetoothDaemonGattServerInterface final
|
||||
: public BluetoothGattServerInterface
|
||||
{
|
||||
public:
|
||||
BluetoothDaemonGattServerInterface(BluetoothDaemonGattModule* aModule);
|
||||
|
||||
/* Register / Unregister */
|
||||
void RegisterServer(const BluetoothUuid& aUuid,
|
||||
BluetoothGattServerResultHandler* aRes);
|
||||
void UnregisterServer(int aServerIf,
|
||||
BluetoothGattServerResultHandler* aRes);
|
||||
|
||||
/* Connect / Disconnect */
|
||||
void ConnectPeripheral(int aServerIf,
|
||||
const nsAString& aBdAddr,
|
||||
bool aIsDirect, /* auto connect */
|
||||
BluetoothTransport aTransport,
|
||||
BluetoothGattServerResultHandler* aRes);
|
||||
void DisconnectPeripheral(int aServerIf,
|
||||
const nsAString& aBdAddr,
|
||||
int aConnId,
|
||||
BluetoothGattServerResultHandler* aRes);
|
||||
|
||||
/* Add a services / a characteristic / a descriptor */
|
||||
void AddService(int aServerIf,
|
||||
const BluetoothGattServiceId& aServiceId,
|
||||
int aNumHandles,
|
||||
BluetoothGattServerResultHandler* aRes);
|
||||
void AddIncludedService(int aServerIf,
|
||||
int aServiceHandle,
|
||||
int aIncludedServiceHandle,
|
||||
BluetoothGattServerResultHandler* aRes);
|
||||
void AddCharacteristic(int aServerIf,
|
||||
int aServiceHandle,
|
||||
const BluetoothUuid& aUuid,
|
||||
BluetoothGattCharProp aProperties,
|
||||
BluetoothGattAttrPerm aPermissions,
|
||||
BluetoothGattServerResultHandler* aRes);
|
||||
void AddDescriptor(int aServerIf,
|
||||
int aServiceHandle,
|
||||
const BluetoothUuid& aUuid,
|
||||
BluetoothGattAttrPerm aPermissions,
|
||||
BluetoothGattServerResultHandler* aRes);
|
||||
|
||||
/* Start / Stop / Delete a service */
|
||||
void StartService(int aServerIf,
|
||||
int aServiceHandle,
|
||||
BluetoothTransport aTransport,
|
||||
BluetoothGattServerResultHandler* aRes);
|
||||
void StopService(int aServerIf,
|
||||
int aServiceHandle,
|
||||
BluetoothGattServerResultHandler* aRes);
|
||||
void DeleteService(int aServerIf,
|
||||
int aServiceHandle,
|
||||
BluetoothGattServerResultHandler* aRes);
|
||||
|
||||
/* Send an indication or a notification */
|
||||
void SendIndication(
|
||||
int aServerIf,
|
||||
int aAttributeHandle,
|
||||
int aConnId,
|
||||
const nsTArray<uint8_t>& aValue,
|
||||
bool aConfirm, /* true: indication, false: notification */
|
||||
BluetoothGattServerResultHandler* aRes);
|
||||
|
||||
/* Send a response for an incoming indication */
|
||||
void SendResponse(int aConnId,
|
||||
int aTransId,
|
||||
BluetoothGattStatus aStatus,
|
||||
const BluetoothGattResponse& aResponse,
|
||||
BluetoothGattServerResultHandler* aRes);
|
||||
|
||||
|
||||
private:
|
||||
void DispatchError(BluetoothGattServerResultHandler* aRes,
|
||||
BluetoothStatus aStatus);
|
||||
void DispatchError(BluetoothGattServerResultHandler* aRes, nsresult aRv);
|
||||
BluetoothDaemonGattModule* mModule;
|
||||
};
|
||||
|
||||
END_BLUETOOTH_NAMESPACE
|
||||
|
||||
#endif
|
||||
|
@ -33,6 +33,7 @@ namespace {
|
||||
StaticRefPtr<BluetoothGattManager> sBluetoothGattManager;
|
||||
static BluetoothGattInterface* sBluetoothGattInterface;
|
||||
static BluetoothGattClientInterface* sBluetoothGattClientInterface;
|
||||
static BluetoothGattServerInterface* sBluetoothGattServerInterface;
|
||||
} // anonymous namespace
|
||||
|
||||
bool BluetoothGattManager::mInShutdown = false;
|
||||
@ -306,6 +307,10 @@ BluetoothGattManager::InitGattInterface(BluetoothProfileResultHandler* aRes)
|
||||
sBluetoothGattInterface->GetBluetoothGattClientInterface();
|
||||
NS_ENSURE_TRUE_VOID(sBluetoothGattClientInterface);
|
||||
|
||||
sBluetoothGattServerInterface =
|
||||
sBluetoothGattInterface->GetBluetoothGattServerInterface();
|
||||
NS_ENSURE_TRUE_VOID(sBluetoothGattServerInterface);
|
||||
|
||||
if (!sClients) {
|
||||
sClients = new nsTArray<nsRefPtr<BluetoothGattClient> >;
|
||||
}
|
||||
@ -335,6 +340,7 @@ public:
|
||||
void Cleanup() override
|
||||
{
|
||||
sBluetoothGattClientInterface = nullptr;
|
||||
sBluetoothGattServerInterface = nullptr;
|
||||
sBluetoothGattInterface = nullptr;
|
||||
sClients = nullptr;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user