ZeroEQ  0.9.0
ZeroEQ - Zero Event Queue
types.h
1 
2 /* Copyright (c) 2014-2017, Human Brain Project
3  * Daniel Nachbaur <daniel.nachbaur@epfl.ch>
4  * Juan Hernando <jhernando@fi.upm.es>
5  */
6 
7 #pragma once
8 
9 #include <functional>
10 #include <memory>
11 #include <servus/serializable.h>
12 #include <servus/servus.h>
13 #include <servus/types.h>
14 #include <servus/uint128_t.h>
15 #include <zeroeq/defines.h>
16 
17 #ifdef _WIN32
18 #define NOMINMAX
19 #include <winsock2.h> // SOCKET
20 #ifdef DELETE
21 #undef DELETE
22 #endif
23 #endif
24 
44 namespace zeroeq
45 {
46 using servus::uint128_t;
47 class Monitor;
48 class Publisher;
49 class Sender;
50 class Subscriber;
51 class URI;
52 
53 using URIs = std::vector<URI>;
54 
56 using EventFunc = std::function<void()>;
57 
59 using EventPayloadFunc = std::function<void(const void*, size_t)>;
60 
62 using ReplyFunc = std::function<void(const uint128_t&, const void*, size_t)>;
63 
65 using ReplyData = std::pair<uint128_t, servus::Serializable::Data>;
66 
68 using HandleFunc = std::function<ReplyData(const void*, size_t)>;
69 
70 #ifdef WIN32
71 typedef SOCKET SocketDescriptor;
72 #else
73 typedef int SocketDescriptor;
74 #endif
75 
77 // Attn: identical to Win32 INFINITE!
78 static const uint32_t TIMEOUT_INDEFINITE = 0xffffffffu;
79 
80 using servus::make_uint128;
81 
82 static const std::string DEFAULT_SESSION("__zeroeq");
83 static const std::string NULL_SESSION("__null_session");
84 static const std::string TEST_SESSION(servus::TEST_DRIVER);
85 static const std::string ENV_PUB_SESSION("ZEROEQ_PUB_SESSION");
86 static const std::string ENV_REP_SESSION("ZEROEQ_SERVER_SESSION");
87 
88 namespace detail
89 {
90 struct Socket;
91 }
92 namespace zmq
93 {
94 using ContextPtr = std::shared_ptr<void>;
95 using SocketPtr = std::shared_ptr<void>;
96 }
97 }
std::pair< uint128_t, servus::Serializable::Data > ReplyData
Return value of Server::handle() function (reply ID, reply data)
Definition: types.h:65
std::function< ReplyData(const void *, size_t)> HandleFunc
Callback for serving a Client::request() in Server::handle().
Definition: types.h:68
static const uint32_t TIMEOUT_INDEFINITE
Constant defining &#39;wait forever&#39; in methods with wait parameters.
Definition: types.h:78
Includes compile-time defines of ZeroEQ.
std::function< void()> EventFunc
Callback for receival of subscribed event without payload.
Definition: types.h:56
std::vector< URI > URIs
A vector of URIs.
Definition: types.h:53
std::function< void(const void *, size_t)> EventPayloadFunc
Callback for receival of subscribed event with payload.
Definition: types.h:59
Publish-subscribe and request-reply.
Definition: client.h:10
std::function< void(const uint128_t &, const void *, size_t)> ReplyFunc
Callback for the reply of a Client::request() (reply ID, reply data).
Definition: types.h:62