libzmq  master
ZeroMQ C++ Core Engine (LIBZMQ)
io_object.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_IO_OBJECT_HPP_INCLUDED__
31 #define __ZMQ_IO_OBJECT_HPP_INCLUDED__
32 
33 #include <stddef.h>
34 
35 #include "stdint.hpp"
36 #include "poller.hpp"
37 #include "i_poll_events.hpp"
38 
39 namespace zmq
40 {
41 
42  class io_thread_t;
43 
44  // Simple base class for objects that live in I/O threads.
45  // It makes communication with the poller object easier and
46  // makes defining unneeded event handlers unnecessary.
47 
48  class io_object_t : public i_poll_events
49  {
50  public:
51 
52  io_object_t (zmq::io_thread_t *io_thread_ = NULL);
53  ~io_object_t ();
54 
55  // When migrating an object from one I/O thread to another, first
56  // unplug it, then migrate it, then plug it to the new thread.
57  void plug (zmq::io_thread_t *io_thread_);
58  void unplug ();
59 
60  protected:
61 
62  typedef poller_t::handle_t handle_t;
63 
64  // Methods to access underlying poller object.
65  handle_t add_fd (fd_t fd_);
66  void rm_fd (handle_t handle_);
67  void set_pollin (handle_t handle_);
68  void reset_pollin (handle_t handle_);
69  void set_pollout (handle_t handle_);
70  void reset_pollout (handle_t handle_);
71  void add_timer (int timout_, int id_);
72  void cancel_timer (int id_);
73 
74  // i_poll_events interface implementation.
75  void in_event ();
76  void out_event ();
77  void timer_event (int id_);
78 
79  private:
80 
81  poller_t *poller;
82 
83  io_object_t (const io_object_t&);
84  const io_object_t &operator = (const io_object_t&);
85  };
86 
87 }
88 
89 #endif
void set_pollout(handle_t handle_)
Definition: io_object.cpp:84
void plug(zmq::io_thread_t *io_thread_)
Definition: io_object.cpp:46
void cancel_timer(int id_)
Definition: io_object.cpp:99
poller_t * poller
Definition: io_object.hpp:81
void set_pollin(handle_t handle_)
Definition: io_object.cpp:74
void timer_event(int id_)
Definition: io_object.cpp:114
void reset_pollout(handle_t handle_)
Definition: io_object.cpp:89
void add_timer(int timout_, int id_)
Definition: io_object.cpp:94
void reset_pollin(handle_t handle_)
Definition: io_object.cpp:79
handle_t add_fd(fd_t fd_)
Definition: io_object.cpp:64
const io_object_t & operator=(const io_object_t &)
Definition: address.hpp:35
io_object_t(zmq::io_thread_t *io_thread_=NULL)
Definition: io_object.cpp:35
void rm_fd(handle_t handle_)
Definition: io_object.cpp:69
poller_t::handle_t handle_t
Definition: io_object.hpp:62