mirror of https://github.com/ARMmbed/mbed-os.git
ble: GattClient PIMPL
parent
909676d159
commit
e3cf59e6cd
|
@ -90,7 +90,9 @@ namespace ble {
|
||||||
* if it intends to register to server initiated events.
|
* if it intends to register to server initiated events.
|
||||||
*/
|
*/
|
||||||
#if !defined(DOXYGEN_ONLY)
|
#if !defined(DOXYGEN_ONLY)
|
||||||
namespace interface {
|
namespace impl {
|
||||||
|
class GattClient;
|
||||||
|
}
|
||||||
#endif // !defined(DOXYGEN_ONLY)
|
#endif // !defined(DOXYGEN_ONLY)
|
||||||
class GattClient {
|
class GattClient {
|
||||||
public:
|
public:
|
||||||
|
@ -703,6 +705,9 @@ public:
|
||||||
* registered handlers.
|
* registered handlers.
|
||||||
*/
|
*/
|
||||||
void processHVXEvent(const GattHVXCallbackParams *params);
|
void processHVXEvent(const GattHVXCallbackParams *params);
|
||||||
|
|
||||||
|
private:
|
||||||
|
impl::GattClient *impl;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -711,14 +716,11 @@ public:
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if !defined(DOXYGEN_ONLY)
|
|
||||||
} // namespace interface
|
|
||||||
#endif // !defined(DOXYGEN_ONLY)
|
|
||||||
} // namespace ble
|
} // namespace ble
|
||||||
|
|
||||||
/* This includes the concrete class implementation, to provide a an alternative API implementation
|
/* This includes the concrete class implementation, to provide a an alternative API implementation
|
||||||
* disable ble-api-implementation and place your header in a path with the same structure */
|
* disable ble-api-implementation and place your header in a path with the same structure */
|
||||||
#include "ble/internal/GattClientImpl.h"
|
//#include "ble/internal/GattClientImpl.h"
|
||||||
|
|
||||||
/** @deprecated Use the namespaced ble::GattClient instead of the global GattClient. */
|
/** @deprecated Use the namespaced ble::GattClient instead of the global GattClient. */
|
||||||
using ble::GattClient;
|
using ble::GattClient;
|
||||||
|
|
|
@ -19,9 +19,12 @@
|
||||||
#ifndef IMPL_GATT_CLIENT_H__
|
#ifndef IMPL_GATT_CLIENT_H__
|
||||||
#define IMPL_GATT_CLIENT_H__
|
#define IMPL_GATT_CLIENT_H__
|
||||||
|
|
||||||
|
#include "ble/BLE.h"
|
||||||
|
|
||||||
#include "CallChainOfFunctionPointersWithContext.h"
|
#include "CallChainOfFunctionPointersWithContext.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
#include "ble/common/ble/blecommon.h"
|
#include "ble/common/ble/blecommon.h"
|
||||||
#include "ble/common/ble/GattAttribute.h"
|
#include "ble/common/ble/GattAttribute.h"
|
||||||
#include "ble/common/ble/ServiceDiscovery.h"
|
#include "ble/common/ble/ServiceDiscovery.h"
|
||||||
|
@ -33,20 +36,33 @@
|
||||||
|
|
||||||
namespace ble {
|
namespace ble {
|
||||||
|
|
||||||
|
class BLEInstanceBase;
|
||||||
|
|
||||||
|
namespace impl {
|
||||||
|
|
||||||
class GattClient :
|
class GattClient :
|
||||||
public ble::interface::GattClient,
|
|
||||||
public PalSigningMonitor,
|
public PalSigningMonitor,
|
||||||
public PalGattClientEventHandler
|
public PalGattClientEventHandler {
|
||||||
{
|
|
||||||
friend PalSigningMonitor;
|
friend PalSigningMonitor;
|
||||||
friend BLEInstanceBase;
|
friend BLEInstanceBase;
|
||||||
public:
|
public:
|
||||||
|
using EventHandler = ble::GattClient::EventHandler;
|
||||||
|
using WriteOp_t = ble::GattClient::WriteOp_t;
|
||||||
|
using HVXCallback_t = ble::GattClient::HVXCallback_t ;
|
||||||
|
using GattClientShutdownCallback_t = ble::GattClient::GattClientShutdownCallback_t ;
|
||||||
|
using GattClientShutdownCallbackChain_t = ble::GattClient::GattClientShutdownCallbackChain_t ;
|
||||||
|
using HVXCallbackChain_t = ble::GattClient::HVXCallbackChain_t ;
|
||||||
|
using ReadCallbackChain_t = ble::GattClient::ReadCallbackChain_t ;
|
||||||
|
using WriteCallbackChain_t = ble::GattClient::WriteCallbackChain_t ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void setEventHandler(EventHandler *handler);
|
void setEventHandler(EventHandler *handler);
|
||||||
|
|
||||||
ble_error_t launchServiceDiscovery(
|
ble_error_t launchServiceDiscovery(
|
||||||
ble::connection_handle_t connectionHandle,
|
ble::connection_handle_t connectionHandle,
|
||||||
ServiceDiscovery::ServiceCallback_t sc = NULL,
|
ServiceDiscovery::ServiceCallback_t sc = NULL,
|
||||||
ServiceDiscovery::CharacteristicCallback_t cc = NULL,
|
ServiceDiscovery::CharacteristicCallback_t cc = NULL,
|
||||||
const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
|
const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
|
||||||
const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)
|
const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)
|
||||||
);
|
);
|
||||||
|
@ -86,28 +102,28 @@ public:
|
||||||
|
|
||||||
void onDataRead(ReadCallback_t callback);
|
void onDataRead(ReadCallback_t callback);
|
||||||
|
|
||||||
ReadCallbackChain_t& onDataRead();
|
ReadCallbackChain_t &onDataRead();
|
||||||
|
|
||||||
void onDataWritten(WriteCallback_t callback);
|
void onDataWritten(WriteCallback_t callback);
|
||||||
|
|
||||||
WriteCallbackChain_t& onDataWritten();
|
WriteCallbackChain_t &onDataWritten();
|
||||||
|
|
||||||
void onServiceDiscoveryTermination(
|
void onServiceDiscoveryTermination(
|
||||||
ServiceDiscovery::TerminationCallback_t callback
|
ServiceDiscovery::TerminationCallback_t callback
|
||||||
);
|
);
|
||||||
|
|
||||||
ble_error_t discoverCharacteristicDescriptors(
|
ble_error_t discoverCharacteristicDescriptors(
|
||||||
const DiscoveredCharacteristic& characteristic,
|
const DiscoveredCharacteristic &characteristic,
|
||||||
const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
|
const CharacteristicDescriptorDiscovery::DiscoveryCallback_t &discoveryCallback,
|
||||||
const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback
|
const CharacteristicDescriptorDiscovery::TerminationCallback_t &terminationCallback
|
||||||
);
|
);
|
||||||
|
|
||||||
bool isCharacteristicDescriptorDiscoveryActive(
|
bool isCharacteristicDescriptorDiscoveryActive(
|
||||||
const DiscoveredCharacteristic& characteristic
|
const DiscoveredCharacteristic &characteristic
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
void terminateCharacteristicDescriptorDiscovery(
|
void terminateCharacteristicDescriptorDiscovery(
|
||||||
const DiscoveredCharacteristic& characteristic
|
const DiscoveredCharacteristic &characteristic
|
||||||
);
|
);
|
||||||
|
|
||||||
ble_error_t negotiateAttMtu(ble::connection_handle_t connection);
|
ble_error_t negotiateAttMtu(ble::connection_handle_t connection);
|
||||||
|
@ -122,14 +138,14 @@ public:
|
||||||
*/
|
*/
|
||||||
void onHVX(HVXCallback_t callback);
|
void onHVX(HVXCallback_t callback);
|
||||||
|
|
||||||
void onShutdown(const GattClientShutdownCallback_t& callback);
|
void onShutdown(const GattClientShutdownCallback_t &callback);
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
void onShutdown(T *objPtr, void (T::*memberPtr)(const GattClient *));
|
void onShutdown(T *objPtr, void (T::*memberPtr)(const GattClient *));
|
||||||
|
|
||||||
GattClientShutdownCallbackChain_t& onShutdown();
|
GattClientShutdownCallbackChain_t &onShutdown();
|
||||||
|
|
||||||
HVXCallbackChain_t& onHVX();
|
HVXCallbackChain_t &onHVX();
|
||||||
|
|
||||||
ble_error_t reset(void);
|
ble_error_t reset(void);
|
||||||
|
|
||||||
|
@ -144,7 +160,8 @@ public:
|
||||||
private:
|
private:
|
||||||
/* Disallow copy and assignment. */
|
/* Disallow copy and assignment. */
|
||||||
GattClient(const GattClient &);
|
GattClient(const GattClient &);
|
||||||
GattClient& operator=(const GattClient &);
|
|
||||||
|
GattClient &operator=(const GattClient &);
|
||||||
|
|
||||||
/* ===================================================================== */
|
/* ===================================================================== */
|
||||||
/* private implementation follows */
|
/* private implementation follows */
|
||||||
|
@ -179,15 +196,22 @@ private:
|
||||||
struct WriteControlBlock;
|
struct WriteControlBlock;
|
||||||
struct DescriptorDiscoveryControlBlock;
|
struct DescriptorDiscoveryControlBlock;
|
||||||
|
|
||||||
ProcedureControlBlock* get_control_block(connection_handle_t connection);
|
ProcedureControlBlock *get_control_block(connection_handle_t connection);
|
||||||
const ProcedureControlBlock* get_control_block(connection_handle_t connection) const;
|
|
||||||
void insert_control_block(ProcedureControlBlock* cb) const;
|
const ProcedureControlBlock *get_control_block(connection_handle_t connection) const;
|
||||||
void remove_control_block(ProcedureControlBlock* cb) const;
|
|
||||||
|
void insert_control_block(ProcedureControlBlock *cb) const;
|
||||||
|
|
||||||
|
void remove_control_block(ProcedureControlBlock *cb) const;
|
||||||
|
|
||||||
void on_termination(connection_handle_t connection_handle);
|
void on_termination(connection_handle_t connection_handle);
|
||||||
void on_server_message_received(connection_handle_t, const AttServerMessage&);
|
|
||||||
void on_server_response(connection_handle_t, const AttServerMessage&);
|
void on_server_message_received(connection_handle_t, const AttServerMessage &);
|
||||||
void on_server_event(connection_handle_t, const AttServerMessage&);
|
|
||||||
|
void on_server_response(connection_handle_t, const AttServerMessage &);
|
||||||
|
|
||||||
|
void on_server_event(connection_handle_t, const AttServerMessage &);
|
||||||
|
|
||||||
void on_transaction_timeout(connection_handle_t);
|
void on_transaction_timeout(connection_handle_t);
|
||||||
|
|
||||||
uint16_t get_mtu(connection_handle_t connection) const;
|
uint16_t get_mtu(connection_handle_t connection) const;
|
||||||
|
@ -222,21 +246,27 @@ private:
|
||||||
*/
|
*/
|
||||||
GattClientShutdownCallbackChain_t shutdownCallChain;
|
GattClientShutdownCallbackChain_t shutdownCallChain;
|
||||||
|
|
||||||
PalGattClient& _pal_client;
|
PalGattClient &_pal_client;
|
||||||
ServiceDiscovery::TerminationCallback_t _termination_callback;
|
ServiceDiscovery::TerminationCallback_t _termination_callback;
|
||||||
PalSigningMonitorEventHandler* _signing_event_handler;
|
PalSigningMonitorEventHandler *_signing_event_handler;
|
||||||
mutable ProcedureControlBlock* control_blocks;
|
mutable ProcedureControlBlock *control_blocks;
|
||||||
bool _is_reseting;
|
bool _is_reseting;
|
||||||
|
|
||||||
|
// TODO initialize
|
||||||
|
::ble::GattClient *client;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
* Create a PalGattClient from a PalGattClient
|
* Create a PalGattClient from a PalGattClient
|
||||||
*/
|
*/
|
||||||
GattClient(PalGattClient& pal_client);
|
GattClient(PalGattClient &pal_client);
|
||||||
|
|
||||||
~GattClient() { }
|
~GattClient()
|
||||||
|
{
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace impl
|
||||||
} // namespace ble
|
} // namespace ble
|
||||||
|
|
||||||
#endif /* ifndef IMPL_GATT_CLIENT_H__ */
|
#endif /* ifndef IMPL_GATT_CLIENT_H__ */
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,211 @@
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
* Copyright (c) 2020 ARM Limited
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* mbed Microcontroller Library
|
||||||
|
* Copyright (c) 2006-2020 ARM Limited
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ble/GattClient.h"
|
||||||
|
#include "ble/internal/GattClientImpl.h"
|
||||||
|
|
||||||
|
namespace ble {
|
||||||
|
|
||||||
|
void GattClient::setEventHandler(EventHandler *handler)
|
||||||
|
{
|
||||||
|
impl->setEventHandler(handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
ble_error_t GattClient::launchServiceDiscovery(
|
||||||
|
ble::connection_handle_t connectionHandle,
|
||||||
|
ServiceDiscovery::ServiceCallback_t sc,
|
||||||
|
ServiceDiscovery::CharacteristicCallback_t cc,
|
||||||
|
const UUID &matchingServiceUUID,
|
||||||
|
const UUID &matchingCharacteristicUUIDIn
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return impl->launchServiceDiscovery(
|
||||||
|
connectionHandle, sc, cc, matchingServiceUUID, matchingCharacteristicUUIDIn
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ble_error_t GattClient::discoverServices(
|
||||||
|
ble::connection_handle_t connectionHandle,
|
||||||
|
ServiceDiscovery::ServiceCallback_t callback,
|
||||||
|
const UUID &matchingServiceUUID
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return impl->discoverServices(connectionHandle, callback, matchingServiceUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
ble_error_t GattClient::discoverServices(
|
||||||
|
ble::connection_handle_t connectionHandle,
|
||||||
|
ServiceDiscovery::ServiceCallback_t callback,
|
||||||
|
GattAttribute::Handle_t startHandle,
|
||||||
|
GattAttribute::Handle_t endHandle
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return impl->discoverServices(connectionHandle, callback, startHandle, endHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GattClient::isServiceDiscoveryActive(void) const
|
||||||
|
{
|
||||||
|
return impl->isServiceDiscoveryActive();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GattClient::terminateServiceDiscovery(void)
|
||||||
|
{
|
||||||
|
return impl->terminateServiceDiscovery();
|
||||||
|
}
|
||||||
|
|
||||||
|
ble_error_t GattClient::read(
|
||||||
|
ble::connection_handle_t connHandle,
|
||||||
|
GattAttribute::Handle_t attributeHandle,
|
||||||
|
uint16_t offset
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return impl->read(connHandle, attributeHandle, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
ble_error_t GattClient::write(
|
||||||
|
GattClient::WriteOp_t cmd,
|
||||||
|
ble::connection_handle_t connHandle,
|
||||||
|
GattAttribute::Handle_t attributeHandle,
|
||||||
|
size_t length,
|
||||||
|
const uint8_t *value
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return impl->write(cmd, connHandle, attributeHandle, length, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Event callback handlers. */
|
||||||
|
|
||||||
|
void GattClient::onDataRead(ble::ReadCallback_t callback)
|
||||||
|
{
|
||||||
|
return impl->onDataRead(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
ble::ReadCallbackChain_t& GattClient::onDataRead()
|
||||||
|
{
|
||||||
|
return impl->onDataRead();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GattClient::onDataWritten(ble::WriteCallback_t callback)
|
||||||
|
{
|
||||||
|
impl->onDataWritten(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
ble::WriteCallbackChain_t& GattClient::onDataWritten()
|
||||||
|
{
|
||||||
|
return impl->onDataWritten();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GattClient::onServiceDiscoveryTermination(
|
||||||
|
ServiceDiscovery::TerminationCallback_t callback
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return impl->onServiceDiscoveryTermination(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
ble_error_t GattClient::discoverCharacteristicDescriptors(
|
||||||
|
const DiscoveredCharacteristic& characteristic,
|
||||||
|
const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
|
||||||
|
const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return impl->discoverCharacteristicDescriptors(
|
||||||
|
characteristic,
|
||||||
|
discoveryCallback,
|
||||||
|
terminationCallback
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GattClient::isCharacteristicDescriptorDiscoveryActive(
|
||||||
|
const DiscoveredCharacteristic& characteristic
|
||||||
|
) const
|
||||||
|
{
|
||||||
|
return impl->isCharacteristicDescriptorDiscoveryActive(characteristic);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GattClient::terminateCharacteristicDescriptorDiscovery(
|
||||||
|
const DiscoveredCharacteristic& characteristic
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return impl->terminateCharacteristicDescriptorDiscovery(characteristic);
|
||||||
|
}
|
||||||
|
|
||||||
|
ble_error_t GattClient::negotiateAttMtu(ble::connection_handle_t connection)
|
||||||
|
{
|
||||||
|
return impl->negotiateAttMtu(connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GattClient::onHVX(HVXCallback_t callback)
|
||||||
|
{
|
||||||
|
return impl->onHVX(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GattClient::onShutdown(const GattClientShutdownCallback_t& callback)
|
||||||
|
{
|
||||||
|
return impl->onShutdown(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
GattClient::GattClientShutdownCallbackChain_t& GattClient::onShutdown()
|
||||||
|
{
|
||||||
|
return impl->onShutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
GattClient::HVXCallbackChain_t& GattClient::onHVX()
|
||||||
|
{
|
||||||
|
return impl->onHVX();
|
||||||
|
}
|
||||||
|
|
||||||
|
ble_error_t GattClient::reset(void)
|
||||||
|
{
|
||||||
|
return impl->reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GattClient::processReadResponse(const GattReadCallbackParams *params)
|
||||||
|
{
|
||||||
|
return impl->processReadResponse(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GattClient::processWriteResponse(const GattWriteCallbackParams *params)
|
||||||
|
{
|
||||||
|
return impl->processWriteResponse(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
void GattClient::processHVXEvent(const GattHVXCallbackParams *params)
|
||||||
|
{
|
||||||
|
return impl->processHVXEvent(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ble
|
||||||
|
|
Loading…
Reference in New Issue