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