Skip to content

Commit

Permalink
align to new olink core
Browse files Browse the repository at this point in the history
  • Loading branch information
dorotaphanSiili committed Oct 25, 2023
1 parent cfc27b7 commit 59bcc9f
Show file tree
Hide file tree
Showing 94 changed files with 1,879 additions and 1,684 deletions.
2 changes: 1 addition & 1 deletion goldenmaster/apigear/olink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if(NOT objectlink-core-cpp_FOUND)
message(STATUS "objectlink-core-cpp NOT FOUND, fetching the git repository")
FetchContent_Declare(olink-core
GIT_REPOSITORY https://github.com/apigear-io/objectlink-core-cpp.git
GIT_TAG v0.2.6
GIT_TAG "dphan/extracting-protocol-format"
GIT_SHALLOW TRUE
EXCLUDE_FROM_ALL FALSE
)
Expand Down
13 changes: 10 additions & 3 deletions goldenmaster/apigear/olink/tests/olink_connection.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ namespace {
!= container.end();
}

std::string propert1Name = "property1";
std::string propert2Name = "property2";
std::string propert3Name = "property3";
std::string stringValue1 = "someString1";
int someIntValue1 = 91;
bool boolFalse = false;

auto initProperties = ApiGear::ObjectLink::argumentsToContent(ApiGear::ObjectLink::toInitialProperty(propert1Name, stringValue1),
ApiGear::ObjectLink::toInitialProperty(propert2Name, someIntValue1),
ApiGear::ObjectLink::toInitialProperty(propert3Name, boolFalse));
}

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

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

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

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

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

auto preparedInitMessage = converter.toString(ApiGear::ObjectLink::Protocol::initMessage(sink1Id, initProperties));
Expand Down
18 changes: 16 additions & 2 deletions goldenmaster/apigear/olink/tests/olinkhost.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,22 @@ namespace {
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, "/ws", Poco::Net::HTTPRequest::HTTP_1_1);
Poco::Net::HTTPResponse response;

nlohmann::json initProperties1 = { {"property1", "some_string1" }, { "property2", 92 }, { "property3", true } };
nlohmann::json initProperties2 = { {"property1", "some_string2" }, { "property2", 29 }, { "property3", false } };
std::string propert1Name = "property1";
std::string propert2Name = "property2";
std::string propert3Name = "property3";
std::string stringValue1 = "someString1";
std::string stringValue2 = "someString2";
int someIntValue1 = 91;
int someIntValue2 = 19;
bool boolFalse = false;
bool boolTrue = true;

auto initProperties1 = ApiGear::ObjectLink::argumentsToContent(ApiGear::ObjectLink::toInitialProperty(propert1Name, stringValue1),
ApiGear::ObjectLink::toInitialProperty( propert2Name, someIntValue1),
ApiGear::ObjectLink::toInitialProperty( propert3Name, boolTrue ));
auto initProperties2 = ApiGear::ObjectLink::argumentsToContent(ApiGear::ObjectLink::toInitialProperty(propert1Name, stringValue2),
ApiGear::ObjectLink::toInitialProperty( propert2Name, someIntValue2),
ApiGear::ObjectLink::toInitialProperty( propert3Name, boolFalse));

std::string any_payload = "any";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "tb_enum/generated/core/tb_enum.json.adapter.h"

#include "olink/iclientnode.h"
#include "olink/core/olinkcontent.h"
#include "apigear/utilities/logger.h"

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

void EnumInterfaceClient::applyState(const nlohmann::json& fields)
{
if(fields.contains("prop0")) {
setProp0Local(fields["prop0"].get<Enum0Enum>());
}
if(fields.contains("prop1")) {
setProp1Local(fields["prop1"].get<Enum1Enum>());
}
if(fields.contains("prop2")) {
setProp2Local(fields["prop2"].get<Enum2Enum>());
}
if(fields.contains("prop3")) {
setProp3Local(fields["prop3"].get<Enum3Enum>());
}
}

void EnumInterfaceClient::applyProperty(const std::string& propertyName, const nlohmann::json& value)
void EnumInterfaceClient::applyProperty(const std::string& propertyName, const ApiGear::ObjectLink::OLinkContent& value)
{
if ( propertyName == "prop0") {
setProp0Local(value.get<Enum0Enum>());
Enum0Enum value_prop0 {};
readValue(value, value_prop0);
setProp0Local(value_prop0);
}
else if ( propertyName == "prop1") {
setProp1Local(value.get<Enum1Enum>());
Enum1Enum value_prop1 {};
readValue(value, value_prop1);
setProp1Local(value_prop1);
}
else if ( propertyName == "prop2") {
setProp2Local(value.get<Enum2Enum>());
Enum2Enum value_prop2 {};
readValue(value, value_prop2);
setProp2Local(value_prop2);
}
else if ( propertyName == "prop3") {
setProp3Local(value.get<Enum3Enum>());
Enum3Enum value_prop3 {};
readValue(value, value_prop3);
setProp3Local(value_prop3);
}
}

