aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-02-01 16:36:59 +0100
committerSven Gothel <[email protected]>2021-02-01 16:36:59 +0100
commitfe3caaf19c429a2fda0a747603e46c39dde4716c (patch)
tree393af70d6022b1d4be51c842e117e437a90e0926
parentb59336ba412fb61046d7f896320b26e797d834e4 (diff)
DBTDevice.hpp/cpp: Remove const_cast on now explicit mutable mutex and atomic-sync members in const methods.
-rw-r--r--api/direct_bt/BTDevice.hpp10
-rw-r--r--src/direct_bt/BTDevice.cpp24
2 files changed, 17 insertions, 17 deletions
diff --git a/api/direct_bt/BTDevice.hpp b/api/direct_bt/BTDevice.hpp
index ae12e33b..f48fee8d 100644
--- a/api/direct_bt/BTDevice.hpp
+++ b/api/direct_bt/BTDevice.hpp
@@ -75,9 +75,9 @@ namespace direct_bt {
std::recursive_mutex mtx_smpHandler;
#endif
std::shared_ptr<BTGattHandler> gattHandler = nullptr;
- std::recursive_mutex mtx_gattHandler;
- std::recursive_mutex mtx_connect;
- std::recursive_mutex mtx_data;
+ mutable std::recursive_mutex mtx_gattHandler;
+ mutable std::recursive_mutex mtx_connect;
+ mutable std::recursive_mutex mtx_data;
std::atomic<bool> isConnected;
std::atomic<bool> allowDisconnect; // allowDisconnect = isConnected || 'isConnectIssued'
@@ -111,8 +111,8 @@ namespace direct_bt {
SMPSignatureResolvingKeyInfo csrk_init, csrk_resp;
};
PairingData pairing_data;
- std::mutex mtx_pairing;
- jau::sc_atomic_bool sync_pairing;
+ mutable std::mutex mtx_pairing;
+ mutable jau::sc_atomic_bool sync_pairing;
/** Private class only for private make_shared(). */
class ctor_cookie { friend BTDevice; ctor_cookie(const uint16_t secret) { (void)secret; } };
diff --git a/src/direct_bt/BTDevice.cpp b/src/direct_bt/BTDevice.cpp
index 27fd5be4..bc01a65e 100644
--- a/src/direct_bt/BTDevice.cpp
+++ b/src/direct_bt/BTDevice.cpp
@@ -120,24 +120,24 @@ int BTDevice::findAdvService(std::shared_ptr<uuid_t> const &uuid) const noexcept
}
std::string const BTDevice::getName() const noexcept {
- const std::lock_guard<std::recursive_mutex> lock(const_cast<BTDevice*>(this)->mtx_data); // RAII-style acquire and relinquish via destructor
+ const std::lock_guard<std::recursive_mutex> lock(mtx_data); // RAII-style acquire and relinquish via destructor
return name;
}
std::shared_ptr<ManufactureSpecificData> const BTDevice::getManufactureSpecificData() const noexcept {
- const std::lock_guard<std::recursive_mutex> lock(const_cast<BTDevice*>(this)->mtx_data); // RAII-style acquire and relinquish via destructor
+ const std::lock_guard<std::recursive_mutex> lock(mtx_data); // RAII-style acquire and relinquish via destructor
return advMSD;
}
jau::darray<std::shared_ptr<uuid_t>> BTDevice::getAdvertisedServices() const noexcept {
- const std::lock_guard<std::recursive_mutex> lock(const_cast<BTDevice*>(this)->mtx_data); // RAII-style acquire and relinquish via destructor
+ const std::lock_guard<std::recursive_mutex> lock(mtx_data); // RAII-style acquire and relinquish via destructor
return advServices;
}
std::string BTDevice::toString(bool includeDiscoveredServices) const noexcept {
- const std::lock_guard<std::recursive_mutex> lock(const_cast<BTDevice*>(this)->mtx_data); // RAII-style acquire and relinquish via destructor
+ const std::lock_guard<std::recursive_mutex> lock(mtx_data); // RAII-style acquire and relinquish via destructor
const uint64_t t0 = jau::getCurrentMilliseconds();
- jau::sc_atomic_critical sync(const_cast<BTDevice*>(this)->sync_pairing);
+ jau::sc_atomic_critical sync(sync_pairing);
std::string msdstr = nullptr != advMSD ? advMSD->toString() : "MSD[null]";
std::string out("Device["+addressAndType.toString()+", name['"+name+
"'], age[total "+std::to_string(t0-ts_creation)+", ldisc "+std::to_string(t0-ts_last_discovery)+", lup "+std::to_string(t0-ts_last_update)+
@@ -960,7 +960,7 @@ void BTDevice::hciSMPMsgCallback(std::shared_ptr<BTDevice> sthis, const SMPPDUMs
}
SMPKeyType BTDevice::getAvailableSMPKeys(const bool responder) const noexcept {
- jau::sc_atomic_critical sync(const_cast<BTDevice*>(this)->sync_pairing);
+ jau::sc_atomic_critical sync(sync_pairing);
if( responder ) {
return pairing_data.keys_resp_has;
} else {
@@ -969,7 +969,7 @@ SMPKeyType BTDevice::getAvailableSMPKeys(const bool responder) const noexcept {
}
SMPLongTermKeyInfo BTDevice::getLongTermKeyInfo(const bool responder) const noexcept {
- jau::sc_atomic_critical sync(const_cast<BTDevice*>(this)->sync_pairing);
+ jau::sc_atomic_critical sync(sync_pairing);
return responder ? pairing_data.ltk_resp : pairing_data.ltk_init;
}
@@ -991,7 +991,7 @@ HCIStatusCode BTDevice::setLongTermKeyInfo(const SMPLongTermKeyInfo& ltk) noexce
}
SMPSignatureResolvingKeyInfo BTDevice::getSignatureResolvingKeyInfo(const bool responder) const noexcept {
- jau::sc_atomic_critical sync(const_cast<BTDevice*>(this)->sync_pairing);
+ jau::sc_atomic_critical sync(sync_pairing);
return responder ? pairing_data.csrk_resp : pairing_data.csrk_init;
}
@@ -1044,7 +1044,7 @@ bool BTDevice::setConnSecurityLevel(const BTSecurityLevel sec_level) noexcept {
}
BTSecurityLevel BTDevice::getConnSecurityLevel() const noexcept {
- jau::sc_atomic_critical sync(const_cast<BTDevice*>(this)->sync_pairing);
+ jau::sc_atomic_critical sync(sync_pairing);
return pairing_data.sec_level_conn;
}
@@ -1071,7 +1071,7 @@ bool BTDevice::setConnIOCapability(const SMPIOCapability io_cap) noexcept {
}
SMPIOCapability BTDevice::getConnIOCapability() const noexcept {
- jau::sc_atomic_critical sync(const_cast<BTDevice*>(this)->sync_pairing);
+ jau::sc_atomic_critical sync(sync_pairing);
return pairing_data.ioCap_conn;
}
@@ -1172,12 +1172,12 @@ HCIStatusCode BTDevice::setPairingNumericComparison(const bool positive) noexcep
}
PairingMode BTDevice::getPairingMode() const noexcept {
- jau::sc_atomic_critical sync(const_cast<BTDevice*>(this)->sync_pairing);
+ jau::sc_atomic_critical sync(sync_pairing);
return pairing_data.mode;
}
SMPPairingState BTDevice::getPairingState() const noexcept {
- jau::sc_atomic_critical sync(const_cast<BTDevice*>(this)->sync_pairing);
+ jau::sc_atomic_critical sync(sync_pairing);
return pairing_data.state;
}