Finish basic examples for all eventqueue methods

pull/8035/head
kegilbert 2018-08-16 16:58:02 -05:00 committed by adbridge
parent 693f0bdf88
commit 1ae9ce9ecc
1 changed files with 89 additions and 48 deletions

View File

@ -208,8 +208,6 @@ public:
* *
* // events are simple callbacks * // events are simple callbacks
* queue.call(printf, "called immediately\n"); * queue.call(printf, "called immediately\n");
* queue.call_in(2000, printf, "called in 2 seconds\n");
* queue.call_every(1000, printf, "called every 1 seconds\n");
* *
* // events are executed by the dispatch method * // events are executed by the dispatch method
* queue.dispatch(); * queue.dispatch();
@ -237,14 +235,26 @@ public:
* executing. * executing.
* *
* @code * @code
* class EventHandler {
* int _id;
* public:
* EventHandler(int id) : _id(id) { }
*
* void handler(int c) {
* printf("ID: %d Param: %d\r\n", _id, c);
* }
* };
*
* int main() { * int main() {
* // creates a queue with the default size * // creates a queue with the default size
* EventQueue queue; * EventQueue queue;
* *
* // events are simple callbacks * // Create EventHandler object with state
* queue.call(printf, "called immediately\n"); * EventHandler handler_cb(1);
* queue.call_in(2000, printf, "called in 2 seconds\n"); *
* queue.call_every(1000, printf, "called every 1 seconds\n"); * // events are simple callbacks, call object method
* // with provided parameter
* queue.call(&handler_cb, &EventHandler::handler, 2);
* *
* // events are executed by the dispatch method * // events are executed by the dispatch method
* queue.dispatch(); * queue.dispatch();
@ -274,9 +284,7 @@ public:
* EventQueue queue; * EventQueue queue;
* *
* // events are simple callbacks * // events are simple callbacks
* queue.call(printf, "called immediately\n");
* queue.call_in(2000, printf, "called in 2 seconds\n"); * queue.call_in(2000, printf, "called in 2 seconds\n");
* queue.call_every(1000, printf, "called every 1 seconds\n");
* *
* // events are executed by the dispatch method * // events are executed by the dispatch method
* queue.dispatch(); * queue.dispatch();
@ -303,14 +311,26 @@ public:
* enough memory to allocate the event. * enough memory to allocate the event.
* *
* @code * @code
* class EventHandler {
* int _id;
* public:
* EventHandler(int id) : _id(id) { }
*
* void handler(int c) {
* printf("ID: %d Param: %d\r\n", _id, c);
* }
* };
*
* int main() { * int main() {
* // creates a queue with the default size * // creates a queue with the default size
* EventQueue queue; * EventQueue queue;
* *
* // events are simple callbacks * // Create EventHandler object with state
* queue.call(printf, "called immediately\n"); * EventHandler handler_cb(3);
* queue.call_in(2000, printf, "called in 2 seconds\n"); *
* queue.call_every(1000, printf, "called every 1 seconds\n"); * // events are simple callbacks, call object method in 2 seconds
* // with provided parameter
* queue.call_in(2000, &handler_cb, &EventHandler::handler, 4);
* *
* // events are executed by the dispatch method * // events are executed by the dispatch method
* queue.dispatch(); * queue.dispatch();
@ -339,14 +359,22 @@ public:
* enough memory to allocate the event. * enough memory to allocate the event.
* *
* @code * @code
* class EventHandler {
* int _id;
* public:
* EventHandler(int id) : _id(id) { }
*
* void handler(int c) {
* printf("ID: %d Param: %d\r\n", _id, c);
* }
* };
*
* int main() { * int main() {
* // creates a queue with the default size * // creates a queue with the default size
* EventQueue queue; * EventQueue queue;
* *
* // events are simple callbacks * // events are simple callbacks, call every 2 seconds
* queue.call(printf, "called immediately\n"); * queue.call_every(2000, printf, "Calling every 2 seconds\n");
* queue.call_in(2000, printf, "called in 2 seconds\n");
* queue.call_every(1000, printf, "called every 1 seconds\n");
* *
* // events are executed by the dispatch method * // events are executed by the dispatch method
* queue.dispatch(); * queue.dispatch();
@ -373,14 +401,26 @@ public:
* @param args Arguments to pass to the callback * @param args Arguments to pass to the callback
* *
* @code * @code
* class EventHandler {
* int _id;
* public:
* EventHandler(int id) : _id(id) { }
*
* void handler(int c) {
* printf("ID: %d Param: %d\r\n", _id, c);
* }
* };
*
* int main() { * int main() {
* // creates a queue with the default size * // creates a queue with the default size
* EventQueue queue; * EventQueue queue;
* *
* // events are simple callbacks * // Create EventHandler object with state
* queue.call(printf, "called immediately\n"); * EventHandler handler_cb(5);
* queue.call_in(2000, printf, "called in 2 seconds\n"); *
* queue.call_every(1000, printf, "called every 1 seconds\n"); * // events are simple callbacks, call object method every 2 seconds
* // with provided parameter
* queue.call_every(2000, &handler_cb, &EventHandler::handler, 6);
* *
* // events are executed by the dispatch method * // events are executed by the dispatch method
* queue.dispatch(); * queue.dispatch();
@ -410,19 +450,19 @@ public:
* printf("Param: %d\r\n", c); * printf("Param: %d\r\n", c);
* } * }
* *
* EventQueue q;
*
* int main() * int main()
* { * {
* EventQueue queue;
*
* // Create event with parameter * // Create event with parameter
* Event<void()> e = q.event(handler, 1); * Event<void()> e = queue.event(handler, 1);
* e(); * e();
* *
* // Create event and post parameter later * // Create event and post parameter later
* Event<void(int)> e2 = q.event(handler); * Event<void(int)> e2 = queue.event(handler);
* e2.post(2); * e2.post(2);
* *
* q.dispatch(); * queue.dispatch();
* } * }
* @endcode * @endcode
*/ */
@ -448,27 +488,27 @@ public:
* @code * @code
* #include "mbed.h" * #include "mbed.h"
* *
* class Test { * class EventHandler {
* int _id; * int _id;
* *
* public: * public:
* Test(int id) : _id(id) { } * EventHandler(int id) : _id(id) { }
* *
* void handler(int c) { * void handler(int c) {
* printf("ID: %d Param: %d\r\n", _id, c); * printf("ID: %d Param: %d\r\n", _id, c);
* } * }
* }; * };
* *
* EventQueue q;
*
* int main() * int main()
* { * {
* Test handler_cb(5); * EventQueue queue;
*
* EventHandler handler_cb(5);
* *
* // Create event on the eventqueue with a method callback * // Create event on the eventqueue with a method callback
* Event<void(int)> e = q.event(&handler_cb, &Test::handler); * Event<void(int)> e = queue.event(&handler_cb, &EventHandler::handler);
* e.post(1); * e.post(1);
* q.dispatch(); * queue.dispatch();
* } * }
* @endcode * @endcode
*/ */
@ -512,15 +552,16 @@ public:
* @code * @code
* #include "mbed.h" * #include "mbed.h"
* *
* EventQueue q;
*
* int main() * int main()
* { * {
* EventQueue queue;
*
* Callback<void(int)> cb(handler); * Callback<void(int)> cb(handler);
*
* // Create event on the eventqueue with a separate callback object * // Create event on the eventqueue with a separate callback object
* Event<void(int)> e = q.event(cb); * Event<void(int)> e = queue.event(cb);
* e.post(1); * e.post(1);
* q.dispatch(); * queue.dispatch();
* } * }
* @endcode * @endcode
*/ */