Skip to content

Commit d522204

Browse files
Merge branch 'main' into feature/split_AttMtuExchange_interface
2 parents c979670 + b978fac commit d522204

13 files changed

+74
-11
lines changed

services/ble/GattServer.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ namespace services
4040

4141
virtual AttAttribute::Handle ServiceHandle() const = 0;
4242
virtual AttAttribute::Handle CharacteristicHandle() const = 0;
43+
virtual AttAttribute::Handle CharacteristicValueHandle() const = 0;
4344
};
4445

4546
class GattServerCharacteristicOperations

services/ble/GattServerCharacteristicImpl.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ namespace services
4242
return handle;
4343
}
4444

45+
AttAttribute::Handle GattServerCharacteristicImpl::CharacteristicValueHandle() const
46+
{
47+
return valueHandle;
48+
}
49+
4550
void GattServerCharacteristicImpl::UpdateValue()
4651
{
4752
auto status = GattServerCharacteristicOperationsObserver::Subject().Update(*this, updateContext->data);

services/ble/GattServerCharacteristicImpl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace services
2222
// Implementation of GattServerCharacteristicOperationsObserver
2323
AttAttribute::Handle ServiceHandle() const override;
2424
AttAttribute::Handle CharacteristicHandle() const override;
25+
AttAttribute::Handle CharacteristicValueHandle() const override;
2526

2627
private:
2728
struct UpdateContext

services/ble/test/TestGattServer.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ TEST(GattServerTest, characteristic_implementation_handles_are_accesible)
2222
s.Handle() = 0xAB;
2323
services::GattServerCharacteristicImpl c{ s, uuid16, valueSize };
2424
c.Handle() = 0xCD;
25+
c.ValueHandle() = 0xEF;
2526

2627
EXPECT_EQ(0xAB, c.ServiceHandle());
2728
EXPECT_EQ(0xCD, c.CharacteristicHandle());
29+
EXPECT_EQ(0xEF, c.CharacteristicValueHandle());
2830
}
2931

3032
TEST(GattServerTest, characteristic_implementation_supports_different_uuid_lengths)

services/ble/test_doubles/GattServerMock.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace services
3535
public:
3636
MOCK_METHOD(AttAttribute::Handle, ServiceHandle, (), (const));
3737
MOCK_METHOD(AttAttribute::Handle, CharacteristicHandle, (), (const));
38+
MOCK_METHOD(AttAttribute::Handle, CharacteristicValueHandle, (), (const));
3839
MOCK_METHOD(void, Update, (infra::ConstByteRange data, infra::Function<void()> onDone));
3940
};
4041
}

services/echo_console/Console.cpp

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,11 @@ namespace application
757757
758758
The method call in echo console for value="{ "bool":true }" would be:
759759
Method "{ \"bool\":true }"
760+
761+
Best practice: To avoid ambiguity when multiple services have methods with the same name, prefix the method with the service name.
762+
For example, if both GapCentral and GapPeripheral in Gap.proto have a RemoveAllBonds method, call the GapCentral version as:
763+
GapCentral.RemoveAllBonds
764+
760765
5. Primitive types mapping table:
761766
+-----------------+-----------------+-------------------------------------+
762767
| Proto Type | Token Type | Example Input |
@@ -923,6 +928,19 @@ namespace application
923928
{
924929
services::GlobalTracer().Trace() << "Incorrect type at index " << error.index << " expected type " << error.correctType << " (contents after that position is " << line.substr(error.index) << ")\n";
925930
}
931+
catch (ConsoleExceptions::AmbiguousMethod& error)
932+
{
933+
services::GlobalTracer().Trace() << "Ambiguous method call: '" << error.methodName << "' exists in multiple services: ";
934+
935+
for (const auto& serviceName : error.serviceNames)
936+
{
937+
if (&serviceName != &error.serviceNames.front())
938+
services::GlobalTracer().Continue() << ", ";
939+
services::GlobalTracer().Continue() << serviceName;
940+
}
941+
942+
services::GlobalTracer().Continue() << "\nPlease specify the service name, e.g., " << error.serviceNames.front() << "." << error.methodName << "\n";
943+
}
926944
catch (ConsoleExceptions::MethodNotFound& error)
927945
{
928946
services::GlobalTracer().Trace() << "Method ";
@@ -940,15 +958,29 @@ namespace application
940958

941959
std::pair<std::shared_ptr<const EchoService>, const EchoMethod&> Console::SearchMethod(MethodInvocation& methodInvocation) const
942960
{
961+
std::vector<std::pair<std::shared_ptr<const EchoService>, const EchoMethod*>> matchingMethods;
962+
943963
for (auto service : root.services)
944964
{
945965
if (methodInvocation.method.size() == 1 || methodInvocation.method.front() == service->name)
946966
for (auto& method : service->methods)
947967
if (method.name == methodInvocation.method.back())
948-
return std::pair<std::shared_ptr<const EchoService>, const EchoMethod&>(service, method);
968+
matchingMethods.emplace_back(std::make_pair(service, &method));
969+
}
970+
971+
if (matchingMethods.empty())
972+
throw ConsoleExceptions::MethodNotFound{ methodInvocation.method };
973+
974+
if (methodInvocation.method.size() == 1 && matchingMethods.size() > 1)
975+
{
976+
std::vector<std::string> serviceNames;
977+
for (const auto& [echoService, echoMethod] : matchingMethods)
978+
serviceNames.push_back(echoService->name);
979+
980+
throw ConsoleExceptions::AmbiguousMethod{ methodInvocation.method.back(), serviceNames };
949981
}
950982

951-
throw ConsoleExceptions::MethodNotFound{ methodInvocation.method };
983+
return std::pair<std::shared_ptr<const EchoService>, const EchoMethod&>(matchingMethods[0].first, *matchingMethods[0].second);
952984
}
953985

954986
Console::MethodInvocation::MethodInvocation(const std::string& line)

services/echo_console/Console.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ namespace application
274274
std::vector<std::string> method;
275275
};
276276

