monitor.h

Go to the documentation of this file.
00001 /* Monitors base class.
00002  *
00003  * PegSoft sockets library (c) 2007 PegSoft
00004  * Contact us at pegsoft@pegsoft.net
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program (see the file COPYING); if not, write to the
00018  * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00024 #ifndef SOCKETS_MONITOR_H
00025 #define SOCKETS_MONITOR_H
00026 
00027 /*************************************************************************/
00028 
00029 #include <string>
00030 
00031 #include <containers/vectorsp.h>
00032 
00033 /*************************************************************************/
00034 
00035 namespace sockets
00036 {
00037 
00038 /*************************************************************************/
00039 
00040 class Socket;
00041 
00042 /*************************************************************************/
00043 
00045 
00052 class Monitor
00053 {
00054     public:
00055         /* Constants */
00056         enum
00057         {
00059             evRead = 0x0001,
00061             evWrite = 0x0002
00062         };
00063         
00064         /* Functions */
00065         
00067 
00073         Monitor(std::string const &name, size_t hint);
00074             
00076         virtual ~Monitor() { }
00077         
00079 
00086         virtual void do_events(time_t wait) { }
00087             
00089 
00100         virtual bool add(Socket *socket, int fd, unsigned int events);
00101         
00103 
00112         virtual bool update(Socket *socket, int fd, unsigned int events);
00113         
00115 
00123         virtual void remove(Socket *socket, int fd);
00124         
00126         std::string const &name() const { return m_name; }
00127     protected:
00129         typedef containers::VectorSP<Socket *, size_t> sockets_list;
00130         
00132         sockets_list m_sockets;
00133         
00135         Socket *get_socket(int fd) const;
00137         void set_socket(int fd, Socket *s);
00138         
00140         size_t hint() const { return m_hint; }
00141     private:
00142         std::string m_name;
00143         size_t m_hint;
00144         
00145         Monitor(Monitor const &);
00146         Monitor &operator=(Monitor const &);
00147 };
00148 
00149 /*************************************************************************/
00150 
00151 typedef containers::VectorSP<Monitor *, size_t> monitors_list;
00152 
00153 extern monitors_list monitors;
00154 extern Monitor *default_monitor;
00155 
00156 /*************************************************************************/
00157 
00159 
00165 extern void setup_monitors(size_t hint);
00166 
00168 
00174 extern void do_events(time_t wait);
00175 
00176 /*************************************************************************/
00177 
00178 } /* namespace sockets */
00179 
00180 /*************************************************************************/
00181 
00182 #endif /* SOCKETS_MONITOR_H */

Generated on Fri Apr 18 22:03:27 2008 for Epona API by  doxygen 1.5.3