Mbed OS Reference
Loading...
Searching...
No Matches
Event.h
1/*
2 * Copyright (c) 2016-2019 ARM Limited
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#ifndef EVENT_H
18#define EVENT_H
19
20#include <utility>
21#include "events/EventQueue.h"
22#include "platform/mbed_assert.h"
23#include "platform/mbed_error.h"
24
25namespace events {
26/** \defgroup events-public-api Events
27 * \ingroup mbed-os-public
28 * @{
29 */
30
31static constexpr std::chrono::duration<int, std::milli> non_periodic{-1};
32
33/** Event
34 *
35 * Representation of an event for fine-grain dispatch control
36 */
37template <typename F>
38class Event;
39
40/**
41 * \defgroup events_Event Event classes
42 * @{
43 */
44
45/** Event
46 *
47 * Representation of an event for fine-grain dispatch control
48 */
49template <typename... ArgTs>
50class Event<void(ArgTs...)> {
51public:
52 using duration = std::chrono::duration<int, std::milli>;
53
54 /** Create an event
55 *
56 * Constructs an event bound to the specified event queue. The specified
57 * callback acts as the target for the event and is executed in the
58 * context of the event queue's dispatch loop once posted.
59 *
60 * @param q Event queue to dispatch on
61 * @param f Function to execute when the event is dispatched
62 */
63 template <typename F>
65 {
66 _event = static_cast<struct event *>(
67 equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F)));
68
69 if (_event) {
70 _event->equeue = &q->_equeue;
71 _event->id = 0;
72 _event->delay = duration(0);
73 _event->period = non_periodic;
74
75 _event->post = &Event::event_post<F>;
76 _event->dtor = &Event::event_dtor<F>;
77
78 new (_event + 1) F(std::move(f));
79
80 _event->ref = 1;
81 }
82 }
83
84 /** Copy constructor for events
85 */
86 Event(const Event &e)
87 {
88 _event = 0;
89 if (e._event) {
90 _event = e._event;
91 _event->ref += 1;
92 }
93 }
94
95 /** Assignment operator for events
96 */
97 Event &operator=(const Event &that)
98 {
99 if (this != &that) {
100 this->~Event();
101 new (this) Event(that);
102 }
103
104 return *this;
105 }
106
107 /** Destructor for events
108 */
110 {
111 if (_event) {
112 _event->ref -= 1;
113 if (_event->ref == 0) {
114 _event->dtor(_event);
115 equeue_dealloc(_event->equeue, _event);
116 }
117 }
118 }
119
120 /** Configure the delay of an event
121 *
122 * @param d Delay (in milliseconds) before dispatching the event, expressed as a Chrono duration.
123 * E.g. delay(50ms)
124 */
125 void delay(duration d)
126 {
127 if (_event) {
128 _event->delay = d;
129 }
130 }
131
132 /** Configure the delay of an event
133 * @deprecated Pass a chrono duration, not an integer millisecond count. For example use `5s` rather than `5000`.
134 *
135 * @param d Millisecond delay before dispatching the event
136 */
137 MBED_DEPRECATED_SINCE("mbed-os-6.0.0", "Pass a chrono duration, not an integer millisecond count. For example use `5s` rather than `5000`.")
138 void delay(int d)
139 {
140 delay(duration(d));
141 }
142
143 /** Configure the period of an event
144 *
145 * @param p Period (in milliseconds) for repeatedly dispatching an event, expressed as a Chrono
146 * duration. Period must be either non_periodic or > 0ms. If an invalid period is supplied
147 * then a default non_periodic value is used.
148 * E.g. period(200ms)
149 */
150 void period(duration p)
151 {
152 if (_event) {
153 if (p > duration(0)) {
154 _event->period = p;
155
156 } else {
157 if (p != non_periodic) {
158 MBED_WARNING(MBED_ERROR_INVALID_ARGUMENT,
159 "Invalid period specified, defaulting to non_periodic.");
160 }
161 _event->period = non_periodic;
162 }
163 }
164 }
165
166 /** Configure the period of an event
167 * @deprecated Pass a chrono duration, not an integer millisecond count. For example use `5s` rather than `5000`.
168 *
169 * @param p Millisecond period for repeatedly dispatching an event
170 */
171 MBED_DEPRECATED_SINCE("mbed-os-6.0.0", "Pass a chrono duration, not an integer millisecond count. For example use `5s` rather than `5000`.")
172 void period(int p)
173 {
174 period(duration(p));
175 }
176
177 /** Posts an event onto the underlying event queue
178 *
179 * The event is posted to the underlying queue and is executed in the
180 * context of the event queue's dispatch loop.
181 *
182 * The post function is IRQ safe and can act as a mechanism for moving
183 * events out of IRQ contexts.
184 *
185 * @param args Arguments to pass to the event
186 * @return A unique id that represents the posted event and can
187 * be passed to EventQueue::cancel, or an id of 0 if
188 * there is not enough memory to allocate the event.
189 */
190 int post(ArgTs... args) const
191 {
192 if (!_event) {
193 return 0;
194 }
195
196 _event->id = _event->post(_event, args...);
197 return _event->id;
198 }
199
200 /** Posts an event onto the underlying event queue, returning void
201 *
202 * @param args Arguments to pass to the event
203 */
204 void call(ArgTs... args) const
205 {
206 MBED_UNUSED int id = post(args...);
207 MBED_ASSERT(id);
208 }
209
210 /** Posts an event onto the underlying event queue, returning void
211 *
212 * @param args Arguments to pass to the event
213 */
214 void operator()(ArgTs... args) const
215 {
216 return call(args...);
217 }
218
219 /** Static thunk for passing as C-style function
220 *
221 * @param func Event to call passed as a void pointer
222 * @param args Arguments to pass to the event
223 */
224 static void thunk(void *func, ArgTs... args)
225 {
226 return static_cast<Event *>(func)->call(args...);
227 }
228
229 /** Cancels the most recently posted event
230 *
231 * Attempts to cancel the most recently posted event. It is not safe to call
232 * cancel after an event has already been dispatched.
233 *
234 * The cancel function is IRQ safe.
235 *
236 * If called while the event queue's dispatch loop is active, the cancel
237 * function does not guarantee that the event will not execute after it
238 * returns, as the event may have already begun executing.
239 */
240 void cancel() const
241 {
242 if (_event) {
243 equeue_cancel(_event->equeue, _event->id);
244 }
245 }
246
247private:
248 struct event {
249 unsigned ref;
251 int id;
252
253 duration delay;
254 duration period;
255
256 int (*post)(struct event *, ArgTs... args);
257 void (*dtor)(struct event *);
258
259 // F follows
260 } *_event;
261
262 // Event attributes
263 template <typename F>
264 static int event_post(struct event *e, ArgTs... args)
265 {
266 typedef EventQueue::context<F, ArgTs...> C;
267 void *p = equeue_alloc(e->equeue, sizeof(C));
268 if (!p) {
269 return 0;
270 }
271
272 new (p) C(*(F *)(e + 1), args...);
273 equeue_event_delay(p, e->delay.count());
274 equeue_event_period(p, e->period.count());
275 equeue_event_dtor(p, &EventQueue::function_dtor<C>);
276 return equeue_post(e->equeue, &EventQueue::function_call<C>, p);
277 }
278
279 template <typename F>
280 static void event_dtor(struct event *e)
281 {
282 ((F *)(e + 1))->~F();
283 }
284
285public:
286 /** Create an event
287 * @param q Event queue to dispatch on
288 * @param f Function to execute when the event is dispatched
289 * @param context_args Arguments to bind to the callback, these arguments are
290 * allocated on an IRQ-safe allocator from the event queue's
291 * memory pool. Must be type-compatible with bound_args, the
292 * arguments to the underlying callback.
293 */
294 template <typename F, typename... ContextArgTs>
295 Event(EventQueue *q, F f, ContextArgTs... context_args) :
296 Event(q, EventQueue::context<F, ContextArgTs...>(f, context_args...)) { }
297
298 /** Create an event
299 * @see Event::Event
300 */
301 template <typename T, typename R, typename B0>
302 Event(EventQueue *q, T *obj, R(T::*method)(B0, ArgTs...), B0 b0) :
303 Event(q, mbed::callback(obj, method), b0) { }
304
305 /** Create an event
306 * @see Event::Event
307 */
308 template <typename T, typename R, typename B0>
309 Event(EventQueue *q, const T *obj, R(T::*method)(B0, ArgTs...) const, B0 b0) :
310 Event(q, mbed::callback(obj, method), b0) { }
311
312 /** Create an event
313 * @see Event::Event
314 */
315 template <typename T, typename R, typename B0>
316 Event(EventQueue *q, volatile T *obj, R(T::*method)(B0, ArgTs...) volatile, B0 b0) :
317 Event(q, mbed::callback(obj, method), b0) { }
318
319 /** Create an event
320 * @see Event::Event
321 */
322 template <typename T, typename R, typename B0>
323 Event(EventQueue *q, const volatile T *obj, R(T::*method)(B0, ArgTs...) const volatile, B0 b0) :
324 Event(q, mbed::callback(obj, method), b0) { }
325
326 /** Create an event
327 * @see Event::Event
328 */
329 template <typename T, typename R, typename B0, typename B1>
330 Event(EventQueue *q, T *obj, R(T::*method)(B0, B1, ArgTs...), B0 b0, B1 b1) :
331 Event(q, mbed::callback(obj, method), b0, b1) { }
332
333 /** Create an event
334 * @see Event::Event
335 */
336 template <typename T, typename R, typename B0, typename B1>
337 Event(EventQueue *q, const T *obj, R(T::*method)(B0, B1, ArgTs...) const, B0 b0, B1 b1) :
338 Event(q, mbed::callback(obj, method), b0, b1) { }
339
340 /** Create an event
341 * @see Event::Event
342 */
343 template <typename T, typename R, typename B0, typename B1>
344 Event(EventQueue *q, volatile T *obj, R(T::*method)(B0, B1, ArgTs...) volatile, B0 b0, B1 b1) :
345 Event(q, mbed::callback(obj, method), b0, b1) { }
346
347 /** Create an event
348 * @see Event::Event
349 */
350 template <typename T, typename R, typename B0, typename B1>
351 Event(EventQueue *q, const volatile T *obj, R(T::*method)(B0, B1, ArgTs...) const volatile, B0 b0, B1 b1) :
352 Event(q, mbed::callback(obj, method), b0, b1) { }
353
354 /** Create an event
355 * @see Event::Event
356 */
357 template <typename T, typename R, typename B0, typename B1, typename B2>
358 Event(EventQueue *q, T *obj, R(T::*method)(B0, B1, B2, ArgTs...), B0 b0, B1 b1, B2 b2) :
359 Event(q, mbed::callback(obj, method), b0, b1, b2) { }
360
361 /** Create an event
362 * @see Event::Event
363 */
364 template <typename T, typename R, typename B0, typename B1, typename B2>
365 Event(EventQueue *q, const T *obj, R(T::*method)(B0, B1, B2, ArgTs...) const, B0 b0, B1 b1, B2 b2) :
366 Event(q, mbed::callback(obj, method), b0, b1, b2) { }
367
368 /** Create an event
369 * @see Event::Event
370 */
371 template <typename T, typename R, typename B0, typename B1, typename B2>
372 Event(EventQueue *q, volatile T *obj, R(T::*method)(B0, B1, B2, ArgTs...) volatile, B0 b0, B1 b1, B2 b2) :
373 Event(q, mbed::callback(obj, method), b0, b1, b2) { }
374
375 /** Create an event
376 * @see Event::Event
377 */
378 template <typename T, typename R, typename B0, typename B1, typename B2>
379 Event(EventQueue *q, const volatile T *obj, R(T::*method)(B0, B1, B2, ArgTs...) const volatile, B0 b0, B1 b1, B2 b2) :
380 Event(q, mbed::callback(obj, method), b0, b1, b2) { }
381
382 /** Create an event
383 * @see Event::Event
384 */
385 template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
386 Event(EventQueue *q, T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...), B0 b0, B1 b1, B2 b2, B3 b3) :
387 Event(q, mbed::callback(obj, method), b0, b1, b2, b3) { }
388
389 /** Create an event
390 * @see Event::Event
391 */
392 template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
393 Event(EventQueue *q, const T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...) const, B0 b0, B1 b1, B2 b2, B3 b3) :
394 Event(q, mbed::callback(obj, method), b0, b1, b2, b3) { }
395
396 /** Create an event
397 * @see Event::Event
398 */
399 template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
400 Event(EventQueue *q, volatile T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...) volatile, B0 b0, B1 b1, B2 b2, B3 b3) :
401 Event(q, mbed::callback(obj, method), b0, b1, b2, b3) { }
402
403 /** Create an event
404 * @see Event::Event
405 */
406 template <typename T, typename R, typename B0, typename B1, typename B2, typename B3>
407 Event(EventQueue *q, const volatile T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...) const volatile, B0 b0, B1 b1, B2 b2, B3 b3) :
408 Event(q, mbed::callback(obj, method), b0, b1, b2, b3) { }
409
410 /** Create an event
411 * @see Event::Event
412 */
413 template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
414 Event(EventQueue *q, T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...), B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) :
415 Event(q, mbed::callback(obj, method), b0, b1, b2, b3, b4) { }
416
417 /** Create an event
418 * @see Event::Event
419 */
420 template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
421 Event(EventQueue *q, const T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...) const, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) :
422 Event(q, mbed::callback(obj, method), b0, b1, b2, b3, b4) { }
423
424 /** Create an event
425 * @see Event::Event
426 */
427 template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
428 Event(EventQueue *q, volatile T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...) volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) :
429 Event(q, mbed::callback(obj, method), b0, b1, b2, b3, b4) { }
430
431 /** Create an event
432 * @see Event::Event
433 */
434 template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4>
435 Event(EventQueue *q, const volatile T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...) const volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4) :
436 Event(q, mbed::callback(obj, method), b0, b1, b2, b3, b4) { }
437};
438
439/** @}*/
440
441#if !defined(DOXYGEN_ONLY)
442
443// Convenience functions declared here to avoid cyclic
444// dependency between Event and EventQueue
445template <typename R, typename... ArgTs>
446Event<void(ArgTs...)> EventQueue::event(R(*func)(ArgTs...))
447{
448 return Event<void(ArgTs...)>(this, func);
449}
450
451template <typename T, typename R, typename... ArgTs>
452Event<void(ArgTs...)> EventQueue::event(T *obj, R(T::*method)(ArgTs...))
453{
454 return Event<void(ArgTs...)>(this, mbed::callback(obj, method));
455}
456
457template <typename T, typename R, typename... ArgTs>
458Event<void(ArgTs...)> EventQueue::event(const T *obj, R(T::*method)(ArgTs...) const)
459{
460 return Event<void(ArgTs...)>(this, mbed::callback(obj, method));
461}
462
463template <typename T, typename R, typename... ArgTs>
464Event<void(ArgTs...)> EventQueue::event(volatile T *obj, R(T::*method)(ArgTs...) volatile)
465{
466 return Event<void(ArgTs...)>(this, mbed::callback(obj, method));
467}
468
469template <typename T, typename R, typename... ArgTs>
470Event<void(ArgTs...)> EventQueue::event(const volatile T *obj, R(T::*method)(ArgTs...) const volatile)
471{
472 return Event<void(ArgTs...)>(this, mbed::callback(obj, method));
473}
474
475template <typename R, typename... ArgTs>
476Event<void(ArgTs...)> EventQueue::event(mbed::Callback<R(ArgTs...)> cb)
477{
478 return Event<void(ArgTs...)>(this, cb);
479}
480
481template <typename R, typename B0, typename C0, typename... ArgTs>
482Event<void(ArgTs...)> EventQueue::event(R(*func)(B0, ArgTs...), C0 c0)
483{
484 return Event<void(ArgTs...)>(this, func, c0);
485}
486
487template <typename T, typename R, typename B0, typename C0, typename... ArgTs>
488Event<void(ArgTs...)> EventQueue::event(T *obj, R(T::*method)(B0, ArgTs...), C0 c0)
489{
490 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0);
491}
492
493template <typename T, typename R, typename B0, typename C0, typename... ArgTs>
494Event<void(ArgTs...)> EventQueue::event(const T *obj, R(T::*method)(B0, ArgTs...) const, C0 c0)
495{
496 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0);
497}
498
499template <typename T, typename R, typename B0, typename C0, typename... ArgTs>
500Event<void(ArgTs...)> EventQueue::event(volatile T *obj, R(T::*method)(B0, ArgTs...) volatile, C0 c0)
501{
502 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0);
503}
504
505template <typename T, typename R, typename B0, typename C0, typename... ArgTs>
506Event<void(ArgTs...)> EventQueue::event(const volatile T *obj, R(T::*method)(B0, ArgTs...) const volatile, C0 c0)
507{
508 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0);
509}
510
511template <typename R, typename B0, typename C0, typename... ArgTs>
512Event<void(ArgTs...)> EventQueue::event(mbed::Callback<R(B0, ArgTs...)> cb, C0 c0)
513{
514 return Event<void(ArgTs...)>(this, cb, c0);
515}
516
517template <typename R, typename B0, typename B1, typename C0, typename C1, typename... ArgTs>
518Event<void(ArgTs...)> EventQueue::event(R(*func)(B0, B1, ArgTs...), C0 c0, C1 c1)
519{
520 return Event<void(ArgTs...)>(this, func, c0, c1);
521}
522
523template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename... ArgTs>
524Event<void(ArgTs...)> EventQueue::event(T *obj, R(T::*method)(B0, B1, ArgTs...), C0 c0, C1 c1)
525{
526 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1);
527}
528
529template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename... ArgTs>
530Event<void(ArgTs...)> EventQueue::event(const T *obj, R(T::*method)(B0, B1, ArgTs...) const, C0 c0, C1 c1)
531{
532 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1);
533}
534
535template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename... ArgTs>
536Event<void(ArgTs...)> EventQueue::event(volatile T *obj, R(T::*method)(B0, B1, ArgTs...) volatile, C0 c0, C1 c1)
537{
538 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1);
539}
540
541template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename... ArgTs>
542Event<void(ArgTs...)> EventQueue::event(const volatile T *obj, R(T::*method)(B0, B1, ArgTs...) const volatile, C0 c0, C1 c1)
543{
544 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1);
545}
546
547template <typename R, typename B0, typename B1, typename C0, typename C1, typename... ArgTs>
548Event<void(ArgTs...)> EventQueue::event(mbed::Callback<R(B0, B1, ArgTs...)> cb, C0 c0, C1 c1)
549{
550 return Event<void(ArgTs...)>(this, cb, c0, c1);
551}
552
553template <typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename... ArgTs>
554Event<void(ArgTs...)> EventQueue::event(R(*func)(B0, B1, B2, ArgTs...), C0 c0, C1 c1, C2 c2)
555{
556 return Event<void(ArgTs...)>(this, func, c0, c1, c2);
557}
558
559template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename... ArgTs>
560Event<void(ArgTs...)> EventQueue::event(T *obj, R(T::*method)(B0, B1, B2, ArgTs...), C0 c0, C1 c1, C2 c2)
561{
562 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2);
563}
564
565template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename... ArgTs>
566Event<void(ArgTs...)> EventQueue::event(const T *obj, R(T::*method)(B0, B1, B2, ArgTs...) const, C0 c0, C1 c1, C2 c2)
567{
568 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2);
569}
570
571template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename... ArgTs>
572Event<void(ArgTs...)> EventQueue::event(volatile T *obj, R(T::*method)(B0, B1, B2, ArgTs...) volatile, C0 c0, C1 c1, C2 c2)
573{
574 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2);
575}
576
577template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename... ArgTs>
578Event<void(ArgTs...)> EventQueue::event(const volatile T *obj, R(T::*method)(B0, B1, B2, ArgTs...) const volatile, C0 c0, C1 c1, C2 c2)
579{
580 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2);
581}
582
583template <typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename... ArgTs>
584Event<void(ArgTs...)> EventQueue::event(mbed::Callback<R(B0, B1, B2, ArgTs...)> cb, C0 c0, C1 c1, C2 c2)
585{
586 return Event<void(ArgTs...)>(this, cb, c0, c1, c2);
587}
588
589template <typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename... ArgTs>
590Event<void(ArgTs...)> EventQueue::event(R(*func)(B0, B1, B2, B3, ArgTs...), C0 c0, C1 c1, C2 c2, C3 c3)
591{
592 return Event<void(ArgTs...)>(this, func, c0, c1, c2, c3);
593}
594
595template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename... ArgTs>
596Event<void(ArgTs...)> EventQueue::event(T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...), C0 c0, C1 c1, C2 c2, C3 c3)
597{
598 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2, c3);
599}
600
601template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename... ArgTs>
602Event<void(ArgTs...)> EventQueue::event(const T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...) const, C0 c0, C1 c1, C2 c2, C3 c3)
603{
604 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2, c3);
605}
606
607template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename... ArgTs>
608Event<void(ArgTs...)> EventQueue::event(volatile T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...) volatile, C0 c0, C1 c1, C2 c2, C3 c3)
609{
610 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2, c3);
611}
612
613template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename... ArgTs>
614Event<void(ArgTs...)> EventQueue::event(const volatile T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...) const volatile, C0 c0, C1 c1, C2 c2, C3 c3)
615{
616 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2, c3);
617}
618
619template <typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename... ArgTs>
620Event<void(ArgTs...)> EventQueue::event(mbed::Callback<R(B0, B1, B2, B3, ArgTs...)> cb, C0 c0, C1 c1, C2 c2, C3 c3)
621{
622 return Event<void(ArgTs...)>(this, cb, c0, c1, c2, c3);
623}
624
625template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename... ArgTs>
626Event<void(ArgTs...)> EventQueue::event(R(*func)(B0, B1, B2, B3, B4, ArgTs...), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
627{
628 return Event<void(ArgTs...)>(this, func, c0, c1, c2, c3, c4);
629}
630
631template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename... ArgTs>
632Event<void(ArgTs...)> EventQueue::event(T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
633{
634 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2, c3, c4);
635}
636
637template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename... ArgTs>
638Event<void(ArgTs...)> EventQueue::event(const T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...) const, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
639{
640 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2, c3, c4);
641}
642
643template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename... ArgTs>
644Event<void(ArgTs...)> EventQueue::event(volatile T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...) volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
645{
646 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2, c3, c4);
647}
648
649template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename... ArgTs>
650Event<void(ArgTs...)> EventQueue::event(const volatile T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...) const volatile, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
651{
652 return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2, c3, c4);
653}
654
655template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename... ArgTs>
656Event<void(ArgTs...)> EventQueue::event(mbed::Callback<R(B0, B1, B2, B3, B4, ArgTs...)> cb, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
657{
658 return Event<void(ArgTs...)>(this, cb, c0, c1, c2, c3, c4);
659}
660
661#endif // !defined(DOXYGEN_ONLY)
662
663/** @}*/
664}
665#endif
Event(EventQueue *q, T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...), B0 b0, B1 b1, B2 b2, B3 b3)
Create an event.
Definition: Event.h:386
Event(EventQueue *q, const volatile T *obj, R(T::*method)(B0, B1, B2, ArgTs...) const volatile, B0 b0, B1 b1, B2 b2)
Create an event.
Definition: Event.h:379
int post(ArgTs... args) const
Posts an event onto the underlying event queue.
Definition: Event.h:190
Event & operator=(const Event &that)
Assignment operator for events.
Definition: Event.h:97
static void thunk(void *func, ArgTs... args)
Static thunk for passing as C-style function.
Definition: Event.h:224
Event(EventQueue *q, const T *obj, R(T::*method)(B0, ArgTs...) const, B0 b0)
Create an event.
Definition: Event.h:309
Event(EventQueue *q, T *obj, R(T::*method)(B0, B1, B2, ArgTs...), B0 b0, B1 b1, B2 b2)
Create an event.
Definition: Event.h:358
void call(ArgTs... args) const
Posts an event onto the underlying event queue, returning void.
Definition: Event.h:204
void period(duration p)
Configure the period of an event.
Definition: Event.h:150
Event(const Event &e)
Copy constructor for events.
Definition: Event.h:86
void operator()(ArgTs... args) const
Posts an event onto the underlying event queue, returning void.
Definition: Event.h:214
Event(EventQueue *q, volatile T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...) volatile, B0 b0, B1 b1, B2 b2, B3 b3)
Create an event.
Definition: Event.h:400
Event(EventQueue *q, const T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...) const, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4)
Create an event.
Definition: Event.h:421
Event(EventQueue *q, F f, ContextArgTs... context_args)
Create an event.
Definition: Event.h:295
Event(EventQueue *q, volatile T *obj, R(T::*method)(B0, ArgTs...) volatile, B0 b0)
Create an event.
Definition: Event.h:316
Event(EventQueue *q, volatile T *obj, R(T::*method)(B0, B1, B2, ArgTs...) volatile, B0 b0, B1 b1, B2 b2)
Create an event.
Definition: Event.h:372
void delay(duration d)
Configure the delay of an event.
Definition: Event.h:125
void cancel() const
Cancels the most recently posted event.
Definition: Event.h:240
Event(EventQueue *q, const volatile T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...) const volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4)
Create an event.
Definition: Event.h:435
~Event()
Destructor for events.
Definition: Event.h:109
Event(EventQueue *q, const T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...) const, B0 b0, B1 b1, B2 b2, B3 b3)
Create an event.
Definition: Event.h:393
Event(EventQueue *q, const volatile T *obj, R(T::*method)(B0, ArgTs...) const volatile, B0 b0)
Create an event.
Definition: Event.h:323
Event(EventQueue *q, const volatile T *obj, R(T::*method)(B0, B1, ArgTs...) const volatile, B0 b0, B1 b1)
Create an event.
Definition: Event.h:351
Event(EventQueue *q, const T *obj, R(T::*method)(B0, B1, ArgTs...) const, B0 b0, B1 b1)
Create an event.
Definition: Event.h:337
Event(EventQueue *q, T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...), B0 b0, B1 b1, B2 b2, B3 b3, B4 b4)
Create an event.
Definition: Event.h:414
Event(EventQueue *q, T *obj, R(T::*method)(B0, B1, ArgTs...), B0 b0, B1 b1)
Create an event.
Definition: Event.h:330
Event(EventQueue *q, volatile T *obj, R(T::*method)(B0, B1, B2, B3, B4, ArgTs...) volatile, B0 b0, B1 b1, B2 b2, B3 b3, B4 b4)
Create an event.
Definition: Event.h:428
Event(EventQueue *q, F f)
Create an event.
Definition: Event.h:64
Event(EventQueue *q, T *obj, R(T::*method)(B0, ArgTs...), B0 b0)
Create an event.
Definition: Event.h:302
Event(EventQueue *q, const volatile T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...) const volatile, B0 b0, B1 b1, B2 b2, B3 b3)
Create an event.
Definition: Event.h:407
Event(EventQueue *q, volatile T *obj, R(T::*method)(B0, B1, ArgTs...) volatile, B0 b0, B1 b1)
Create an event.
Definition: Event.h:344
Event(EventQueue *q, const T *obj, R(T::*method)(B0, B1, B2, ArgTs...) const, B0 b0, B1 b1, B2 b2)
Create an event.
Definition: Event.h:365
Event.
Definition: Event.h:38
EventQueue.
Definition: EventQueue.h:62
Event< void(ArgTs...)> event(R(*func)(BoundArgTs..., ArgTs...), ContextArgTs ...context_args)
Creates an event bound to the event queue.
Callback class based on template specialization.
Definition: Callback.h:53
#define MBED_ASSERT(expr)
MBED_ASSERT Declare runtime assertions: results in runtime error if condition is false.
Definition: mbed_assert.h:66
Callback< R(ArgTs...)> callback(R(*func)(ArgTs...)=nullptr) noexcept
Create a callback class with type inferred from the arguments.
Definition: Callback.h:678
#define MBED_DEPRECATED_SINCE(D, M)
MBED_DEPRECATED("message string") Mark a function declaration as deprecated, if it used then a warnin...
#define MBED_UNUSED
MBED_UNUSED Declare a function argument to be unused, suppressing compiler warnings.
Definition: equeue.h:61