This is a fork of the `events` subdirectory of https://github.com/ARMmbed/mbed-os

Dependents:   HelloWorld_CCA01M1 HelloWorld_CCA02M1 CI-data-logger-server HelloWorld_CCA02M1 ... more

This is a fork of the events subdirectory of https://github.com/ARMmbed/mbed-os.

Note, you must import this library with import name: events!!!

Files at this revision

API Documentation at this revision

Comitter:
Christopher Haster
Date:
Mon Oct 03 18:33:25 2016 -0500
Parent:
3:3d3560169945
Child:
6:29dc481c8037
Commit message:
callback - Added workaround for IAR issue with type information

In the IAR ide, implicitly generated structures based on function
templates end up with missing type information. This has no effect
on using the IAR compiler standalone, but when used through the ide
the missing type information causes the ide to error.

As a workaround, moved the function attributes generated for the
Callback and Event classes into the class scope. This avoids the
syntax that confuses IAR.

Changed in this revision

Event.h Show annotated file Show diff for this revision Revisions of this file
--- a/Event.h	Sat Oct 01 23:11:42 2016 -0500
+++ b/Event.h	Mon Oct 03 18:33:25 2016 -0500
@@ -47,41 +47,17 @@
      */
     template <typename F>
     Event(EventQueue *q, F f) {
-        struct local {
-            static int post(struct event *e) {
-                typedef EventQueue::context00<F> C;
-                struct local {
-                    static void call(void *p) { (*static_cast<C*>(p))(); }
-                    static void dtor(void *p) { static_cast<C*>(p)->~C(); }
-                };
-
-                void *p = equeue_alloc(e->equeue, sizeof(C));
-                if (!p) {
-                    return 0;
-                }
-
-                new (p) C(*reinterpret_cast<F*>(e+1));
-                equeue_event_delay(p, e->delay);
-                equeue_event_period(p, e->period);
-                equeue_event_dtor(p, &local::dtor);
-                return equeue_post(e->equeue, &local::call, p);
-            }
-
-            static void dtor(struct event *e) {
-                reinterpret_cast<F*>(e+1)->~F();
-            }
-        };
-
         _event = static_cast<struct event *>(
                 equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F)));
+
         if (_event) {
             _event->equeue = &q->_equeue;
             _event->id = 0;
             _event->delay = 0;
             _event->period = -1;
 
-            _event->post = &local::post;
-            _event->dtor = &local::dtor;
+            _event->post = &Event::event_post<F>;
+            _event->dtor = &Event::event_dtor<F>;
 
             new (_event+1) F(f);
 
@@ -222,6 +198,38 @@
         // F follows
     } *_event;
 
+    // Event attributes
+    template <typename F>
+    static int event_post(struct event *e) {
+        typedef EventQueue::context00<F> C;
+        void *p = equeue_alloc(e->equeue, sizeof(C));
+        if (!p) {
+            return 0;
+        }
+
+        new (p) C(*(F*)(e + 1));
+        equeue_event_delay(p, e->delay);
+        equeue_event_period(p, e->period);
+        equeue_event_dtor(p, &Event::function_dtor<C>);
+        return equeue_post(e->equeue, &Event::function_call<C>, p);
+    }
+
+    template <typename F>
+    static void event_dtor(struct event *e) {
+        ((F*)(e + 1))->~F();
+    }
+
+    // Function attributes
+    template <typename F>
+    static void function_call(void *p) {
+        (*(F*)p)();
+    }
+
+    template <typename F>
+    static void function_dtor(void *p) {
+        ((F*)p)->~F();
+    }
+
 public:
     /** Create an event
      *  @see Event::Event
@@ -443,41 +451,17 @@
      */
     template <typename F>
     Event(EventQueue *q, F f) {
-        struct local {
-            static int post(struct event *e, A0 a0) {
-                typedef EventQueue::context10<F, A0> C;
-                struct local {
-                    static void call(void *p) { (*static_cast<C*>(p))(); }
-                    static void dtor(void *p) { static_cast<C*>(p)->~C(); }
-                };
-
-                void *p = equeue_alloc(e->equeue, sizeof(C));
-                if (!p) {
-                    return 0;
-                }
-
-                new (p) C(*reinterpret_cast<F*>(e+1), a0);
-                equeue_event_delay(p, e->delay);
-                equeue_event_period(p, e->period);
-                equeue_event_dtor(p, &local::dtor);
-                return equeue_post(e->equeue, &local::call, p);
-            }
-
-            static void dtor(struct event *e) {
-                reinterpret_cast<F*>(e+1)->~F();
-            }
-        };
-
         _event = static_cast<struct event *>(
                 equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F)));
