ArnLib  4.0.x
Active Registry Network
ArnM.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 ARNM_HPP
33 #define ARNM_HPP
34 
35 #include "ArnLib_global.hpp"
36 #include "Arn.hpp"
37 #include "MQFlags.hpp"
38 #include "ArnError.hpp"
39 #include "ArnItem.hpp"
40 #include <QIODevice>
41 #include <QStringList>
42 #include <QVector>
43 #include <QMetaType>
44 #include <QObject>
45 #include <QMutex>
46 #include <QWaitCondition>
47 
48 class ArnThreadComStorage;
49 class QDir;
50 class QTimer;
51 
52 
54 class ArnThreadCom
55 {
56  friend class ArnThreadComCaller;
57  friend class ArnThreadComProxyLock;
58 
59 public:
60  ArnThreadCom() {
61  _retObj = 0;
62  }
63 
65  void* _retObj;
66  QStringList _retStringList;
67 
68 private:
69  static ArnThreadComStorage* getThreadComStorage();
70  static ArnThreadCom* getThreadCom();
71 
72  QWaitCondition _commandEnd;
73  QMutex _mutex;
74 };
75 
76 Q_DECLARE_METATYPE(ArnThreadCom*)
77 
78 
79 class ArnThreadComCaller
80 {
81  ArnThreadCom* _p;
82 public:
83  ArnThreadComCaller();
84  ~ArnThreadComCaller();
85  void waitCommandEnd();
86  ArnThreadCom* p();
87 };
88 
89 
90 class ArnThreadComProxyLock
91 {
92  ArnThreadCom* _p;
93 public:
94  ArnThreadComProxyLock( ArnThreadCom* threadCom);
95  ~ArnThreadComProxyLock();
96 };
98 
99 
101 
106 class ARNLIBSHARED_EXPORT ArnM : public QObject
107 {
108  Q_OBJECT
109  friend class ArnBasicItem;
110 
111 public:
112  static ArnM& instance();
113 
114  static void setConsoleError( bool isConsoleError);
115 
117 
119  static void setDefaultIgnoreSameValue( bool isIgnore = true);
120 
124  static bool defaultIgnoreSameValue();
125 
128  static bool isMainThread();
129 
132  static bool isThreadedApp();
133 
135 
138  static int valueInt( const QString& path);
139 
141 
144  static double valueDouble( const QString& path);
145 
147 
150  static ARNREAL valueReal( const QString& path);
151 
153 
156  static QString valueString( const QString& path);
157 
159 
162  static QByteArray valueByteArray( const QString& path);
163 
165 
168  static QVariant valueVariant( const QString& path);
169 
171 
175  static QStringList items( const QString& path);
176 
180  static bool exist(const QString& path);
181 
185  static bool isFolder( const QString& path);
186 
190  static bool isLeaf( const QString& path);
191 
193 
196  static void setAtomicOpProvider( const QString& path);
197 
202  static bool isAtomicOpProvider( const QString& path);
203 
205 
208  static void setValue( const QString& path, int value);
209 
211 
214  static void setValue( const QString& path, ARNREAL value);
215 
217 
220  static void setValue( const QString& path, const QString& value);
221 
223 
226  static void setValue( const QString& path, const QByteArray& value);
227 
229 
233  static void setValue( const QString& path, const QVariant& value, const char* typeName = arnNullptr);
234 
236 
239  static void setValue( const QString& path, const char* value);
240 
242 
247  static bool loadFromFile( const QString& path, const QString& fileName, Arn::Coding coding);
248 
250 
257  static bool loadFromDirRoot( const QString& path, const QDir& dirRoot, Arn::Coding coding);
258 
260 
265  static bool saveToFile( const QString& path, const QString& fileName, Arn::Coding coding);
266 
267  static void errorLog( QString errText, ArnError err = ArnError::Undef, void* reference = arnNullptr);
268  static QString errorSysName();
269 
271 
273  static QByteArray info();
274 
276 
279  bool skipLocalSysLoading() const;
280 
282 
288  void setSkipLocalSysLoading( bool skipLocalSysLoading);
289 
291 
296  static void destroyLinkLocal( const QString& path)
297  { destroyLink( path, false); }
298 
299 public slots:
301 
308  static void destroyLink( const QString& path, bool isGlobal = true);
309 
310  static void setupErrorlog( QObject* errLog);
311 
312 signals:
313  void errorLogSig( const QString& errText, uint errCode, void* reference);
314 
315 protected:
316 #ifndef DOXYGEN_SKIP
317  virtual void customEvent( QEvent* ev);
318 
319  static ArnLink* root();
320  static ArnLink* link( const QString& path, Arn::LinkFlags flags,
322  static ArnLink* addTwin( const QString& path, ArnLink* child,
324  Arn::LinkFlags flags = Arn::LinkFlags());
325  static void destroyLink( ArnLink* link, bool isGlobal);
326  static void destroyLinkMain( ArnLink* link, ArnLink* startLink, bool isGlobal);
327  static void changeRefCounter( int step);
328 #endif
329 
330 private slots:
331  void postSetup();
332  void onTimerMetrics();
333  static void linkProxy( ArnThreadCom* threadCom, const QString& path,
334  int flagValue, int syncMode = 0);
335  static void itemsProxy( ArnThreadCom* threadCom, const QString& path);
336 
337 private:
339  ArnM();
340  ArnM( const ArnM&);
341  ~ArnM();
342  ArnM& operator=( const ArnM&);
343 
344  static ArnLink* linkMain( const QString& path, Arn::LinkFlags flags,
346  static ArnLink* linkThread( const QString& path, Arn::LinkFlags flags,
348  static ArnLink* linkMain( const QString& path, ArnLink *parent, const QString& name,
350  static ArnLink* addTwinMain( const QString& path, ArnLink* child,
352  Arn::LinkFlags flags = Arn::LinkFlags::fromInt(0));
353  static ArnLink* getRawLink( ArnLink *parent, const QString& name, Arn::LinkFlags flags);
354  static QStringList itemsMain( const ArnLink *parent);
355  static QStringList itemsMain( const QString& path);
356 
357  static void doZeroRefLink( ArnLink* link);
358 
359  // The root object of all other arn data
360  ArnLink* _root;
361 
362  QVector<QString> _errTextTab;
363  bool _consoleError;
364  bool _defaultIgnoreSameValue;
365  bool _skipLocalSysLoading;
366  QObject* _errorLogger;
367 
368  volatile bool _isThreadedApp;
369  QThread* _mainThread;
370 
371  static int _countFolder;
372  static int _countLeaf;
373  static QAtomicInt _countRef;
374  ArnLink* _countFolderLink;
375  ArnLink* _countLeafLink;
376  ArnLink* _countRefLink;
377  QTimer* _timerMetrics;
378 };
379 
380 #endif // ARNM_HPP
381 
void destroyLink(bool isGlobal=true)
Destroy the Arn Data Object
void setValue(const ArnBasicItem &other, int ignoreSame=Arn::SameValue::DefaultAction)
Arn main class.
Definition: ArnM.hpp:106
Arn::ObjectSyncMode syncMode() const
bool isAtomicOpProvider() const
void setAtomicOpProvider()
Set this Arn Data Object as Atomic Operator Provider
void * reference() const
Get the stored external reference.
static void destroyLinkLocal(const QString &path)
Destroy the local Arn Data Object at path
Definition: ArnM.hpp:296
QString path(Arn::NameF nameF=Arn::NameF::EmptyOk) const
Path of the Arn Data Object
#define ARNREAL
Definition: Arn.hpp:44
bool isFolder() const
#define ARNLIBSHARED_EXPORT
QString name(Arn::NameF nameF) const
Name of the Arn Data Object
ArnBasicItem & operator=(const ArnBasicItem &other)
Base class handle for an Arn Data Object.