libzmq  master
ZeroMQ C++ Core Engine (LIBZMQ)
dish.hpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
3 
4  This file is part of libzmq, the ZeroMQ core engine in C++.
5 
6  libzmq is free software; you can redistribute it and/or modify it under
7  the terms of the GNU Lesser General Public License (LGPL) as published
8  by the Free Software Foundation; either version 3 of the License, or
9  (at your option) any later version.
10 
11  As a special exception, the Contributors give you permission to link
12  this library with independent modules to produce an executable,
13  regardless of the license terms of these independent modules, and to
14  copy and distribute the resulting executable under terms of your choice,
15  provided that you also meet, for each linked independent module, the
16  terms and conditions of the license of that module. An independent
17  module is a module which is not derived from or based on this library.
18  If you modify this library, you must extend this exception to your
19  version of the library.
20 
21  libzmq is distributed in the hope that it will be useful, but WITHOUT
22  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
24  License for more details.
25 
26  You should have received a copy of the GNU Lesser General Public License
27  along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */
29 
30 #ifndef __ZMQ_DISH_HPP_INCLUDED__
31 #define __ZMQ_DISH_HPP_INCLUDED__
32 
33 #include <string>
34 #include <vector>
35 
36 #include "socket_base.hpp"
37 #include "session_base.hpp"
38 #include "dist.hpp"
39 #include "fq.hpp"
40 #include "trie.hpp"
41 
42 namespace zmq
43 {
44 
45  class ctx_t;
46  class pipe_t;
47  class io_thread_t;
48 
49  class dish_t :
50  public socket_base_t
51  {
52  public:
53 
54  dish_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_);
55  ~dish_t ();
56 
57  protected:
58 
59  // Overrides of functions from socket_base_t.
60  void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_);
61  int xsend (zmq::msg_t *msg_);
62  bool xhas_out ();
63  int xrecv (zmq::msg_t *msg_);
64  bool xhas_in ();
65  blob_t get_credential () const;
66  void xread_activated (zmq::pipe_t *pipe_);
67  void xwrite_activated (zmq::pipe_t *pipe_);
68  void xhiccuped (pipe_t *pipe_);
69  void xpipe_terminated (zmq::pipe_t *pipe_);
70  int xjoin (const char *group_);
71  int xleave (const char *group_);
72  private:
73 
74  // Send subscriptions to a pipe
75  void send_subscriptions (pipe_t *pipe_);
76 
77  // Fair queueing object for inbound pipes.
79 
80  // Object for distributing the subscriptions upstream.
82 
83  // The repository of subscriptions.
84  typedef std::set<std::string> subscriptions_t;
85  subscriptions_t subscriptions;
86 
87  // If true, 'message' contains a matching message to return on the
88  // next recv call.
91 
92  dish_t (const dish_t&);
93  const dish_t &operator = (const dish_t&);
94  };
95 
97  {
98  public:
99 
100  dish_session_t (zmq::io_thread_t *io_thread_, bool connect_,
101  zmq::socket_base_t *socket_, const options_t &options_,
102  address_t *addr_);
103  ~dish_session_t ();
104 
105  // Overrides of the functions from session_base_t.
106  int push_msg (msg_t *msg_);
107  int pull_msg (msg_t *msg_);
108  void reset ();
109 
110  private:
111 
112  enum {
114  body
115  } state;
116 
118 
121  };
122 
123 }
124 
125 #endif
void xpipe_terminated(zmq::pipe_t *pipe_)
Definition: dish.cpp:86
subscriptions_t subscriptions
Definition: dish.hpp:85
~dish_t()
Definition: dish.cpp:58
void xread_activated(zmq::pipe_t *pipe_)
Definition: dish.cpp:76
int xleave(const char *group_)
Definition: dish.cpp:135
void xwrite_activated(zmq::pipe_t *pipe_)
Definition: dish.cpp:81
void xhiccuped(pipe_t *pipe_)
Definition: dish.cpp:92
int xrecv(zmq::msg_t *msg_)
Definition: dish.cpp:184
int xsend(zmq::msg_t *msg_)
Definition: dish.cpp:171
bool xhas_out()
Definition: dish.cpp:178
dist_t dist
Definition: dish.hpp:81
bool xhas_in()
Definition: dish.cpp:212
std::basic_string< unsigned char > blob_t
Definition: blob.hpp:134
fq_t fq
Definition: dish.hpp:78
bool has_message
Definition: dish.hpp:89
blob_t get_credential() const
Definition: dish.cpp:239
const dish_t & operator=(const dish_t &)
void send_subscriptions(pipe_t *pipe_)
Definition: dish.cpp:244
void xattach_pipe(zmq::pipe_t *pipe_, bool subscribe_to_all_)
Definition: dish.cpp:64
std::set< std::string > subscriptions_t
Definition: dish.hpp:84
dish_t(zmq::ctx_t *parent_, uint32_t tid_, int sid_)
Definition: dish.cpp:44
int xjoin(const char *group_)
Definition: dish.cpp:98
Definition: address.hpp:35
Definition: fq.hpp:45
msg_t message
Definition: dish.hpp:90