Fixed errors in VAB protocol serialization
Change-Id: I7377682dfb1b94380678d1795ef539981410b199
Signed-off-by: Thomas Psota <thomas.psota@iese.fraunhofer.de>
diff --git a/sdks/c++/basys.sdk.cc/include/BaSyx/server/BaSyxTCPServer.h b/sdks/c++/basys.sdk.cc/include/BaSyx/server/BaSyxTCPServer.h
index e2a6a24..6c554ee 100644
--- a/sdks/c++/basys.sdk.cc/include/BaSyx/server/BaSyxTCPServer.h
+++ b/sdks/c++/basys.sdk.cc/include/BaSyx/server/BaSyxTCPServer.h
@@ -35,7 +35,7 @@
// asio::ip::tcp::endpoint endpoint;
asio::ip::tcp::acceptor acceptor;
- std::vector<basyx::thread> threads;
+ std::vector<std::thread> threads;
std::vector<std::unique_ptr<asio::ip::tcp::socket>> sockets;
bool closed;
@@ -109,7 +109,7 @@
log.info("Incoming new connection");
sockets.emplace_back(std::move(ClientSocket));
- basyx::thread handlerThread{ &TCPServer<T>::processConnection, this, std::ref(*sockets.back()) };
+ std::thread handlerThread{ &TCPServer<T>::processConnection, this, std::ref(*sockets.back()) };
threads.emplace_back(std::move(handlerThread));
}
}
diff --git a/sdks/c++/basys.sdk.cc/include/BaSyx/vab/backend/connector/JSONProvider.h b/sdks/c++/basys.sdk.cc/include/BaSyx/vab/backend/connector/JSONProvider.h
index b6b9ad9..e3a5e4c 100644
--- a/sdks/c++/basys.sdk.cc/include/BaSyx/vab/backend/connector/JSONProvider.h
+++ b/sdks/c++/basys.sdk.cc/include/BaSyx/vab/backend/connector/JSONProvider.h
@@ -37,36 +37,44 @@
return serializeToJSON(path, res);
}
- void processBaSysSet(std::string const& path, std::string const& serializedJSONValue)
+ std::string processBaSysSet(std::string const& path, std::string const& serializedJSONValue)
{
if (!isFrozen(BaSysID::getAddress(path))) {
auto deserialized = basyx::serialization::json::deserialize(serializedJSONValue);
providerBackend->setModelPropertyValue(path, std::move(deserialized));
incrementClock(BaSysID::getAddress(path));
}
+
+ return serializeSuccess();
}
- void processBaSysCreate(std::string const& path, std::string const& serializedJSONValue)
+ std::string processBaSysCreate(std::string const& path, std::string const& serializedJSONValue)
{
auto deserialized = basyx::serialization::json::deserialize(serializedJSONValue);
providerBackend->createValue(path, std::move(deserialized));
+
+ return serializeSuccess();
}
- void processBaSysDelete(std::string const& path, std::string const& serializedJSONValue)
+ std::string processBaSysDelete(std::string const& path, std::string const& serializedJSONValue)
{
if (!isFrozen(BaSysID::getAddress(path))) {
auto deserialized = basyx::serialization::json::deserialize(serializedJSONValue);
providerBackend->deleteValue(path, std::move(deserialized));
incrementClock(BaSysID::getAddress(path));
}
+
+ return serializeSuccess();
}
- void processBaSysDelete(std::string const& path)
+ std::string processBaSysDelete(std::string const& path)
{
if (!isFrozen(BaSysID::getAddress(path))) {
providerBackend->deleteValue(path);
incrementClock(BaSysID::getAddress(path));
}
+
+ return serializeSuccess();
}
std::string processBaSysInvoke(std::string const& path, std::string const& serializedJSONValue, char* output, size_t* size)
@@ -90,6 +98,13 @@
private:
Provider* providerBackend;
+ std::string serializeSuccess()
+ {
+ nlohmann::json retJson { { "success", true } };
+
+ return retJson.dump(4);
+ }
+
std::string serializeToJSON(const std::string& path, const basyx::object& value)
{
auto json = basyx::serialization::json::serialize(value);
diff --git a/sdks/c++/basys.sdk.cc/src/vab/vab/provider/native/frame/BaSyxNativeFrameProcessor.cpp b/sdks/c++/basys.sdk.cc/src/vab/vab/provider/native/frame/BaSyxNativeFrameProcessor.cpp
index 3baa356..10e8098 100644
--- a/sdks/c++/basys.sdk.cc/src/vab/vab/provider/native/frame/BaSyxNativeFrameProcessor.cpp
+++ b/sdks/c++/basys.sdk.cc/src/vab/vab/provider/native/frame/BaSyxNativeFrameProcessor.cpp
@@ -83,9 +83,14 @@
// TODO: Error Handling?
std::string serializedValue = BaSyxNativeFrameHelper::getString(rxFrame, 1);
- jsonProvider.processBaSysSet(path, serializedValue);
+ std::string getResult = jsonProvider.processBaSysSet(path, serializedValue);
+ memcpy(txFrame + 5, getResult.c_str(), getResult.size());
- // Set result field to 0 to indicate success
+ // Set return string size
+ CoderTools::setInt32(txFrame + 1, 0, *txSize);
+ *txSize += BASYX_STRINGSIZE_SIZE;
+
+ // Set result field to 0 to indicate success
txFrame[0] = 0;
*txSize += 1;
}
@@ -96,9 +101,15 @@
// TODO: Error Handling?
std::string serializedValue = BaSyxNativeFrameHelper::getString(rxFrame, 1);
- jsonProvider.processBaSysCreate(path, serializedValue);
- // Set result field to 0 to indicate success
+ std::string getResult = jsonProvider.processBaSysCreate(path, serializedValue);
+ memcpy(txFrame + 5, getResult.c_str(), getResult.size());
+
+ // Set return string size
+ CoderTools::setInt32(txFrame + 1, 0, *txSize);
+ *txSize += BASYX_STRINGSIZE_SIZE;
+
+ // Set result field to 0 to indicate success
txFrame[0] = 0;
*txSize += 1;
}
@@ -107,15 +118,23 @@
{
std::string path = BaSyxNativeFrameHelper::getString(rxFrame, 0);
+ std::string result;
+
// Check if there is a serialized json after the path to distinguish between map/collection delete and simple delete
if (path.size() + BASYX_STRINGSIZE_SIZE < rxSize) {
std::string serializedValue = BaSyxNativeFrameHelper::getString(rxFrame,
1);
- jsonProvider.processBaSysDelete(path, serializedValue);
+ result = jsonProvider.processBaSysDelete(path, serializedValue);
} else {
- jsonProvider.processBaSysDelete(path);
+ result = jsonProvider.processBaSysDelete(path);
}
+ memcpy(txFrame + 5, result.c_str(), result.size());
+
+ // Set return string size
+ CoderTools::setInt32(txFrame + 1, 0, *txSize);
+ *txSize += BASYX_STRINGSIZE_SIZE;
+
// Set result field to 0 to indicate success
txFrame[0] = 0;
*txSize += 1;