ArnLib  4.0.x
Active Registry Network
ArnEvent.hpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2022 Michael Wiklund.
2 // All rights reserved.
3 // Contact: arnlib@wiklunden.se
4 //
5 // This file is part of the ArnLib - Active Registry Network.
6 // Parts of ArnLib depend on Qt and/or other libraries that have their own
7 // licenses. Usage of these other libraries is subject to their respective
8 // license agreements.
9 //
10 // GNU Lesser General Public License Usage
11 // This file may be used under the terms of the GNU Lesser General Public
12 // License version 2.1 as published by the Free Software Foundation and
13 // appearing in the file LICENSE_LGPL.txt included in the packaging of this
14 // file. In addition, as a special exception, you may use the rights described
15 // in the Nokia Qt LGPL Exception version 1.1, included in the file
16 // LGPL_EXCEPTION.txt in this package.
17 //
18 // GNU General Public License Usage
19 // Alternatively, this file may be used under the terms of the GNU General Public
20 // License version 3.0 as published by the Free Software Foundation and appearing
21 // in the file LICENSE_GPL.txt included in the packaging of this file.
22 //
23 // Other Usage
24 // Alternatively, this file may be used in accordance with the terms and conditions
25 // contained in a signed written agreement between you and Michael Wiklund.
26 //
27 // This program is distributed in the hope that it will be useful, but WITHOUT ANY
28 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
29 // PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
30 //
31 
32 #ifndef ARNEVENT_HPP
33 #define ARNEVENT_HPP
34 
35 #include "ArnInc/Arn.hpp"
36 #include "ArnInc/MQFlags.hpp"
37 #include <QEvent>
38 #include <QString>
39 #include <QVariant>
40 
41 class ArnLink;
42 class ArnLinkHandle;
43 class ArnEvent;
44 class QMutex;
45 
46 
47 class ArnEventIdx {
48  Q_GADGET
49  Q_ENUMS(E)
50 public:
51  enum E {
52  QtEvent = -1,
62  N
63  };
65 };
66 
67 class ArnAtomicOp {
68  Q_GADGET
69  Q_ENUMS(E)
70 public:
71  enum E {
72  None = 0,
77  N
78  };
80 
81  enum NS {NsEnum, NsCom};
83  { NsCom, BitSet, "bs" },
84  { NsCom, AddInt, "+i" },
85  { NsCom, AddReal, "+r" },
87  )
88 };
89 
90 
91 class ARNLIBSHARED_EXPORT ArnEvent : public QEvent
92 {
93  void* _target;
94  QMutex* _targetMutex;
95  ArnEvent* _targetNextPending;
96  ArnEvent** _targetPendingChain;
97 
98  void* _spare; // Can be used later as d-ptr
99 
100 public:
101  typedef ArnEventIdx Idx;
102 
103  ArnEvent( QEvent::Type type);
104  virtual ~ArnEvent();
105 
106  static int baseType( int setVal = -1);
107  static bool isArnEvent( int evType);
108  static int toIdx( QEvent::Type type);
109  static QString toString( QEvent::Type type);
110 
111  int toIdx() const;
112  QString toString() const;
113 
114  virtual ArnEvent* makeHeapClone() = 0;
115 
116  inline void* target() const
117  { return _target;}
118 
119  void setTarget( void* target);
120  void setTargetPendingChain( ArnEvent** targetPendingChain = arnNullptr);
121  void setTargetMutex( QMutex* targetMutex);
122  void inhibitPendingChain();
123 
124 protected:
125  ArnEvent* copyOpt( const ArnEvent* other);
126 };
127 
128 
129 class ArnEvLinkCreate : public ArnEvent
130 {
131  QString _path;
132  ArnLink* _arnLink;
133  bool _isLastLink;
134 
135 public:
136  ArnEvLinkCreate( const QString& path, ArnLink* arnLink, bool isLastLink);
137  static QEvent::Type type();
138  virtual ArnEvent* makeHeapClone();
139 
140  inline const QString& path() const
141  { return _path;}
142 
143  inline ArnLink* arnLink() const
144  { return _arnLink;}
145 
146  inline bool isLastLink() const
147  { return _isLastLink;}
148 };
149 
150 
151 class ArnEvModeChange : public ArnEvent
152 {
153  QString _path;
154  uint _linkId;
155  Arn::ObjectMode _mode;
156 
157 public:
158  ArnEvModeChange( const QString& path, uint linkId, Arn::ObjectMode mode);
159  static QEvent::Type type();
160  virtual ArnEvent* makeHeapClone();
161 
162  inline const QString& path() const
163  { return _path;}
164 
165  inline uint linkId() const
166  { return _linkId;}
167 
168  inline Arn::ObjectMode mode() const
169  { return _mode;}
170 };
171 
172 
173 class ArnEvMonitor : public ArnEvent
174 {
175  int _monEvType;
176  QByteArray _data;
177  bool _isLocal;
178  void* _sessionHandler;
179 
180 public:
181  ArnEvMonitor( int monEvType, const QByteArray& data, bool isLocal, void* sessionHandler);
182  static QEvent::Type type();
183  virtual ArnEvent* makeHeapClone();
184 
185  inline int monEvType() const
186  { return _monEvType;}
187 
188  inline const QByteArray& data() const
189  { return _data;}
190 
191  inline bool isLocal() const
192  { return _isLocal;}
193 
194  inline void* sessionHandler() const
195  { return _sessionHandler;}
196 };
197 
198 
199 class ArnEvRetired : public ArnEvent
200 {
201  ArnLink* _startLink;
202  bool _isBelow;
203  bool _isGlobal;
204 
205 public:
206  ArnEvRetired( ArnLink* startLink, bool isBelow, bool isGlobal);
207  static QEvent::Type type();
208  virtual ArnEvent* makeHeapClone();
209 
210  inline ArnLink* startLink() const
211  { return _startLink;}
212 
213  inline bool isBelow() const
214  { return _isBelow;}
215 
216  inline bool isGlobal() const
217  { return _isGlobal;}
218 };
219 
220 
221 class ArnEvZeroRef : public ArnEvent
222 {
223  ArnLink* _arnLink;
224 
225 public:
226  ArnEvZeroRef( ArnLink* arnLink);
227  static QEvent::Type type();
228  virtual ArnEvent* makeHeapClone();
229 
230  inline ArnLink* arnLink() const
231  { return _arnLink;}
232 };
233 
234 
236 {
237  int _sendId;
238  const QByteArray* _valueData;
239  const ArnLinkHandle* _handleData;
240 
241 public:
242  ArnEvValueChange( int sendId, const QByteArray* valueData, const ArnLinkHandle& handleData);
243  virtual ~ArnEvValueChange();
244  static QEvent::Type type();
245  virtual ArnEvent* makeHeapClone();
246 
247  inline int sendId() const
248  { return _sendId;}
249 
250  inline const QByteArray* valueData() const
251  { return _valueData;}
252 
253  inline const ArnLinkHandle& handleData() const
254  { return *_handleData;}
255 };
256 
257 
258 class ArnEvAtomicOp : public ArnEvent
259 {
260 public:
261  typedef ArnAtomicOp Op;
262 
263 private:
264  Op _op;
265  QVariant _arg1;
266  QVariant _arg2;
267 
268 public:
269  ArnEvAtomicOp( int op, const QVariant& arg1, const QVariant& arg2);
270  virtual ~ArnEvAtomicOp();
271  static QEvent::Type type();
272  virtual ArnEvent* makeHeapClone();
273 
274  inline const Op& op() const
275  { return _op;}
276 
277  inline const QVariant& arg1() const
278  { return _arg1;}
279 
280  inline const QVariant& arg2() const
281  { return _arg2;}
282 };
283 
284 
285 class ArnEvRefChange : public ArnEvent
286 {
287  int _refStep;
288 
289 public:
290  ArnEvRefChange( int refStep);
291  virtual ~ArnEvRefChange();
292  static QEvent::Type type();
293  virtual ArnEvent* makeHeapClone();
294 
295  inline int refStep() const
296  { return _refStep;}
297 };
298 
299 #endif // ARNEVENT_HPP
virtual ~ArnEvRefChange()
Definition: ArnEvent.cpp:381
static QEvent::Type type()
Definition: ArnEvent.cpp:241
ArnAtomicOp Op
Definition: ArnEvent.hpp:261
const QByteArray * valueData() const
Definition: ArnEvent.hpp:250
#define MQ_DECLARE_ENUM_NSTXT(...)
Definition: MQFlags.hpp:113
const QByteArray & data() const
Definition: ArnEvent.hpp:188
static QEvent::Type type()
Definition: ArnEvent.cpp:313
static QEvent::Type type()
Definition: ArnEvent.cpp:359
#define MQ_NSTXT_FILL_MISSING_FROM(FromNs)
Definition: MQFlags.hpp:53
Max index.
Definition: ArnEvent.hpp:77
virtual ArnEvent * makeHeapClone()
Definition: ArnEvent.cpp:367
const QVariant & arg1() const
Definition: ArnEvent.hpp:277
virtual ArnEvent * makeHeapClone()
Definition: ArnEvent.cpp:221
const QString & path() const
Definition: ArnEvent.hpp:162
bool isGlobal() const
Definition: ArnEvent.hpp:216
static QEvent::Type type()
Definition: ArnEvent.cpp:213
ArnEvMonitor(int monEvType, const QByteArray &data, bool isLocal, void *sessionHandler)
Definition: ArnEvent.cpp:303
ArnEvZeroRef(ArnLink *arnLink)
Definition: ArnEvent.cpp:352
uint linkId() const
Definition: ArnEvent.hpp:165
int refStep() const
Definition: ArnEvent.hpp:295
Arn::ObjectMode mode() const
Definition: ArnEvent.hpp:168
Max index.
Definition: ArnEvent.hpp:62
ArnEvValueChange(int sendId, const QByteArray *valueData, const ArnLinkHandle &handleData)
Definition: ArnEvent.cpp:189
virtual ~ArnEvAtomicOp()
Definition: ArnEvent.cpp:236
virtual ~ArnEvValueChange()
Definition: ArnEvent.cpp:204
const ArnLinkHandle & handleData() const
Definition: ArnEvent.hpp:253
int sendId() const
Definition: ArnEvent.hpp:247
ArnEventIdx Idx
Definition: ArnEvent.hpp:101
ArnLink * startLink() const
Definition: ArnEvent.hpp:210
static QEvent::Type type()
Definition: ArnEvent.cpp:288
void * sessionHandler() const
Definition: ArnEvent.hpp:194
const QVariant & arg2() const
Definition: ArnEvent.hpp:280
ArnEvRefChange(int refStep)
Definition: ArnEvent.cpp:374
static QEvent::Type type()
Definition: ArnEvent.cpp:386
int monEvType() const
Definition: ArnEvent.hpp:185
virtual ArnEvent * makeHeapClone()
Definition: ArnEvent.cpp:321
virtual ArnEvent * makeHeapClone()
Definition: ArnEvent.cpp:345
bool isBelow() const
Definition: ArnEvent.hpp:213
static QEvent::Type type()
Definition: ArnEvent.cpp:337
#define MQ_DECLARE_ENUMTXT(EStruct)
Enums text.
Definition: MQFlags.hpp:102
virtual ArnEvent * makeHeapClone()
Definition: ArnEvent.cpp:394
ArnEvRetired(ArnLink *startLink, bool isBelow, bool isGlobal)
Definition: ArnEvent.cpp:328
virtual ArnEvent * makeHeapClone()
Definition: ArnEvent.cpp:249
#define ARNLIBSHARED_EXPORT
ArnLink * arnLink() const
Definition: ArnEvent.hpp:230
const Op & op() const
Definition: ArnEvent.hpp:274
ArnEvAtomicOp(int op, const QVariant &arg1, const QVariant &arg2)
Definition: ArnEvent.cpp:227
void * target() const
Definition: ArnEvent.hpp:116
bool isLocal() const
Definition: ArnEvent.hpp:191
ArnEvModeChange(const QString &path, uint linkId, Arn::ObjectMode mode)
Definition: ArnEvent.cpp:279
virtual ArnEvent * makeHeapClone()
Definition: ArnEvent.cpp:296