Expand All @@ -58,7 +51,7 @@ void EnumInterfaceClient::setProp0(Enum0Enum prop0)
return;
}
static const auto propertyId = ApiGear::ObjectLink::Name::createMemberId(olinkObjectName(), "prop0");
m_node->setRemoteProperty(propertyId, prop0);
m_node->setRemoteProperty(propertyId, ApiGear::ObjectLink::propertyToContent(prop0));
}

void EnumInterfaceClient::setProp0Local(Enum0Enum prop0)
Expand All @@ -81,7 +74,7 @@ void EnumInterfaceClient::setProp1(Enum1Enum prop1)
return;
}
static const auto propertyId = ApiGear::ObjectLink::Name::createMemberId(olinkObjectName(), "prop1");
m_node->setRemoteProperty(propertyId, prop1);
m_node->setRemoteProperty(propertyId, ApiGear::ObjectLink::propertyToContent(prop1));
}

void EnumInterfaceClient::setProp1Local(Enum1Enum prop1)
Expand All @@ -104,7 +97,7 @@ void EnumInterfaceClient::setProp2(Enum2Enum prop2)
return;
}
static const auto propertyId = ApiGear::ObjectLink::Name::createMemberId(olinkObjectName(), "prop2");
m_node->setRemoteProperty(propertyId, prop2);
m_node->setRemoteProperty(propertyId, ApiGear::ObjectLink::propertyToContent(prop2));
}

void EnumInterfaceClient::setProp2Local(Enum2Enum prop2)
Expand All @@ -127,7 +120,7 @@ void EnumInterfaceClient::setProp3(Enum3Enum prop3)
return;
}
static const auto propertyId = ApiGear::ObjectLink::Name::createMemberId(olinkObjectName(), "prop3");
m_node->setRemoteProperty(propertyId, prop3);
m_node->setRemoteProperty(propertyId, ApiGear::ObjectLink::propertyToContent(prop3));
}

