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 
00082         virtual void do_events() { }
00083             
00085 
00096         virtual bool add(Socket *socket, int fd, unsigned int events);
00097         
00099 
00108         virtual bool update(Socket *socket, int fd, unsigned int events);
00109         
00111 
00119         virtual void remove(Socket *socket, int fd);
00120         
00122         std::string const &name() const { return m_name; }
00123     protected:
00125         typedef containers::VectorSP<Socket *, size_t> sockets_list;
00126         
00128         sockets_list m_sockets;
00129         
00131         Socket *get_socket(int fd) const;
00133         void set_socket(int fd, Socket *s);
00134         
00136         size_t hint() const { return m_hint; }
00137     private:
00138         std::string m_name;
00139         size_t m_hint;
00140         
00141         Monitor(Monitor const &);
00142         Monitor &operator=(Monitor const &);
00143 };
00144 
00145 /*************************************************************************/
00146 
00147 typedef containers::VectorSP<Monitor *, size_t> monitors_list;
00148 
00149 extern monitors_list monitors;
00150 extern Monitor *default_monitor;
00151 
00152 /*************************************************************************/
00153 
00155 
00162 extern void setup_monitors(size_t hint);
00163 
00165 
00168 extern void do_events();
00169 
00170 /*************************************************************************/
00171 
00172 } /* namespace sockets */
00173 
00174 /*************************************************************************/
00175 
00176 #endif /* SOCKETS_MONITOR_H */

Generated on Sun May 20 21:32:14 2007 for Epona API by  doxygen 1.4.6