-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAfterTime.cpp
More file actions
77 lines (65 loc) · 1.68 KB
/
AfterTime.cpp
File metadata and controls
77 lines (65 loc) · 1.68 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*******************************************************************************
* Copyright (c) 2018 Rediscover.
*
*******************************************************************************/
#include "AfterTime.h"
#include "Msg.h"
//#define AFTERTIME_DEBUG 1
#ifdef AFTERTIME_DEBUG
#define atlog(fmt, args...) printf(fmt, ## args)
#else
#define atlog(fmt, args...) /* Don't do anything in release builds */
#endif
/*!
Constructor for afterTime
*/
AfterTime::AfterTime()
{
atlog("AfterTime::AfterTime()\r\n");
th.start(mbed::callback(this, &AfterTime::doDispatch));
}
/*!
Destructor for afterTime, terminates the running dispatch thread.
*/
AfterTime::~AfterTime()
{
atlog("AfterTime::~AfterTime()\r\n");
th.terminate();
}
/*!
This method is called by the client actor to start
the timer.
*/
void AfterTime::sendAfter(Actor *act, int time, MsgType type)
{
atlog("AfterTime::sendAfter() %d %c\r\n", time, type);
actor = act;
// ok
//queue.call_in(time, callback(this, &AfterTime::timeHandler));
// niet ok
//queue.call_in(time, callback(this, &AfterTime::timeHandler), 5);
queue.call_in(time, mbed::Callback<void(MsgType)>(this, &AfterTime::timeHandler), type);
}
/*!
This callback will be called at timeout.
The chosen message is sent to the client actor.
This method is called within a ISR context, so printf() is forbidden.
*/
void AfterTime::timeHandler(MsgType c)
{
// ISR context
//atlog("After::timeHandler()\r\n");
Msg *msg = actor->alloc();
if (msg != NULL)
{
msg->type = c;
actor->put(msg);
}
}
/*!
The dispatch thread for the queue.
*/
void AfterTime::doDispatch()
{
queue.dispatch();
}