Skip to content

Commit a08ade3

Browse files
committed
Finish basic examples for all eventqueue methods
1 parent c802f77 commit a08ade3

File tree

1 file changed

+89
-48
lines changed

1 file changed

+89
-48
lines changed

events/EventQueue.h

Lines changed: 89 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -202,12 +202,10 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
202202
* int main() {
203203
* // creates a queue with the default size
204204
* EventQueue queue;
205-
*
205+
*
206206
* // events are simple callbacks
207207
* queue.call(printf, "called immediately\n");
208-
* queue.call_in(2000, printf, "called in 2 seconds\n");
209-
* queue.call_every(1000, printf, "called every 1 seconds\n");
210-
*
208+
*
211209
* // events are executed by the dispatch method
212210
* queue.dispatch();
213211
* }
@@ -234,15 +232,27 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
234232
* executing.
235233
*
236234
* @code
235+
* class EventHandler {
236+
* int _id;
237+
* public:
238+
* EventHandler(int id) : _id(id) { }
239+
*
240+
* void handler(int c) {
241+
* printf("ID: %d Param: %d\r\n", _id, c);
242+
* }
243+
* };
244+
*
237245
* int main() {
238246
* // creates a queue with the default size
239247
* EventQueue queue;
240-
*
241-
* // events are simple callbacks
242-
* queue.call(printf, "called immediately\n");
243-
* queue.call_in(2000, printf, "called in 2 seconds\n");
244-
* queue.call_every(1000, printf, "called every 1 seconds\n");
245-
*
248+
*
249+
* // Create EventHandler object with state
250+
* EventHandler handler_cb(1);
251+
*
252+
* // events are simple callbacks, call object method
253+
* // with provided parameter
254+
* queue.call(&handler_cb, &EventHandler::handler, 2);
255+
*
246256
* // events are executed by the dispatch method
247257
* queue.dispatch();
248258
* }
@@ -269,12 +279,10 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
269279
* int main() {
270280
* // creates a queue with the default size
271281
* EventQueue queue;
272-
*
282+
*
273283
* // events are simple callbacks
274-
* queue.call(printf, "called immediately\n");
275284
* queue.call_in(2000, printf, "called in 2 seconds\n");
276-
* queue.call_every(1000, printf, "called every 1 seconds\n");
277-
*
285+
*
278286
* // events are executed by the dispatch method
279287
* queue.dispatch();
280288
* }
@@ -300,15 +308,27 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
300308
* enough memory to allocate the event.
301309
*
302310
* @code
311+
* class EventHandler {
312+
* int _id;
313+
* public:
314+
* EventHandler(int id) : _id(id) { }
315+
*
316+
* void handler(int c) {
317+
* printf("ID: %d Param: %d\r\n", _id, c);
318+
* }
319+
* };
320+
*
303321
* int main() {
304322
* // creates a queue with the default size
305323
* EventQueue queue;
306-
*
307-
* // events are simple callbacks
308-
* queue.call(printf, "called immediately\n");
309-
* queue.call_in(2000, printf, "called in 2 seconds\n");
310-
* queue.call_every(1000, printf, "called every 1 seconds\n");
311-
*
324+
*
325+
* // Create EventHandler object with state
326+
* EventHandler handler_cb(3);
327+
*
328+
* // events are simple callbacks, call object method in 2 seconds
329+
* // with provided parameter
330+
* queue.call_in(2000, &handler_cb, &EventHandler::handler, 4);
331+
*
312332
* // events are executed by the dispatch method
313333
* queue.dispatch();
314334
* }
@@ -336,15 +356,23 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
336356
* enough memory to allocate the event.
337357
*
338358
* @code
359+
* class EventHandler {
360+
* int _id;
361+
* public:
362+
* EventHandler(int id) : _id(id) { }
363+
*
364+
* void handler(int c) {
365+
* printf("ID: %d Param: %d\r\n", _id, c);
366+
* }
367+
* };
368+
*
339369
* int main() {
340370
* // creates a queue with the default size
341371
* EventQueue queue;
342-
*
343-
* // events are simple callbacks
344-
* queue.call(printf, "called immediately\n");
345-
* queue.call_in(2000, printf, "called in 2 seconds\n");
346-
* queue.call_every(1000, printf, "called every 1 seconds\n");
347-
*
372+
*
373+
* // events are simple callbacks, call every 2 seconds
374+
* queue.call_every(2000, printf, "Calling every 2 seconds\n");
375+
*
348376
* // events are executed by the dispatch method
349377
* queue.dispatch();
350378
* }
@@ -370,15 +398,27 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
370398
* @param args Arguments to pass to the callback
371399
*
372400
* @code
401+
* class EventHandler {
402+
* int _id;
403+
* public:
404+
* EventHandler(int id) : _id(id) { }
405+
*
406+
* void handler(int c) {
407+
* printf("ID: %d Param: %d\r\n", _id, c);
408+
* }
409+
* };
410+
*
373411
* int main() {
374412
* // creates a queue with the default size
375413
* EventQueue queue;
376-
*
377-
* // events are simple callbacks
378-
* queue.call(printf, "called immediately\n");
379-
* queue.call_in(2000, printf, "called in 2 seconds\n");
380-
* queue.call_every(1000, printf, "called every 1 seconds\n");
381-
*
414+
*
415+
* // Create EventHandler object with state
416+
* EventHandler handler_cb(5);
417+
*
418+
* // events are simple callbacks, call object method every 2 seconds
419+
* // with provided parameter
420+
* queue.call_every(2000, &handler_cb, &EventHandler::handler, 6);
421+
*
382422
* // events are executed by the dispatch method
383423
* queue.dispatch();
384424
* }
@@ -407,19 +447,19 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
407447
* printf("Param: %d\r\n", c);
408448
* }
409449
*
410-
* EventQueue q;
411-
*
412450
* int main()
413451
* {
452+
* EventQueue queue;
453+
*
414454
* // Create event with parameter
415-
* Event<void()> e = q.event(handler, 1);
455+
* Event<void()> e = queue.event(handler, 1);
416456
* e();
417457
*
418458
* // Create event and post parameter later
419-
* Event<void(int)> e2 = q.event(handler);
459+
* Event<void(int)> e2 = queue.event(handler);
420460
* e2.post(2);
421461
*
422-
* q.dispatch();
462+
* queue.dispatch();
423463
* }
424464
* @endcode
425465
*/
@@ -445,27 +485,27 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
445485
* @code
446486
* #include "mbed.h"
447487
*
448-
* class Test {
488+
* class EventHandler {
449489
* int _id;
450490
*
451491
* public:
452-
* Test(int id) : _id(id) { }
492+
* EventHandler(int id) : _id(id) { }
453493
*
454494
* void handler(int c) {
455495
* printf("ID: %d Param: %d\r\n", _id, c);
456496
* }
457497
* };
458498
*
459-
* EventQueue q;
460-
*
461499
* int main()
462500
* {
463-
* Test handler_cb(5);
501+
* EventQueue queue;
502+
*
503+
* EventHandler handler_cb(5);
464504
*
465505
* // Create event on the eventqueue with a method callback
466-
* Event<void(int)> e = q.event(&handler_cb, &Test::handler);
506+
* Event<void(int)> e = queue.event(&handler_cb, &EventHandler::handler);
467507
* e.post(1);
468-
* q.dispatch();
508+
* queue.dispatch();
469509
* }
470510
* @endcode
471511
*/
@@ -509,15 +549,16 @@ class EventQueue : private mbed::NonCopyable<EventQueue> {
509549
* @code
510550
* #include "mbed.h"
511551
*
512-
* EventQueue q;
513-
*
514552
* int main()
515553
* {
554+
* EventQueue queue;
555+
*
516556
* Callback<void(int)> cb(handler);
557+
*
517558
* // Create event on the eventqueue with a separate callback object
518-
* Event<void(int)> e = q.event(cb);
559+
* Event<void(int)> e = queue.event(cb);
519560
* e.post(1);
520-
* q.dispatch();
561+
* queue.dispatch();
521562
* }
522563
* @endcode
523564
*/

0 commit comments

Comments
 (0)