aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2020-05-28 19:07:20 +0200
committerSven Gothel <[email protected]>2020-05-28 19:07:20 +0200
commitfafc8db2ed2f2975148665e7224412b72ac03df2 (patch)
treedd6ac35e6db3617fee632003cc2a005a6d99c516 /examples
parent7af0d9dee655f67b8531f3e42cb318b54259e135 (diff)
AdapterStatusListener (C++): Add toString() for error handling purposes; DBTDevice::toString(..) defaults to not incl. services
Diffstat (limited to 'examples')
-rw-r--r--examples/direct_bt_scanner00/dbt_scanner00.cpp10
-rw-r--r--examples/direct_bt_scanner01/dbt_scanner01.cpp10
-rw-r--r--examples/direct_bt_scanner10/dbt_scanner10.cpp20
3 files changed, 26 insertions, 14 deletions
diff --git a/examples/direct_bt_scanner00/dbt_scanner00.cpp b/examples/direct_bt_scanner00/dbt_scanner00.cpp
index 57d3d41a..09bb83e6 100644
--- a/examples/direct_bt_scanner00/dbt_scanner00.cpp
+++ b/examples/direct_bt_scanner00/dbt_scanner00.cpp
@@ -62,7 +62,7 @@ class MyAdapterStatusListener : public AdapterStatusListener {
}
void deviceFound(std::shared_ptr<DBTDevice> device, const uint64_t timestamp) override {
- fprintf(stderr, "****** FOUND__: %s\n", device->toString().c_str());
+ fprintf(stderr, "****** FOUND__: %s\n", device->toString(true).c_str());
fprintf(stderr, "Status Adapter:\n");
fprintf(stderr, "%s\n", device->getAdapter().toString().c_str());
{
@@ -73,17 +73,21 @@ class MyAdapterStatusListener : public AdapterStatusListener {
(void)timestamp;
}
void deviceUpdated(std::shared_ptr<DBTDevice> device, const uint64_t timestamp, const EIRDataType updateMask) override {
- fprintf(stderr, "****** UPDATED: %s of %s\n", eirDataMaskToString(updateMask).c_str(), device->toString().c_str());
+ fprintf(stderr, "****** UPDATED: %s of %s\n", eirDataMaskToString(updateMask).c_str(), device->toString(true).c_str());
fprintf(stderr, "Status Adapter:\n");
fprintf(stderr, "%s\n", device->getAdapter().toString().c_str());
(void)timestamp;
}
void deviceConnectionChanged(std::shared_ptr<DBTDevice> device, const bool connected, const uint64_t timestamp) override {
- fprintf(stderr, "****** CONNECTION: connected %d: %s\n", connected, device->toString().c_str());
+ fprintf(stderr, "****** CONNECTION: connected %d: %s\n", connected, device->toString(true).c_str());
fprintf(stderr, "Status Adapter:\n");
fprintf(stderr, "%s\n", device->getAdapter().toString().c_str());
(void)timestamp;
}
+
+ std::string toString() const override {
+ return "MyAdapterStatusListener[this "+aptrHexString(this)+"]";
+ }
};
static const uuid16_t _TEMPERATURE_MEASUREMENT(GattCharacteristicType::TEMPERATURE_MEASUREMENT);
diff --git a/examples/direct_bt_scanner01/dbt_scanner01.cpp b/examples/direct_bt_scanner01/dbt_scanner01.cpp
index 8d6d2d61..30b82b5d 100644
--- a/examples/direct_bt_scanner01/dbt_scanner01.cpp
+++ b/examples/direct_bt_scanner01/dbt_scanner01.cpp
@@ -61,7 +61,7 @@ class MyAdapterStatusListener : public AdapterStatusListener {
}
void deviceFound(std::shared_ptr<DBTDevice> device, const uint64_t timestamp) override {
- fprintf(stderr, "****** FOUND__: %s\n", device->toString().c_str());
+ fprintf(stderr, "****** FOUND__: %s\n", device->toString(true).c_str());
fprintf(stderr, "Status Adapter:\n");
fprintf(stderr, "%s\n", device->getAdapter().toString().c_str());
{
@@ -72,17 +72,21 @@ class MyAdapterStatusListener : public AdapterStatusListener {
(void)timestamp;
}
void deviceUpdated(std::shared_ptr<DBTDevice> device, const uint64_t timestamp, const EIRDataType updateMask) override {
- fprintf(stderr, "****** UPDATED: %s of %s\n", eirDataMaskToString(updateMask).c_str(), device->toString().c_str());
+ fprintf(stderr, "****** UPDATED: %s of %s\n", eirDataMaskToString(updateMask).c_str(), device->toString(true).c_str());
fprintf(stderr, "Status Adapter:\n");
fprintf(stderr, "%s\n", device->getAdapter().toString().c_str());
(void)timestamp;
}
void deviceConnectionChanged(std::shared_ptr<DBTDevice> device, const bool connected, const uint64_t timestamp) override {
- fprintf(stderr, "****** CONNECTION: connected %d: %s\n", connected, device->toString().c_str());
+ fprintf(stderr, "****** CONNECTION: connected %d: %s\n", connected, device->toString(true).c_str());
fprintf(stderr, "Status Adapter:\n");
fprintf(stderr, "%s\n", device->getAdapter().toString().c_str());
(void)timestamp;
}
+
+ std::string toString() const override {
+ return "MyAdapterStatusListener[this "+aptrHexString(this)+"]";
+ }
};
static const uuid16_t _TEMPERATURE_MEASUREMENT(GattCharacteristicType::TEMPERATURE_MEASUREMENT);
diff --git a/examples/direct_bt_scanner10/dbt_scanner10.cpp b/examples/direct_bt_scanner10/dbt_scanner10.cpp
index ebc7b8cd..d6190f99 100644
--- a/examples/direct_bt_scanner10/dbt_scanner10.cpp
+++ b/examples/direct_bt_scanner10/dbt_scanner10.cpp
@@ -158,7 +158,7 @@ class MyAdapterStatusListener : public AdapterStatusListener {
if( BDAddressType::BDADDR_LE_PUBLIC != device->getAddressType() &&
BDAddressType::BDADDR_LE_RANDOM != device->getAddressType() ) {
- fprintf(stderr, "****** FOUND__-2: Skip non LE %s\n", device->toString().c_str());
+ fprintf(stderr, "****** FOUND__-2: Skip non LE %s\n", device->toString(true).c_str());
return;
}
if( waitForDevice == EUI48_ANY_DEVICE ||
@@ -167,16 +167,16 @@ class MyAdapterStatusListener : public AdapterStatusListener {
!isDeviceTaskInProgress(device)
) )
{
- fprintf(stderr, "****** FOUND__-0: Connecting %s\n", device->toString().c_str());
+ fprintf(stderr, "****** FOUND__-0: Connecting %s\n", device->toString(true).c_str());
std::thread dc(::deviceConnectTask, device);
dc.detach();
} else {
- fprintf(stderr, "****** FOUND__-1: NOP %s\n", device->toString().c_str());
+ fprintf(stderr, "****** FOUND__-1: NOP %s\n", device->toString(true).c_str());
}
}
void deviceUpdated(std::shared_ptr<DBTDevice> device, const uint64_t timestamp, const EIRDataType updateMask) override {
- fprintf(stderr, "****** UPDATED: %s of %s\n", eirDataMaskToString(updateMask).c_str(), device->toString().c_str());
+ fprintf(stderr, "****** UPDATED: %s of %s\n", eirDataMaskToString(updateMask).c_str(), device->toString(true).c_str());
(void)timestamp;
}
@@ -184,13 +184,13 @@ class MyAdapterStatusListener : public AdapterStatusListener {
(void)timestamp;
if( !connected ) {
- fprintf(stderr, "****** DISCONNECTED: %s\n", device->toString().c_str());
+ fprintf(stderr, "****** DISCONNECTED: %s\n", device->toString(true).c_str());
return;
}
if( BDAddressType::BDADDR_LE_PUBLIC != device->getAddressType() &&
BDAddressType::BDADDR_LE_RANDOM != device->getAddressType() ) {
- fprintf(stderr, "****** CONNECTED-2: Skip non LE %s\n", device->toString().c_str());
+ fprintf(stderr, "****** CONNECTED-2: Skip non LE %s\n", device->toString(true).c_str());
return;
}
if( waitForDevice == EUI48_ANY_DEVICE ||
@@ -199,12 +199,16 @@ class MyAdapterStatusListener : public AdapterStatusListener {
!isDeviceTaskInProgress(device)
) )
{
- fprintf(stderr, "****** CONNECTED-0: Processing %s\n", device->toString().c_str());
+ fprintf(stderr, "****** CONNECTED-0: Processing %s\n", device->toString(true).c_str());
addDeviceTask( device );
} else {
- fprintf(stderr, "****** CONNECTED-1: NOP %s\n", device->toString().c_str());
+ fprintf(stderr, "****** CONNECTED-1: NOP %s\n", device->toString(true).c_str());
}
}
+
+ std::string toString() const override {
+ return "MyAdapterStatusListener[this "+aptrHexString(this)+"]";
+ }
};
static const uuid16_t _TEMPERATURE_MEASUREMENT(GattCharacteristicType::TEMPERATURE_MEASUREMENT);