diff --git a/events/EventQueue.h b/events/EventQueue.h index b1350be3fbc..3c7bc044ec2 100644 --- a/events/EventQueue.h +++ b/events/EventQueue.h @@ -197,6 +197,21 @@ class EventQueue : private mbed::NonCopyable { * enough memory to allocate the event. * Returned id will remain valid until event has finished * executing. + * + * @code + * int main() { + * // creates a queue with the default size + * EventQueue queue; + * + * // events are simple callbacks + * 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 + * queue.dispatch(); + * } + * @endcode */ template int call(F f, Args ...args); @@ -217,6 +232,21 @@ class EventQueue : private mbed::NonCopyable { * enough memory to allocate the event. * Returned id will remain valid until event has finished * executing. + * + * @code + * int main() { + * // creates a queue with the default size + * EventQueue queue; + * + * // events are simple callbacks + * 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 + * queue.dispatch(); + * } + * @endcode */ template int call(T *obj, R (T::*method)(Args ...args), Args ...args); @@ -234,6 +264,21 @@ class EventQueue : private mbed::NonCopyable { * @return A unique id that represents the posted event and can * be passed to cancel, or an id of 0 if there is not * enough memory to allocate the event. + * + * @code + * int main() { + * // creates a queue with the default size + * EventQueue queue; + * + * // events are simple callbacks + * 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 + * queue.dispatch(); + * } + * @endcode */ template int call_in(int ms, Args ...args); @@ -253,6 +298,21 @@ class EventQueue : private mbed::NonCopyable { * @return A unique id that represents the posted event and can * be passed to cancel, or an id of 0 if there is not * enough memory to allocate the event. + * + * @code + * int main() { + * // creates a queue with the default size + * EventQueue queue; + * + * // events are simple callbacks + * 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 + * queue.dispatch(); + * } + * @endcode */ template int call_in(int ms, T *obj, R (T::*method)(Args ...args), Args ...args); @@ -274,6 +334,21 @@ class EventQueue : private mbed::NonCopyable { * @return A unique id that represents the posted event and can * be passed to cancel, or an id of 0 if there is not * enough memory to allocate the event. + * + * @code + * int main() { + * // creates a queue with the default size + * EventQueue queue; + * + * // events are simple callbacks + * 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 + * queue.dispatch(); + * } + * @endcode */ template int call_every(int ms, F f, Args ...args); @@ -293,6 +368,21 @@ class EventQueue : private mbed::NonCopyable { * @param obj Object to call with the member function * @param method Member function to execute in the context of the dispatch loop * @param args Arguments to pass to the callback + * + * @code + * int main() { + * // creates a queue with the default size + * EventQueue queue; + * + * // events are simple callbacks + * 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 + * queue.dispatch(); + * } + * @endcode */ template int call_every(int ms, T *obj, R (T::*method)(Args ...args), Args ...args); @@ -311,7 +401,26 @@ class EventQueue : private mbed::NonCopyable { * @return Event that will dispatch on the specific queue * * @code - * event(...TODO....); + * #include "mbed.h" + * + * void handler(int c) { + * printf("Param: %d\r\n", c); + * } + * + * EventQueue q; + * + * int main() + * { + * // Create event with parameter + * Event e = q.event(handler, 1); + * e(); + * + * // Create event and post parameter later + * Event e2 = q.event(handler); + * e2.post(2); + * + * q.dispatch(); + * } * @endcode */ template @@ -332,6 +441,33 @@ class EventQueue : private mbed::NonCopyable { * @param method Member function to execute in the context of the dispatch loop * @param context_args TODO * @return Event that will dispatch on the specific queue + * + * @code + * #include "mbed.h" + * + * class Test { + * int _id; + * + * public: + * Test(int id) : _id(id) { } + * + * void handler(int c) { + * printf("ID: %d Param: %d\r\n", _id, c); + * } + * }; + * + * EventQueue q; + * + * int main() + * { + * Test handler_cb(5); + * + * // Create event on the eventqueue with a method callback + * Event e = q.event(&handler_cb, &Test::handler); + * e.post(1); + * q.dispatch(); + * } + * @endcode */ template Event event(T *obj, R (T::*method)(BoundArgs..., Args...), ContextArgs ...context_args); @@ -369,6 +505,21 @@ class EventQueue : private mbed::NonCopyable { * enough memory to allocate the event. * Returned id will remain valid until event has finished * executing. + * + * @code + * #include "mbed.h" + * + * EventQueue q; + * + * int main() + * { + * Callback cb(handler); + * // Create event on the eventqueue with a separate callback object + * Event e = q.event(cb); + * e.post(1); + * q.dispatch(); + * } + * @endcode */ template int call(F f) {