diff options
author | Sven Gothel <[email protected]> | 2021-01-18 18:44:04 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2021-01-18 18:44:04 +0100 |
commit | a6d4061fbeabe75e1789a97be2457ff1274b9a73 (patch) | |
tree | 53bad95999406d5732eb66e9cb709def2051604d /examples/direct_bt_scanner01/dbt_scanner01.cpp | |
parent | 52779efd5e925f7b59848b52e3fa5e31919851ff (diff) |
DBTManager/DBTAdapter: DBTManager own zero or all DBTAdapter
DBTManager/DBTAdapter Relationship (C++)
aligning to Java DBTManager owning DBTAdapter to harmonize and simplify API
and DBTAdapter lifecycle in respect to the event-driven ChangedAdapterSetFunc() approach.
API doc reflecting this change WIP.
DBTManager:
- Owns all DBTAdapter
- processAdapterRemoved: Issue DBTAdapter::close() (align Java + C++ behavior)
- ChangedAdapterSetFunc passes 'std::shared_ptr<DBTAdapter>&', instead of 'dev_id' (like Java)
- Fix adding ChangedAdapterSetFunc: Only pass all known DBTAdapter through newly added callback, not all.
- Aligned method names with Java
-
DBTAdapter:
- No public ctor (DBTManager owns all);
- Owns adapterInfo;
- dtor unregisters instance in DBTManager;
- dev_id is uint16_t;
AdapterInfo: Support copy/move ctor and copy assignment
Diffstat (limited to 'examples/direct_bt_scanner01/dbt_scanner01.cpp')
-rw-r--r-- | examples/direct_bt_scanner01/dbt_scanner01.cpp | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/examples/direct_bt_scanner01/dbt_scanner01.cpp b/examples/direct_bt_scanner01/dbt_scanner01.cpp index 5a036a00..7e3a8db7 100644 --- a/examples/direct_bt_scanner01/dbt_scanner01.cpp +++ b/examples/direct_bt_scanner01/dbt_scanner01.cpp @@ -192,30 +192,29 @@ int main(int argc, char *argv[]) fprintf(stderr, "Press ENTER to continue\n"); getchar(); } + DBTManager & mngr = DBTManager::get(); - DBTAdapter adapter(dev_id); - if( !adapter.hasDevId() ) { - fprintf(stderr, "Default adapter not available.\n"); + std::shared_ptr<DBTAdapter> adapter = mngr.getAdapter(dev_id); + if( nullptr == adapter ) { + fprintf(stderr, "adapter dev_id %d not available.\n", dev_id); exit(1); } - if( !adapter.isValid() ) { - fprintf(stderr, "Adapter invalid.\n"); + if( !adapter->isValid() ) { + fprintf(stderr, "Adapter invalid: %s\n", adapter->toString().c_str()); exit(1); } - if( !adapter.isPowered() ) { - fprintf(stderr, "Adapter not powered: device %s, address %s: %s\n", - adapter.getName().c_str(), adapter.getAddressString().c_str(), adapter.toString().c_str()); + if( !adapter->isPowered() ) { + fprintf(stderr, "Adapter not powered: %s\n", adapter->toString().c_str()); exit(1); } - fprintf(stderr, "Using adapter: device %s, address %s: %s\n", - adapter.getName().c_str(), adapter.getAddressString().c_str(), adapter.toString().c_str()); + fprintf(stderr, "Using adapter: %s\n", adapter->toString().c_str()); - adapter.addStatusListener(std::shared_ptr<AdapterStatusListener>(new MyAdapterStatusListener())); + adapter->addStatusListener(std::shared_ptr<AdapterStatusListener>(new MyAdapterStatusListener())); const uint64_t t0 = getCurrentMilliseconds(); while( ok && ( forever || !foundDevice ) ) { - ok = HCIStatusCode::SUCCESS == adapter.startDiscovery(true /* keepAlive */); + ok = HCIStatusCode::SUCCESS == adapter->startDiscovery(true /* keepAlive */); if( !ok) { perror("Adapter start discovery failed"); goto out; @@ -235,7 +234,7 @@ int main(int argc, char *argv[]) } } } - adapter.stopDiscovery(); + adapter->stopDiscovery(); if( ok && nullptr != device ) { const uint64_t t1 = getCurrentMilliseconds(); |