aboutsummaryrefslogtreecommitdiff
path: root/node/nextnode.hpp
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2016-10-01 12:08:22 +0200
committerDennis Brentjes <d.brentjes@gmail.com>2016-10-01 12:08:22 +0200
commit43c7aff79e4ea4a88313fcc81f3281b304d95f0d (patch)
treed266ada73e9ebb025dcf46eb0eb21cfa604e80b6 /node/nextnode.hpp
parent2969016625c22d9b1e73534f82aed5a4f26b602f (diff)
downloadcmix-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.hpp25
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