DCC-EX Simple Throttle
Simple throttle for a DCC-EX CommandStation
Loading...
Searching...
No Matches
/home/runner/work/DCCEXSimpleThrottle/DCCEXSimpleThrottle/EventManager.h
Go to the documentation of this file.
1/*
2 * © 2024 Peter Cole
3 *
4 * This is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * It is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this code. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18#ifndef EVENTMANAGER_H
19#define EVENTMANAGER_H
20
21#include "EventListener.h"
22#include "EventStructure.h"
23
29public:
32
36 void subscribe(EventListener *eventListener, EventType eventType);
37
41 void unsubscribe(EventListener *eventListener, EventType eventType);
42
47 bool isSubscribed(EventListener *eventListener, EventType eventType);
48
52 void publish(EventType eventType, EventData eventData);
53
54private:
57 EventListener *eventListener; // Pointer to the class instance extending EventListener
58 EventType eventType; // EventType to listen for
59 EventSubscriber *next; // Pointer to the next subscriber in the list
60
66 };
67
68 EventSubscriber *_firstEventSubscriber; // Pointer to the first subscriber in the list
69};
70
71#endif // EVENTMANAGER_H
EventType
Enum containing all the event types that subscribers can listen for, and publishers can publish Liste...
Definition EventStructure.h:26
Class to extend for all other classes that need to respond to events For example: Class <MyClass> : p...
Definition EventListener.h:26
Class to centrally manage all events for the application Exposes methods to register subscribers that...
Definition EventManager.h:28
void publish(EventType eventType, EventData eventData)
Method to publish an event.
Definition EventManager.cpp:82
EventManager()
Constructor for the instance.
Definition EventManager.cpp:20
EventSubscriber * _firstEventSubscriber
Definition EventManager.h:68
bool isSubscribed(EventListener *eventListener, EventType eventType)
Method to check if the specified listener is subscribed to the specified event type.
Definition EventManager.cpp:66
void subscribe(EventListener *eventListener, EventType eventType)
Method to subscribe a listener to the specified event type.
Definition EventManager.cpp:22
void unsubscribe(EventListener *eventListener, EventType eventType)
Method to unsubscribe the listener from the specified event type.
Definition EventManager.cpp:39
Structure to enable supporting EventData that has various different types Byte - caters for 8 bit uns...
Definition EventStructure.h:66
EventSubscriber structure to maintain the linked list of subscribers.
Definition EventManager.h:56
EventSubscriber(EventListener *eventListener, EventType eventType)
Constructor for each event listener.
Definition EventManager.h:64
EventSubscriber * next
Definition EventManager.h:59
EventListener * eventListener
Definition EventManager.h:57
EventType eventType
Definition EventManager.h:58