diff options
author | Sven Gothel <[email protected]> | 2021-09-01 12:55:24 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-09-01 12:55:24 +0200 |
commit | 39b34d8480a6a2516665845c98cb153c788555b9 (patch) | |
tree | 1c053230e5f0ee176efcec0c7ea93b9bb06cbd61 | |
parent | 73f9420460dcd3a362bfafad55976a74eac85336 (diff) |
BT[Device|Security]Registry: Inline static func definition in header and add noexcept, include 'em in DirectBT.hpp
-rw-r--r-- | api/direct_bt/BTDeviceRegistry.hpp | 44 | ||||
-rw-r--r-- | api/direct_bt/BTSecurityRegistry.hpp | 24 | ||||
-rw-r--r-- | api/direct_bt/DirectBT.hpp | 3 | ||||
-rw-r--r-- | examples/direct_bt_scanner10/dbt_scanner10.cpp | 3 | ||||
-rw-r--r-- | src/direct_bt/BTDeviceRegistry.cpp | 40 | ||||
-rw-r--r-- | src/direct_bt/BTSecurityRegistry.cpp | 14 |
6 files changed, 64 insertions, 64 deletions
diff --git a/api/direct_bt/BTDeviceRegistry.hpp b/api/direct_bt/BTDeviceRegistry.hpp index d15c5279..1c9c3848 100644 --- a/api/direct_bt/BTDeviceRegistry.hpp +++ b/api/direct_bt/BTDeviceRegistry.hpp @@ -71,18 +71,18 @@ namespace direct_bt { } }; - void addToWaitForDevices(const std::string& addrOrNameSub); - bool isWaitingForAnyDevice(); - size_t getWaitForDevicesCount(); - std::string getWaitForDevicesString(); + void addToWaitForDevices(const std::string& addrOrNameSub) noexcept; + bool isWaitingForAnyDevice() noexcept; + size_t getWaitForDevicesCount() noexcept; + std::string getWaitForDevicesString() noexcept; /** * Returns the reference of the current list of DeviceQuery, not a copy. */ - jau::darray<DeviceQuery>& getWaitForDevices(); + jau::darray<DeviceQuery>& getWaitForDevices() noexcept; /** * Clears internal list */ - void clearWaitForDevices(); + void clearWaitForDevices() noexcept; /** * Specifies unique device identities, @@ -126,20 +126,20 @@ namespace direct_bt { inline bool operator!=(const DeviceID& lhs, const DeviceID& rhs) noexcept { return !(lhs == rhs); } - void addToProcessedDevices(const BDAddressAndType &a, const std::string& n); - bool isDeviceProcessed(const BDAddressAndType & a); - size_t getProcessedDeviceCount(); + void addToProcessedDevices(const BDAddressAndType &a, const std::string& n) noexcept; + bool isDeviceProcessed(const BDAddressAndType & a) noexcept; + size_t getProcessedDeviceCount() noexcept; - std::string getProcessedDevicesString(); + std::string getProcessedDevicesString() noexcept; /** * Returns a copy of the current collection of processed DeviceID. */ - jau::darray<DeviceID> getProcessedDevices(); + jau::darray<DeviceID> getProcessedDevices() noexcept; /** * Clears internal list */ - void clearProcessedDevices(); + void clearProcessedDevices() noexcept; /** * Function for user defined BTDeviceRegistry::DeviceQuery matching criteria and algorithm. @@ -167,7 +167,7 @@ namespace direct_bt { * </p> * @see BTDeviceRegistry::isWaitingForDevice() */ - bool isWaitingForDevice(const EUI48 &address, const std::string &name, DeviceQueryMatchFunc m); + bool isWaitingForDevice(const EUI48 &address, const std::string &name, DeviceQueryMatchFunc m) noexcept; /** * Returns {@code true} if the given {@code address} and/or {@code name} @@ -182,7 +182,7 @@ namespace direct_bt { * </p> * @see BTDeviceRegistry::isWaitingForDevice() */ - bool isWaitingForDevice(const EUI48 &address, const std::string &name) { + inline bool isWaitingForDevice(const EUI48 &address, const std::string &name) noexcept { return isWaitingForDevice(address, name, [](const EUI48& a, const std::string& n, const DeviceQuery& q)->bool { return q.isEUI48Sub() ? a.contains(q.addressSub) : n.find(q.nameSub) != std::string::npos; }); @@ -196,7 +196,7 @@ namespace direct_bt { * </p> * @see BTDeviceRegistry::areAllDevicesProcessed() */ - bool areAllDevicesProcessed(DeviceQueryMatchFunc m); + bool areAllDevicesProcessed(DeviceQueryMatchFunc m) noexcept; /** * Returns {@code true} if all addToWaitForDevices() awaited devices @@ -211,24 +211,24 @@ namespace direct_bt { * </p> * @see BTDeviceRegistry::areAllDevicesProcessed() */ - bool areAllDevicesProcessed() { + inline bool areAllDevicesProcessed() noexcept { return areAllDevicesProcessed( [](const EUI48& a, const std::string& n, const DeviceQuery& q)->bool { return q.isEUI48Sub() ? a.contains(q.addressSub) : n.find(q.nameSub) != std::string::npos; }); } - void addToProcessingDevices(const BDAddressAndType &a, const std::string& n); - bool removeFromProcessingDevices(const BDAddressAndType &a); - bool isDeviceProcessing(const BDAddressAndType & a); - size_t getProcessingDeviceCount(); + void addToProcessingDevices(const BDAddressAndType &a, const std::string& n) noexcept; + bool removeFromProcessingDevices(const BDAddressAndType &a) noexcept; + bool isDeviceProcessing(const BDAddressAndType & a) noexcept; + size_t getProcessingDeviceCount() noexcept; /** * Returns a copy of the current collection of processing DeviceID. */ - jau::darray<DeviceID> getProcessingDevices(); + jau::darray<DeviceID> getProcessingDevices() noexcept; /** * Clears internal list */ - void clearProcessingDevices(); + void clearProcessingDevices() noexcept; } } // namespace direct_bt diff --git a/api/direct_bt/BTSecurityRegistry.hpp b/api/direct_bt/BTSecurityRegistry.hpp index e96c773e..d3e507b9 100644 --- a/api/direct_bt/BTSecurityRegistry.hpp +++ b/api/direct_bt/BTSecurityRegistry.hpp @@ -125,7 +125,7 @@ namespace direct_bt { * Matching criteria and algorithm is defined by the given AddressNameEntryMatchFunc. * </p> */ - Entry* get(const EUI48& addr, const std::string& name, AddressNameEntryMatchFunc m); + Entry* get(const EUI48& addr, const std::string& name, AddressNameEntryMatchFunc m) noexcept; /** * Returns a matching BTSecurityRegistry::Entry with the given {@code addrSub} and/or {@code name}. @@ -133,7 +133,7 @@ namespace direct_bt { * Matching criteria and algorithm is defined by the given AddressSubNameEntryMatchFunc. * </p> */ - Entry* get(const EUI48Sub& addrSub, const std::string& name, AddressSubNameEntryMatchFunc m); + Entry* get(const EUI48Sub& addrSub, const std::string& name, AddressSubNameEntryMatchFunc m) noexcept; /** * Returns a matching BTSecurityRegistry::Entry with the given {@code name}. @@ -141,7 +141,7 @@ namespace direct_bt { * Matching criteria and algorithm is defined by the given NameEntryMatchFunc. * </p> */ - Entry* get(const std::string& name, NameEntryMatchFunc m); + Entry* get(const std::string& name, NameEntryMatchFunc m) noexcept; /** * Returns a matching Entry, @@ -150,7 +150,7 @@ namespace direct_bt { * * Otherwise {@code null} is returned. */ - Entry* getStartOf(const EUI48& addr, const std::string& name) { + inline Entry* getStartOf(const EUI48& addr, const std::string& name) noexcept { return get(addr, name, [](const EUI48& a, const std::string& n, const Entry& e)->bool { return ( e.addrSub.length > 0 && 0 == a.indexOf(e.addrSub) ) || ( e.nameSub.length() > 0 && 0 == n.find(e.nameSub) ); @@ -163,7 +163,7 @@ namespace direct_bt { * * Otherwise {@code null} is returned. */ - Entry* getStartOf(const EUI48Sub& addrSub, const std::string& name) { + inline Entry* getStartOf(const EUI48Sub& addrSub, const std::string& name) noexcept { return get(addrSub, name, [](const EUI48Sub& as, const std::string& n, const Entry& e)->bool { return ( e.addrSub.length > 0 && 0 == as.indexOf(e.addrSub) ) || ( e.nameSub.length() > 0 && 0 == n.find(e.nameSub) ); @@ -175,7 +175,7 @@ namespace direct_bt { * * Otherwise {@code null} is returned. */ - Entry* getStartOf(const std::string& name) { + inline Entry* getStartOf(const std::string& name) noexcept { return get(name, [](const std::string& n, const Entry& e)->bool { return e.nameSub.length() > 0 && 0 == n.find(e.nameSub); }); @@ -188,7 +188,7 @@ namespace direct_bt { * * Otherwise {@code null} is returned. */ - Entry* getEqual(const EUI48Sub& addrSub, const std::string& name) { + inline Entry* getEqual(const EUI48Sub& addrSub, const std::string& name) noexcept { return get(addrSub, name, [](const EUI48Sub& as, const std::string& n, const Entry& e)->bool { return ( e.addrSub.length > 0 && as == e.addrSub ) || ( e.nameSub.length() > 0 && n == e.nameSub ); @@ -200,7 +200,7 @@ namespace direct_bt { * * Otherwise {@code null} is returned. */ - Entry* getEqual(const std::string& name) { + inline Entry* getEqual(const std::string& name) noexcept { return get(name, [](const std::string& n, const Entry& e)->bool { return e.nameSub.length() > 0 && n == e.nameSub; }); @@ -209,7 +209,7 @@ namespace direct_bt { /** * Returns the reference of the current list of Entry, not a copy. */ - jau::darray<Entry>& getEntries(); + jau::darray<Entry>& getEntries() noexcept; /** * Determines whether the given {@code addrOrNameSub} is a EUI48Sub or just a {@code name} @@ -220,14 +220,14 @@ namespace direct_bt { * @param addrOrNameSub either a EUI48Sub or just a name * @return new or existing instance */ - Entry* getOrCreate(const std::string& addrOrNameSub); + Entry* getOrCreate(const std::string& addrOrNameSub) noexcept; /** * Clears internal list */ - void clear(); + void clear() noexcept; - std::string allToString(); + std::string allToString() noexcept; } // namespace BTSecurityRegistry diff --git a/api/direct_bt/DirectBT.hpp b/api/direct_bt/DirectBT.hpp index b573b2fe..44d7d0f0 100644 --- a/api/direct_bt/DirectBT.hpp +++ b/api/direct_bt/DirectBT.hpp @@ -52,4 +52,7 @@ #include "SMPKeyBin.hpp" +#include "BTDeviceRegistry.hpp" +#include "BTSecurityRegistry.hpp" + #endif /* DIRECTBT_HPP_ */ diff --git a/examples/direct_bt_scanner10/dbt_scanner10.cpp b/examples/direct_bt_scanner10/dbt_scanner10.cpp index 6964769b..396788c6 100644 --- a/examples/direct_bt_scanner10/dbt_scanner10.cpp +++ b/examples/direct_bt_scanner10/dbt_scanner10.cpp @@ -42,9 +42,6 @@ #include <direct_bt/DirectBT.hpp> -#include <direct_bt/BTDeviceRegistry.hpp> -#include <direct_bt/BTSecurityRegistry.hpp> - extern "C" { #include <unistd.h> } diff --git a/src/direct_bt/BTDeviceRegistry.cpp b/src/direct_bt/BTDeviceRegistry.cpp index 54123fa0..83b1de7c 100644 --- a/src/direct_bt/BTDeviceRegistry.cpp +++ b/src/direct_bt/BTDeviceRegistry.cpp @@ -43,7 +43,7 @@ namespace direct_bt::BTDeviceRegistry { static std::unordered_set<DeviceID> devicesProcessed; static std::recursive_mutex mtx_devicesProcessed; - void addToWaitForDevices(const std::string& addrOrNameSub) { + void addToWaitForDevices(const std::string& addrOrNameSub) noexcept { EUI48Sub addr1; std::string errmsg; if( EUI48Sub::scanEUI48Sub(addrOrNameSub, addr1, errmsg) ) { @@ -53,13 +53,13 @@ namespace direct_bt::BTDeviceRegistry { waitForDevices.emplace_back( addrOrNameSub ); } } - bool isWaitingForAnyDevice() { + bool isWaitingForAnyDevice() noexcept { return !waitForDevices.empty(); } - size_t getWaitForDevicesCount() { + size_t getWaitForDevicesCount() noexcept { return waitForDevices.size(); } - std::string getWaitForDevicesString() { + std::string getWaitForDevicesString() noexcept { std::string res; jau::for_each(waitForDevices.cbegin(), waitForDevices.cend(), [&res](const DeviceQuery &q) { if( res.length() > 0 ) { @@ -70,26 +70,26 @@ namespace direct_bt::BTDeviceRegistry { return res; } - jau::darray<DeviceQuery>& getWaitForDevices() { + jau::darray<DeviceQuery>& getWaitForDevices() noexcept { return waitForDevices; } - void clearWaitForDevices() { + void clearWaitForDevices() noexcept { waitForDevices.clear(); } - void addToProcessedDevices(const BDAddressAndType &a, const std::string& n) { + void addToProcessedDevices(const BDAddressAndType &a, const std::string& n) noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_devicesProcessed); // RAII-style acquire and relinquish via destructor devicesProcessed.emplace_hint(devicesProcessed.end(), a, n); } - bool isDeviceProcessed(const BDAddressAndType & a) { + bool isDeviceProcessed(const BDAddressAndType & a) noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_devicesProcessed); // RAII-style acquire and relinquish via destructor return devicesProcessed.end() != devicesProcessed.find( DeviceID(a, "") ); } - size_t getProcessedDeviceCount() { + size_t getProcessedDeviceCount() noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_devicesProcessed); // RAII-style acquire and relinquish via destructor return devicesProcessed.size(); } - std::string getProcessedDevicesString() { + std::string getProcessedDevicesString() noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_devicesProcessed); // RAII-style acquire and relinquish via destructor std::string res; jau::for_each(devicesProcessed.cbegin(), devicesProcessed.cend(), [&res](const DeviceID &id) { @@ -100,7 +100,7 @@ namespace direct_bt::BTDeviceRegistry { }); return res; } - jau::darray<DeviceID> getProcessedDevices() { + jau::darray<DeviceID> getProcessedDevices() noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_devicesProcessed); // RAII-style acquire and relinquish via destructor // std::unordered_set<DeviceID>::iterator is not suitable for: // return jau::darray<DeviceID>(devicesProcessed.size(), devicesProcessed.begin(), devicesProcessed.end()); @@ -112,18 +112,18 @@ namespace direct_bt::BTDeviceRegistry { } return res; } - void clearProcessedDevices() { + void clearProcessedDevices() noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_devicesProcessed); // RAII-style acquire and relinquish via destructor devicesProcessed.clear(); } - bool isWaitingForDevice(const EUI48 &address, const std::string &name, DeviceQueryMatchFunc m) { + bool isWaitingForDevice(const EUI48 &address, const std::string &name, DeviceQueryMatchFunc m) noexcept { return waitForDevices.cend() != jau::find_if(waitForDevices.cbegin(), waitForDevices.cend(), [&](const DeviceQuery & it)->bool { return m(address, name, it); }); } - bool areAllDevicesProcessed(DeviceQueryMatchFunc m) { + bool areAllDevicesProcessed(DeviceQueryMatchFunc m) noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_devicesProcessed); // RAII-style acquire and relinquish via destructor for (auto it1 = waitForDevices.cbegin(); it1 != waitForDevices.cend(); ++it1) { const DeviceQuery& q = *it1; @@ -142,11 +142,11 @@ namespace direct_bt::BTDeviceRegistry { return true; } - void addToProcessingDevices(const BDAddressAndType &a, const std::string& n) { + void addToProcessingDevices(const BDAddressAndType &a, const std::string& n) noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_devicesProcessing); // RAII-style acquire and relinquish via destructor devicesInProcessing.emplace_hint(devicesInProcessing.end(), a, n); } - bool removeFromProcessingDevices(const BDAddressAndType &a) { + bool removeFromProcessingDevices(const BDAddressAndType &a) noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_devicesProcessing); // RAII-style acquire and relinquish via destructor auto it = devicesInProcessing.find( DeviceID(a, "") ); if( devicesInProcessing.end() != it ) { @@ -155,15 +155,15 @@ namespace direct_bt::BTDeviceRegistry { } return false; } - bool isDeviceProcessing(const BDAddressAndType & a) { + bool isDeviceProcessing(const BDAddressAndType & a) noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_devicesProcessing); // RAII-style acquire and relinquish via destructor return devicesInProcessing.end() != devicesInProcessing.find( DeviceID(a, "") ); } - size_t getProcessingDeviceCount() { + size_t getProcessingDeviceCount() noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_devicesProcessing); // RAII-style acquire and relinquish via destructor return devicesInProcessing.size(); } - jau::darray<DeviceID> getProcessingDevices() { + jau::darray<DeviceID> getProcessingDevices() noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_devicesProcessing); // RAII-style acquire and relinquish via destructor // std::unordered_set<DeviceID>::iterator is not suitable for: // return jau::darray<DeviceID>(devicesInProcessing.size(), devicesInProcessing.begin(), devicesInProcessing.end()); @@ -175,7 +175,7 @@ namespace direct_bt::BTDeviceRegistry { } return res; } - void clearProcessingDevices() { + void clearProcessingDevices() noexcept { const std::lock_guard<std::recursive_mutex> lock(mtx_devicesProcessing); // RAII-style acquire and relinquish via destructor devicesInProcessing.clear(); } diff --git a/src/direct_bt/BTSecurityRegistry.cpp b/src/direct_bt/BTSecurityRegistry.cpp index 70c7c6f0..a75915c1 100644 --- a/src/direct_bt/BTSecurityRegistry.cpp +++ b/src/direct_bt/BTSecurityRegistry.cpp @@ -33,7 +33,7 @@ namespace direct_bt::BTSecurityRegistry { static jau::darray<Entry> devicesSecDetails; - Entry* get(const EUI48& addr, const std::string& name, AddressNameEntryMatchFunc m) { + Entry* get(const EUI48& addr, const std::string& name, AddressNameEntryMatchFunc m) noexcept { auto first = devicesSecDetails.begin(); auto last = devicesSecDetails.end(); for (; first != last; ++first) { @@ -43,7 +43,7 @@ namespace direct_bt::BTSecurityRegistry { } return nullptr; } - Entry* get(const EUI48Sub& addrSub, const std::string& name, AddressSubNameEntryMatchFunc m) { + Entry* get(const EUI48Sub& addrSub, const std::string& name, AddressSubNameEntryMatchFunc m) noexcept { auto first = devicesSecDetails.begin(); auto last = devicesSecDetails.end(); for (; first != last; ++first) { @@ -53,7 +53,7 @@ namespace direct_bt::BTSecurityRegistry { } return nullptr; } - Entry* get(const std::string& name, NameEntryMatchFunc m) { + Entry* get(const std::string& name, NameEntryMatchFunc m) noexcept { auto first = devicesSecDetails.begin(); auto last = devicesSecDetails.end(); for (; first != last; ++first) { @@ -64,11 +64,11 @@ namespace direct_bt::BTSecurityRegistry { return nullptr; } - jau::darray<Entry>& getEntries() { + jau::darray<Entry>& getEntries() noexcept { return devicesSecDetails; } - Entry* getOrCreate(const std::string& addrOrNameSub) { + Entry* getOrCreate(const std::string& addrOrNameSub) noexcept { EUI48Sub addr1; std::string errmsg; Entry* sec = nullptr; @@ -87,10 +87,10 @@ namespace direct_bt::BTSecurityRegistry { } return sec; } - void clear() { + void clear() noexcept { devicesSecDetails.clear(); } - std::string allToString() { + std::string allToString() noexcept { std::string res; int i=0; for(auto iter = devicesSecDetails.cbegin(); iter != devicesSecDetails.cend(); ++iter, ++i) { |