| 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 | class io_thread_t; |
| 42 | |
| 43 | // Simple base class for objects that live in I/O threads. |
| 44 | // It makes communication with the poller object easier and |
| 45 | // makes defining unneeded event handlers unnecessary. |
| 46 | |
| 47 | class io_object_t : public i_poll_events |
| 48 | { |
| 49 | public: |
| 50 | io_object_t (zmq::io_thread_t *io_thread_ = NULL); |
| 51 | ~io_object_t (); |
| 52 | |
| 53 | // When migrating an object from one I/O thread to another, first |
| 54 | // unplug it, then migrate it, then plug it to the new thread. |
| 55 | void plug (zmq::io_thread_t *io_thread_); |
| 56 | void unplug (); |
| 57 | |
| 58 | protected: |
| 59 | typedef poller_t::handle_t handle_t; |
| 60 | |
| 61 | // Methods to access underlying poller object. |
| 62 | handle_t add_fd (fd_t fd_); |
| 63 | void rm_fd (handle_t handle_); |
| 64 | void set_pollin (handle_t handle_); |
| 65 | void reset_pollin (handle_t handle_); |
| 66 | void set_pollout (handle_t handle_); |
| 67 | void reset_pollout (handle_t handle_); |
| 68 | void add_timer (int timeout_, int id_); |
| 69 | void cancel_timer (int id_); |
| 70 | |
| 71 | // i_poll_events interface implementation. |
| 72 | void in_event (); |
| 73 | void out_event (); |
| 74 | void timer_event (int id_); |
| 75 | |
| 76 | private: |
| 77 | poller_t *_poller; |
| 78 | |
| 79 | ZMQ_NON_COPYABLE_NOR_MOVABLE (io_object_t) |
| 80 | }; |
| 81 | } |
| 82 | |
| 83 | #endif |
| 84 | |