1 // File: Events_LongOp.cpp
2 // Created: 29 Jul 2014
3 // Author: Mikhail PONIKAROV
5 #include <Events_LongOp.h>
6 #include <Events_Loop.h>
8 /// senders of the long operation collected, ends the long operation event only
9 /// if all senders are stopped
10 std::map<void*, int> MY_SENDERS;
12 Events_LongOp::Events_LongOp(void* theSender)
13 : Events_Message(Events_LongOp::eventID(), theSender)
17 Events_LongOp::~Events_LongOp()
21 Events_ID Events_LongOp::eventID()
23 Events_Loop* aLoop = Events_Loop::loop();
24 return aLoop->eventByName("LongOperation");
27 void Events_LongOp::start(void* theSender)
29 bool toSend = MY_SENDERS.empty();
30 if (MY_SENDERS.find(theSender) == MY_SENDERS.end())
31 MY_SENDERS[theSender] = 1;
33 MY_SENDERS[theSender]++;
36 Events_LongOp anEvent(theSender);
37 Events_Loop::loop()->send(anEvent);
41 void Events_LongOp::end(void* theSender)
43 if (MY_SENDERS.find(theSender) != MY_SENDERS.end()) {
44 int aCount = MY_SENDERS[theSender];
46 MY_SENDERS.erase(theSender);
48 MY_SENDERS[theSender] = aCount - 1;
50 if (MY_SENDERS.empty()) {
51 Events_LongOp anEvent(theSender);
52 Events_Loop::loop()->send(anEvent);
56 bool Events_LongOp::isPerformed()
58 return !MY_SENDERS.empty();