Skip to content

Commit

Permalink
BT[Device|Security]Registry: Inline static func definition in header …
Browse files Browse the repository at this point in the history
…and add noexcept, include 'em in DirectBT.hpp
  • Loading branch information
sgothel committed Sep 1, 2021
1 parent 73f9420 commit 39b34d8
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 64 deletions.
44 changes: 22 additions & 22 deletions api/direct_bt/BTDeviceRegistry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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}
Expand All @@ -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;
});
Expand All @@ -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
Expand All @@ -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
Expand Down
24 changes: 12 additions & 12 deletions api/direct_bt/BTSecurityRegistry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,23 @@ 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}.
* <p>
* 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}.
* <p>
* 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,
Expand All @@ -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) );
Expand All @@ -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) );
Expand All @@ -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);
});
Expand All @@ -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 );
Expand All @@ -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;
});
Expand All @@ -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}
Expand All @@ -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

Expand Down
3 changes: 3 additions & 0 deletions api/direct_bt/DirectBT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@

#include "SMPKeyBin.hpp"

#include "BTDeviceRegistry.hpp"
#include "BTSecurityRegistry.hpp"

#endif /* DIRECTBT_HPP_ */
3 changes: 0 additions & 3 deletions examples/direct_bt_scanner10/dbt_scanner10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@

#include <direct_bt/DirectBT.hpp>

#include <direct_bt/BTDeviceRegistry.hpp>
#include <direct_bt/BTSecurityRegistry.hpp>

extern "C" {
#include <unistd.h>
}
Expand Down
40 changes: 20 additions & 20 deletions src/direct_bt/BTDeviceRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) ) {
Expand All @@ -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 ) {
Expand All @@ -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) {
Expand All @@ -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());
Expand All @@ -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;
Expand All @@ -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 ) {
Expand All @@ -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());
Expand All @@ -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();
}
Expand Down
Loading

0 comments on commit 39b34d8

Please sign in to comment.