aboutsummaryrefslogtreecommitdiff
path: root/libcmix-common
diff options
context:
space:
mode:
Diffstat (limited to 'libcmix-common')
-rw-r--r--libcmix-common/CMakeLists.txt16
-rw-r--r--libcmix-common/cmixprotofunctor.cpp16
-rw-r--r--libcmix-common/cmixprotofunctor.hpp19
-rw-r--r--libcmix-common/receiver.hpp24
-rw-r--r--libcmix-common/sender.hpp24
-rw-r--r--libcmix-common/senderreceiver.cpp10
-rw-r--r--libcmix-common/senderreceiver.hpp28
7 files changed, 137 insertions, 0 deletions
diff --git a/libcmix-common/CMakeLists.txt b/libcmix-common/CMakeLists.txt
new file mode 100644
index 0000000..0861e95
--- /dev/null
+++ b/libcmix-common/CMakeLists.txt
@@ -0,0 +1,16 @@
+
+add_library(cmix-common
+ cmixprotofunctor.hpp cmixprotofunctor.cpp
+ receiver.hpp
+ sender.hpp
+ senderreceiver.hpp senderreceiver.cpp
+)
+
+target_include_directories(cmix-common
+ PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
+)
+
+target_link_libraries(cmix-common
+ PRIVATE cmix-protobuf
+ PRIVATE cmix-network
+) \ No newline at end of file
diff --git a/libcmix-common/cmixprotofunctor.cpp b/libcmix-common/cmixprotofunctor.cpp
new file mode 100644
index 0000000..a026628
--- /dev/null
+++ b/libcmix-common/cmixprotofunctor.cpp
@@ -0,0 +1,16 @@
+#include "cmixprotofunctor.hpp"
+
+#define MESSAGE_SETTER_DEF(TYPE, NAME) \
+ CMixProtoFunctor::proto_type CMixProtoFunctor::operator()(cmix_proto::TYPE const& v) { \
+ proto_type m; \
+ *m.mutable_##NAME() = v; \
+ return m; \
+ } \
+
+MESSAGE_SETTER_DEF(Initialization, initialization)
+MESSAGE_SETTER_DEF(ImANode, imanode)
+MESSAGE_SETTER_DEF(ImAClient, imaclient)
+MESSAGE_SETTER_DEF(Bye, bye)
+MESSAGE_SETTER_DEF(KeyExchange, keyexchange)
+
+#undef MESSAGE_SETTER_DEF \ No newline at end of file
diff --git a/libcmix-common/cmixprotofunctor.hpp b/libcmix-common/cmixprotofunctor.hpp
new file mode 100644
index 0000000..c15f218
--- /dev/null
+++ b/libcmix-common/cmixprotofunctor.hpp
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "cmix.pb.h"
+
+struct CMixProtoFunctor {
+
+ typedef cmix_proto::CMixMessage proto_type;
+
+ #define MESSAGE_SETTER_DECL(TYPE) \
+ proto_type operator()(cmix_proto::TYPE const& v)
+
+ MESSAGE_SETTER_DECL(Initialization);
+ MESSAGE_SETTER_DECL(ImANode);
+ MESSAGE_SETTER_DECL(ImAClient);
+ MESSAGE_SETTER_DECL(Bye);
+ MESSAGE_SETTER_DECL(KeyExchange);
+
+ #undef MESSAGE_SETTER
+};
diff --git a/libcmix-common/receiver.hpp b/libcmix-common/receiver.hpp
new file mode 100644
index 0000000..a70cde0
--- /dev/null
+++ b/libcmix-common/receiver.hpp
@@ -0,0 +1,24 @@
+#pragma once
+
+#include "cmixprotofunctor.hpp"
+
+#include "protobufclient.hpp"
+
+struct SenderReceiver;
+
+struct Receiver : private ProtobufClient<CMixProtoFunctor>
+{
+ friend SenderReceiver;
+
+ using ProtobufClient::ProtobufClient;
+
+ using ProtobufClient::async_receive;
+
+ using ProtobufClient::async_connect;
+
+ using ProtobufClient::close;
+
+ using ProtobufClient::on_done;
+
+ using ProtobufClient::is_open;
+};
diff --git a/libcmix-common/sender.hpp b/libcmix-common/sender.hpp
new file mode 100644
index 0000000..72f0b3d
--- /dev/null
+++ b/libcmix-common/sender.hpp
@@ -0,0 +1,24 @@
+#pragma once
+
+#include "cmixprotofunctor.hpp"
+
+#include "protobufclient.hpp"
+
+struct SenderReceiver;
+
+struct Sender : private ProtobufClient<CMixProtoFunctor>
+{
+ friend SenderReceiver;
+
+ using ProtobufClient::ProtobufClient;
+
+ using ProtobufClient::async_send;
+
+ using ProtobufClient::async_connect;
+
+ using ProtobufClient::close;
+
+ using ProtobufClient::on_done;
+
+ using ProtobufClient::is_open;
+};
diff --git a/libcmix-common/senderreceiver.cpp b/libcmix-common/senderreceiver.cpp
new file mode 100644
index 0000000..eafa8a5
--- /dev/null
+++ b/libcmix-common/senderreceiver.cpp
@@ -0,0 +1,10 @@
+
+#include "senderreceiver.hpp"
+
+SenderReceiver::SenderReceiver(Receiver&& r)
+: ProtobufClient(std::move(r))
+{}
+
+SenderReceiver::SenderReceiver(Sender&& s)
+: ProtobufClient(std::move(s))
+{}
diff --git a/libcmix-common/senderreceiver.hpp b/libcmix-common/senderreceiver.hpp
new file mode 100644
index 0000000..9a07f78
--- /dev/null
+++ b/libcmix-common/senderreceiver.hpp
@@ -0,0 +1,28 @@
+#pragma once
+
+#include "cmixprotofunctor.hpp"
+#include "receiver.hpp"
+#include "sender.hpp"
+
+#include "protobufclient.hpp"
+
+struct SenderReceiver : private ProtobufClient<CMixProtoFunctor>
+{
+ explicit SenderReceiver(Receiver&& r);
+
+ explicit SenderReceiver(Sender&& s);
+
+ using ProtobufClient::ProtobufClient;
+
+ using ProtobufClient::async_receive;
+
+ using ProtobufClient::async_send;
+
+ using ProtobufClient::async_connect;
+
+ using ProtobufClient::close;
+
+ using ProtobufClient::on_done;
+
+ using ProtobufClient::is_open;
+}; \ No newline at end of file