--- a/src/Configuration.h Sat Jul 30 11:33:56 2022 +0200
+++ b/src/Configuration.h Sat Jul 30 12:58:14 2022 +0200
@@ -44,7 +44,7 @@
};
- relpipe::common::type::StringX relation = L"socket";
+ relpipe::common::type::StringX relation = L"message";
std::vector<SocketOption> options;
virtual ~Configuration() {
--- a/src/SocketHandler.h Sat Jul 30 11:33:56 2022 +0200
+++ b/src/SocketHandler.h Sat Jul 30 12:58:14 2022 +0200
@@ -23,6 +23,7 @@
#include <sstream>
#include <locale>
#include <codecvt>
+#include <regex>
#include <relpipe/common/type/typedefs.h>
#include <relpipe/reader/TypeId.h>
@@ -42,10 +43,12 @@
std::wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings.
Configuration configuration;
std::shared_ptr<Socket> socket;
+ std::wregex relationPattern;
struct CurrentRelation {
relpipe::common::type::StringX name;
std::vector<relpipe::reader::handlers::AttributeMetadata> attributes;
+ bool valid;
relpipe::common::type::Integer attributeIndex = 0;
std::string currentValue;
} currentRelation;
@@ -62,28 +65,28 @@
public:
- SocketHandler(Configuration configuration) : configuration(configuration) {
+ SocketHandler(Configuration configuration) : configuration(configuration), relationPattern(std::wregex(configuration.relation)) {
}
void startRelation(relpipe::common::type::StringX name, std::vector<relpipe::reader::handlers::AttributeMetadata> attributes) override {
- configureSocket();
- currentRelation = CurrentRelation{name, attributes};
+ currentRelation = CurrentRelation{name, attributes, std::regex_match(name, relationPattern)};
+ if (currentRelation.valid) configureSocket();
}
void attribute(const relpipe::common::type::StringX& value) override {
-
- auto attributeName = currentRelation.attributes[currentRelation.attributeIndex].getAttributeName();
- if (attributeName == L"text" && value.size()) currentRelation.currentValue = convertor.to_bytes(value);
- else if (attributeName == L"data" && value.size()) currentRelation.currentValue = Hex::fromHex(value).str();
- else if (attributeName == L"text"); // keep empty or value from 'data'
- else if (attributeName == L"data"); // keep empty or value from 'text'
+ if (currentRelation.valid) {
+ auto attributeName = currentRelation.attributes[currentRelation.attributeIndex].getAttributeName();
+ if (attributeName == L"text" && value.size()) currentRelation.currentValue = convertor.to_bytes(value);
+ else if (attributeName == L"data" && value.size()) currentRelation.currentValue = Hex::fromHex(value).str();
+ else if (attributeName == L"text"); // keep empty or value from 'data'
+ else if (attributeName == L"data"); // keep empty or value from 'text'
- currentRelation.attributeIndex++;
- if (currentRelation.attributeIndex == currentRelation.attributes.size()) {
- currentRelation.attributeIndex = 0;
- socket->send(currentRelation.currentValue);
+ currentRelation.attributeIndex++;
+ if (currentRelation.attributeIndex == currentRelation.attributes.size()) {
+ currentRelation.attributeIndex = 0;
+ socket->send(currentRelation.currentValue);
+ }
}
-
}
void endOfPipe() {