diff options
author | Sven Gothel <[email protected]> | 2020-09-15 00:04:00 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-09-15 00:04:00 +0200 |
commit | 62795b6204988dd56e61b0c8e6d8b1107c020cce (patch) | |
tree | 1d910263cf30e6930be6945e34a6f95c6078a4fd /src | |
parent | 1acf3bf7e1b7e0f019c5078201ce9800d2a2dc37 (diff) |
C++ noexcept: GATT* Data Types
Diffstat (limited to 'src')
-rw-r--r-- | src/direct_bt/GATTCharacteristic.cpp | 12 | ||||
-rw-r--r-- | src/direct_bt/GATTDescriptor.cpp | 4 | ||||
-rw-r--r-- | src/direct_bt/GATTNumbers.cpp | 38 | ||||
-rw-r--r-- | src/direct_bt/GATTService.cpp | 4 |
4 files changed, 29 insertions, 29 deletions
diff --git a/src/direct_bt/GATTCharacteristic.cpp b/src/direct_bt/GATTCharacteristic.cpp index 8de18cd0..cdea6db8 100644 --- a/src/direct_bt/GATTCharacteristic.cpp +++ b/src/direct_bt/GATTCharacteristic.cpp @@ -65,7 +65,7 @@ using namespace direct_bt; #define CASE_TO_STRING2(V,S) case V: return #S; -std::string GATTCharacteristic::getPropertyString(const PropertyBitVal prop) { +std::string GATTCharacteristic::getPropertyString(const PropertyBitVal prop) noexcept { switch(prop) { CHAR_DECL_PROPS_ENUM(CASE_TO_STRING2) default: ; // fall through intended @@ -73,7 +73,7 @@ std::string GATTCharacteristic::getPropertyString(const PropertyBitVal prop) { return "Unknown property"; } -std::string GATTCharacteristic::getPropertiesString(const PropertyBitVal properties) { +std::string GATTCharacteristic::getPropertiesString(const PropertyBitVal properties) noexcept { const PropertyBitVal none = static_cast<PropertyBitVal>(0); const uint8_t one = 1; bool has_pre = false; @@ -90,7 +90,7 @@ std::string GATTCharacteristic::getPropertiesString(const PropertyBitVal propert return out; } -std::vector<std::unique_ptr<std::string>> GATTCharacteristic::getPropertiesStringList(const PropertyBitVal properties) { +std::vector<std::unique_ptr<std::string>> GATTCharacteristic::getPropertiesStringList(const PropertyBitVal properties) noexcept { std::vector<std::unique_ptr<std::string>> out; const PropertyBitVal none = static_cast<PropertyBitVal>(0); const uint8_t one = 1; @@ -103,7 +103,7 @@ std::vector<std::unique_ptr<std::string>> GATTCharacteristic::getPropertiesStrin return out; } -std::string GATTCharacteristic::toString() const { +std::string GATTCharacteristic::toString() const noexcept { std::shared_ptr<const uuid_t> service_uuid; uint16_t service_handle_end = 0xffff; GATTServiceRef serviceRef = getServiceUnchecked(); @@ -138,7 +138,7 @@ std::string GATTCharacteristic::toString() const { service_name+", enabled[notify "+std::to_string(enabledNotifyState)+", indicate "+std::to_string(enabledIndicateState)+"] ]"; } -std::string GATTCharacteristic::toSafeString() const { +std::string GATTCharacteristic::toSafeString() const noexcept { std::string char_name = ""; if( uuid_t::TypeSize::UUID16_SZ == value_type->getTypeSize() ) { @@ -160,7 +160,7 @@ std::shared_ptr<GATTService> GATTCharacteristic::getServiceChecked() const { return ref; } -std::shared_ptr<DBTDevice> GATTCharacteristic::getDeviceUnchecked() const { +std::shared_ptr<DBTDevice> GATTCharacteristic::getDeviceUnchecked() const noexcept { std::shared_ptr<GATTService> s = getServiceUnchecked(); if( nullptr != s ) { return s->getDeviceUnchecked(); diff --git a/src/direct_bt/GATTDescriptor.cpp b/src/direct_bt/GATTDescriptor.cpp index 08cddbfd..8b8e2df6 100644 --- a/src/direct_bt/GATTDescriptor.cpp +++ b/src/direct_bt/GATTDescriptor.cpp @@ -73,10 +73,10 @@ bool GATTDescriptor::writeValue() { return gatt->writeDescriptorValue(*this); } -std::string GATTDescriptor::toString() const { +std::string GATTDescriptor::toString() const noexcept { return "[type 0x"+type->toString()+", handle "+uint16HexString(handle)+", value["+value.toString()+"]]"; } -std::string GATTDescriptor::toSafeString() const { +std::string GATTDescriptor::toSafeString() const noexcept { return "[handle "+uint16HexString(handle)+", value["+value.toString()+"]]"; } diff --git a/src/direct_bt/GATTNumbers.cpp b/src/direct_bt/GATTNumbers.cpp index bbcb944f..32742845 100644 --- a/src/direct_bt/GATTNumbers.cpp +++ b/src/direct_bt/GATTNumbers.cpp @@ -204,7 +204,7 @@ const std::vector<const GattServiceCharacteristic*> direct_bt::GATT_SERVICES = { X(DEVICE_INFORMATION) \ X(BATTERY_SERVICE) -std::string direct_bt::GattServiceTypeToString(const GattServiceType v) { +std::string direct_bt::GattServiceTypeToString(const GattServiceType v) noexcept { switch(v) { SERVICE_TYPE_ENUM(CASE_TO_STRING) default: ; // fall through intended @@ -236,7 +236,7 @@ std::string direct_bt::GattServiceTypeToString(const GattServiceType v) { X(PNP_ID) -std::string direct_bt::GattCharacteristicTypeToString(const GattCharacteristicType v) { +std::string direct_bt::GattCharacteristicTypeToString(const GattCharacteristicType v) noexcept { switch(v) { CHARACTERISTIC_TYPE_ENUM(CASE_TO_STRING) default: ; // fall through intended @@ -256,7 +256,7 @@ std::string direct_bt::GattCharacteristicTypeToString(const GattCharacteristicTy X(ReliableWriteExt) \ X(AuxWriteExt) -std::string direct_bt::GattCharacteristicPropertyToString(const GattCharacteristicProperty v) { +std::string direct_bt::GattCharacteristicPropertyToString(const GattCharacteristicProperty v) noexcept { switch(v) { CHARACTERISTIC_PROP_ENUM(CASE_TO_STRING) default: ; // fall through intended @@ -273,7 +273,7 @@ std::string direct_bt::GattCharacteristicPropertyToString(const GattCharacterist X(if_notify_or_indicate_supported) \ X(C1) -std::string direct_bt::GattRequirementSpecToString(const GattRequirementSpec v) { +std::string direct_bt::GattRequirementSpecToString(const GattRequirementSpec v) noexcept { switch(v) { REQUIREMENT_SPEC_ENUM(CASE_TO_STRING) default: ; // fall through intended @@ -281,15 +281,15 @@ std::string direct_bt::GattRequirementSpecToString(const GattRequirementSpec v) return "Unknown"; } -std::string GattCharacteristicPropertySpec::toString() const { +std::string GattCharacteristicPropertySpec::toString() const noexcept { return GattCharacteristicPropertyToString(property)+": "+GattRequirementSpecToString(requirement); } -std::string GattClientCharacteristicConfigSpec::toString() const { +std::string GattClientCharacteristicConfigSpec::toString() const noexcept { return "ClientCharCfg["+GattRequirementSpecToString(requirement)+"["+read.toString()+", "+writeWithAck.toString()+"]]"; } -std::string GattCharacteristicSpec::toString() const { +std::string GattCharacteristicSpec::toString() const noexcept { std::string res = GattCharacteristicTypeToString(characteristic)+": "+GattRequirementSpecToString(requirement)+", Properties["; for(size_t i=0; i<propertySpec.size(); i++) { if(0<i) { @@ -301,7 +301,7 @@ std::string GattCharacteristicSpec::toString() const { return res; } -std::string GattServiceCharacteristic::toString() const { +std::string GattServiceCharacteristic::toString() const noexcept { std::string res = GattServiceTypeToString(service)+": ["; for(size_t i=0; i<characteristics.size(); i++) { if(0<i) { @@ -313,7 +313,7 @@ std::string GattServiceCharacteristic::toString() const { return res; } -const GattServiceCharacteristic * direct_bt::findGattServiceChar(const uint16_t uuid16) { +const GattServiceCharacteristic * direct_bt::findGattServiceChar(const uint16_t uuid16) noexcept { for(size_t i=0; i<GATT_SERVICES.size(); i++) { const GattServiceCharacteristic & serviceChar = *GATT_SERVICES.at(i); if( uuid16 == serviceChar.service ) { @@ -329,7 +329,7 @@ const GattServiceCharacteristic * direct_bt::findGattServiceChar(const uint16_t return nullptr; } -const GattCharacteristicSpec * direct_bt::findGattCharSpec(const uint16_t uuid16) { +const GattCharacteristicSpec * direct_bt::findGattCharSpec(const uint16_t uuid16) noexcept { for(size_t i=0; i<GATT_SERVICES.size(); i++) { const GattServiceCharacteristic & serviceChar = *GATT_SERVICES.at(i); for(size_t j=0; j<serviceChar.characteristics.size(); j++) { @@ -346,7 +346,7 @@ const GattCharacteristicSpec * direct_bt::findGattCharSpec(const uint16_t uuid16 /********************************************************/ /********************************************************/ -std::string direct_bt::GattNameToString(const TROOctets &v) { +std::string direct_bt::GattNameToString(const TROOctets &v) noexcept { const int str_len = v.getSize(); POctets s(str_len+1); // dtor releases chunk memcpy(s.get_wptr(), v.get_ptr(), str_len); @@ -354,42 +354,42 @@ std::string direct_bt::GattNameToString(const TROOctets &v) { return std::string((const char*)s.get_ptr()); } -PeriphalPreferredConnectionParameters::PeriphalPreferredConnectionParameters(const TROOctets &source) +PeriphalPreferredConnectionParameters::PeriphalPreferredConnectionParameters(const TROOctets &source) noexcept : minConnectionInterval(source.get_uint16(0)), maxConnectionInterval(source.get_uint16(2)), slaveLatency(source.get_uint16(4)), connectionSupervisionTimeoutMultiplier(source.get_uint16(6)) { } -std::string PeriphalPreferredConnectionParameters::toString() const { +std::string PeriphalPreferredConnectionParameters::toString() const noexcept { return "PrefConnectionParam[interval["+ std::to_string(minConnectionInterval)+".."+std::to_string(maxConnectionInterval)+ "], slaveLatency "+std::to_string(slaveLatency)+ ", csTimeoutMul "+std::to_string(connectionSupervisionTimeoutMultiplier)+"]"; } -std::string GenericAccess::toString() const { +std::string GenericAccess::toString() const noexcept { return "'"+deviceName+"'[appearance "+uint16HexString(static_cast<uint16_t>(appearance))+" ("+getAppearanceCatString(appearance)+"), "+ prefConnParam.toString()+"]"; } -PnP_ID::PnP_ID(const TROOctets &source) +PnP_ID::PnP_ID(const TROOctets &source) noexcept : vendor_id_source(source.get_uint8(0)), vendor_id(source.get_uint16(1)), product_id(source.get_uint16(3)), product_version(source.get_uint16(5)) {} -std::string PnP_ID::toString() const { +std::string PnP_ID::toString() const noexcept { return "vendor_id[source "+uint8HexString(vendor_id_source, true)+ ", id "+uint16HexString(vendor_id, true)+ "], product_id "+uint16HexString(product_id, true)+ ", product_version "+uint16HexString(product_version, true); } -std::string DeviceInformation::toString() const { +std::string DeviceInformation::toString() const noexcept { return "DeviceInfo[manufacturer '"+manufacturer+"', model '"+modelNumber+"', serial '"+serialNumber+"', systemID '"+systemID.toString()+ "', revisions[firmware '"+firmwareRevision+"', hardware '"+hardwareRevision+"', software '"+softwareRevision+ "'], pnpID["+pnpID.toString()+"], regCertData '"+regulatoryCertDataList.toString()+"']"; } -std::shared_ptr<TemperatureMeasurementCharateristic> TemperatureMeasurementCharateristic::get(const TROOctets &source) { +std::shared_ptr<TemperatureMeasurementCharateristic> TemperatureMeasurementCharateristic::get(const TROOctets &source) noexcept { const int size = source.getSize(); int reqSize = 1 + 4; // max size = 13 if( reqSize > size ) { @@ -427,7 +427,7 @@ std::shared_ptr<TemperatureMeasurementCharateristic> TemperatureMeasurementChara return std::shared_ptr<TemperatureMeasurementCharateristic>(new TemperatureMeasurementCharateristic(flags, temperatureValue, timestamp, temperature_type)); } -std::string TemperatureMeasurementCharateristic::toString() const { +std::string TemperatureMeasurementCharateristic::toString() const noexcept { std::string res = std::to_string(temperatureValue); res += isFahrenheit() ? " F" : " C"; if( hasTimestamp() ) { diff --git a/src/direct_bt/GATTService.cpp b/src/direct_bt/GATTService.cpp index e0d92ab0..5de4524c 100644 --- a/src/direct_bt/GATTService.cpp +++ b/src/direct_bt/GATTService.cpp @@ -46,7 +46,7 @@ std::shared_ptr<DBTDevice> GATTService::getDeviceChecked() const { return ref; } -std::string GATTService::toString() const { +std::string GATTService::toString() const noexcept { std::string name = ""; if( uuid_t::TypeSize::UUID16_SZ == type->getTypeSize() ) { const uint16_t uuid16 = (static_cast<const uuid16_t*>(type.get()))->value; @@ -56,7 +56,7 @@ std::string GATTService::toString() const { name+", "+std::to_string(characteristicList.size())+" characteristics"; } -std::string GATTService::toSafeString() const { +std::string GATTService::toSafeString() const noexcept { std::string name = ""; if( uuid_t::TypeSize::UUID16_SZ == type->getTypeSize() ) { const uint16_t uuid16 = (static_cast<const uuid16_t*>(type.get()))->value; |