void EnumInterfaceClient::setProp3Local(Enum3Enum prop3)
Expand Down Expand Up @@ -164,10 +157,12 @@ std::future<Enum0Enum> EnumInterfaceClient::func0Async(Enum0Enum param0)
{
std::promise<Enum0Enum> resultPromise;
static const auto operationId = ApiGear::ObjectLink::Name::createMemberId(olinkObjectName(), "func0");
m_node->invokeRemote(operationId,
nlohmann::json::array({param0}), [&resultPromise](ApiGear::ObjectLink::InvokeReplyArg arg) {
const Enum0Enum& value = arg.value.get<Enum0Enum>();
resultPromise.set_value(value);
auto args = ApiGear::ObjectLink::argumentsToContent( param0 );
m_node->invokeRemote(operationId, args,
[&resultPromise](ApiGear::ObjectLink::InvokeReplyArg arg) {
Enum0Enum result{};
readValue(arg.value, result);
resultPromise.set_value(result);
});
return resultPromise.get_future().get();
}
Expand Down Expand Up @@ -195,10 +190,12 @@ std::future<Enum1Enum> EnumInterfaceClient::func1Async(Enum1Enum param1)
{
std::promise<Enum1Enum> resultPromise;
static const auto operationId = ApiGear::ObjectLink::Name::createMemberId(olinkObjectName(), "func1");
m_node->invokeRemote(operationId,
nlohmann::json::array({param1}), [&resultPromise](ApiGear::ObjectLink::InvokeReplyArg arg) {
const Enum1Enum& value = arg.value.get<Enum1Enum>();
resultPromise.set_value(value);
auto args = ApiGear::ObjectLink::argumentsToContent( param1 );
m_node->invokeRemote(operationId, args,
[&resultPromise](ApiGear::ObjectLink::InvokeReplyArg arg) {
Enum1Enum result{};
readValue(arg.value, result);
resultPromise.set_value(result);
});
return resultPromise.get_future().get();
}
Expand Down Expand Up @@ -226,10 +223,12 @@ std::future<Enum2Enum> EnumInterfaceClient::func2Async(Enum2Enum param2)
{
std::promise<Enum2Enum> resultPromise;
static const auto operationId = ApiGear::ObjectLink::Name::createMemberId(olinkObjectName(), "func2");
m_node->invokeRemote(operationId,
nlohmann::json::array({param2}), [&resultPromise](ApiGear::ObjectLink::InvokeReplyArg arg) {
const Enum2Enum& value = arg.value.get<Enum2Enum>();
resultPromise.set_value(value);
auto args = ApiGear::ObjectLink::argumentsToContent( param2 );
m_node->invokeRemote(operationId, args,
[&resultPromise](ApiGear::ObjectLink::InvokeReplyArg arg) {
Enum2Enum result{};
readValue(arg.value, result);
resultPromise.set_value(result);
});
return resultPromise.get_future().get();
}
Expand Down Expand Up @@ -257,10 +256,12 @@ std::future<Enum3Enum> EnumInterfaceClient::func3Async(Enum3Enum param3)
{
std::promise<Enum3Enum> resultPromise;
static const auto operationId = ApiGear::ObjectLink::Name::createMemberId(olinkObjectName(), "func3");
m_node->invokeRemote(operationId,
nlohmann::json::array({param3}), [&resultPromise](ApiGear::ObjectLink::InvokeReplyArg arg) {
const Enum3Enum& value = arg.value.get<Enum3Enum>();
resultPromise.set_value(value);
auto args = ApiGear::ObjectLink::argumentsToContent( param3 );
m_node->invokeRemote(operationId, args,
[&resultPromise](ApiGear::ObjectLink::InvokeReplyArg arg) {
Enum3Enum result{};
readValue(arg.value, result);
resultPromise.set_value(result);
});
return resultPromise.get_future().get();
}
Expand All @@ -272,35 +273,43 @@ std::string EnumInterfaceClient::olinkObjectName()
return interfaceId;
}

void EnumInterfaceClient::olinkOnSignal(const std::string& signalId, const nlohmann::json& args)
void EnumInterfaceClient::olinkOnSignal(const std::string& signalId, const ApiGear::ObjectLink::OLinkContent& args)
{
const auto& signalName = ApiGear::ObjectLink::Name::getMemberName(signalId);
if(signalName == "sig0") {
m_publisher->publishSig0(args[0].get<Enum0Enum>());
ApiGear::ObjectLink::OLinContentStreamReader argumentsReader(args);
if(signalName == "sig0") {Enum0Enum arg_param0 {};
argumentsReader.read(arg_param0);m_publisher->publishSig0(arg_param0);
return;
}
if(signalName == "sig1") {
m_publisher->publishSig1(args[0].get<Enum1Enum>());
if(signalName == "sig1") {Enum1Enum arg_param1 {};
argumentsReader.read(arg_param1);m_publisher->publishSig1(arg_param1);
return;
}
if(signalName == "sig2") {
m_publisher->publishSig2(args[0].get<Enum2Enum>());
if(signalName == "sig2") {Enum2Enum arg_param2 {};
argumentsReader.read(arg_param2);m_publisher->publishSig2(arg_param2);
return;
}
if(signalName == "sig3") {
m_publisher->publishSig3(args[0].get<Enum3Enum>());
if(signalName == "sig3") {Enum3Enum arg_param3 {};
argumentsReader.read(arg_param3);m_publisher->publishSig3(arg_param3);
return;
}
}

void EnumInterfaceClient::olinkOnPropertyChanged(const std::string& propertyId, const nlohmann::json& value)
void EnumInterfaceClient::olinkOnPropertyChanged(const std::string& propertyId, const ApiGear::ObjectLink::OLinkContent& value)
{
applyProperty(ApiGear::ObjectLink::Name::getMemberName(propertyId), value);
}
void EnumInterfaceClient::olinkOnInit(const std::string& /*name*/, const nlohmann::json& props, ApiGear::ObjectLink::IClientNode *node)
void EnumInterfaceClient::olinkOnInit(const std::string& /*name*/, const ApiGear::ObjectLink::OLinkContent& props, ApiGear::ObjectLink::IClientNode *node)
{
m_node = node;
applyState(props);
ApiGear::ObjectLink::OLinContentStreamReader reader(props);
size_t propertyCount = reader.argumentsCount();
ApiGear::ObjectLink::InitialProperty currentProperty;
for (size_t i = 0; i < propertyCount; i++)
{
reader.read(currentProperty);
applyProperty(currentProperty.propertyName, currentProperty.propertyValue);
}
}

void EnumInterfaceClient::olinkOnRelease()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,38 +137,33 @@ class TEST_TB_ENUM_EXPORT EnumInterfaceClient : public IEnumInterface,
* @param signalId Unique identifier for the signal emitted from object.
* @param args The arguments for the signal.
*/
void olinkOnSignal(const std::string& signalId, const nlohmann::json& args) override;
void olinkOnSignal(const std::string& signalId, const ApiGear::ObjectLink::OLinkContent& args) override;

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

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

private:
/**
* Applies received data to local state and publishes changes to subscribers.
* @param the data received from EnumInterface service.
*/
void applyState(const nlohmann::json& fields);
/**
* Applies received property value to local state and publishes changes to subscribers.
* @param propertyName the name of property to be changed.
* @param value The value for property.
*/
void applyProperty(const std::string& propertyName, const nlohmann::json& value);
void applyProperty(const std::string& propertyName, const ApiGear::ObjectLink::OLinkContent& value);
/** Updates local value for Prop0 and informs subscriber about the change*/
void setProp0Local(Enum0Enum prop0);
/** Updates local value for Prop1 and informs subscriber about the change*/
Expand Down
Loading

0 comments on commit 59bcc9f

Please sign in to comment.