OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
aMessenger.h
Go to the documentation of this file.
1/*
2 * File: aMessenger.h
3 * Package: akCore
4 *
5 * Created on: February 06, 2020
6 * Author: Alexander Kuester
7 * Copyright (c) 2022 Alexander Kuester
8 * This file is part of the uiCore component.
9 * This file is subject to the terms and conditions defined in
10 * file 'LICENSE', which is part of this source code package.
11 */
12
13#pragma once
14
15// C++ header
16#include <map> // Map ids and message types
17#include <vector> // Notifiers collection in the map
18#include <mutex>
19
20// AK header
21#include <akCore/globalDataTypes.h> // UID and ID type
22#include <akCore/akCore.h> // eventType
23
24namespace ak {
25
26 // Forward declaration
27 class aNotifier;
28 class aUidManager;
29
35 public:
36
38 aMessenger();
39
41 virtual ~aMessenger();
42
43 // ####################################################################################################
44 // Data exchange
45
55 void sendMessage(
56 UID _senderId,
57 eventType _event,
58 int _info1 = 0,
59 int _info2 = 0
60 );
61
62 // Data exchange
63 // ####################################################################################################
64 // Sender/receiver organisation
65
71 void registerUidReceiver(
72 UID _senderId,
73 aNotifier * _notifier
74 );
75
79 void registerEventTypeReceiver(
80 eventType _eventType,
81 aNotifier * _notifier
82 );
83
86 void registerNotifierForAllMessages(
87 aNotifier * _notifier
88 );
89
92 int uidNotifierCount(
93 UID _senderUID
94 );
95
98 int eventNotifierCount(
99 eventType _event
100 );
101
102 // ####################################################################################################
103
105 void clearAll(void);
106
108 void enable(void) { m_isEnabled = true; }
109
111 void disable(void) { m_isEnabled = false; }
112
116 bool _enabled
117 ) { m_isEnabled = _enabled; }
118
120 bool isEnabled(void) const { return m_isEnabled; }
121
122 private:
123
125
126 bool m_isEnabled;
127
128 std::map<UID, std::vector<aNotifier *> * > m_uidReceivers;
129 std::map<eventType, std::vector<aNotifier *> *> m_eventReceivers;
130
131 std::vector<aNotifier *> m_allMessageReceivers;
132
133 // Block copy constructor
134 aMessenger(aMessenger & other) = delete;
135
136 // Block assignment operator
137 aMessenger & operator = (aMessenger & other) = delete;
138
139 };
140}
#define UICORE_API_EXPORT
Definition globalDataTypes.h:20
Class used to forward messages to receivers This class is used to forward a message to receivers....
Definition aMessenger.h:34
void disable(void)
Will disable the messenger.
Definition aMessenger.h:111
void setEnabled(bool _enabled)
Will set the messengers enabled state.
Definition aMessenger.h:115
void enable(void)
Will enable the messenger.
Definition aMessenger.h:108
bool isEnabled(void) const
Will return the current enabled state of the messenger.
Definition aMessenger.h:120
This abstract class is used to provide the receiver functionallity used in the messaging class.
Definition aNotifier.h:22
This class is used to manage UIDs. This UID manager is incrementing the UID on each getId call.
Definition aUidMangager.h:25
Definition uiAPI.h:45
unsigned long long UID
The UID datatype used for objects.
Definition globalDataTypes.h:65
eventType
Describes the type of an event.
Definition akCore.h:86
static ak::aUidManager * m_uidManager
The messenger used in this API.
Definition uiAPI.cpp:59