32 UERROR(
"Handler is null!");
45 UERROR(
"Handler is null!");
70 const std::string & eventName)
72 if(!sender || !receiver)
74 UERROR(
"Sender and/or receiver is null!");
86 const std::string & eventName)
88 if(!sender || !receiver)
90 UERROR(
"Sender and/or receiver is null!");
103 UERROR(
"Sender is null!");
116 UERROR(
"Sender is null!");
145 for(std::list<std::pair<UEvent*, const UEventsSender*> >::iterator it=
events_.begin(); it!=
events_.end(); ++it)
177 std::list<std::pair<UEvent*, const UEventsSender*> >::iterator it;
178 std::list<std::pair<UEvent*, const UEventsSender*> > eventsBuf;
191 for(it=eventsBuf.begin(); it!=eventsBuf.end(); ++it)
203 std::list<UEventsHandler*> handlers;
212 if(handlers.size() == 0)
218 bool handled =
false;
220 for(std::list<UEventsHandler*>::iterator it=handlers.begin(); it!=handlers.end() && !handled; ++it)
231 if(handler != sender)
252 bool handlerFound =
false;
253 for(std::list<UEventsHandler*>::iterator it=
handlers_.begin(); it!=
handlers_.end(); ++it)
275 for (std::list<UEventsHandler*>::iterator it =
handlers_.begin(); it!=
handlers_.end(); ++it)
288 for(std::list<Pipe>::iterator iter=
pipes_.begin(); iter!=
pipes_.end(); ++iter)
290 if(iter->receiver_ == handler)
308 events_.push_back(std::make_pair(event, sender));
331 const std::string & eventName)
333 std::list<UEventsHandler*> pipes;
336 for(std::list<Pipe>::iterator iter=
pipes_.begin(); iter!=
pipes_.end(); ++iter)
338 if(iter->sender_ == sender && iter->eventName_.compare(eventName) == 0)
344 for(std::list<UEventsHandler*>::iterator jter=
handlers_.begin(); jter!=
handlers_.end(); ++jter)
346 if(*jter == iter->receiver_)
348 pipes.push_back(*jter);
370 const std::string & eventName)
374 for(std::list<Pipe>::iterator iter=
pipes_.begin(); iter!=
pipes_.end();++iter)
376 if(iter->sender_ == sender && iter->receiver_ == receiver && iter->eventName_.compare(eventName) == 0)
385 bool handlerFound =
false;
387 for(std::list<UEventsHandler*>::iterator iter=
handlers_.begin(); iter!=
handlers_.end(); ++iter)
389 if(*iter == receiver)
398 pipes_.push_back(
Pipe(sender, receiver, eventName));
402 UERROR(
"Cannot create the pipe because the receiver is not yet " 403 "added to UEventsManager's handlers list.");
408 UWARN(
"Pipe between sender %p and receiver %p with event %s was already created.",
409 sender, receiver, eventName.c_str());
417 const std::string & eventName)
421 bool removed =
false;
422 for(std::list<Pipe>::iterator iter=
pipes_.begin(); iter!=
pipes_.end();)
424 if(iter->sender_ == sender && iter->receiver_ == receiver && iter->eventName_.compare(eventName) == 0)
426 iter =
pipes_.erase(iter);
437 UWARN(
"Pipe between sender %p and receiver %p with event %s didn't exist.",
438 sender, receiver, eventName.c_str());
447 for(std::list<Pipe>::iterator iter=
pipes_.begin(); iter!=
pipes_.end();)
449 if(iter->sender_ == sender)
451 iter =
pipes_.erase(iter);
464 for(std::list<Pipe>::iterator iter=
pipes_.begin(); iter!=
pipes_.end();)
466 if(iter->receiver_ == 0)
468 iter =
pipes_.erase(iter);
static void createPipe(const UEventsSender *sender, const UEventsHandler *receiver, const std::string &eventName)
static void post(UEvent *event, bool async=true, const UEventsSender *sender=0)
void _removeAllPipes(const UEventsSender *sender)
bool setDoomed(T *doomed)
virtual ~UEventsManager()
void _removeNullPipes(const UEventsSender *sender)
std::list< UEventsHandler * > getPipes(const UEventsSender *sender, const std::string &eventName)
void _addHandler(UEventsHandler *handler)
void _postEvent(UEvent *event, bool async=true, const UEventsSender *sender=0)
void _createPipe(const UEventsSender *sender, const UEventsHandler *receiver, const std::string &eventName)
static void removeNullPipes(const UEventsSender *sender)
bool acquire(int n=1, int ms=0)
void _removeHandler(UEventsHandler *handler)
static UEventsManager * instance_
Wrappers of STL for convenient functions.
virtual bool dispatchEvent(UEvent *event, const UEventsSender *sender)
virtual std::string getClassName() const =0
virtual void dispatchEvents()
static void removePipe(const UEventsSender *sender, const UEventsHandler *receiver, const std::string &eventName)
virtual bool handleEvent(UEvent *event)=0
static UDestroyer< UEventsManager > destroyer_
static void addHandler(UEventsHandler *handler)
void _removePipe(const UEventsSender *sender, const UEventsHandler *receiver, const std::string &eventName)
std::list< UEventsHandler * > handlers_
static void removeHandler(UEventsHandler *handler)
virtual void mainLoopKill()
void join(bool killFirst=false)
std::list< std::pair< UEvent *, const UEventsSender * > > events_
static void removeAllPipes(const UEventsSender *sender)
static UEventsManager * getInstance()