277+
struct AmbiguousMethod
278+
{
279+
std::string methodName;
280+
std::vector<std::string> serviceNames;
281+
};
282+
277283
struct SyntaxError
278284
{
279285
std::size_t index;

services/network_instantiations/ConnectionBsd.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace services
3232

3333
ConnectionBsd::~ConnectionBsd()
3434
{
35-
if (socket != 0)
35+
if (Connected())
3636
{
3737
int result = close(socket);
3838
if (result == -1)
@@ -94,6 +94,11 @@ namespace services
9494
Attach(connectionObserver);
9595
}
9696

97+
bool ConnectionBsd::Connected() const
98+
{
99+
return socket != 0;
100+
}
101+
97102
void ConnectionBsd::Receive()
98103
{
99104
while (!receiveBuffer.full())
@@ -103,7 +108,7 @@ namespace services
103108
if (received == -1)
104109
{
105110
if (errno != EWOULDBLOCK)
106-
ResetOwnership();
111+
AbortAndDestroy();
107112
return;
108113
}
109114
else if (received != 0)
@@ -118,7 +123,7 @@ namespace services
118123
}
119124
else
120125
{
121-
ResetOwnership();
126+
CloseAndDestroy();
122127
return;
123128
}
124129
}
@@ -163,7 +168,8 @@ namespace services
163168

164169
void ConnectionBsd::ResetOwnership()
165170
{
166-
Detach();
171+
if (IsAttached())
172+
Detach();
167173
self = nullptr;
168174
}
169175

services/network_instantiations/ConnectionBsd.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace services
3131

3232
IPv4Address Ipv4Address() const;
3333
void SetObserver(infra::SharedPtr<services::ConnectionObserver> connectionObserver);
34+
bool Connected() const;
3435

3536
void Receive();
3637
void Send();

services/network_instantiations/ConnectionWin.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ namespace services
8282
Attach(connectionObserver);
8383
}
8484

85+
bool ConnectionWin::Connected() const
86+
{
87+
return socket != 0;
88+
}
89+
8590
void ConnectionWin::Receive()
8691
{
8792
while (!receiveBuffer.full())
@@ -91,7 +96,7 @@ namespace services
9196
if (received == SOCKET_ERROR)
9297
{
9398
if (WSAGetLastError() != WSAEWOULDBLOCK)
94-
ResetOwnership();
99+
AbortAndDestroy();
95100
return;
96101
}
97102
else if (received != 0)
@@ -107,7 +112,7 @@ namespace services
107112
}
108113
else
109114
{
110-
ResetOwnership();
115+
CloseAndDestroy();
111116
return;
112117
}
113118
}
@@ -126,7 +131,7 @@ namespace services
126131
if (sent == SOCKET_ERROR)
127132
{
128133
if (WSAGetLastError() != WSAEWOULDBLOCK)
129-
ResetOwnership();
134+
AbortAndDestroy();
130135
return;
131136
}
132137

0 commit comments

Comments
 (0)