Skip to content
This repository was archived by the owner on Aug 19, 2021. It is now read-only.

Commit 2c4e6a2

Browse files
committed
Renamed post -> call functions
- Matches names of underlying C api - Allows option of moving C api's post function into C++ api - Potentially more intuitive to new users post -> call post_in -> call_in post_every -> call_every
1 parent 7c44753 commit 2c4e6a2

File tree

3 files changed

+75
-75
lines changed

3 files changed

+75
-75
lines changed

EventQueue.h

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class EventQueue {
8888
* or 0 on failure
8989
*/
9090
template <typename F>
91-
int post(F f) {
91+
int call(F f) {
9292
void *p = event_alloc(&_equeue, sizeof(F));
9393
if (!p) {
9494
return 0;
@@ -100,28 +100,28 @@ class EventQueue {
100100
}
101101

102102
template <typename F, typename A0>
103-
int post(F f, A0 a0) {
104-
return post(Context1<F,A0>(f,a0));
103+
int call(F f, A0 a0) {
104+
return call(Context1<F,A0>(f,a0));
105105
}
106106

107107
template <typename F, typename A0, typename A1>
108-
int post(F f, A0 a0, A1 a1) {
109-
return post(Context2<F,A0,A1>(f,a0,a1));
108+
int call(F f, A0 a0, A1 a1) {
109+
return call(Context2<F,A0,A1>(f,a0,a1));
110110
}
111111

112112
template <typename F, typename A0, typename A1, typename A2>
113-
int post(F f, A0 a0, A1 a1, A2 a2) {
114-
return post(Context3<F,A0,A1,A2>(f,a0,a1,a2));
113+
int call(F f, A0 a0, A1 a1, A2 a2) {
114+
return call(Context3<F,A0,A1,A2>(f,a0,a1,a2));
115115
}
116116

117117
template <typename F, typename A0, typename A1, typename A2, typename A3>
118-
int post(F f, A0 a0, A1 a1, A2 a2, A3 a3) {
119-
return post(Context4<F,A0,A1,A2,A3>(f,a0,a1,a2,a3));
118+
int call(F f, A0 a0, A1 a1, A2 a2, A3 a3) {
119+
return call(Context4<F,A0,A1,A2,A3>(f,a0,a1,a2,a3));
120120
}
121121

122122
template <typename F, typename A0, typename A1, typename A2, typename A3, typename A4>
123-
int post(F f, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
124-
return post(Context5<F,A0,A1,A2,A3,A4>(f,a0,a1,a2,a3,a4));
123+
int call(F f, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
124+
return call(Context5<F,A0,A1,A2,A3,A4>(f,a0,a1,a2,a3,a4));
125125
}
126126

127127
/** Post an event to the queue after a specified delay
@@ -133,7 +133,7 @@ class EventQueue {
133133
* or 0 on failure
134134
*/
135135
template <typename F>
136-
int post_in(int ms, F f) {
136+
int call_in(int ms, F f) {
137137
void *p = event_alloc(&_equeue, sizeof(F));
138138
if (!p) {
139139
return 0;
@@ -146,28 +146,28 @@ class EventQueue {
146146
}
147147

148148
template <typename F, typename A0>
149-
int post_in(int ms, F f, A0 a0) {
150-
return post_in(ms, Context1<F,A0>(f,a0));
149+
int call_in(int ms, F f, A0 a0) {
150+
return call_in(ms, Context1<F,A0>(f,a0));
151151
}
152152

153153
template <typename F, typename A0, typename A1>
154-
int post_in(int ms, F f, A0 a0, A1 a1) {
155-
return post_in(ms, Context2<F,A0,A1>(f,a0,a1));
154+
int call_in(int ms, F f, A0 a0, A1 a1) {
155+
return call_in(ms, Context2<F,A0,A1>(f,a0,a1));
156156
}
157157

158158
template <typename F, typename A0, typename A1, typename A2>
159-
int post_in(int ms, F f, A0 a0, A1 a1, A2 a2) {
160-
return post_in(ms, Context3<F,A0,A1,A2>(f,a0,a1,a2));
159+
int call_in(int ms, F f, A0 a0, A1 a1, A2 a2) {
160+
return call_in(ms, Context3<F,A0,A1,A2>(f,a0,a1,a2));
161161
}
162162

163163
template <typename F, typename A0, typename A1, typename A2, typename A3>
164-
int post_in(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3) {
165-
return post_in(ms, Context4<F,A0,A1,A2,A3>(f,a0,a1,a2,a3));
164+
int call_in(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3) {
165+
return call_in(ms, Context4<F,A0,A1,A2,A3>(f,a0,a1,a2,a3));
166166
}
167167

168168
template <typename F, typename A0, typename A1, typename A2, typename A3, typename A4>
169-
int post_in(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
170-
return post_in(ms, Context5<F,A0,A1,A2,A3,A4>(f,a0,a1,a2,a3,a4));
169+
int call_in(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
170+
return call_in(ms, Context5<F,A0,A1,A2,A3,A4>(f,a0,a1,a2,a3,a4));
171171
}
172172

173173
/** Post an event to the queue periodically
@@ -179,7 +179,7 @@ class EventQueue {
179179
* or 0 on failure
180180
*/
181181
template <typename F>
182-
int post_every(int ms, F f) {
182+
int call_every(int ms, F f) {
183183
void *p = event_alloc(&_equeue, sizeof(F));
184184
if (!p) {
185185
return 0;
@@ -193,28 +193,28 @@ class EventQueue {
193193
}
194194

195195
template <typename F, typename A0>
196-
int post_every(int ms, F f, A0 a0) {
197-
return post_every(ms, Context1<F,A0>(f,a0));
196+
int call_every(int ms, F f, A0 a0) {
197+
return call_every(ms, Context1<F,A0>(f,a0));
198198
}
199199

200200
template <typename F, typename A0, typename A1>
201-
int post_every(int ms, F f, A0 a0, A1 a1) {
202-
return post_every(ms, Context2<F,A0,A1>(f,a0,a1));
201+
int call_every(int ms, F f, A0 a0, A1 a1) {
202+
return call_every(ms, Context2<F,A0,A1>(f,a0,a1));
203203
}
204204

205205
template <typename F, typename A0, typename A1, typename A2>
206-
int post_every(int ms, F f, A0 a0, A1 a1, A2 a2) {
207-
return post_every(ms, Context3<F,A0,A1,A2>(f,a0,a1,a2));
206+
int call_every(int ms, F f, A0 a0, A1 a1, A2 a2) {
207+
return call_every(ms, Context3<F,A0,A1,A2>(f,a0,a1,a2));
208208
}
209209

210210
template <typename F, typename A0, typename A1, typename A2, typename A3>
211-
int post_every(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3) {
212-
return post_every(ms, Context4<F,A0,A1,A2,A3>(f,a0,a1,a2,a3));
211+
int call_every(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3) {
212+
return call_every(ms, Context4<F,A0,A1,A2,A3>(f,a0,a1,a2,a3));
213213
}
214214

215215
template <typename F, typename A0, typename A1, typename A2, typename A3, typename A4>
216-
int post_every(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
217-
return post_every(ms, Context5<F,A0,A1,A2,A3,A4>(f,a0,a1,a2,a3,a4));
216+
int call_every(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
217+
return call_every(ms, Context5<F,A0,A1,A2,A3,A4>(f,a0,a1,a2,a3,a4));
218218
}
219219

220220
protected:

README.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ int main() {
1111
EventQueue queue;
1212

1313
// events are simple callbacks
14-
queue.post(printf, "called immediately\n");
15-
queue.post_in(printf, 2000, "called in 2 seconds\n");
16-
queue.post_every(printf, 1000, "called every 1 seconds\n");
14+
queue.call(printf, "called immediately\n");
15+
queue.call_in(2000, printf, "called in 2 seconds\n");
16+
queue.call_every(1000, printf, "called every 1 seconds\n");
1717

1818
// executed by the dispatch method
1919
queue.dispatch();
@@ -33,7 +33,7 @@ The core API of the events library is contained in the
3333
EventQueue queue(2048);
3434

3535
// Enqueues events on the underlying event queue
36-
queue.post(printf, "hi!\n");
36+
queue.call(printf, "hi!\n");
3737

3838
// The dispatch method acts as the core entry point into the event loop
3939
// A millisecond timeout can be provided to return from the event loop
@@ -51,40 +51,40 @@ EventLoop loop(osHighPriority);
5151
loop.start();
5252
5353
// Posting events is thread and irq safe
54-
loop.post(doit);
54+
loop.call(doit);
5555
5656
// Stops the event loop cleanly
5757
loop.stop();
5858
```
5959

60-
The EventQueue and EvenLoop classes provide several post functions for
61-
sending events. The post functions are thread and irq safe and don't need
60+
The EventQueue and EvenLoop classes provide several call functions for
61+
sending events. The call functions are thread and irq safe and don't need
6262
the underlying loop to be running.
6363

6464
``` cpp
65-
// Simple post function registers events to be called as soon as possible
66-
queue.post(doit);
67-
queue.post(printf, "called immediately\n");
68-
queue.post(Callback<void(char)>(&serial, &Serial::printf), "hello\n");
65+
// Simple call function registers events to be called as soon as possible
66+
queue.call(doit);
67+
queue.call(printf, "called immediately\n");
68+
queue.call(Callback<void(char)>(&serial, &Serial::printf), "hello\n");
6969

70-
// The post_in function registers events to be called after a delay
70+
// The call_in function registers events to be called after a delay
7171
// specified in milliseconds
72-
queue.post_in(2000, doit_in_two_seconds);
73-
queue.post_in(300, printf, "called in 0.3 seconds\n");
72+
queue.call_in(2000, doit_in_two_seconds);
73+
queue.call_in(300, printf, "called in 0.3 seconds\n");
7474

75-
// The post_every function registers events to be called repeatedly
75+
// The call_every function registers events to be called repeatedly
7676
// with a period specified in milliseconds
77-
queue.post_every(2000, doit_every_two_seconds);
78-
queue.post_every(400, printf, "called every 0.4 seconds\n");
77+
queue.call_every(2000, doit_every_two_seconds);
78+
queue.call_every(400, printf, "called every 0.4 seconds\n");
7979
```
8080

81-
All post calls return an integer id that uniquely represents the event
82-
on the event queue. The post calls can not block, so 0 is returned if
81+
All call calls return an integer id that uniquely represents the event
82+
on the event queue. The call calls can not block, so 0 is returned if
8383
there is no memory or the queue's event size is exceeded.
8484

8585
``` cpp
8686
// The event id is uniqueue to the queue
87-
int id = queue.post_in(100, printf, "will this work?\n");
87+
int id = queue.call_in(100, printf, "will this work?\n");
8888

8989
// An id of 0 indicates an error
9090
if (id) {

TESTS/events/queue/main.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ void simple_posts_test##i() { \
4646
EventQueue queue; \
4747
\
4848
touched = false; \
49-
queue.post(func##i,##__VA_ARGS__); \
49+
queue.call(func##i,##__VA_ARGS__); \
5050
queue.dispatch(0); \
5151
TEST_ASSERT(touched); \
5252
\
5353
touched = false; \
54-
queue.post_in(1, func##i,##__VA_ARGS__); \
54+
queue.call_in(1, func##i,##__VA_ARGS__); \
5555
queue.dispatch(2); \
5656
TEST_ASSERT(touched); \
5757
\
5858
touched = false; \
59-
queue.post_every(1, func##i,##__VA_ARGS__); \
59+
queue.call_every(1, func##i,##__VA_ARGS__); \
6060
queue.dispatch(2); \
6161
TEST_ASSERT(touched); \
6262
}
@@ -75,28 +75,28 @@ void time_func(Timer *t, int ms) {
7575
}
7676

7777
template <int N>
78-
void post_in_test() {
78+
void call_in_test() {
7979
Timer tickers[N];
8080

8181
EventQueue queue;
8282

8383
for (int i = 0; i < N; i++) {
8484
tickers[i].start();
85-
queue.post_in((i+1)*100, time_func, &tickers[i], (i+1)*100);
85+
queue.call_in((i+1)*100, time_func, &tickers[i], (i+1)*100);
8686
}
8787

8888
queue.dispatch(N*100);
8989
}
9090

9191
template <int N>
92-
void post_every_test() {
92+
void call_every_test() {
9393
Timer tickers[N];
9494

9595
EventQueue queue;
9696

9797
for (int i = 0; i < N; i++) {
9898
tickers[i].start();
99-
queue.post_every((i+1)*100, time_func, &tickers[i], (i+1)*100);
99+
queue.call_every((i+1)*100, time_func, &tickers[i], (i+1)*100);
100100
}
101101

102102
queue.dispatch(N*100);
@@ -109,7 +109,7 @@ void event_loop_test1() {
109109
TEST_ASSERT_EQUAL(osOK, status);
110110

111111
touched = false;
112-
loop.post(func0);
112+
loop.call(func0);
113113
Thread::yield();
114114
TEST_ASSERT(touched);
115115

@@ -127,7 +127,7 @@ void event_loop_test2() {
127127

128128
for (int i = 0; i < N; i++) {
129129
tickers[i].start();
130-
loop.post_every((i+1)*100, time_func, &tickers[i], (i+1)*100);
130+
loop.call_every((i+1)*100, time_func, &tickers[i], (i+1)*100);
131131
Thread::yield();
132132
wait_ms(75);
133133
}
@@ -140,7 +140,7 @@ struct big { char data[4096]; } big;
140140

141141
void allocate_failure_test1() {
142142
EventQueue queue;
143-
int id = queue.post((void (*)(struct big))0, big);
143+
int id = queue.call((void (*)(struct big))0, big);
144144
TEST_ASSERT(!id);
145145
}
146146

@@ -149,7 +149,7 @@ void allocate_failure_test2() {
149149
int id;
150150

151151
for (int i = 0; i < 100; i++) {
152-
id = queue.post((void (*)())0);
152+
id = queue.call((void (*)())0);
153153
}
154154

155155
TEST_ASSERT(!id);
@@ -166,7 +166,7 @@ void cancel_test1() {
166166
int ids[N];
167167

168168
for (int i = 0; i < N; i++) {
169-
ids[i] = queue.post_in(1000, no);
169+
ids[i] = queue.call_in(1000, no);
170170
}
171171

172172
for (int i = N-1; i >= 0; i--) {
@@ -186,7 +186,7 @@ void cancel_test2() {
186186
int ids[N];
187187

188188
for (int i = 0; i < N; i++) {
189-
ids[i] = loop.post_in(1000, no);
189+
ids[i] = loop.call_in(1000, no);
190190
}
191191

192192
for (int i = N-1; i >= 0; i--) {
@@ -206,15 +206,15 @@ utest::v1::status_t test_setup(const size_t number_of_cases) {
206206
}
207207

208208
const Case cases[] = {
209-
Case("Testing posts with 5 args", simple_posts_test5),
210-
Case("Testing posts with 4 args", simple_posts_test4),
211-
Case("Testing posts with 3 args", simple_posts_test3),
212-
Case("Testing posts with 2 args", simple_posts_test2),
213-
Case("Testing posts with 1 args", simple_posts_test1),
214-
Case("Testing posts with 0 args", simple_posts_test0),
215-
216-
Case("Testing post_in", post_in_test<20>),
217-
Case("Testing post_every", post_every_test<20>),
209+
Case("Testing calls with 5 args", simple_posts_test5),
210+
Case("Testing calls with 4 args", simple_posts_test4),
211+
Case("Testing calls with 3 args", simple_posts_test3),
212+
Case("Testing calls with 2 args", simple_posts_test2),
213+
Case("Testing calls with 1 args", simple_posts_test1),
214+
Case("Testing calls with 0 args", simple_posts_test0),
215+
216+
Case("Testing call_in", call_in_test<20>),
217+
Case("Testing call_every", call_every_test<20>),
218218

219219
#ifdef MBED_CONF_RTOS_PRESENT
220220
Case("Testing event loop 1", event_loop_test1),

0 commit comments

Comments
 (0)