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