EventFramework library allows the creation of an event-driven infrastructure in which small "threads" can handle events in a multithreaded execution context. The EventFramework can be configured to act as a cooperative or a fully-preemptive kernel with fixed-priority scheduling. Furthermore, this kernel matches run-to-completion semantics, and hence a single-stack configuration is enough to keep running this multithreaded execution environment. As running threads shares global stack, a huge quantity of RAM is saved in contrast with traditional RTOSes.

Dependents:   sensors_KL46Z_xmn

Committer:
raulMrello
Date:
Wed Oct 03 21:02:16 2012 +0000
Revision:
1:ec12f2e32faf
Parent:
0:9d09acc8f9d9
Nesting correction on RestoreContext interface.; Erase invalid comment-block

Who changed what in which revision?

UserRevisionLine numberNew contents of line
raulMrello 0:9d09acc8f9d9 1 /* mbed EventFramework Library
raulMrello 0:9d09acc8f9d9 2 * Copyright (c) 2012-2016 raulMrello
raulMrello 0:9d09acc8f9d9 3 *
raulMrello 0:9d09acc8f9d9 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
raulMrello 0:9d09acc8f9d9 5 * of this software and associated documentation files (the "Software"), to deal
raulMrello 0:9d09acc8f9d9 6 * in the Software without restriction, including without limitation the rights
raulMrello 0:9d09acc8f9d9 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
raulMrello 0:9d09acc8f9d9 8 * copies of the Software, and to permit persons to whom the Software is
raulMrello 0:9d09acc8f9d9 9 * furnished to do so, subject to the following conditions:
raulMrello 0:9d09acc8f9d9 10 *
raulMrello 0:9d09acc8f9d9 11 * The above copyright notice and this permission notice shall be included in
raulMrello 0:9d09acc8f9d9 12 * all copies or substantial portions of the Software.
raulMrello 0:9d09acc8f9d9 13 *
raulMrello 0:9d09acc8f9d9 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
raulMrello 0:9d09acc8f9d9 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
raulMrello 0:9d09acc8f9d9 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
raulMrello 0:9d09acc8f9d9 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
raulMrello 0:9d09acc8f9d9 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
raulMrello 0:9d09acc8f9d9 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
raulMrello 0:9d09acc8f9d9 20 * THE SOFTWARE.
raulMrello 0:9d09acc8f9d9 21 */
raulMrello 0:9d09acc8f9d9 22
raulMrello 0:9d09acc8f9d9 23 #ifndef _EVENT_H_
raulMrello 0:9d09acc8f9d9 24 #define _EVENT_H_
raulMrello 0:9d09acc8f9d9 25
raulMrello 0:9d09acc8f9d9 26 #include "../List/List.h"
raulMrello 0:9d09acc8f9d9 27 #include "../EventHandler/EventHandler.h"
raulMrello 0:9d09acc8f9d9 28
raulMrello 0:9d09acc8f9d9 29 /** Event class
raulMrello 0:9d09acc8f9d9 30 *
raulMrello 0:9d09acc8f9d9 31 * Events are the inter-process communication mechanism within the EventFramework. Each
raulMrello 0:9d09acc8f9d9 32 * event registered in the framework stands for a type of signal, which can accept
raulMrello 0:9d09acc8f9d9 33 * attached data to be processed by any processing entity; in this case by EventHandlers
raulMrello 0:9d09acc8f9d9 34 * through its attached EventDispatchingRoutine.
raulMrello 0:9d09acc8f9d9 35 * Each event has a fixed priority in the range: 0 (max) to 65535 (min) and can keep track
raulMrello 0:9d09acc8f9d9 36 * of a list of installed EventHandlers to invoke when the event is published. Published
raulMrello 0:9d09acc8f9d9 37 * events are queued into a PendingList managed by the EventFramework scheduler, who will
raulMrello 0:9d09acc8f9d9 38 * dispatch them accordingly with their priority (from highest to lowest).
raulMrello 0:9d09acc8f9d9 39 */
raulMrello 0:9d09acc8f9d9 40 class Event{
raulMrello 0:9d09acc8f9d9 41 public:
raulMrello 0:9d09acc8f9d9 42 /** Creates an Event with a specified priority
raulMrello 0:9d09acc8f9d9 43 *
raulMrello 0:9d09acc8f9d9 44 * @param prio Event priority. Range 0[max] - 65535[min]
raulMrello 0:9d09acc8f9d9 45 */
raulMrello 0:9d09acc8f9d9 46 Event(uint16_t prio);
raulMrello 0:9d09acc8f9d9 47
raulMrello 0:9d09acc8f9d9 48 ~Event();
raulMrello 0:9d09acc8f9d9 49
raulMrello 0:9d09acc8f9d9 50 /** Gets the Event priority.
raulMrello 0:9d09acc8f9d9 51 *
raulMrello 0:9d09acc8f9d9 52 * @returns event priority
raulMrello 0:9d09acc8f9d9 53 */
raulMrello 0:9d09acc8f9d9 54 uint16_t GetPrio(void);
raulMrello 0:9d09acc8f9d9 55
raulMrello 0:9d09acc8f9d9 56 /** Gets the base event reference
raulMrello 0:9d09acc8f9d9 57 *
raulMrello 0:9d09acc8f9d9 58 * To explain the way in which a base reference is used, it is necessary to explain what
raulMrello 0:9d09acc8f9d9 59 * happens on event publishing. Within the framework, only registered events can be published.
raulMrello 0:9d09acc8f9d9 60 * while publishing an event of one type, a new event is allocated (by: new Event()) and it is referenced
raulMrello 0:9d09acc8f9d9 61 * to the existing one by its private [base] property. This base reference allows the scheduler to invoke
raulMrello 0:9d09acc8f9d9 62 * to all its listeners.
raulMrello 0:9d09acc8f9d9 63 *
raulMrello 0:9d09acc8f9d9 64 * @returns event reference to the base event.
raulMrello 0:9d09acc8f9d9 65 */
raulMrello 0:9d09acc8f9d9 66 Event* GetBase(void);
raulMrello 0:9d09acc8f9d9 67
raulMrello 0:9d09acc8f9d9 68 /** Sets the Event reference to which this is based from.
raulMrello 0:9d09acc8f9d9 69 *
raulMrello 0:9d09acc8f9d9 70 * @param ev event reference to link with.
raulMrello 0:9d09acc8f9d9 71 */
raulMrello 0:9d09acc8f9d9 72 void SetBase(Event* ev);
raulMrello 0:9d09acc8f9d9 73
raulMrello 0:9d09acc8f9d9 74 /** Sets attached data to the Event.
raulMrello 0:9d09acc8f9d9 75 *
raulMrello 0:9d09acc8f9d9 76 * Events can attach extra data to be processed by the listener. Through this interface, a data
raulMrello 0:9d09acc8f9d9 77 * reference can be attached to the event.
raulMrello 0:9d09acc8f9d9 78 *
raulMrello 0:9d09acc8f9d9 79 * @param data data reference to be attached to the event for further processing.
raulMrello 0:9d09acc8f9d9 80 */
raulMrello 0:9d09acc8f9d9 81 void SetData(void* data);
raulMrello 0:9d09acc8f9d9 82
raulMrello 0:9d09acc8f9d9 83 /** Gets event's attached data.
raulMrello 0:9d09acc8f9d9 84 *
raulMrello 0:9d09acc8f9d9 85 * @returns reference to the attached data.
raulMrello 0:9d09acc8f9d9 86 */
raulMrello 0:9d09acc8f9d9 87 void* GetData(void);
raulMrello 0:9d09acc8f9d9 88
raulMrello 0:9d09acc8f9d9 89 /** Adds an EventHandler to process this kind of events.
raulMrello 0:9d09acc8f9d9 90 *
raulMrello 0:9d09acc8f9d9 91 * Each event manages an internal list of handlers. If an event of this kind is published
raulMrello 0:9d09acc8f9d9 92 * all handlers in this list will be fired to process the event.
raulMrello 0:9d09acc8f9d9 93 *
raulMrello 0:9d09acc8f9d9 94 * @param hnd EventHandler reference to subscribe to this Event.
raulMrello 0:9d09acc8f9d9 95 */
raulMrello 0:9d09acc8f9d9 96 void Subscribe(EventHandler* hnd);
raulMrello 0:9d09acc8f9d9 97
raulMrello 0:9d09acc8f9d9 98 /** Erases an EventHandler to stop processing this kind of events.
raulMrello 0:9d09acc8f9d9 99 *
raulMrello 0:9d09acc8f9d9 100 * @param hnd EventHandler reference to unsubscribe from this Event.
raulMrello 0:9d09acc8f9d9 101 */
raulMrello 0:9d09acc8f9d9 102 void Unsubscribe(EventHandler* hnd);
raulMrello 0:9d09acc8f9d9 103
raulMrello 0:9d09acc8f9d9 104 /** Gets the list of subscribed EventHandlers
raulMrello 0:9d09acc8f9d9 105 *
raulMrello 0:9d09acc8f9d9 106 * @returns reference to the list of subscribed EventHandlers.
raulMrello 0:9d09acc8f9d9 107 */
raulMrello 0:9d09acc8f9d9 108 List* GetList(void);
raulMrello 0:9d09acc8f9d9 109
raulMrello 0:9d09acc8f9d9 110 private:
raulMrello 0:9d09acc8f9d9 111 uint16_t prio;
raulMrello 0:9d09acc8f9d9 112 void* data;
raulMrello 0:9d09acc8f9d9 113 List* hlist;
raulMrello 0:9d09acc8f9d9 114 Event* base;
raulMrello 0:9d09acc8f9d9 115 };
raulMrello 0:9d09acc8f9d9 116
raulMrello 0:9d09acc8f9d9 117 #endif