From 366bae00016bfbfdd354ab010555c2927505b2b2 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Thu, 13 Oct 2016 14:35:32 +0200 Subject: Second big network rewrite. This time without the ugly SFINAE hack to restrict sending and receiving on Senders and Receivers respectively. Replaced this hack with private inheritance and using declerations. Also renamed receive to async_receive to better reflect the behaviour. --- libcmix-common/CMakeLists.txt | 16 ++++++++++++++++ libcmix-common/cmixprotofunctor.cpp | 16 ++++++++++++++++ libcmix-common/cmixprotofunctor.hpp | 19 +++++++++++++++++++ libcmix-common/receiver.hpp | 24 ++++++++++++++++++++++++ libcmix-common/sender.hpp | 24 ++++++++++++++++++++++++ libcmix-common/senderreceiver.cpp | 10 ++++++++++ libcmix-common/senderreceiver.hpp | 28 ++++++++++++++++++++++++++++ 7 files changed, 137 insertions(+) create mode 100644 libcmix-common/CMakeLists.txt create mode 100644 libcmix-common/cmixprotofunctor.cpp create mode 100644 libcmix-common/cmixprotofunctor.hpp create mode 100644 libcmix-common/receiver.hpp create mode 100644 libcmix-common/sender.hpp create mode 100644 libcmix-common/senderreceiver.cpp create mode 100644 libcmix-common/senderreceiver.hpp (limited to 'libcmix-common') 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 +{ + 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 +{ + 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 +{ + 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 -- cgit v1.2.3-70-g09d2