+
         if (_event) {
             _event->equeue = &q->_equeue;
             _event->id = 0;
             _event->delay = 0;
             _event->period = -1;
 
-            _event->post = &local::post;
-            _event->dtor = &local::dtor;
+            _event->post = &Event::event_post<F>;
+            _event->dtor = &Event::event_dtor<F>;
 
             new (_event+1) F(f);
 
@@ -618,6 +602,38 @@
         // F follows
     } *_event;
 
+    // Event attributes
+    template <typename F>
+    static int event_post(struct event *e, A0 a0) {
+        typedef EventQueue::context10<F, A0> C;
+        void *p = equeue_alloc(e->equeue, sizeof(C));
+        if (!p) {
+            return 0;
+        }
+
+        new (p) C(*(F*)(e + 1), a0);
+        equeue_event_delay(p, e->delay);
+        equeue_event_period(p, e->period);
+        equeue_event_dtor(p, &Event::function_dtor<C>);
+        return equeue_post(e->equeue, &Event::function_call<C>, p);
+    }
+
+    template <typename F>
+    static void event_dtor(struct event *e) {
+        ((F*)(e + 1))->~F();
+    }
+
+    // Function attributes
+    template <typename F>
+    static void function_call(void *p) {
+        (*(F*)p)();
+    }
+
+    template <typename F>
+    static void function_dtor(void *p) {
+        ((F*)p)->~F();
+    }
+
 public:
     /** Create an event
      *  @see Event::Event
@@ -839,41 +855,17 @@
      */
     template <typename F>
     Event(EventQueue *q, F f) {
-        struct local {
-            static int post(struct event *e, A0 a0, A1 a1) {
-                typedef EventQueue::context20<F, A0, A1> C;
-                struct local {
-                    static void call(void *p) { (*static_cast<C*>(p))(); }
-                    static void dtor(void *p) { static_cast<C*>(p)->~C(); }
-                };
-
-                void *p = equeue_alloc(e->equeue, sizeof(C));
-                if (!p) {
-                    return 0;
-                }
-
-                new (p) C(*reinterpret_cast<F*>(e+1), a0, a1);
-                equeue_event_delay(p, e->delay);
-                equeue_event_period(p, e->period);
-                equeue_event_dtor(p, &local::dtor);
-                return equeue_post(e->equeue, &local::call, p);
-            }
-
-            static void dtor(struct event *e) {
-                reinterpret_cast<F*>(e+1)->~F();
-            }
-        };
-
         _event = static_cast<struct event *>(
                 equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F)));
+
         if (_event) {
             _event->equeue = &q->_equeue;
             _event->id = 0;
             _event->delay = 0;
             _event->period = -1;
 
-            _event->post = &local::post;
-            _event->dtor = &local::dtor;
+            _event->post = &Event::event_post<F>;
+            _event->dtor = &Event::event_dtor<F>;
 
             new (_event+1) F(f);
 
@@ -1014,6 +1006,38 @@
         // F follows
     } *_event;
 
