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

Commit 12b2a2f

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 6be60bf commit 12b2a2f

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
@@ -82,7 +82,7 @@ class EventQueue {
8282
* or 0 on failure
8383
*/
8484
template <typename F>
85-
int post(F f) {
85+
int call(F f) {
8686
void *p = event_alloc(&_equeue, sizeof(F));
8787
if (!p) {
8888
return 0;
@@ -94,28 +94,28 @@ class EventQueue {
9494
}
9595

9696
template <typename F, typename A0>
97-
int post(F f, A0 a0) {
98-
return post(Context1<F,A0>(f,a0));
97+
int call(F f, A0 a0) {
98+
return call(Context1<F,A0>(f,a0));
9999
}
100100

101101
template <typename F, typename A0, typename A1>
102-
int post(F f, A0 a0, A1 a1) {
103-
return post(Context2<F,A0,A1>(f,a0,a1));
102+
int call(F f, A0 a0, A1 a1) {
103+
return call(Context2<F,A0,A1>(f,a0,a1));
104104
}
105105

106106
template <typename F, typename A0, typename A1, typename A2>
107-
int post(F f, A0 a0, A1 a1, A2 a2) {
108-
return post(Context3<F,A0,A1,A2>(f,a0,a1,a2));
107+
int call(F f, A0 a0, A1 a1, A2 a2) {
108+
return call(Context3<F,A0,A1,A2>(f,a0,a1,a2));
109109
}
110110

111111
template <typename F, typename A0, typename A1, typename A2, typename A3>
112-
int post(F f, A0 a0, A1 a1, A2 a2, A3 a3) {
113-
return post(Context4<F,A0,A1,A2,A3>(f,a0,a1,a2,a3));
112+
int call(F f, A0 a0, A1 a1, A2 a2, A3 a3) {
113+
return call(Context4<F,A0,A1,A2,A3>(f,a0,a1,a2,a3));
114114
}
115115

116116
template <typename F, typename A0, typename A1, typename A2, typename A3, typename A4>
117-
int post(F f, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
118-
return post(Context5<F,A0,A1,A2,A3,A4>(f,a0,a1,a2,a3,a4));
117+
int call(F f, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
118+
return call(Context5<F,A0,A1,A2,A3,A4>(f,a0,a1,a2,a3,a4));
119119
}
120120

121121
/** Post an event to the queue after a specified delay
@@ -127,7 +127,7 @@ class EventQueue {
127127
* or 0 on failure
128128
*/
129129
template <typename F>
130-
int post_in(int ms, F f) {
130+
int call_in(int ms, F f) {
131131
void *p = event_alloc(&_equeue, sizeof(F));
132132
if (!p) {
133133
return 0;
@@ -140,28 +140,28 @@ class EventQueue {
140140
}
141141

142142
template <typename F, typename A0>
143-
int post_in(int ms, F f, A0 a0) {
144-
return post_in(ms, Context1<F,A0>(f,a0));
143+
int call_in(int ms, F f, A0 a0) {
144+
return call_in(ms, Context1<F,A0>(f,a0));
145145
}
146146

147147
template <typename F, typename A0, typename A1>
148-
int post_in(int ms, F f, A0 a0, A1 a1) {
149-
return post_in(ms, Context2<F,A0,A1>(f,a0,a1));
148+
int call_in(int ms, F f, A0 a0, A1 a1) {
149+
return call_in(ms, Context2<F,A0,A1>(f,a0,a1));
150150
}
151151

152152
template <typename F, typename A0, typename A1, typename A2>
153-
int post_in(int ms, F f, A0 a0, A1 a1, A2 a2) {
154-
return post_in(ms, Context3<F,A0,A1,A2>(f,a0,a1,a2));
153+
int call_in(int ms, F f, A0 a0, A1 a1, A2 a2) {
154+
return call_in(ms, Context3<F,A0,A1,A2>(f,a0,a1,a2));
155155
}
156156

157157
template <typename F, typename A0, typename A1, typename A2, typename A3>
158-
int post_in(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3) {
159-
return post_in(ms, Context4<F,A0,A1,A2,A3>(f,a0,a1,a2,a3));
158+
int call_in(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3) {
159+
return call_in(ms, Context4<F,A0,A1,A2,A3>(f,a0,a1,a2,a3));
160160
}
161161

162162
template <typename F, typename A0, typename A1, typename A2, typename A3, typename A4>
163-
int post_in(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
164-
return post_in(ms, Context5<F,A0,A1,A2,A3,A4>(f,a0,a1,a2,a3,a4));
163+
int call_in(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
164+
return call_in(ms, Context5<F,A0,A1,A2,A3,A4>(f,a0,a1,a2,a3,a4));
165165
}
166166

167167
/** Post an event to the queue periodically
@@ -173,7 +173,7 @@ class EventQueue {
173173
* or 0 on failure
174174
*/
175175
template <typename F>
176-
int post_every(int ms, F f) {
176+
int call_every(int ms, F f) {
177177
void *p = event_alloc(&_equeue, sizeof(F));
178178
if (!p) {
179179
return 0;
@@ -187,28 +187,28 @@ class EventQueue {
187187
}
188188

189189
template <typename F, typename A0>
190-
int post_every(int ms, F f, A0 a0) {
191-
return post_every(ms, Context1<F,A0>(f,a0));
190+
int call_every(int ms, F f, A0 a0) {
191+
return call_every(ms, Context1<F,A0>(f,a0));
192192
}
193193

194194
template <typename F, typename A0, typename A1>
195-
int post_every(int ms, F f, A0 a0, A1 a1) {
196-
return post_every(ms, Context2<F,A0,A1>(f,a0,a1));
195+
int call_every(int ms, F f, A0 a0, A1 a1) {
196+
return call_every(ms, Context2<F,A0,A1>(f,a0,a1));
197197
}
198198

199199
template <typename F, typename A0, typename A1, typename A2>
200-
int post_every(int ms, F f, A0 a0, A1 a1, A2 a2) {
201-
return post_every(ms, Context3<F,A0,A1,A2>(f,a0,a1,a2));
200+
int call_every(int ms, F f, A0 a0, A1 a1, A2 a2) {
201+
return call_every(ms, Context3<F,A0,A1,A2>(f,a0,a1,a2));
202202
}
203203

204204
template <typename F, typename A0, typename A1, typename A2, typename A3>
205-
int post_every(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3) {
206-
return post_every(ms, Context4<F,A0,A1,A2,A3>(f,a0,a1,a2,a3));
205+
int call_every(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3) {
206+
return call_every(ms, Context4<F,A0,A1,A2,A3>(f,a0,a1,a2,a3));
207207
}
208208

209209
template <typename F, typename A0, typename A1, typename A2, typename A3, typename A4>
210-
int post_every(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
211-
return post_every(ms, Context5<F,A0,A1,A2,A3,A4>(f,a0,a1,a2,a3,a4));
210+
int call_every(int ms, F f, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
211+
return call_every(ms, Context5<F,A0,A1,A2,A3,A4>(f,a0,a1,a2,a3,a4));
212212
}
213213

214214
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();
@@ -32,7 +32,7 @@ The core API of the events library is contained in the
3232
EventQueue queue(2048);
3333

3434
// Enqueues events on the underlying event queue
35-
queue.post(printf, "hi!\n");
35+
queue.call(printf, "hi!\n");
3636

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

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

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

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

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

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

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

8888
// An id of 0 indicates an error
8989
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)