libzmq  master
ZeroMQ C++ Core Engine (LIBZMQ)
radio.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_RADIO_HPP_INCLUDED__
31 #define __ZMQ_RADIO_HPP_INCLUDED__
32 
33 #include <map>
34 #include <string>
35 #include <vector>
36 
37 #include "socket_base.hpp"
38 #include "session_base.hpp"
39 #include "mtrie.hpp"
40 #include "array.hpp"
41 #include "dist.hpp"
42 
43 namespace zmq
44 {
45 
46  class ctx_t;
47  class msg_t;
48  class pipe_t;
49  class io_thread_t;
50 
51  class radio_t :
52  public socket_base_t
53  {
54  public:
55 
56  radio_t (zmq::ctx_t *parent_, uint32_t tid_, int sid_);
57  ~radio_t ();
58 
59  // Implementations of virtual functions from socket_base_t.
60  void xattach_pipe (zmq::pipe_t *pipe_, bool subscribe_to_all_ = false);
61  int xsend (zmq::msg_t *msg_);
62  bool xhas_out ();
63  int xrecv (zmq::msg_t *msg_);
64  bool xhas_in ();
65  void xread_activated (zmq::pipe_t *pipe_);
66  void xwrite_activated (zmq::pipe_t *pipe_);
67  void xpipe_terminated (zmq::pipe_t *pipe_);
68 
69  private:
70  // List of all subscriptions mapped to corresponding pipes.
71  typedef std::multimap<std::string, pipe_t*> subscriptions_t;
72  subscriptions_t subscriptions;
73 
74  // List of udp pipes
75  typedef std::vector<pipe_t*> udp_pipes_t;
76  udp_pipes_t udp_pipes;
77 
78  // Distributor of messages holding the list of outbound pipes.
80 
81  radio_t (const radio_t&);
82  const radio_t &operator = (const radio_t&);
83  };
84 
86  {
87  public:
88 
89  radio_session_t (zmq::io_thread_t *io_thread_, bool connect_,
90  zmq::socket_base_t *socket_, const options_t &options_,
91  address_t *addr_);
92  ~radio_session_t ();
93 
94  // Overrides of the functions from session_base_t.
95  int push_msg (msg_t *msg_);
96  int pull_msg (msg_t *msg_);
97  void reset ();
98  private:
99 
100  enum {
102  body
103  } state;
104 
106 
109  };
110 }
111 
112 #endif
void xread_activated(zmq::pipe_t *pipe_)
Definition: radio.cpp:69
void xwrite_activated(zmq::pipe_t *pipe_)
Definition: radio.cpp:96
int xrecv(zmq::msg_t *msg_)
Definition: radio.cpp:148
udp_pipes_t udp_pipes
Definition: radio.hpp:76
int xsend(zmq::msg_t *msg_)
Definition: radio.cpp:119
radio_t(zmq::ctx_t *parent_, uint32_t tid_, int sid_)
Definition: radio.cpp:39
void xattach_pipe(zmq::pipe_t *pipe_, bool subscribe_to_all_=false)
Definition: radio.cpp:49
bool xhas_out()
Definition: radio.cpp:143
std::multimap< std::string, pipe_t * > subscriptions_t
Definition: radio.hpp:71
bool xhas_in()
Definition: radio.cpp:156
void xpipe_terminated(zmq::pipe_t *pipe_)
Definition: radio.cpp:101
const radio_t & operator=(const radio_t &)
std::vector< pipe_t * > udp_pipes_t
Definition: radio.hpp:75
Definition: address.hpp:35
dist_t dist
Definition: radio.hpp:79
subscriptions_t subscriptions
Definition: radio.hpp:72