summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-11-13 04:55:34 +0100
committerSven Gothel <[email protected]>2021-11-13 04:55:34 +0100
commit518e9df7f00134c12a402da1174410d285376c28 (patch)
treef2e83e62835331032e8d73dbac4bb101bb95bb0a /api
parentb131b42ebfb64ee66e59fe9c41ee66840a9f7bf1 (diff)
Use 'typedef std::shared_ptr<BTDevice> BTDeviceRef' to shorten code lines
Diffstat (limited to 'api')
-rw-r--r--api/direct_bt/BTAdapter.hpp50
-rw-r--r--api/direct_bt/BTDevice.hpp2
-rw-r--r--api/direct_bt/BTGattHandler.hpp9
3 files changed, 32 insertions, 29 deletions
diff --git a/api/direct_bt/BTAdapter.hpp b/api/direct_bt/BTAdapter.hpp
index 92e655f0..6c6020f8 100644
--- a/api/direct_bt/BTAdapter.hpp
+++ b/api/direct_bt/BTAdapter.hpp
@@ -141,7 +141,7 @@ namespace direct_bt {
* @return true if the device shall be made persistent and BTDevice::remove() issued later. Otherwise false to remove device right away.
* @see BTDevice::unpair()
*/
- virtual bool deviceFound(std::shared_ptr<BTDevice> device, const uint64_t timestamp) {
+ virtual bool deviceFound(BTDeviceRef device, const uint64_t timestamp) {
(void)device;
(void)timestamp;
return false;
@@ -153,7 +153,7 @@ namespace direct_bt {
* @param updateMask the update mask of changed data
* @param timestamp the time in monotonic milliseconds when this event occurred. See BasicTypes::getCurrentMilliseconds().
*/
- virtual void deviceUpdated(std::shared_ptr<BTDevice> device, const EIRDataType updateMask, const uint64_t timestamp) {
+ virtual void deviceUpdated(BTDeviceRef device, const EIRDataType updateMask, const uint64_t timestamp) {
(void)device;
(void)updateMask;
(void)timestamp;
@@ -169,7 +169,7 @@ namespace direct_bt {
* @param timestamp the time in monotonic milliseconds when this event occurred. See BasicTypes::getCurrentMilliseconds().
* @see BTDevice::unpair()
*/
- virtual void deviceConnected(std::shared_ptr<BTDevice> device, const uint16_t handle, const uint64_t timestamp) {
+ virtual void deviceConnected(BTDeviceRef device, const uint16_t handle, const uint64_t timestamp) {
(void)device;
(void)handle;
(void)timestamp;
@@ -184,7 +184,7 @@ namespace direct_bt {
* @see BTDevice::setPairingPasskey()
* @see BTDevice::setPairingNumericComparison()
*/
- virtual void devicePairingState(std::shared_ptr<BTDevice> device, const SMPPairingState state, const PairingMode mode, const uint64_t timestamp) {
+ virtual void devicePairingState(BTDeviceRef device, const SMPPairingState state, const PairingMode mode, const uint64_t timestamp) {
(void)device;
(void)state;
(void)mode;
@@ -200,7 +200,7 @@ namespace direct_bt {
* @param timestamp the time in monotonic milliseconds when this event occurred. See BasicTypes::getCurrentMilliseconds().
* @see ::SMPPairingState::COMPLETED
*/
- virtual void deviceReady(std::shared_ptr<BTDevice> device, const uint64_t timestamp) {
+ virtual void deviceReady(BTDeviceRef device, const uint64_t timestamp) {
(void)device;
(void)timestamp;
}
@@ -216,7 +216,7 @@ namespace direct_bt {
* @param timestamp the time in monotonic milliseconds when this event occurred. See BasicTypes::getCurrentMilliseconds().
* @see BTDevice::unpair()
*/
- virtual void deviceDisconnected(std::shared_ptr<BTDevice> device, const HCIStatusCode reason, const uint16_t handle, const uint64_t timestamp) {
+ virtual void deviceDisconnected(BTDeviceRef device, const HCIStatusCode reason, const uint16_t handle, const uint64_t timestamp) {
(void)device;
(void)reason;
(void)handle;
@@ -322,7 +322,7 @@ namespace direct_bt {
std::mutex mtx_single_conn_device;
std::condition_variable cv_single_conn_device;
- typedef jau::darray<std::shared_ptr<BTDevice>> device_list_t;
+ typedef jau::darray<BTDeviceRef> device_list_t;
/** All discovered devices: Transient until removeDiscoveredDevices(), startDiscovery(). */
device_list_t discoveredDevices;
/** All connected devices: Transient until disconnect or removal. */
@@ -352,8 +352,8 @@ namespace direct_bt {
bool initialSetup() noexcept;
bool enableListening(const bool enable) noexcept;
- static std::shared_ptr<BTDevice> findDevice(device_list_t & devices, const EUI48 & address, const BDAddressType addressType) noexcept;
- static std::shared_ptr<BTDevice> findDevice(device_list_t & devices, BTDevice const & device) noexcept;
+ static BTDeviceRef findDevice(device_list_t & devices, const EUI48 & address, const BDAddressType addressType) noexcept;
+ static BTDeviceRef findDevice(device_list_t & devices, BTDevice const & device) noexcept;
static void printDeviceList(const std::string& prefix, const BTAdapter::device_list_t& list) noexcept;
/** Private class only for private make_shared(). */
@@ -377,7 +377,7 @@ namespace direct_bt {
*/
void poweredOff(bool active) noexcept;
- friend std::shared_ptr<BTDevice> BTDevice::getSharedInstance() const noexcept;
+ friend BTDeviceRef BTDevice::getSharedInstance() const noexcept;
friend void BTDevice::remove() noexcept;
friend BTDevice::~BTDevice() noexcept;
@@ -388,28 +388,28 @@ namespace direct_bt {
uint16_t min_interval, uint16_t max_interval,
uint16_t latency, uint16_t supervision_timeout) noexcept;
friend HCIStatusCode BTDevice::connectBREDR(const uint16_t pkt_type, const uint16_t clock_offset, const uint8_t role_switch) noexcept;
- friend void BTDevice::processL2CAPSetup(std::shared_ptr<BTDevice> sthis);
- friend bool BTDevice::updatePairingState(std::shared_ptr<BTDevice> sthis, const MgmtEvent& evt, const HCIStatusCode evtStatus, SMPPairingState claimed_state) noexcept;
- friend void BTDevice::hciSMPMsgCallback(std::shared_ptr<BTDevice> sthis, const SMPPDUMsg& msg, const HCIACLData::l2cap_frame& source) noexcept;
- friend void BTDevice::processDeviceReady(std::shared_ptr<BTDevice> sthis, const uint64_t timestamp);
+ friend void BTDevice::processL2CAPSetup(BTDeviceRef sthis);
+ friend bool BTDevice::updatePairingState(BTDeviceRef sthis, const MgmtEvent& evt, const HCIStatusCode evtStatus, SMPPairingState claimed_state) noexcept;
+ friend void BTDevice::hciSMPMsgCallback(BTDeviceRef sthis, const SMPPDUMsg& msg, const HCIACLData::l2cap_frame& source) noexcept;
+ friend void BTDevice::processDeviceReady(BTDeviceRef sthis, const uint64_t timestamp);
friend jau::darray<std::shared_ptr<BTGattService>> BTDevice::getGattServices() noexcept;
bool lockConnect(const BTDevice & device, const bool wait, const SMPIOCapability io_cap) noexcept;
bool unlockConnect(const BTDevice & device) noexcept;
bool unlockConnectAny() noexcept;
- bool addConnectedDevice(const std::shared_ptr<BTDevice> & device) noexcept;
+ bool addConnectedDevice(const BTDeviceRef & device) noexcept;
bool removeConnectedDevice(const BTDevice & device) noexcept;
int disconnectAllDevices(const HCIStatusCode reason=HCIStatusCode::REMOTE_USER_TERMINATED_CONNECTION ) noexcept;
- std::shared_ptr<BTDevice> findConnectedDevice (const EUI48 & address, const BDAddressType & addressType) noexcept;
+ BTDeviceRef findConnectedDevice (const EUI48 & address, const BDAddressType & addressType) noexcept;
int getConnectedDeviceCount() const noexcept;
- bool addDiscoveredDevice(std::shared_ptr<BTDevice> const &device) noexcept;
+ bool addDiscoveredDevice(BTDeviceRef const &device) noexcept;
void removeDevice(BTDevice & device) noexcept;
- bool addSharedDevice(std::shared_ptr<BTDevice> const &device) noexcept;
- std::shared_ptr<BTDevice> getSharedDevice(const BTDevice & device) noexcept;
+ bool addSharedDevice(BTDeviceRef const &device) noexcept;
+ BTDeviceRef getSharedDevice(const BTDevice & device) noexcept;
void removeSharedDevice(const BTDevice & device) noexcept;
static SMPKeyBinRef findSMPKeyBin(key_list_t & keys, BDAddressAndType const & remoteAddress) noexcept;
@@ -456,8 +456,8 @@ namespace direct_bt {
bool hciSMPMsgCallback(const BDAddressAndType & addressAndType,
const SMPPDUMsg& msg, const HCIACLData::l2cap_frame& source) noexcept;
- void sendDevicePairingState(std::shared_ptr<BTDevice> device, const SMPPairingState state, const PairingMode mode, uint64_t timestamp) noexcept;
- void sendDeviceReady(std::shared_ptr<BTDevice> device, uint64_t timestamp) noexcept;
+ void sendDevicePairingState(BTDeviceRef device, const SMPPairingState state, const PairingMode mode, uint64_t timestamp) noexcept;
+ void sendDeviceReady(BTDeviceRef device, uint64_t timestamp) noexcept;
void startDiscoveryBackground() noexcept;
void checkDiscoveryState() noexcept;
@@ -466,7 +466,7 @@ namespace direct_bt {
const uint64_t timestampMS) noexcept;
void sendAdapterSettingsInitial(AdapterStatusListener & asl, const uint64_t timestampMS) noexcept;
- void sendDeviceUpdated(std::string cause, std::shared_ptr<BTDevice> device, uint64_t timestamp, EIRDataType updateMask) noexcept;
+ void sendDeviceUpdated(std::string cause, BTDeviceRef device, uint64_t timestamp, EIRDataType updateMask) noexcept;
int removeAllStatusListener(const BTDevice& d);
@@ -974,7 +974,7 @@ namespace direct_bt {
* use 'DeviceStatusListener::deviceFound(..)' callback.
* </p>
*/
- jau::darray<std::shared_ptr<BTDevice>> getDiscoveredDevices() const noexcept;
+ jau::darray<BTDeviceRef> getDiscoveredDevices() const noexcept;
/** Discards all discovered devices. Returns number of removed discovered devices. */
int removeDiscoveredDevices() noexcept;
@@ -983,10 +983,10 @@ namespace direct_bt {
bool removeDiscoveredDevice(const BDAddressAndType & addressAndType) noexcept;
/** Returns shared BTDevice if found, otherwise nullptr */
- std::shared_ptr<BTDevice> findDiscoveredDevice (const EUI48 & address, const BDAddressType addressType) noexcept;
+ BTDeviceRef findDiscoveredDevice (const EUI48 & address, const BDAddressType addressType) noexcept;
/** Returns shared BTDevice if found, otherwise nullptr */
- std::shared_ptr<BTDevice> findSharedDevice (const EUI48 & address, const BDAddressType addressType) noexcept;
+ BTDeviceRef findSharedDevice (const EUI48 & address, const BDAddressType addressType) noexcept;
/**
* Starts advertising
diff --git a/api/direct_bt/BTDevice.hpp b/api/direct_bt/BTDevice.hpp
index d1e23777..4239c92f 100644
--- a/api/direct_bt/BTDevice.hpp
+++ b/api/direct_bt/BTDevice.hpp
@@ -1249,6 +1249,8 @@ namespace direct_bt {
inline bool operator!=(const BTDevice& lhs, const BTDevice& rhs) noexcept
{ return !(lhs == rhs); }
+ typedef std::shared_ptr<BTDevice> BTDeviceRef;
+
} // namespace direct_bt
#endif /* BT_DEVICE_HPP_ */
diff --git a/api/direct_bt/BTGattHandler.hpp b/api/direct_bt/BTGattHandler.hpp
index aa756403..0eec414f 100644
--- a/api/direct_bt/BTGattHandler.hpp
+++ b/api/direct_bt/BTGattHandler.hpp
@@ -58,6 +58,7 @@
namespace direct_bt {
class BTDevice; // forward
+ typedef std::shared_ptr<BTDevice> BTDeviceRef;
/**
* GATT Singleton runtime environment properties
@@ -218,7 +219,7 @@ namespace direct_bt {
bool hasServerHandle(const uint16_t handle) noexcept;
DBGattChar* findServerGattCharByValueHandle(const uint16_t char_value_handle) noexcept;
- AttErrorRsp::ErrorCode applyWrite(std::shared_ptr<BTDevice> device, const uint16_t handle, const jau::TROOctets & value, const uint16_t value_offset);
+ AttErrorRsp::ErrorCode applyWrite(BTDeviceRef device, const uint16_t handle, const jau::TROOctets & value, const uint16_t value_offset);
void replyWriteReq(const AttPDUMsg * pdu);
void replyReadReq(const AttPDUMsg * pdu);
void replyFindInfoReq(const AttFindInfoReq * pdu);
@@ -291,7 +292,7 @@ namespace direct_bt {
* @param l2cap_att the underlying used L2CAP
* @param supervision_timeout the connection supervising timeout in [ms]
*/
- BTGattHandler(const std::shared_ptr<BTDevice> & device, L2CAPComm& l2cap_att, const int32_t supervision_timeout) noexcept;
+ BTGattHandler(const BTDeviceRef & device, L2CAPComm& l2cap_att, const int32_t supervision_timeout) noexcept;
BTGattHandler(const BTGattHandler&) = delete;
void operator=(const BTGattHandler&) = delete;
@@ -299,8 +300,8 @@ namespace direct_bt {
/** Destructor closing this instance including L2CAP channel, see {@link #disconnect()}. */
~BTGattHandler() noexcept;
- std::shared_ptr<BTDevice> getDeviceUnchecked() const noexcept { return wbr_device.lock(); }
- std::shared_ptr<BTDevice> getDeviceChecked() const;
+ BTDeviceRef getDeviceUnchecked() const noexcept { return wbr_device.lock(); }
+ BTDeviceRef getDeviceChecked() const;
/**
* Return the local GATTRole to the remote BTDevice.