ArnLib  4.0.x
Active Registry Network
ArnLink.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 ARNLINK_HPP
33 #define ARNLINK_HPP
34 
35 #include "ArnInc/ArnLib_global.hpp"
36 #include "ArnInc/ArnLinkHandle.hpp"
37 #include "ArnInc/Arn.hpp"
38 #include "ArnInc/ArnCoreItem.hpp"
39 #include "ArnInc/MQFlags.hpp"
40 #include <QObject>
41 #include <QString>
42 #include <QVariant>
43 #include <QAtomicInt>
44 #include <QMutex>
45 
46 struct ArnLinkValue;
47 class ArnEvent;
48 class ArnLink;
49 
50 typedef QList<ArnLink*> ArnLinkList;
51 typedef QList<ArnCoreItem*> ArnCoreItemList;
52 
53 
55 class ArnLink
56 {
57  friend class ArnM;
58 
59 public:
60  struct RetireType {
61  enum E { // Warning limited number (ArnLink stores in bitfield)
62  None,
63  LeafLocal,
64  LeafGlobal,
65  Tree
66  };
67  MQ_DECLARE_ENUM( RetireType)
68  };
69 
70  ~ArnLink();
71 
72  void setValue( int value, int sendId = 0, bool useUncrossed = false);
73  void setValue( ARNREAL value, int sendId = 0, bool useUncrossed = false);
74  void setValue( const QString& value, int sendId = 0, bool useUncrossed = false,
75  const ArnLinkHandle& handleData = ArnLinkHandle::null());
76  void setValue( const QByteArray& value, int sendId = 0, bool useUncrossed = false,
77  const ArnLinkHandle& handleData = ArnLinkHandle::null());
78  void setValue( const QVariant& value, int sendId = 0, bool useUncrossed = false,
79  const ArnLinkHandle& handleData = ArnLinkHandle::null());
80  void setIgnoredValue( const ArnLinkHandle& handleData = ArnLinkHandle::null());
81 
82  void setBits( int mask, int value, int sendId = 0, bool useUncrossed = false);
83  void addValue( int value, int sendId = 0, bool useUncrossed = false);
84  void addValue( ARNREAL value, int sendId = 0, bool useUncrossed = false);
85 
86  int toInt( bool* isOk = arnNullptr);
87  ARNREAL toReal( bool* isOk = arnNullptr);
88  QString toString( bool* isOk = arnNullptr);
89  QByteArray toByteArray( bool* isOk = arnNullptr);
90  QVariant toVariant( bool* isOk = arnNullptr);
91 
92  Arn::DataType type();
93 
94  QString linkPath( Arn::NameF nameF = Arn::NameF::EmptyOk);
95  QString linkName( Arn::NameF nameF = Arn::NameF());
96  uint linkId() const;
97  bool isFolder();
98 
99  void sendArnEvent( ArnEvent* ev);
100  void addSyncMode( Arn::ObjectSyncMode syncMode);
101  Arn::ObjectSyncMode syncMode();
102  Arn::ObjectMode getMode();
103  bool isBiDirMode();
104  void setPipeMode( bool isPipeMode, bool alsoSetTwin = true);
105  bool isPipeMode();
106  void setSaveMode( bool isSaveMode);
107  bool isSaveMode();
108  void setAtomicOpProvider( bool isProvider);
109  bool isAtomicOpProvider() const;
110  bool isProvider() const;
111  bool isThreaded() const;
112  bool isRetired();
113  uint retireType();
114  ArnLink* twinLink();
115  ArnLink* valueLink();
116  ArnLink* providerLink();
117  ArnLink* holderLink( bool useUncrossed);
118  QString twinName();
119  bool subscribe( ArnCoreItem* subscriber);
120  bool unsubscribe( ArnCoreItem* subscriber);
121  void deref();
122  int refCount();
123  quint32 localUpdateCount();
124 
125  QString objectName() const;
126  ArnLink* parent() const;
127  const ArnLinkList& children() const;
128 
129  QMutex* getMutex() const;
130 
131 
132 protected:
134  ArnLink( ArnLink* parent, const QString& name, Arn::LinkFlags flags);
135  void setupEnd( const QString& path, Arn::ObjectSyncMode syncMode, Arn::LinkFlags flags);
136  void setParent( ArnLink* parent);
137  void doModeChanged();
138  ArnLink* findLink( const QString& name);
139  void ref();
140  void setRefCount( int count);
141  void decZeroRefs();
142  bool isLastZeroRef();
143  void setRetired( RetireType retireType);
144  void doRetired( ArnLink* startLink, bool isGlobal);
145  void setThreaded(); // Only used in main thread
146  void lock();
147  void unlock();
148  static QObject* arnM( QObject* inArnM = arnNullptr);
149 
150  ArnLink* _twin; // Used for bidirectional functionality
151 
152 private:
153  void resetHave();
154  void needInt( bool* isOk = arnNullptr);
155  void needReal( bool* isOk = arnNullptr);
156  void doValueChanged( int sendId, const QByteArray* valueData = arnNullptr,
157  const ArnLinkHandle& handleData = ArnLinkHandle::null());
158  void sendEventsInThread( ArnEvent* ev, const ArnCoreItemList& recipients);
159  void sendEventsDirRoot( ArnEvent* ev, ArnLink* startLink);
160  void sendEventArnM( ArnEvent* ev);
161 
162  // Source for unique id to all ArnLink ..
163  static QAtomicInt _idCount;
164 
165  QMutex* _mutex;
166  ArnLinkValue* _val;
167  ArnCoreItemList* _subscribeTab;
168  ArnLink* _parent;
169  QString _objectName;
170  ArnLinkList* _children;
171 
172  quint32 _id;
173  volatile qint32 _refCount;
174 
175  volatile quint8 _syncMode;
176 
177  volatile quint8 _type;
178  volatile quint8 _zeroRefCount;
179 
180  bool _hasBeenSetup : 1;
181  bool _isFolder : 1;
182  bool _isProvider : 1;
183  bool _isAtomicOpProvider : 1;
184 
185  volatile bool _isPipeMode : 1;
186  volatile bool _isSaveMode : 1;
187 
188  volatile bool _isRetired : 1;
189  volatile uint _retireType : 2;
190 
191  volatile bool _haveInt : 1;
192  volatile bool _haveReal : 1;
193  volatile bool _haveString : 1;
194  volatile bool _haveByteArray : 1;
195  volatile bool _haveVariant : 1;
196 };
198 
199 #endif // ARNLINK_HPP
Data type of an Arn Data Object
Definition: Arn.hpp:74
Arn main class.
Definition: ArnM.hpp:106
Path: "/@/test" ==> "//test", Item: "@" ==> "".
Definition: Arn.hpp:189
Core base class for the inherited ArnItem classes.
Definition: ArnCoreItem.hpp:56
#define ARNREAL
Definition: Arn.hpp:44
#define MQ_DECLARE_ENUM(EStruct)
Enums.
Definition: MQFlagsBase.hpp:70