Mistake on this page?
Report an issue in GitHub or email us
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 
25 namespace events {
26 /** \defgroup events-public-api Events
27  * \ingroup mbed-os-public
28  * @{
29  */
30 
31 static 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  */
37 template <typename F>
38 class Event;
39 
40 /**
41  * \defgroup events_Event Event<void()> class
42  * @{
43  */
44 
45 /** Event
46  *
47  * Representation of an event for fine-grain dispatch control
48  */
49 template <typename... ArgTs>
50 class Event<void(ArgTs...)> {
51 public:
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>
64  Event(EventQueue *q, F 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 
247 private:
248  struct event {
249  unsigned ref;
250  equeue_t *equeue;
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 
285 public:
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 
442 // Convenience functions declared here to avoid cyclic
443 // dependency between Event and EventQueue
444 template <typename R, typename... ArgTs>
445 Event<void(ArgTs...)> EventQueue::event(R(*func)(ArgTs...))
446 {
447  return Event<void(ArgTs...)>(this, func);
448 }
449 
450 template <typename T, typename R, typename... ArgTs>
451 Event<void(ArgTs...)> EventQueue::event(T *obj, R(T::*method)(ArgTs...))
452 {
453  return Event<void(ArgTs...)>(this, mbed::callback(obj, method));
454 }
455 
456 template <typename T, typename R, typename... ArgTs>
457 Event<void(ArgTs...)> EventQueue::event(const T *obj, R(T::*method)(ArgTs...) const)
458 {
459  return Event<void(ArgTs...)>(this, mbed::callback(obj, method));
460 }
461 
462 template <typename T, typename R, typename... ArgTs>
463 Event<void(ArgTs...)> EventQueue::event(volatile T *obj, R(T::*method)(ArgTs...) volatile)
464 {
465  return Event<void(ArgTs...)>(this, mbed::callback(obj, method));
466 }
467 
468 template <typename T, typename R, typename... ArgTs>
469 Event<void(ArgTs...)> EventQueue::event(const volatile T *obj, R(T::*method)(ArgTs...) const volatile)
470 {
471  return Event<void(ArgTs...)>(this, mbed::callback(obj, method));
472 }
473 
474 template <typename R, typename... ArgTs>
475 Event<void(ArgTs...)> EventQueue::event(mbed::Callback<R(ArgTs...)> cb)
476 {
477  return Event<void(ArgTs...)>(this, cb);
478 }
479 
480 template <typename R, typename B0, typename C0, typename... ArgTs>
481 Event<void(ArgTs...)> EventQueue::event(R(*func)(B0, ArgTs...), C0 c0)
482 {
483  return Event<void(ArgTs...)>(this, func, c0);
484 }
485 
486 template <typename T, typename R, typename B0, typename C0, typename... ArgTs>
487 Event<void(ArgTs...)> EventQueue::event(T *obj, R(T::*method)(B0, ArgTs...), C0 c0)
488 {
489  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0);
490 }
491 
492 template <typename T, typename R, typename B0, typename C0, typename... ArgTs>
493 Event<void(ArgTs...)> EventQueue::event(const T *obj, R(T::*method)(B0, ArgTs...) const, C0 c0)
494 {
495  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0);
496 }
497 
498 template <typename T, typename R, typename B0, typename C0, typename... ArgTs>
499 Event<void(ArgTs...)> EventQueue::event(volatile T *obj, R(T::*method)(B0, ArgTs...) volatile, C0 c0)
500 {
501  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0);
502 }
503 
504 template <typename T, typename R, typename B0, typename C0, typename... ArgTs>
505 Event<void(ArgTs...)> EventQueue::event(const volatile T *obj, R(T::*method)(B0, ArgTs...) const volatile, C0 c0)
506 {
507  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0);
508 }
509 
510 template <typename R, typename B0, typename C0, typename... ArgTs>
511 Event<void(ArgTs...)> EventQueue::event(mbed::Callback<R(B0, ArgTs...)> cb, C0 c0)
512 {
513  return Event<void(ArgTs...)>(this, cb, c0);
514 }
515 
516 template <typename R, typename B0, typename B1, typename C0, typename C1, typename... ArgTs>
517 Event<void(ArgTs...)> EventQueue::event(R(*func)(B0, B1, ArgTs...), C0 c0, C1 c1)
518 {
519  return Event<void(ArgTs...)>(this, func, c0, c1);
520 }
521 
522 template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename... ArgTs>
523 Event<void(ArgTs...)> EventQueue::event(T *obj, R(T::*method)(B0, B1, ArgTs...), C0 c0, C1 c1)
524 {
525  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1);
526 }
527 
528 template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename... ArgTs>
529 Event<void(ArgTs...)> EventQueue::event(const T *obj, R(T::*method)(B0, B1, ArgTs...) const, C0 c0, C1 c1)
530 {
531  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1);
532 }
533 
534 template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename... ArgTs>
535 Event<void(ArgTs...)> EventQueue::event(volatile T *obj, R(T::*method)(B0, B1, ArgTs...) volatile, C0 c0, C1 c1)
536 {
537  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1);
538 }
539 
540 template <typename T, typename R, typename B0, typename B1, typename C0, typename C1, typename... ArgTs>
541 Event<void(ArgTs...)> EventQueue::event(const volatile T *obj, R(T::*method)(B0, B1, ArgTs...) const volatile, C0 c0, C1 c1)
542 {
543  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1);
544 }
545 
546 template <typename R, typename B0, typename B1, typename C0, typename C1, typename... ArgTs>
547 Event<void(ArgTs...)> EventQueue::event(mbed::Callback<R(B0, B1, ArgTs...)> cb, C0 c0, C1 c1)
548 {
549  return Event<void(ArgTs...)>(this, cb, c0, c1);
550 }
551 
552 template <typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename... ArgTs>
553 Event<void(ArgTs...)> EventQueue::event(R(*func)(B0, B1, B2, ArgTs...), C0 c0, C1 c1, C2 c2)
554 {
555  return Event<void(ArgTs...)>(this, func, c0, c1, c2);
556 }
557 
558 template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename... ArgTs>
559 Event<void(ArgTs...)> EventQueue::event(T *obj, R(T::*method)(B0, B1, B2, ArgTs...), C0 c0, C1 c1, C2 c2)
560 {
561  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2);
562 }
563 
564 template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename... ArgTs>
565 Event<void(ArgTs...)> EventQueue::event(const T *obj, R(T::*method)(B0, B1, B2, ArgTs...) const, C0 c0, C1 c1, C2 c2)
566 {
567  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2);
568 }
569 
570 template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename... ArgTs>
571 Event<void(ArgTs...)> EventQueue::event(volatile T *obj, R(T::*method)(B0, B1, B2, ArgTs...) volatile, C0 c0, C1 c1, C2 c2)
572 {
573  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2);
574 }
575 
576 template <typename T, typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename... ArgTs>
577 Event<void(ArgTs...)> EventQueue::event(const volatile T *obj, R(T::*method)(B0, B1, B2, ArgTs...) const volatile, C0 c0, C1 c1, C2 c2)
578 {
579  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2);
580 }
581 
582 template <typename R, typename B0, typename B1, typename B2, typename C0, typename C1, typename C2, typename... ArgTs>
583 Event<void(ArgTs...)> EventQueue::event(mbed::Callback<R(B0, B1, B2, ArgTs...)> cb, C0 c0, C1 c1, C2 c2)
584 {
585  return Event<void(ArgTs...)>(this, cb, c0, c1, c2);
586 }
587 
588 template <typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename... ArgTs>
589 Event<void(ArgTs...)> EventQueue::event(R(*func)(B0, B1, B2, B3, ArgTs...), C0 c0, C1 c1, C2 c2, C3 c3)
590 {
591  return Event<void(ArgTs...)>(this, func, c0, c1, c2, c3);
592 }
593 
594 template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename... ArgTs>
595 Event<void(ArgTs...)> EventQueue::event(T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...), C0 c0, C1 c1, C2 c2, C3 c3)
596 {
597  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2, c3);
598 }
599 
600 template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename... ArgTs>
601 Event<void(ArgTs...)> EventQueue::event(const T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...) const, C0 c0, C1 c1, C2 c2, C3 c3)
602 {
603  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2, c3);
604 }
605 
606 template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename... ArgTs>
607 Event<void(ArgTs...)> EventQueue::event(volatile T *obj, R(T::*method)(B0, B1, B2, B3, ArgTs...) volatile, C0 c0, C1 c1, C2 c2, C3 c3)
608 {
609  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2, c3);
610 }
611 
612 template <typename T, typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename... ArgTs>
613 Event<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)
614 {
615  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2, c3);
616 }
617 
618 template <typename R, typename B0, typename B1, typename B2, typename B3, typename C0, typename C1, typename C2, typename C3, typename... ArgTs>
619 Event<void(ArgTs...)> EventQueue::event(mbed::Callback<R(B0, B1, B2, B3, ArgTs...)> cb, C0 c0, C1 c1, C2 c2, C3 c3)
620 {
621  return Event<void(ArgTs...)>(this, cb, c0, c1, c2, c3);
622 }
623 
624 template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename... ArgTs>
625 Event<void(ArgTs...)> EventQueue::event(R(*func)(B0, B1, B2, B3, B4, ArgTs...), C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
626 {
627  return Event<void(ArgTs...)>(this, func, c0, c1, c2, c3, c4);
628 }
629 
630 template <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>
631 Event<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)
632 {
633  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2, c3, c4);
634 }
635 
636 template <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>
637 Event<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)
638 {
639  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2, c3, c4);
640 }
641 
642 template <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>
643 Event<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)
644 {
645  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2, c3, c4);
646 }
647 
648 template <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>
649 Event<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)
650 {
651  return Event<void(ArgTs...)>(this, mbed::callback(obj, method), c0, c1, c2, c3, c4);
652 }
653 
654 template <typename R, typename B0, typename B1, typename B2, typename B3, typename B4, typename C0, typename C1, typename C2, typename C3, typename C4, typename... ArgTs>
655 Event<void(ArgTs...)> EventQueue::event(mbed::Callback<R(B0, B1, B2, B3, B4, ArgTs...)> cb, C0 c0, C1 c1, C2 c2, C3 c3, C4 c4)
656 {
657  return Event<void(ArgTs...)>(this, cb, c0, c1, c2, c3, c4);
658 }
659 
660 /** @}*/
661 }
662 #endif
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
int post(ArgTs...args) const
Posts an event onto the underlying event queue.
Definition: Event.h:190
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, ArgTs...) const, B0 b0, B1 b1, B2 b2, B3 b3)
Create an event.
Definition: Event.h:393
void cancel() const
Cancels the most recently posted event.
Definition: Event.h:240
EventQueue.
Definition: EventQueue.h:62
Event.
Definition: Event.h:38
Event & operator=(const Event &that)
Assignment operator for events.
Definition: Event.h:97
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, 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(const Event &e)
Copy constructor for events.
Definition: Event.h:86
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, T *obj, R(T::*method)(B0, B1, ArgTs...), B0 b0, B1 b1)
Create an event.
Definition: Event.h:330
void period(duration p)
Configure the period of an event.
Definition: Event.h:150
Callback< R(ArgTs...)> callback(R(*func)(ArgTs...)=nullptr) noexcept
Create a callback class with type inferred from the arguments.
Definition: Callback.h:678
Event(EventQueue *q, const volatile T *obj, R(T::*method)(B0, ArgTs...) const volatile, B0 b0)
Create an event.
Definition: Event.h:323
static void thunk(void *func, ArgTs...args)
Static thunk for passing as C-style function.
Definition: Event.h:224
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
Event(EventQueue *q, const T *obj, R(T::*method)(B0, ArgTs...) const, B0 b0)
Create an event.
Definition: Event.h:309
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(EventQueue *q, F f)
Create an event.
Definition: Event.h:64
#define MBED_ASSERT(expr)
MBED_ASSERT Declare runtime assertions: results in runtime error if condition is false.
Definition: mbed_assert.h:66
void call(ArgTs...args) const
Posts an event onto the underlying event queue, returning void.
Definition: Event.h:204
Definition: equeue.h:61
Event(EventQueue *q, T *obj, R(T::*method)(B0, ArgTs...), B0 b0)
Create an event.
Definition: Event.h:302
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, T *obj, R(T::*method)(B0, B1, B2, ArgTs...), B0 b0, B1 b1, B2 b2)
Create an event.
Definition: Event.h:358
void delay(duration d)
Configure the delay of an event.
Definition: Event.h:125
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, ArgTs...) const, B0 b0, B1 b1)
Create an event.
Definition: Event.h:337
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, B1, B2, ArgTs...) volatile, B0 b0, B1 b1, B2 b2)
Create an event.
Definition: Event.h:372
void operator()(ArgTs...args) const
Posts an event onto the underlying event queue, returning void.
Definition: Event.h:214
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(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< 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
Definition: ATHandler.h:46
Event(EventQueue *q, volatile T *obj, R(T::*method)(B0, ArgTs...) volatile, B0 b0)
Create an event.
Definition: Event.h:316
#define MBED_UNUSED
MBED_UNUSED Declare a function argument to be unused, suppressing compiler warnings.
#define MBED_DEPRECATED_SINCE(D, M)
MBED_DEPRECATED("message string") Mark a function declaration as deprecated, if it used then a warnin...
~Event()
Destructor for events.
Definition: Event.h:109
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.