Skip to content

Commit 59bcc9f

Browse files
align to new olink core
1 parent cfc27b7 commit 59bcc9f

File tree

94 files changed

+1879
-1684
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1879
-1684
lines changed

goldenmaster/apigear/olink/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if(NOT objectlink-core-cpp_FOUND)
1515
message(STATUS "objectlink-core-cpp NOT FOUND, fetching the git repository")
1616
FetchContent_Declare(olink-core
1717
GIT_REPOSITORY https://github.com/apigear-io/objectlink-core-cpp.git
18-
GIT_TAG v0.2.6
18+
GIT_TAG "dphan/extracting-protocol-format"
1919
GIT_SHALLOW TRUE
2020
EXCLUDE_FROM_ALL FALSE
2121
)

goldenmaster/apigear/olink/tests/olink_connection.test.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ namespace {
6464
!= container.end();
6565
}
6666

67+
std::string propert1Name = "property1";
68+
std::string propert2Name = "property2";
69+
std::string propert3Name = "property3";
70+
std::string stringValue1 = "someString1";
71+
int someIntValue1 = 91;
72+
bool boolFalse = false;
73+
74+
auto initProperties = ApiGear::ObjectLink::argumentsToContent(ApiGear::ObjectLink::toInitialProperty(propert1Name, stringValue1),
75+
ApiGear::ObjectLink::toInitialProperty(propert2Name, someIntValue1),
76+
ApiGear::ObjectLink::toInitialProperty(propert3Name, boolFalse));
6777
}
6878

6979
TEST_CASE("OlinkConnection tests")
@@ -96,7 +106,6 @@ TEST_CASE("OlinkConnection tests")
96106
REQUIRE(msgs[0].flags == Poco::Net::WebSocket::FRAME_TEXT);
97107

98108
// Send init message from server and check it is delivered and decoded
99-
nlohmann::json initProperties = { {"property1", "some_string" }, { "property2", 9 }, { "property3", false } };
100109
REQUIRE_CALL(*sink1, olinkOnInit(sink1Id, initProperties, testOlinkConnection->node().get()));
101110

102111
auto preparedInitMessage = converter.toString(ApiGear::ObjectLink::Protocol::initMessage(sink1Id, initProperties));
@@ -143,7 +152,6 @@ TEST_CASE("OlinkConnection tests")
143152
REQUIRE(registry.getNode(sink1Id).lock() == testOlinkConnection->node());
144153

145154
// Send from server init message
146-
nlohmann::json initProperties = { {"property1", "some_string" }, { "property2", 9 }, { "property3", false } };
147155
REQUIRE_CALL(*sink1, olinkOnInit(sink1Id, initProperties, testOlinkConnection->node().get()));
148156
auto preparedInitMessage = converter.toString(ApiGear::ObjectLink::Protocol::initMessage(sink1Id, initProperties));
149157
server.sendFrame(preparedInitMessage);
@@ -274,7 +282,6 @@ TEST_CASE("OlinkConnection tests")
274282
REQUIRE(msgs[0].flags == Poco::Net::WebSocket::FRAME_TEXT);
275283

276284
// Send init message from server and check it is delivered and decoded
277-
nlohmann::json initProperties = { {"property1", "some_string" }, { "property2", 9 }, { "property3", false } };
278285
REQUIRE_CALL(*sink1, olinkOnInit(sink1Id, initProperties, testOlinkConnection->node().get()));
279286

280287
auto preparedInitMessage = converter.toString(ApiGear::ObjectLink::Protocol::initMessage(sink1Id, initProperties));

