diff options
| author | Dennis Brentjes <d.brentjes@gmail.com> | 2016-10-01 12:08:22 +0200 |
|---|---|---|
| committer | Dennis Brentjes <d.brentjes@gmail.com> | 2016-10-01 12:08:22 +0200 |
| commit | 43c7aff79e4ea4a88313fcc81f3281b304d95f0d (patch) | |
| tree | d266ada73e9ebb025dcf46eb0eb21cfa604e80b6 /node/nextnode.hpp | |
| parent | 2969016625c22d9b1e73534f82aed5a4f26b602f (diff) | |
| download | cmix-43c7aff79e4ea4a88313fcc81f3281b304d95f0d.tar.gz cmix-43c7aff79e4ea4a88313fcc81f3281b304d95f0d.tar.bz2 cmix-43c7aff79e4ea4a88313fcc81f3281b304d95f0d.zip | |
All CMix communication is now wrapped in a CMixMessage.
Diffstat (limited to 'node/nextnode.hpp')
| -rw-r--r-- | node/nextnode.hpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/node/nextnode.hpp b/node/nextnode.hpp index 6550445..9601ab5 100644 --- a/node/nextnode.hpp +++ b/node/nextnode.hpp @@ -2,6 +2,8 @@ #include "client.hpp" +#include "cmix.pb.h" + #include <boost/asio/ip/tcp.hpp> /*! @@ -9,6 +11,20 @@ */ /*! + * MESSAGE_SETTER is a boilerplate macro that generates a setter function for our CMix + * protobuf messages, This because there are seperate functions for each to type to use. + * And there seems no way to solve this using templates. + */ +#define MESSAGE_SETTER(T,F,NAME) \ +inline void message_setter(cmix_proto::CMixMessage& m, cmix_proto::T##NAME const& v) { \ + *m.mutable_##F##NAME() = v; \ +} \ + +MESSAGE_SETTER(I,i,nitialization) + +#undef MESSAGE_SETTER + +/*! * \brief The NextNode class represents the next node in the network, will only be sent to. */ class NextNode @@ -23,9 +39,14 @@ public: /*! * \brief send - * \param message is the string that is send to the next node. + * \param v The CMixMessage type we try to send and first have to wrap in a CMixMessage. */ - void send(std::string message); + template <typename T> + void send(T v) { + cmix_proto::CMixMessage m; + message_setter(m, v); + client.send(m.SerializeAsString()); + } /*! * \brief async_connect |
