-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWebUITimer.cpp
45 lines (41 loc) · 1.35 KB
/
WebUITimer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "WebUITimer.h"
#include <Wt/WServer>
namespace WebUITimerHelper{
// function object to trigger an update in the application thread
class TriggerUpdate{
public:
void operator()()
{
Wt::WApplication::instance()->triggerUpdate();
}
};
}
void WebUITimer::tick()
{
RsStackMutex stack(mMtx);
if(mServer == NULL){
std::cerr << "WebUITimer::tick(): wrong usage error. Please call setServer() before ticking the timer." << std::endl;
return;
}
std::vector<std::list<Event>::iterator > eventsToDelete;
for(std::list<Event>::iterator lit = mEvents.begin(); lit != mEvents.end(); lit++)
{
Event& event = *lit;
if(event.when <= time(NULL))
{
mServer->post(event.sessionId, event.functionToCall);
// trigger an update
// this propagates the changes to the browser
// do it here, then all the receiving objects don't have to worry about it
// this makes WebUITimer behave very similar as Wt::WTimer
mServer->post(event.sessionId, WebUITimerHelper::TriggerUpdate());
eventsToDelete.push_back(lit);
}
}
// erase handled events
std::vector<std::list<Event>::iterator >::iterator vit;
for(vit = eventsToDelete.begin(); vit != eventsToDelete.end(); vit++)
{
mEvents.erase(*vit);
}
}