goldenmaster/apigear/olink/tests/olinkhost.test.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,22 @@ namespace {
5353
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/ws", Poco::Net::HTTPRequest::HTTP_1_1);
5454
Poco::Net::HTTPResponse response;
5555

56-
nlohmann::json initProperties1 = { {"property1", "some_string1" }, { "property2", 92 }, { "property3", true } };
57-
nlohmann::json initProperties2 = { {"property1", "some_string2" }, { "property2", 29 }, { "property3", false } };
56+
std::string propert1Name = "property1";
57+
std::string propert2Name = "property2";
58+
std::string propert3Name = "property3";
59+
std::string stringValue1 = "someString1";
60+
std::string stringValue2 = "someString2";
61+
int someIntValue1 = 91;
62+
int someIntValue2 = 19;
63+
bool boolFalse = false;
64+
bool boolTrue = true;
65+
66+
auto initProperties1 = ApiGear::ObjectLink::argumentsToContent(ApiGear::ObjectLink::toInitialProperty(propert1Name, stringValue1),
67+
ApiGear::ObjectLink::toInitialProperty( propert2Name, someIntValue1),
68+
ApiGear::ObjectLink::toInitialProperty( propert3Name, boolTrue ));
69+
auto initProperties2 = ApiGear::ObjectLink::argumentsToContent(ApiGear::ObjectLink::toInitialProperty(propert1Name, stringValue2),
70+
ApiGear::ObjectLink::toInitialProperty( propert2Name, someIntValue2),
71+
ApiGear::ObjectLink::toInitialProperty( propert3Name, boolFalse));
5872

5973
std::string any_payload = "any";
6074

goldenmaster/modules/tb_enum_module/tb_enum/generated/olink/enuminterfaceclient.cpp

Lines changed: 62 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "tb_enum/generated/core/tb_enum.json.adapter.h"
66

77
#include "olink/iclientnode.h"
8+
#include "olink/core/olinkcontent.h"
89
#include "apigear/utilities/logger.h"
910

1011
using namespace Test::TbEnum;
@@ -19,35 +20,27 @@ EnumInterfaceClient::EnumInterfaceClient()
1920
: m_publisher(std::make_unique<EnumInterfacePublisher>())
2021
{}
2122

22-
void EnumInterfaceClient::applyState(const nlohmann::json& fields)
23-
{
24-
if(fields.contains("prop0")) {
25-
setProp0Local(fields["prop0"].get<Enum0Enum>());
26-
}
27-
if(fields.contains("prop1")) {
28-
setProp1Local(fields["prop1"].get<Enum1Enum>());
29-
}
30-
if(fields.contains("prop2")) {
31-
setProp2Local(fields["prop2"].get<Enum2Enum>());
32-
}
33-
if(fields.contains("prop3")) {
34-
setProp3Local(fields["prop3"].get<Enum3Enum>());
35-
}
36-
}
37-
38-
void EnumInterfaceClient::applyProperty(const std::string& propertyName, const nlohmann::json& value)
23+
void EnumInterfaceClient::applyProperty(const std::string& propertyName, const ApiGear::ObjectLink::OLinkContent& value)
3924
{
4025
if ( propertyName == "prop0") {
41-
setProp0Local(value.get<Enum0Enum>());
26+
Enum0Enum value_prop0 {};
27+
readValue(value, value_prop0);
28+
setProp0Local(value_prop0);
4229
}
4330
else if ( propertyName == "prop1") {
44-
setProp1Local(value.get<Enum1Enum>());
31+
Enum1Enum value_prop1 {};
32+
readValue(value, value_prop1);
33+
setProp1Local(value_prop1);
4534
}
4635
else if ( propertyName == "prop2") {
47-
setProp2Local(value.get<Enum2Enum>());
36+
Enum2Enum value_prop2 {};
37+
readValue(value, value_prop2);
38+
setProp2Local(value_prop2);
4839
}
4940
else if ( propertyName == "prop3") {
50-
setProp3Local(value.get<Enum3Enum>());
41+
Enum3Enum value_prop3 {};
42+
readValue(value, value_prop3);
43+
setProp3Local(value_prop3);
5144
}
5245
}
5346

@@ -58,7 +51,7 @@ void EnumInterfaceClient::setProp0(Enum0Enum prop0)
5851
return;
5952
}
6053
static const auto propertyId = ApiGear::ObjectLink::Name::createMemberId(olinkObjectName(), "prop0");
61-
m_node->setRemoteProperty(propertyId, prop0);
54+
m_node->setRemoteProperty(propertyId, ApiGear::ObjectLink::propertyToContent(prop0));
6255
}
6356

