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

Commit 5015222

Browse files
authored
Merge pull request #17 from ARMmbed/event-callable
Add callback operations to event class
2 parents 7393a80 + 66f5ee2 commit 5015222

File tree

1 file changed

+156
-0
lines changed

1 file changed

+156
-0
lines changed

Event.h

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,32 @@ class Event<void()> {
188188
return _event->id;
189189
}
190190

191+
/** Posts an event onto the underlying event queue, returning void
192+
*
193+
* @param a0..a4 Arguments to pass to the event
194+
*/
195+
void call() {
196+
int id = post();
197+
MBED_ASSERT(id);
198+
}
199+
200+
/** Posts an event onto the underlying event queue, returning void
201+
*
202+
* @param a0..a4 Arguments to pass to the event
203+
*/
204+
void operator()() {
205+
return call();
206+
}
207+
208+
/** Static thunk for passing as C-style function
209+
*
210+
* @param func Event to call passed as a void pointer
211+
* @param a0..a4 Arguments to pass to the event
212+
*/
213+
static void thunk(void *func) {
214+
return static_cast<Event*>(func)->call();
215+
}
216+
191217
/** Cancels the most recently posted event
192218
*
193219
* Attempts to cancel the most recently posted event. It is safe to call
@@ -381,6 +407,32 @@ class Event<void(A0)> {
381407
return _event->id;
382408
}
383409

410+
/** Posts an event onto the underlying event queue, returning void
411+
*
412+
* @param a0..a4 Arguments to pass to the event
413+
*/
414+
void call(A0 a0) {
415+
int id = post(a0);
416+
MBED_ASSERT(id);
417+
}
418+
419+
/** Posts an event onto the underlying event queue, returning void
420+
*
421+
* @param a0..a4 Arguments to pass to the event
422+
*/
423+
void operator()(A0 a0) {
424+
return call(a0);
425+
}
426+
427+
/** Static thunk for passing as C-style function
428+
*
429+
* @param func Event to call passed as a void pointer
430+
* @param a0..a4 Arguments to pass to the event
431+
*/
432+
static void thunk(void *func, A0 a0) {
433+
return static_cast<Event*>(func)->call(a0);
434+
}
435+
384436
/** Cancels the most recently posted event
385437
*
386438
* Attempts to cancel the most recently posted event. It is safe to call
@@ -574,6 +626,32 @@ class Event<void(A0, A1)> {
574626
return _event->id;
575627
}
576628

629+
/** Posts an event onto the underlying event queue, returning void
630+
*
631+
* @param a0..a4 Arguments to pass to the event
632+
*/
633+
void call(A0 a0, A1 a1) {
634+
int id = post(a0, a1);
635+
MBED_ASSERT(id);
636+
}
637+
638+
/** Posts an event onto the underlying event queue, returning void
639+
*
640+
* @param a0..a4 Arguments to pass to the event
641+
*/
642+
void operator()(A0 a0, A1 a1) {
643+
return call(a0, a1);
644+
}
645+
646+
/** Static thunk for passing as C-style function
647+
*
648+
* @param func Event to call passed as a void pointer
649+
* @param a0..a4 Arguments to pass to the event
650+
*/
651+
static void thunk(void *func, A0 a0, A1 a1) {
652+
return static_cast<Event*>(func)->call(a0, a1);
653+
}
654+
577655
/** Cancels the most recently posted event
578656
*
579657
* Attempts to cancel the most recently posted event. It is safe to call
@@ -767,6 +845,32 @@ class Event<void(A0, A1, A2)> {
767845
return _event->id;
768846
}
769847

848+
/** Posts an event onto the underlying event queue, returning void
849+
*
850+
* @param a0..a4 Arguments to pass to the event
851+
*/
852+
void call(A0 a0, A1 a1, A2 a2) {
853+
int id = post(a0, a1, a2);
854+
MBED_ASSERT(id);
855+
}
856+
857+
/** Posts an event onto the underlying event queue, returning void
858+
*
859+
* @param a0..a4 Arguments to pass to the event
860+
*/
861+
void operator()(A0 a0, A1 a1, A2 a2) {
862+
return call(a0, a1, a2);
863+
}
864+
865+
/** Static thunk for passing as C-style function
866+
*
867+
* @param func Event to call passed as a void pointer
868+
* @param a0..a4 Arguments to pass to the event
869+
*/
870+
static void thunk(void *func, A0 a0, A1 a1, A2 a2) {
871+
return static_cast<Event*>(func)->call(a0, a1, a2);
872+
}
873+
770874
/** Cancels the most recently posted event
771875
*
772876
* Attempts to cancel the most recently posted event. It is safe to call
@@ -960,6 +1064,32 @@ class Event<void(A0, A1, A2, A3)> {
9601064
return _event->id;
9611065
}
9621066

1067+
/** Posts an event onto the underlying event queue, returning void
1068+
*
1069+
* @param a0..a4 Arguments to pass to the event
1070+
*/
1071+
void call(A0 a0, A1 a1, A2 a2, A3 a3) {
1072+
int id = post(a0, a1, a2, a3);
1073+
MBED_ASSERT(id);
1074+
}
1075+
1076+
/** Posts an event onto the underlying event queue, returning void
1077+
*
1078+
* @param a0..a4 Arguments to pass to the event
1079+
*/
1080+
void operator()(A0 a0, A1 a1, A2 a2, A3 a3) {
1081+
return call(a0, a1, a2, a3);
1082+
}
1083+
1084+
/** Static thunk for passing as C-style function
1085+
*
1086+
* @param func Event to call passed as a void pointer
1087+
* @param a0..a4 Arguments to pass to the event
1088+
*/
1089+
static void thunk(void *func, A0 a0, A1 a1, A2 a2, A3 a3) {
1090+
return static_cast<Event*>(func)->call(a0, a1, a2, a3);
1091+
}
1092+
9631093
/** Cancels the most recently posted event
9641094
*
9651095
* Attempts to cancel the most recently posted event. It is safe to call
@@ -1153,6 +1283,32 @@ class Event<void(A0, A1, A2, A3, A4)> {
11531283
return _event->id;
11541284
}
11551285

1286+
/** Posts an event onto the underlying event queue, returning void
1287+
*
1288+
* @param a0..a4 Arguments to pass to the event
1289+
*/
1290+
void call(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
1291+
int id = post(a0, a1, a2, a3, a4);
1292+
MBED_ASSERT(id);
1293+
}
1294+
1295+
/** Posts an event onto the underlying event queue, returning void
1296+
*
1297+
* @param a0..a4 Arguments to pass to the event
1298+
*/
1299+
void operator()(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
1300+
return call(a0, a1, a2, a3, a4);
1301+
}
1302+
1303+
/** Static thunk for passing as C-style function
1304+
*
1305+
* @param func Event to call passed as a void pointer
1306+
* @param a0..a4 Arguments to pass to the event
1307+
*/
1308+
static void thunk(void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
1309+
return static_cast<Event*>(func)->call(a0, a1, a2, a3, a4);
1310+
}
1311+
11561312
/** Cancels the most recently posted event
11571313
*
11581314
* Attempts to cancel the most recently posted event. It is safe to call

0 commit comments

Comments
 (0)