![]() |
libzmq master
The Intelligent Transport Layer
|
00001 /* 00002 Copyright (c) 2009-2011 250bpm s.r.o. 00003 Copyright (c) 2007-2009 iMatix Corporation 00004 Copyright (c) 2007-2011 Other contributors as noted in the AUTHORS file 00005 00006 This file is part of 0MQ. 00007 00008 0MQ is free software; you can redistribute it and/or modify it under 00009 the terms of the GNU Lesser General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 0MQ is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU Lesser General Public License for more details. 00017 00018 You should have received a copy of the GNU Lesser General Public License 00019 along with this program. If not, see <http://www.gnu.org/licenses/>. 00020 */ 00021 00022 #ifndef __ZMQ_IO_OBJECT_HPP_INCLUDED__ 00023 #define __ZMQ_IO_OBJECT_HPP_INCLUDED__ 00024 00025 #include <stddef.h> 00026 00027 #include "stdint.hpp" 00028 #include "poller.hpp" 00029 #include "i_poll_events.hpp" 00030 00031 namespace zmq 00032 { 00033 00034 // Simple base class for objects that live in I/O threads. 00035 // It makes communication with the poller object easier and 00036 // makes defining unneeded event handlers unnecessary. 00037 00038 class io_object_t : public i_poll_events 00039 { 00040 public: 00041 00042 io_object_t (class io_thread_t *io_thread_ = NULL); 00043 ~io_object_t (); 00044 00045 // When migrating an object from one I/O thread to another, first 00046 // unplug it, then migrate it, then plug it to the new thread. 00047 void plug (class io_thread_t *io_thread_); 00048 void unplug (); 00049 00050 protected: 00051 00052 typedef poller_t::handle_t handle_t; 00053 00054 // Methods to access underlying poller object. 00055 handle_t add_fd (fd_t fd_); 00056 void rm_fd (handle_t handle_); 00057 void set_pollin (handle_t handle_); 00058 void reset_pollin (handle_t handle_); 00059 void set_pollout (handle_t handle_); 00060 void reset_pollout (handle_t handle_); 00061 void add_timer (int timout_, int id_); 00062 void cancel_timer (int id_); 00063 00064 // i_poll_events interface implementation. 00065 void in_event (); 00066 void out_event (); 00067 void timer_event (int id_); 00068 00069 private: 00070 00071 poller_t *poller; 00072 00073 io_object_t (const io_object_t&); 00074 const io_object_t &operator = (const io_object_t&); 00075 }; 00076 00077 } 00078 00079 #endif