6457
void EnumInterfaceClient::setProp0Local(Enum0Enum prop0)
@@ -81,7 +74,7 @@ void EnumInterfaceClient::setProp1(Enum1Enum prop1)
8174
return;
8275
}
8376
static const auto propertyId = ApiGear::ObjectLink::Name::createMemberId(olinkObjectName(), "prop1");
84-
m_node->setRemoteProperty(propertyId, prop1);
77+
m_node->setRemoteProperty(propertyId, ApiGear::ObjectLink::propertyToContent(prop1));
8578
}
8679

8780
void EnumInterfaceClient::setProp1Local(Enum1Enum prop1)
@@ -104,7 +97,7 @@ void EnumInterfaceClient::setProp2(Enum2Enum prop2)
10497
return;
10598
}
10699
static const auto propertyId = ApiGear::ObjectLink::Name::createMemberId(olinkObjectName(), "prop2");
107-
m_node->setRemoteProperty(propertyId, prop2);
100+
m_node->setRemoteProperty(propertyId, ApiGear::ObjectLink::propertyToContent(prop2));
108101
}
109102

110103
void EnumInterfaceClient::setProp2Local(Enum2Enum prop2)
@@ -127,7 +120,7 @@ void EnumInterfaceClient::setProp3(Enum3Enum prop3)
127120
return;
128121
}
129122
static const auto propertyId = ApiGear::ObjectLink::Name::createMemberId(olinkObjectName(), "prop3");
130-
m_node->setRemoteProperty(propertyId, prop3);
123+
m_node->setRemoteProperty(propertyId, ApiGear::ObjectLink::propertyToContent(prop3));
131124
}
132125

