aboutsummaryrefslogtreecommitdiffstats
path: root/api/direct_bt
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2021-08-04 04:53:33 +0200
committerSven Gothel <[email protected]>2021-08-04 04:53:33 +0200
commite4d18c7c17c1e6356747e5ad17c85ed9a47cc2da (patch)
treeb3c3183be67ad917c71af7a8a49e63ef2c447c1d /api/direct_bt
parent2476284db28c32c219c76ba8bcd3db7a6aaa1ba7 (diff)
BTDeviceRegistry + BTSecurityRegistry: Expose underlying collection (C++ and Java)
Diffstat (limited to 'api/direct_bt')
-rw-r--r--api/direct_bt/BTDeviceRegistry.hpp93
-rw-r--r--api/direct_bt/BTSecurityRegistry.hpp12
2 files changed, 105 insertions, 0 deletions
diff --git a/api/direct_bt/BTDeviceRegistry.hpp b/api/direct_bt/BTDeviceRegistry.hpp
index a09c5248..3879eb2c 100644
--- a/api/direct_bt/BTDeviceRegistry.hpp
+++ b/api/direct_bt/BTDeviceRegistry.hpp
@@ -38,24 +38,117 @@ namespace direct_bt {
* The latter on a pattern matching basis, i.e. EUI48Sub or name-sub.
*/
namespace BTDeviceRegistry {
+ /**
+ * Specifies devices queries to act upon.
+ */
+ struct DeviceQuery {
+ EUI48Sub addressSub;
+ std::string nameSub;
+ DeviceQuery(const EUI48Sub& as, const std::string& ns) : addressSub(as), nameSub(ns) {}
+ DeviceQuery() : addressSub(), nameSub() {}
+ std::string toString() const {
+ if( addressSub.length>0 ) {
+ return addressSub.toString();
+ } else {
+ return "'"+nameSub+"'";
+ }
+ }
+ };
+
void addToWaitForDevices(const std::string& addrOrNameSub);
bool isWaitingForDevice(const BDAddressAndType &mac, const std::string &name);
bool isWaitingForAnyDevice();
size_t getWaitForDevicesCount();
void printWaitForDevices(FILE *out, const std::string &msg);
+ /**
+ * Returns the reference of the current list of DeviceQuery, not a copy.
+ */
+ jau::darray<DeviceQuery>& getWaitForDevices();
+ /**
+ * Clears internal list
+ */
+ void clearWaitForDevices();
+
+ /**
+ * Specifies unique device identities,
+ * using {@link BDAddressAndType} as key.
+ */
+ struct DeviceID {
+ BDAddressAndType addressAndType;
+ std::string name;
+
+ DeviceID(const BDAddressAndType& a, const std::string& n) : addressAndType(a), name(n) {}
+ DeviceID() : addressAndType(), name() {}
+
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Implementation simply returns the BDAddressAndType hash code,
+ * `name` is ignored.
+ * </p>
+ */
+ std::size_t hash_code() const noexcept {
+ return addressAndType.hash_code();
+ }
+
+ std::string toString() const {
+ return "["+addressAndType.toString()+", '"+name+"']";
+ }
+ };
+ /**
+ * {@inheritDoc}
+ * <p>
+ * Implementation simply tests the {@link BDAddressAndType} fields for equality,
+ * `name` is ignored.
+ * </p>
+ */
+ inline bool operator==(const DeviceID& lhs, const DeviceID& rhs) noexcept {
+ if( &lhs == &rhs ) {
+ return true;
+ }
+ return lhs.addressAndType == rhs.addressAndType;
+ }
+ inline bool operator!=(const DeviceID& lhs, const DeviceID& rhs) noexcept
+ { return !(lhs == rhs); }
void addToDevicesProcessed(const BDAddressAndType &a, const std::string& n);
bool isDeviceProcessed(const BDAddressAndType & a);
size_t getDeviceProcessedCount();
bool allDevicesProcessed();
void printDevicesProcessed(FILE *out, const std::string &msg);
+ /**
+ * Returns a copy of the current collection of processed DeviceID.
+ */
+ jau::darray<DeviceID> getProcessedDevices();
+ /**
+ * Clears internal list
+ */
+ void clearProcessedDevices();
void addToDevicesProcessing(const BDAddressAndType &a, const std::string& n);
bool removeFromDevicesProcessing(const BDAddressAndType &a);
bool isDeviceProcessing(const BDAddressAndType & a);
size_t getDeviceProcessingCount();
+ /**
+ * Returns a copy of the current collection of processing DeviceID.
+ */
+ jau::darray<DeviceID> getProcessingDevices();
+ /**
+ * Clears internal list
+ */
+ void clearProcessingDevices();
}
} // namespace direct_bt
+// injecting specialization of std::hash to namespace std of our types above
+namespace std
+{
+ template<> struct hash<direct_bt::BTDeviceRegistry::DeviceID> {
+ std::size_t operator()(direct_bt::BTDeviceRegistry::DeviceID const& a) const noexcept {
+ return a.hash_code();
+ }
+ };
+}
+
#endif /* DBT_DEV_ACCOUNTING_HPP_ */
diff --git a/api/direct_bt/BTSecurityRegistry.hpp b/api/direct_bt/BTSecurityRegistry.hpp
index ace42cd1..969a7ec9 100644
--- a/api/direct_bt/BTSecurityRegistry.hpp
+++ b/api/direct_bt/BTSecurityRegistry.hpp
@@ -93,7 +93,19 @@ namespace direct_bt {
Entry* get(const EUI48& addr);
Entry* get(const EUI48Sub& addrSub);
Entry* get(const std::string& nameSub);
+
+ /**
+ * Returns the reference of the current list of Entry, not a copy.
+ */
+ jau::darray<Entry>& getEntries();
+
Entry* getOrCreate(const std::string& addrOrNameSub);
+
+ /**
+ * Clears internal list
+ */
+ void clear();
+
std::string allToString();
} // namespace BTSecurityRegistry