21 #ifndef G_EVENT_HANDLER_H
22 #define G_EVENT_HANDLER_H
34 class EventExceptionHandler ;
35 class EventHandlerList ;
110 typedef std::pair<Descriptor,EventHandler*> Pair ;
111 Iterator(
const std::vector<Pair> & ,
bool ) ;
113 const Pair & operator*()
const ;
114 bool operator==(
const Iterator & )
const ;
115 bool operator!=(
const Iterator & )
const ;
118 std::vector<Pair>::const_iterator m_p ;
119 std::vector<Pair>::const_iterator m_end ;
159 typedef std::vector<Iterator::Pair> List ;
165 static bool disable( List & list ,
Descriptor fd ) ;
166 static bool remove( List & list ,
Descriptor fd ) ;
172 List m_pending_list ;
173 unsigned int m_lock ;
192 GNet::EventHandlerList::Iterator::Iterator(
const std::vector<Pair> & v ,
bool end ) :
193 m_p(end?v.end():v.begin()) ,
196 while( m_p != m_end && (*m_p).second ==
nullptr )
204 while( m_p != m_end && (*m_p).second ==
nullptr )
210 const GNet::EventHandlerList::Iterator::Pair & GNet::EventHandlerList::Iterator::operator*()
const
218 return (*m_p).first ;
224 return (*m_p).second ;
228 bool GNet::EventHandlerList::Iterator::operator==(
const Iterator & other )
const
230 return m_p == other.m_p ;
234 bool GNet::EventHandlerList::Iterator::operator!=(
const Iterator & other )
const
236 return !(*
this == other) ;
void collectGarbage()
Collects garbage resulting from remove()s.
An abstract interface for handling exceptions thrown out of event-loop callbacks (socket events and t...
Iterator begin() const
Returns a forward iterator.
virtual void readEvent()
Called for a read event.
virtual void onException(std::exception &)=0
Called by the event loop when an exception is thrown out of an event loop callback.
A class that encapsulates a network file descriptor and hides knowledge of its o/s-spefific error val...
void lock()
To be called at the start of an begin()/end() iteration if the list might change during the iteration...
virtual void writeEvent()
Called for a write event.
bool contains(Descriptor fd) const
Returns true if the list contains the given file-descriptor.
A base class for classes that handle asynchronous events from the event loop.
void add(Descriptor fd, EventHandler *handler)
Adds a file-descriptor/handler pair to the list.
virtual ~EventExceptionHandler()
Destructor.
void unlock()
Called at the end of a begin()/end() iteration to match a call to lock().
Iterator end() const
Returns an end iterator.
An iterator for file-descriptor/handler-function pairs in a GNet::EventHandlerList.
EventHandlerList(const std::string &type)
Constructor.
EventHandler * find(Descriptor fd)
Finds the handler associated with the given file descriptor.
virtual ~EventHandler()
Destructor.
virtual void exceptionEvent()
Called for a socket-exception event.
A class that maps from a file descriptor to an event handler, used in the implemention of classes der...