133126
void EnumInterfaceClient::setProp3Local(Enum3Enum prop3)
@@ -164,10 +157,12 @@ std::future<Enum0Enum> EnumInterfaceClient::func0Async(Enum0Enum param0)
164157
{
165158
std::promise<Enum0Enum> resultPromise;
166159
static const auto operationId = ApiGear::ObjectLink::Name::createMemberId(olinkObjectName(), "func0");
167-
m_node->invokeRemote(operationId,
168-
nlohmann::json::array({param0}), [&resultPromise](ApiGear::ObjectLink::InvokeReplyArg arg) {
169-
const Enum0Enum& value = arg.value.get<Enum0Enum>();
170-
resultPromise.set_value(value);
160+
auto args = ApiGear::ObjectLink::argumentsToContent( param0 );
161+
m_node->invokeRemote(operationId, args,
162+
[&resultPromise](ApiGear::ObjectLink::InvokeReplyArg arg) {
163+
Enum0Enum result{};
164+
readValue(arg.value, result);
165+
resultPromise.set_value(result);
171166
});
172167
return resultPromise.get_future().get();
173168
}
@@ -195,10 +190,12 @@ std::future<Enum1Enum> EnumInterfaceClient::func1Async(Enum1Enum param1)
195190
{
196191
std::promise<Enum1Enum> resultPromise;
197192
static const auto operationId = ApiGear::ObjectLink::Name::createMemberId(olinkObjectName(), "func1");
198-
m_node->invokeRemote(operationId,
199-
nlohmann::json::array({param1}), [&resultPromise](ApiGear::ObjectLink::InvokeReplyArg arg) {
200-
const Enum1Enum& value = arg.value.get<Enum1Enum>();
201-
resultPromise.set_value(value);
193+
auto args = ApiGear::ObjectLink::argumentsToContent( param1 );
194+
m_node->invokeRemote(operationId, args,
195+
[&resultPromise](ApiGear::ObjectLink::InvokeReplyArg arg) {
196+
Enum1Enum result{};
197+
readValue(arg.value, result);
198+
resultPromise.set_value(result);
202199
});
203200
return resultPromise.get_future().get();
204201
}
@@ -226,10 +223,12 @@ std::future<Enum2Enum> EnumInterfaceClient::func2Async(Enum2Enum param2)
226223
{
227224
std::promise<Enum2Enum> resultPromise;
228225
static const auto operationId = ApiGear::ObjectLink::Name::createMemberId(olinkObjectName(), "func2");
229-
m_node->invokeRemote(operationId,
230-
nlohmann::json::array({param2}), [&resultPromise](ApiGear::ObjectLink::InvokeReplyArg arg) {
231-
const Enum2Enum& value = arg.value.get<Enum2Enum>();
232-
resultPromise.set_value(value);
226+
auto args = ApiGear::ObjectLink::argumentsToContent( param2 );
227+
m_node->invokeRemote(operationId, args,
228+
[&resultPromise](ApiGear::ObjectLink::InvokeReplyArg arg) {
229+
Enum2Enum result{};
230+
readValue(arg.value, result);
231+
resultPromise.set_value(result);
233232
});
234233
return resultPromise.get_future().get();
235234
}
@@ -257,10 +256,12 @@ std::future<Enum3Enum> EnumInterfaceClient::func3Async(Enum3Enum param3)
257256
{
258257
std::promise<Enum3Enum> resultPromise;
259258
static const auto operationId = ApiGear::ObjectLink::Name::createMemberId(olinkObjectName(), "func3");
260-
m_node->invokeRemote(operationId,
261-
nlohmann::json::array({param3}), [&resultPromise](ApiGear::ObjectLink::InvokeReplyArg arg) {
262-
const Enum3Enum& value = arg.value.get<Enum3Enum>();
263-
resultPromise.set_value(value);
259+
auto args = ApiGear::ObjectLink::argumentsToContent( param3 );
260+
m_node->invokeRemote(operationId, args,
261+
[&resultPromise](ApiGear::ObjectLink::InvokeReplyArg arg) {
262+
Enum3Enum result{};
263+
readValue(arg.value, result);
264+
resultPromise.set_value(result);
264265
});
265266
return resultPromise.get_future().get();
266267
}
@@ -272,35 +273,43 @@ std::string EnumInterfaceClient::olinkObjectName()
272273
return interfaceId;
273274
}
274275

275-
void EnumInterfaceClient::olinkOnSignal(const std::string& signalId, const nlohmann::json& args)
276+
void EnumInterfaceClient::olinkOnSignal(const std::string& signalId, const ApiGear::ObjectLink::OLinkContent& args)
276277
{
277278
const auto& signalName = ApiGear::ObjectLink::Name::getMemberName(signalId);
278-
if(signalName == "sig0") {
279-
m_publisher->publishSig0(args[0].get<Enum0Enum>());
279+
ApiGear::ObjectLink::OLinContentStreamReader argumentsReader(args);
280+
if(signalName == "sig0") {Enum0Enum arg_param0 {};
281+
argumentsReader.read(arg_param0);m_publisher->publishSig0(arg_param0);
280282
return;
281283
}
282-
if(signalName == "sig1") {
283-
m_publisher->publishSig1(args[0].get<Enum1Enum>());
284+
if(signalName == "sig1") {Enum1Enum arg_param1 {};
285+
argumentsReader.read(arg_param1);m_publisher->publishSig1(arg_param1);
284286
return;
285287
}
286-
if(signalName == "sig2") {
287-
m_publisher->publishSig2(args[0].get<Enum2Enum>());
288+
if(signalName == "sig2") {Enum2Enum arg_param2 {};
289+
argumentsReader.read(arg_param2);m_publisher->publishSig2(arg_param2);
288290
return;
289291
}
290-
if(signalName == "sig3") {
291-
m_publisher->publishSig3(args[0].get<Enum3Enum>());
292+
if(signalName == "sig3") {Enum3Enum arg_param3 {};
293+
argumentsReader.read(arg_param3);m_publisher->publishSig3(arg_param3);
292294
return;
293295
}
294296
}
295297

296-
void EnumInterfaceClient::olinkOnPropertyChanged(const std::string& propertyId, const nlohmann::json& value)
298+
void EnumInterfaceClient::olinkOnPropertyChanged(const std::string& propertyId, const ApiGear::ObjectLink::OLinkContent& value)
297299
{
298300
applyProperty(ApiGear::ObjectLink::Name::getMemberName(propertyId), value);
299301
}
300-
void EnumInterfaceClient::olinkOnInit(const std::string& /*name*/, const nlohmann::json& props, ApiGear::ObjectLink::IClientNode *node)
302+
void EnumInterfaceClient::olinkOnInit(const std::string& /*name*/, const ApiGear::ObjectLink::OLinkContent& props, ApiGear::ObjectLink::IClientNode *node)
301303
{
302304
m_node = node;
303-
applyState(props);
305+
ApiGear::ObjectLink::OLinContentStreamReader reader(props);
306+
size_t propertyCount = reader.argumentsCount();
307+
ApiGear::ObjectLink::InitialProperty currentProperty;
308+
for (size_t i = 0; i < propertyCount; i++)
309+
{
310+
reader.read(currentProperty);
311+
applyProperty(currentProperty.propertyName, currentProperty.propertyValue);
312+
}
304313
}
305314

306315
void EnumInterfaceClient::olinkOnRelease()

goldenmaster/modules/tb_enum_module/tb_enum/generated/olink/enuminterfaceclient.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,38 +137,33 @@ class TEST_TB_ENUM_EXPORT EnumInterfaceClient : public IEnumInterface,
137137
* @param signalId Unique identifier for the signal emitted from object.
138138
* @param args The arguments for the signal.
139139
*/
140-
void olinkOnSignal(const std::string& signalId, const nlohmann::json& args) override;
140+
void olinkOnSignal(const std::string& signalId, const ApiGear::ObjectLink::OLinkContent& args) override;
141141

142142
/**
143143
* Applies the information about the property changed on server side.
144144
* @param propertyId Unique identifier of a changed property in object .
145145
* @param value The value of the property.
146146
*/
147-
void olinkOnPropertyChanged(const std::string& propertyId, const nlohmann::json& value) override;
147+
void olinkOnPropertyChanged(const std::string& propertyId, const ApiGear::ObjectLink::OLinkContent& value) override;
148148

149149
/** Informs this object sink that connection was is established.
150150
* @param interfaceId The name of the object for which link was established.
151151
* @param props Initial values obtained from the EnumInterface service
152152
* @param the initialized link endpoint for this sink.
153153
*/
154-
void olinkOnInit(const std::string& interfaceId, const nlohmann::json& props, ApiGear::ObjectLink::IClientNode *node) override;
154+
void olinkOnInit(const std::string& interfaceId, const ApiGear::ObjectLink::OLinkContent& props, ApiGear::ObjectLink::IClientNode *node) override;
155155
/**
156156
* Informs this object source that the link was disconnected and cannot be used anymore.
157157
*/
158158
void olinkOnRelease() override;
159159

160160
private:
161-
/**
162-
* Applies received data to local state and publishes changes to subscribers.
163-
* @param the data received from EnumInterface service.
164-
*/
165-
void applyState(const nlohmann::json& fields);
166161
/**
167162
* Applies received property value to local state and publishes changes to subscribers.
168163
* @param propertyName the name of property to be changed.
169164
* @param value The value for property.
170165
*/
171-
void applyProperty(const std::string& propertyName, const nlohmann::json& value);
166+
void applyProperty(const std::string& propertyName, const ApiGear::ObjectLink::OLinkContent& value);
172167
/** Updates local value for Prop0 and informs subscriber about the change*/
173168
void setProp0Local(Enum0Enum prop0);
174169
/** Updates local value for Prop1 and informs subscriber about the change*/

0 commit comments

Comments
 (0)