diff --git a/infra/event/EventDispatcher.cpp b/infra/event/EventDispatcher.cpp index bf26d1db5..9e4e43c78 100644 --- a/infra/event/EventDispatcher.cpp +++ b/infra/event/EventDispatcher.cpp @@ -65,6 +65,10 @@ namespace infra { struct ExceptionSafePop { + ExceptionSafePop(EventDispatcherWorkerImpl& worker) + : worker(worker) + {} + ExceptionSafePop(const ExceptionSafePop&) = delete; ExceptionSafePop& operator=(const ExceptionSafePop&) = delete; diff --git a/infra/event/EventDispatcherWithWeakPtr.cpp b/infra/event/EventDispatcherWithWeakPtr.cpp index d256a633d..1cb0e7694 100644 --- a/infra/event/EventDispatcherWithWeakPtr.cpp +++ b/infra/event/EventDispatcherWithWeakPtr.cpp @@ -81,6 +81,10 @@ namespace infra { struct ExceptionSafePop { + ExceptionSafePop(EventDispatcherWithWeakPtrWorker& worker) + : worker(worker) + {} + ExceptionSafePop(const ExceptionSafePop&) = delete; ExceptionSafePop& operator=(const ExceptionSafePop&) = delete; diff --git a/infra/util/Endian.hpp b/infra/util/Endian.hpp index af9214146..deb75d690 100644 --- a/infra/util/Endian.hpp +++ b/infra/util/Endian.hpp @@ -163,24 +163,24 @@ namespace infra friend bool operator==(T x, BigEndian y) { - return y == x; + return y.operator==(x); } friend bool operator!=(T x, BigEndian y) { - return y != x; + return y.operator!=(x); } template friend bool operator==(U x, BigEndian y) { - return y == x; + return y.operator==(x); } template friend bool operator!=(U x, BigEndian y) { - return y != x; + return y.operator!=(x); } private: diff --git a/infra/util/Variant.hpp b/infra/util/Variant.hpp index 0c00b9727..2562a6a02 100644 --- a/infra/util/Variant.hpp +++ b/infra/util/Variant.hpp @@ -20,6 +20,7 @@ namespace infra Variant(); Variant(const Variant& other); + Variant(Variant&& other) noexcept((std::is_nothrow_move_constructible_v && ...)) = default; template Variant(const Variant& other); template @@ -30,6 +31,7 @@ namespace infra Variant(AtIndex, std::size_t index, Args&&... args); Variant& operator=(const Variant& other); + Variant& operator=(Variant&& other) noexcept((std::is_nothrow_move_assignable_v && ...) && (std::is_nothrow_move_constructible_v && ...)) = default; template Variant& operator=(const Variant& other); template diff --git a/protobuf/echo/Serialization.cpp b/protobuf/echo/Serialization.cpp index aea1646c9..3b16b155f 100644 --- a/protobuf/echo/Serialization.cpp +++ b/protobuf/echo/Serialization.cpp @@ -11,8 +11,6 @@ namespace services { while (!reader->Empty()) reader->ExtractContiguousRange(std::numeric_limits::max()); - - reader = nullptr; } void MethodDeserializerDummy::ExecuteMethod() diff --git a/protobuf/echo/TracingEcho.cpp b/protobuf/echo/TracingEcho.cpp index 1f56fbf98..ace696933 100644 --- a/protobuf/echo/TracingEcho.cpp +++ b/protobuf/echo/TracingEcho.cpp @@ -173,7 +173,7 @@ namespace services if (contents.Is() && contents.Get().length > stream.Available()) { - tracer.Trace() << "< message too big"; + tracer.Trace() << "< message too big for service " << serviceId << " method " << methodId << " length " << contents.Get().length << " available " << stream.Available(); skipping = contents.Get().length; writerBuffer.erase(writerBuffer.begin(), writerBuffer.begin() + stream.Reader().Processed()); auto skippingNow = std::min(skipping, writerBuffer.size()); diff --git a/protobuf/protoc_echo_plugin/ProtoCEchoPlugin.cpp b/protobuf/protoc_echo_plugin/ProtoCEchoPlugin.cpp index 1da7ccf4e..aa5870bf1 100644 --- a/protobuf/protoc_echo_plugin/ProtoCEchoPlugin.cpp +++ b/protobuf/protoc_echo_plugin/ProtoCEchoPlugin.cpp @@ -1584,7 +1584,7 @@ switch (methodId) printer.Print("}\n"); } else - printer.Print(R"(tracer.Continue() << "$servicename$ method " << methodId << " not found";\n)", "servicename", service->name); + printer.Print(R"(tracer.Continue() << "$servicename$ method " << methodId << " not found";\ncontents.SkipEverything();\n)", "servicename", service->name); } return result.str(); diff --git a/services/ble/Gatt.cpp b/services/ble/Gatt.cpp index 283798149..55ba3ad06 100644 --- a/services/ble/Gatt.cpp +++ b/services/ble/Gatt.cpp @@ -2,6 +2,36 @@ namespace services { + GattDescriptor::GattDescriptor(const AttAttribute::Uuid& type, AttAttribute::Handle handle) + : type(type) + , handle(handle) + {} + + const AttAttribute::Uuid& GattDescriptor::Type() const + { + return type; + } + + AttAttribute::Handle GattDescriptor::Handle() const + { + return handle; + } + + AttAttribute::Handle& GattDescriptor::Handle() + { + return handle; + } + + bool GattDescriptor::operator==(const GattDescriptor& other) const + { + return type == other.type && handle == other.handle; + } + + bool GattDescriptor::operator!=(const GattDescriptor& other) const + { + return !(*this == other); + } + GattCharacteristic::GattCharacteristic(const AttAttribute::Uuid& type, AttAttribute::Handle handle, AttAttribute::Handle valueHandle, GattCharacteristic::PropertyFlags properties) : type(type) , handle(handle) diff --git a/services/ble/Gatt.hpp b/services/ble/Gatt.hpp index 82e9972c5..4d04aa21d 100644 --- a/services/ble/Gatt.hpp +++ b/services/ble/Gatt.hpp @@ -35,6 +35,21 @@ namespace services enableIndication = 0x0002, }; }; + + GattDescriptor(const AttAttribute::Uuid& type, AttAttribute::Handle handle); + GattDescriptor() = default; + + const AttAttribute::Uuid& Type() const; + + AttAttribute::Handle Handle() const; + AttAttribute::Handle& Handle(); + + bool operator==(const GattDescriptor& other) const; + bool operator!=(const GattDescriptor& other) const; + + private: + AttAttribute::Uuid type; + AttAttribute::Handle handle; }; namespace uuid @@ -72,9 +87,6 @@ namespace services public: GattCharacteristic(const AttAttribute::Uuid& type, AttAttribute::Handle handle, AttAttribute::Handle valueHandle, PropertyFlags properties); GattCharacteristic() = default; - GattCharacteristic(GattCharacteristic& other) = delete; - GattCharacteristic& operator=(const GattCharacteristic& other) = delete; - virtual ~GattCharacteristic() = default; const PropertyFlags& Properties() const; const AttAttribute::Uuid& Type() const; @@ -96,9 +108,6 @@ namespace services public: GattService(const AttAttribute::Uuid& type); GattService(const AttAttribute::Uuid& type, AttAttribute::Handle handle, AttAttribute::Handle endHandle); - GattService(GattService& other) = delete; - GattService& operator=(const GattService& other) = delete; - virtual ~GattService() = default; AttAttribute::Uuid Type() const; AttAttribute::Handle Handle() const; diff --git a/services/ble/Gatt.proto b/services/ble/Gatt.proto index a857aa531..d1c1146e8 100644 --- a/services/ble/Gatt.proto +++ b/services/ble/Gatt.proto @@ -94,13 +94,8 @@ service GattClient rpc MtuSizeExchangeRequest(Nothing) returns (Nothing) { option (method_id) = 1; } rpc StartServiceDiscovery(Nothing) returns (Nothing) { option (method_id) = 2; } - rpc StopServiceDiscovery(Nothing) returns (Nothing) { option (method_id) = 3; } - rpc StartCharacteristicDiscovery(HandleRange) returns (Nothing) { option (method_id) = 4; } - rpc StopCharacteristicDiscovery(Nothing) returns (Nothing) { option (method_id) = 5; } - rpc StartDescriptorDiscovery(HandleRange) returns (Nothing) { option (method_id) = 6; } - rpc StopDescriptorDiscovery(Nothing) returns (Nothing) { option (method_id) = 7; } rpc Read(Handle) returns (Nothing) { option (method_id) = 8; } rpc Write(CharacteristicData) returns (Nothing) { option (method_id) = 9; } diff --git a/services/ble/GattClient.cpp b/services/ble/GattClient.cpp index ddf67e65d..cf4b385a1 100644 --- a/services/ble/GattClient.cpp +++ b/services/ble/GattClient.cpp @@ -148,13 +148,13 @@ namespace services GattClientDiscoveryObserver::Subject().StartServiceDiscovery(); } - void GattClientDiscoveryDecorator::StartCharacteristicDiscovery(const GattService& service) + void GattClientDiscoveryDecorator::StartCharacteristicDiscovery(AttAttribute::Handle handle, AttAttribute::Handle endHandle) { - GattClientDiscoveryObserver::Subject().StartCharacteristicDiscovery(service); + GattClientDiscoveryObserver::Subject().StartCharacteristicDiscovery(handle, endHandle); } - void GattClientDiscoveryDecorator::StartDescriptorDiscovery(const GattService& service) + void GattClientDiscoveryDecorator::StartDescriptorDiscovery(AttAttribute::Handle handle, AttAttribute::Handle endHandle) { - GattClientDiscoveryObserver::Subject().StartDescriptorDiscovery(service); + GattClientDiscoveryObserver::Subject().StartDescriptorDiscovery(handle, endHandle); } } diff --git a/services/ble/GattClient.hpp b/services/ble/GattClient.hpp index f591abadb..9f16ce54b 100644 --- a/services/ble/GattClient.hpp +++ b/services/ble/GattClient.hpp @@ -50,14 +50,14 @@ namespace services , public infra::Subject { public: - virtual void Read(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onRead) const = 0; - virtual void Write(const GattClientCharacteristicOperationsObserver& characteristic, infra::ConstByteRange data, const infra::Function& onDone) const = 0; - virtual void WriteWithoutResponse(const GattClientCharacteristicOperationsObserver& characteristic, infra::ConstByteRange data) const = 0; - - virtual void EnableNotification(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onDone) const = 0; - virtual void DisableNotification(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onDone) const = 0; - virtual void EnableIndication(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onDone) const = 0; - virtual void DisableIndication(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onDone) const = 0; + virtual void Read(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onRead) = 0; + virtual void Write(const GattClientCharacteristicOperationsObserver& characteristic, infra::ConstByteRange data, const infra::Function& onDone) = 0; + virtual void WriteWithoutResponse(const GattClientCharacteristicOperationsObserver& characteristic, infra::ConstByteRange data) = 0; + + virtual void EnableNotification(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onDone) = 0; + virtual void DisableNotification(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onDone) = 0; + virtual void EnableIndication(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onDone) = 0; + virtual void DisableIndication(const GattClientCharacteristicOperationsObserver& characteristic, const infra::Function& onDone) = 0; }; class GattClientCharacteristic @@ -111,11 +111,10 @@ namespace services using infra::Observer::Observer; virtual void ServiceDiscovered(const AttAttribute::Uuid& type, AttAttribute::Handle handle, AttAttribute::Handle endHandle) = 0; - virtual void CharacteristicDiscovered(const AttAttribute::Uuid& type, AttAttribute::Handle handle, AttAttribute::Handle valueHandle, GattCharacteristic::PropertyFlags properties) = 0; - virtual void DescriptorDiscovered(const AttAttribute::Uuid& type, AttAttribute::Handle handle) = 0; - virtual void ServiceDiscoveryComplete() = 0; + virtual void CharacteristicDiscovered(const AttAttribute::Uuid& type, AttAttribute::Handle handle, AttAttribute::Handle valueHandle, GattCharacteristic::PropertyFlags properties) = 0; virtual void CharacteristicDiscoveryComplete() = 0; + virtual void DescriptorDiscovered(const AttAttribute::Uuid& type, AttAttribute::Handle handle) = 0; virtual void DescriptorDiscoveryComplete() = 0; }; @@ -124,8 +123,18 @@ namespace services { public: virtual void StartServiceDiscovery() = 0; - virtual void StartCharacteristicDiscovery(const GattService& service) = 0; - virtual void StartDescriptorDiscovery(const GattService& service) = 0; + virtual void StartCharacteristicDiscovery(AttAttribute::Handle handle, AttAttribute::Handle endHandle) = 0; + virtual void StartDescriptorDiscovery(AttAttribute::Handle handle, AttAttribute::Handle endHandle) = 0; + + void StartCharacteristicDiscovery(const GattService& service) + { + StartCharacteristicDiscovery(service.Handle(), service.EndHandle()); + } + + void StartDescriptorDiscovery(const GattService& service) + { + StartDescriptorDiscovery(service.Handle(), service.EndHandle()); + } }; class GattClientDiscoveryDecorator @@ -146,8 +155,8 @@ namespace services // Implementation of GattClientDiscovery void StartServiceDiscovery() override; - void StartCharacteristicDiscovery(const GattService& service) override; - void StartDescriptorDiscovery(const GattService& service) override; + void StartCharacteristicDiscovery(AttAttribute::Handle handle, AttAttribute::Handle endHandle) override; + void StartDescriptorDiscovery(AttAttribute::Handle handle, AttAttribute::Handle endHandle) override; }; } diff --git a/services/ble/GattServerCharacteristicImpl.hpp b/services/ble/GattServerCharacteristicImpl.hpp index 292cf4a76..ac01faec7 100644 --- a/services/ble/GattServerCharacteristicImpl.hpp +++ b/services/ble/GattServerCharacteristicImpl.hpp @@ -13,7 +13,7 @@ namespace services GattServerCharacteristicImpl(GattServerService& service, const AttAttribute::Uuid& type, uint16_t valueLength); GattServerCharacteristicImpl(GattServerService& service, const AttAttribute::Uuid& type, uint16_t valueLength, PropertyFlags properties); GattServerCharacteristicImpl(GattServerService& service, const AttAttribute::Uuid& type, uint16_t valueLength, PropertyFlags properties, PermissionFlags permissions); - ~GattServerCharacteristicImpl() override; + ~GattServerCharacteristicImpl(); // Implementation of GattServerCharacteristic void Update(infra::ConstByteRange data, infra::Function onDone) override; diff --git a/services/ble/test/TestGattClient.cpp b/services/ble/test/TestGattClient.cpp index a378f57ba..e40b3b33c 100644 --- a/services/ble/test/TestGattClient.cpp +++ b/services/ble/test/TestGattClient.cpp @@ -243,14 +243,12 @@ TEST_F(GattClientDiscoveryDecoratorTest, forward_descriptors_discovered_event_to TEST_F(GattClientDiscoveryDecoratorTest, forward_all_calls_to_subject) { - services::GattService service{ uuid16, 0x1, 0x9 }; - EXPECT_CALL(gattDiscovery, StartServiceDiscovery()); decorator.StartServiceDiscovery(); - EXPECT_CALL(gattDiscovery, StartCharacteristicDiscovery(::testing::Ref(service))); - decorator.StartCharacteristicDiscovery(service); + EXPECT_CALL(gattDiscovery, StartCharacteristicDiscovery(1, 9)); + decorator.StartCharacteristicDiscovery(1, 9); - EXPECT_CALL(gattDiscovery, StartDescriptorDiscovery(::testing::Ref(service))); - decorator.StartDescriptorDiscovery(service); + EXPECT_CALL(gattDiscovery, StartDescriptorDiscovery(1, 9)); + decorator.StartDescriptorDiscovery(1, 9); } \ No newline at end of file diff --git a/services/ble/test_doubles/GattClientMock.hpp b/services/ble/test_doubles/GattClientMock.hpp index 48882166f..77281d44f 100644 --- a/services/ble/test_doubles/GattClientMock.hpp +++ b/services/ble/test_doubles/GattClientMock.hpp @@ -14,18 +14,26 @@ namespace services MOCK_METHOD(void, UpdateReceived, (infra::ConstByteRange data), (override)); }; + class GattClientCharacteristicOperationsObserverMock + : public services::GattClientCharacteristicOperationsObserver + { + public: + MOCK_METHOD(AttAttribute::Handle, CharacteristicValueHandle, (), (const, override)); + MOCK_METHOD(GattCharacteristic::PropertyFlags, CharacteristicProperties, (), (const, override)); + }; + class GattClientCharacteristicOperationsMock : public services::GattClientCharacteristicOperations { public: - MOCK_METHOD(void, Read, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (const, override)); - MOCK_METHOD(void, Write, (const GattClientCharacteristicOperationsObserver&, infra::ConstByteRange, const infra::Function&), (const, override)); - MOCK_METHOD(void, WriteWithoutResponse, (const GattClientCharacteristicOperationsObserver&, infra::ConstByteRange), (const, override)); - - MOCK_METHOD(void, EnableNotification, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (const, override)); - MOCK_METHOD(void, DisableNotification, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (const, override)); - MOCK_METHOD(void, EnableIndication, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (const, override)); - MOCK_METHOD(void, DisableIndication, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (const, override)); + MOCK_METHOD(void, Read, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (override)); + MOCK_METHOD(void, Write, (const GattClientCharacteristicOperationsObserver&, infra::ConstByteRange, const infra::Function&), (override)); + MOCK_METHOD(void, WriteWithoutResponse, (const GattClientCharacteristicOperationsObserver&, infra::ConstByteRange), (override)); + + MOCK_METHOD(void, EnableNotification, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (override)); + MOCK_METHOD(void, DisableNotification, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (override)); + MOCK_METHOD(void, EnableIndication, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (override)); + MOCK_METHOD(void, DisableIndication, (const GattClientCharacteristicOperationsObserver&, const infra::Function&), (override)); }; class GattClientDiscoveryObserverMock @@ -48,8 +56,8 @@ namespace services { public: MOCK_METHOD(void, StartServiceDiscovery, (), (override)); - MOCK_METHOD(void, StartCharacteristicDiscovery, (const GattService& service), (override)); - MOCK_METHOD(void, StartDescriptorDiscovery, (const GattService& service), (override)); + MOCK_METHOD(void, StartCharacteristicDiscovery, (AttAttribute::Handle handle, AttAttribute::Handle endHandle), (override)); + MOCK_METHOD(void, StartDescriptorDiscovery, (AttAttribute::Handle handle, AttAttribute::Handle endHandle), (override)); }; } diff --git a/services/cucumber/test/TestCucumberWireProtocolServer.cpp b/services/cucumber/test/TestCucumberWireProtocolServer.cpp index 44550a6d7..58398e327 100644 --- a/services/cucumber/test/TestCucumberWireProtocolServer.cpp +++ b/services/cucumber/test/TestCucumberWireProtocolServer.cpp @@ -86,7 +86,7 @@ GIVEN("nothing happens for %d seconds") infra::StringInputStream secondsStream(secondsString); uint32_t seconds; secondsStream >> seconds; - Context().TimeoutTimer().Start(std::chrono::seconds(seconds), [=]() + Context().TimeoutTimer().Start(std::chrono::seconds(seconds), [this]() { Success(); });