1 /** \file EventHandler.h
2  **	\date  2005-12-07
3  **	\author grymse@alhem.net
4 **/
5 /*
6 Copyright (C) 2005-2011  Anders Hedstrom
7 
8 This library is made available under the terms of the GNU GPL, with
9 the additional exemption that compiling, linking, and/or using OpenSSL
10 is allowed.
11 
12 If you would like to use this library in a closed-source application,
13 a separate license agreement is available. For information about
14 the closed-source license agreement for the C++ sockets library,
15 please visit http://www.alhem.net/Sockets/license.html and/or
16 email license@alhem.net.
17 
18 This program is free software; you can redistribute it and/or
19 modify it under the terms of the GNU General Public License
20 as published by the Free Software Foundation; either version 2
21 of the License, or (at your option) any later version.
22 
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 GNU General Public License for more details.
27 
28 You should have received a copy of the GNU General Public License
29 along with this program; if not, write to the Free Software
30 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
31 */
32 #ifndef _SOCKETS_EventHandler_H
33 #define _SOCKETS_EventHandler_H
34 
35 #include "sockets-config.h"
36 #include "SocketHandler.h"
37 #include "IEventHandler.h"
38 
39 #ifdef SOCKETS_NAMESPACE
40 namespace SOCKETS_NAMESPACE {
41 #endif
42 
43 
44 class StdLog;
45 class IEventOwner;
46 class Event;
47 class TcpSocket;
48 
49 /** SocketHandler implementing the IEventHandler interface.
50 	\ingroup timer */
51 class EventHandler : public SocketHandler,public IEventHandler
52 {
53 public:
54 	EventHandler(StdLog * = NULL);
55 	EventHandler(IMutex&,StdLog * = NULL);
56 	~EventHandler();
57 
58 	bool GetTimeUntilNextEvent(struct timeval *tv);
59 	void CheckEvents();
60 	long AddEvent(IEventOwner *from,long sec,long usec);
61 	void ClearEvents(IEventOwner *from);
62 	void RemoveEvent(IEventOwner *from,long eid);
63 
64 	/** SocketHandler while() loop implemented with event functionality. */
65 	void EventLoop();
66 	/** Stop event loop. */
67 	void SetQuit(bool = true);
68 
69 	void Add(Socket *);
70 
71 private:
EventHandler(const EventHandler &)72 	EventHandler(const EventHandler& ) {} // copy constructor
73 	EventHandler& operator=(const EventHandler& ) { return *this; } // assignment operator
74 	std::list<Event *> m_events;
75 	bool m_quit;
76 };
77 
78 
79 
80 #ifdef SOCKETS_NAMESPACE
81 }
82 #endif
83 
84 #endif // _SOCKETS_EventHandler_H
85 
86