+    // Event attributes
+    template <typename F>
+    static int event_post(struct event *e, A0 a0, A1 a1) {
+        typedef EventQueue::context20<F, A0, A1> C;
+        void *p = equeue_alloc(e->equeue, sizeof(C));
+        if (!p) {
+            return 0;
+        }
+
+        new (p) C(*(F*)(e + 1), a0, a1);
+        equeue_event_delay(p, e->delay);
+        equeue_event_period(p, e->period);
+        equeue_event_dtor(p, &Event::function_dtor<C>);
+        return equeue_post(e->equeue, &Event::function_call<C>, p);
+    }
+
+    template <typename F>
+    static void event_dtor(struct event *e) {
+        ((F*)(e + 1))->~F();
+    }
+
+    // Function attributes
+    template <typename F>
+    static void function_call(void *p) {
+        (*(F*)p)();
+    }
+
+    template <typename F>
+    static void function_dtor(void *p) {
+        ((F*)p)->~F();
+    }
+
 public:
     /** Create an event
      *  @see Event::Event
@@ -1235,41 +1259,17 @@
      */
     template <typename F>
     Event(EventQueue *q, F f) {
-        struct local {
-            static int post(struct event *e, A0 a0, A1 a1, A2 a2) {
-                typedef EventQueue::context30<F, A0, A1, A2> C;
-                struct local {
-                    static void call(void *p) { (*static_cast<C*>(p))(); }
-                    static void dtor(void *p) { static_cast<C*>(p)->~C(); }
-                };
-
-                void *p = equeue_alloc(e->equeue, sizeof(C));
-                if (!p) {
-                    return 0;
-                }
-
-                new (p) C(*reinterpret_cast<F*>(e+1), a0, a1, a2);
-                equeue_event_delay(p, e->delay);
-                equeue_event_period(p, e->period);
-                equeue_event_dtor(p, &local::dtor);
-                return equeue_post(e->equeue, &local::call, p);
-            }
-
-            static void dtor(struct event *e) {
-                reinterpret_cast<F*>(e+1)->~F();
-            }
-        };
-
         _event = static_cast<struct event *>(
                 equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F)));
+
         if (_event) {
             _event->equeue = &q->_equeue;
             _event->id = 0;
             _event->delay = 0;
             _event->period = -1;
 
-            _event->post = &local::post;
-            _event->dtor = &local::dtor;
+            _event->post = &Event::event_post<F>;
+            _event->dtor = &Event::event_dtor<F>;
 
             new (_event+1) F(f);
 
@@ -1410,6 +1410,38 @@
         // F follows
     } *_event;
 
+    // Event attributes
+    template <typename F>
+    static int event_post(struct event *e, A0 a0, A1 a1, A2 a2) {
+        typedef EventQueue::context30<F, A0, A1, A2> C;
+        void *p = equeue_alloc(e->equeue, sizeof(C));
+        if (!p) {
+            return 0;
+        }
+
+        new (p) C(*(F*)(e + 1), a0, a1, a2);
+        equeue_event_delay(p, e->delay);
+        equeue_event_period(p, e->period);
+        equeue_event_dtor(p, &Event::function_dtor<C>);
+        return equeue_post(e->equeue, &Event::function_call<C>, p);
+    }
+
+    template <typename F>
+    static void event_dtor(struct event *e) {
+        ((F*)(e + 1))->~F();
+    }
+
+    // Function attributes
+    template <typename F>
+    static void function_call(void *p) {
+        (*(F*)p)();
+    }
+
+    template <typename F>
+    static void function_dtor(void *p) {
+        ((F*)p)->~F();
+    }
+
 public:
     /** Create an event
      *  @see Event::Event
@@ -1631,41 +1663,17 @@
      */
     template <typename F>
     Event(EventQueue *q, F f) {
-        struct local {
-            static int post(struct event *e, A0 a0, A1 a1, A2 a2, A3 a3) {
-                typedef EventQueue::context40<F, A0, A1, A2, A3> C;
-                struct local {
-                    static void call(void *p) { (*static_cast<C*>(p))(); }
-                    static void dtor(void *p) { static_cast<C*>(p)->~C(); }
-                };
-
-                void *p = equeue_alloc(e->equeue, sizeof(C));
-                if (!p) {
-                    return 0;
-                }
-
-                new (p) C(*reinterpret_cast<F*>(e+1), a0, a1, a2, a3);
-                equeue_event_delay(p, e->delay);
-                equeue_event_period(p, e->period);
-                equeue_event_dtor(p, &local::dtor);
-                return equeue_post(e->equeue, &local::call, p);
-            }
-
-            static void dtor(struct event *e) {
-                reinterpret_cast<F*>(e+1)->~F();
-            }
-        };
-
         _event = static_cast<struct event *>(
                 equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F)));
