1 /** \file IEventOwner.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_IEventOwner_H 33 #define _SOCKETS_IEventOwner_H 34 35 #include "sockets-config.h" 36 #include "IEventHandler.h" 37 38 #ifdef SOCKETS_NAMESPACE 39 namespace SOCKETS_NAMESPACE { 40 #endif 41 42 43 /** Any class that wants to use timer events inherits this. 44 \ingroup timer */ 45 class IEventOwner 46 { 47 public: 48 IEventOwner(IEventHandler& h); 49 virtual ~IEventOwner(); 50 51 /** Schedule event. 52 \param sec Seconds until event 53 \param usec Microseconds until event 54 \return Event ID */ 55 long AddEvent(long sec,long usec); 56 /** Clear all events scheduled by this owner. */ 57 void ClearEvents(); 58 /** Remove one event scheduled by this owner. 59 \param eid Event ID to remove */ 60 void RemoveEvent(long eid); 61 /** Event callback will fire when time is up. */ 62 virtual void OnEvent(int) = 0; 63 64 IEventHandler& GetEventHandler(); 65 void SetHandlerInvalid(bool x = true) { m_handler_invalid = x; } 66 67 private: 68 IEventHandler& m_event_handler; 69 bool m_handler_invalid; 70 }; 71 72 73 74 #ifdef SOCKETS_NAMESPACE 75 } 76 #endif 77 78 #endif // _SOCKETS_IEventOwner_H 79 80