diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-10-13 14:35:32 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-10-13 14:35:32 +0200 |
| commit | 366bae00016bfbfdd354ab010555c2927505b2b2 (patch) | |
| tree | e329c2ff179f62f093c6c53f84fb8faf4f5fccce /libcmix-common | |
| parent | d9587cfd27aa5ef26170ec1983b47f1e26dc8136 (diff) | |
| download | cmix-366bae00016bfbfdd354ab010555c2927505b2b2.tar.gz cmix-366bae00016bfbfdd354ab010555c2927505b2b2.tar.bz2 cmix-366bae00016bfbfdd354ab010555c2927505b2b2.zip | |
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.
Diffstat (limited to 'libcmix-common')
| -rw-r--r-- | libcmix-common/CMakeLists.txt | 16 | ||||
| -rw-r--r-- | libcmix-common/cmixprotofunctor.cpp | 16 | ||||
| -rw-r--r-- | libcmix-common/cmixprotofunctor.hpp | 19 | ||||
| -rw-r--r-- | libcmix-common/receiver.hpp | 24 | ||||
| -rw-r--r-- | libcmix-common/sender.hpp | 24 | ||||
| -rw-r--r-- | libcmix-common/senderreceiver.cpp | 10 | ||||
| -rw-r--r-- | libcmix-common/senderreceiver.hpp | 28 |
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 |