+
         if (_event) {
             _event->equeue = &q->_equeue;
             _event->id = 0;
             _event->delay = 0;
             _event->period = -1;
 
-            _event->post = &local::post;
-            _event->dtor = &local::dtor;
+            _event->post = &Event::event_post<F>;
+            _event->dtor = &Event::event_dtor<F>;
 
             new (_event+1) F(f);
 
@@ -1806,6 +1814,38 @@
         // F follows
     } *_event;
 
+    // Event attributes
+    template <typename F>
+    static int event_post(struct event *e, A0 a0, A1 a1, A2 a2, A3 a3) {
+        typedef EventQueue::context40<F, A0, A1, A2, A3> C;
+        void *p = equeue_alloc(e->equeue, sizeof(C));
+        if (!p) {
+            return 0;
+        }
+
+        new (p) C(*(F*)(e + 1), a0, a1, a2, a3);
+        equeue_event_delay(p, e->delay);
+        equeue_event_period(p, e->period);
+        equeue_event_dtor(p, &Event::function_dtor<C>);
+        return equeue_post(e->equeue, &Event::function_call<C>, p);
+    }
+
+    template <typename F>
+    static void event_dtor(struct event *e) {
+        ((F*)(e + 1))->~F();
+    }
+
+    // Function attributes
+    template <typename F>
+    static void function_call(void *p) {
+        (*(F*)p)();
+    }
+
+    template <typename F>
+    static void function_dtor(void *p) {
+        ((F*)p)->~F();
+    }
+
 public:
     /** Create an event
      *  @see Event::Event
@@ -2027,41 +2067,17 @@
      */
     template <typename F>
     Event(EventQueue *q, F f) {
-        struct local {
-            static int post(struct event *e, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
-                typedef EventQueue::context50<F, A0, A1, A2, A3, A4> C;
-                struct local {
-                    static void call(void *p) { (*static_cast<C*>(p))(); }
-                    static void dtor(void *p) { static_cast<C*>(p)->~C(); }
-                };
-
-                void *p = equeue_alloc(e->equeue, sizeof(C));
-                if (!p) {
-                    return 0;
-                }
-
-                new (p) C(*reinterpret_cast<F*>(e+1), a0, a1, a2, a3, a4);
-                equeue_event_delay(p, e->delay);
-                equeue_event_period(p, e->period);
-                equeue_event_dtor(p, &local::dtor);
-                return equeue_post(e->equeue, &local::call, p);
-            }
-
-            static void dtor(struct event *e) {
-                reinterpret_cast<F*>(e+1)->~F();
-            }
-        };
-
         _event = static_cast<struct event *>(
                 equeue_alloc(&q->_equeue, sizeof(struct event) + sizeof(F)));
+
         if (_event) {
             _event->equeue = &q->_equeue;
             _event->id = 0;
             _event->delay = 0;
             _event->period = -1;
 
-            _event->post = &local::post;
-            _event->dtor = &local::dtor;
+            _event->post = &Event::event_post<F>;
+            _event->dtor = &Event::event_dtor<F>;
 
             new (_event+1) F(f);
 
@@ -2202,6 +2218,38 @@
         // F follows
     } *_event;
 
+    // Event attributes
+    template <typename F>
+    static int event_post(struct event *e, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
+        typedef EventQueue::context50<F, A0, A1, A2, A3, A4> C;
+        void *p = equeue_alloc(e->equeue, sizeof(C));
+        if (!p) {
+            return 0;
+        }
+
+        new (p) C(*(F*)(e + 1), a0, a1, a2, a3, a4);
+        equeue_event_delay(p, e->delay);
+        equeue_event_period(p, e->period);
+        equeue_event_dtor(p, &Event::function_dtor<C>);
+        return equeue_post(e->equeue, &Event::function_call<C>, p);
+    }
+
+    template <typename F>
+    static void event_dtor(struct event *e) {
+        ((F*)(e + 1))->~F();
+    }
+
+    // Function attributes
+    template <typename F>
+    static void function_call(void *p) {
+        (*(F*)p)();
+    }
+
+    template <typename F>
+    static void function_dtor(void *p) {
+        ((F*)p)->~F();
+    }
+
 public:
     /** Create an event
      *  @see Event::Event