ArnLib  4.0.x
Active Registry Network
ArnAdaptItem.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 ARNADAPTITEM_HPP
33 #define ARNADAPTITEM_HPP
34 
35 #include "ArnLib_global.hpp"
36 #include "Arn.hpp"
37 #include "ArnBasicItem.hpp"
38 #include "ArnEvent.hpp"
39 #include "ArnCompat.hpp"
40 #include "MQFlags.hpp"
41 #include <QString>
42 #include <QByteArray>
43 #include <QVariant>
44 
45 class ArnAdaptItem;
46 class ArnAdaptItemPrivate;
47 
49 
134 {
135  Q_DECLARE_PRIVATE(ArnAdaptItem)
136 
137 public:
138  typedef void (*ChangedCB)( ArnAdaptItem& target, const QByteArray& value);
139  typedef void (*LinkDestroyedCB)( ArnAdaptItem& target);
140  typedef void (*ArnEventCB)( QEvent* ev, int arnEvIdx);
141 
143 
145  ArnAdaptItem();
146 
147  virtual ~ArnAdaptItem();
148 
150 
153  bool open( const QString& path);
154 
156  void close();
157 
159 
165  void destroyLink( bool isGlobal = true);
166 
168 
173  { destroyLink( false);}
174 
176 
178  bool isOpen() const;
179 
181 
184  QString path( Arn::NameF nameF = Arn::NameF::EmptyOk) const;
185 
187 
190  QString name( Arn::NameF nameF) const;
191 
193 
200  void setReference( void* reference);
201 
203 
206  void* reference() const;
207 
209 
214  uint itemId() const;
215 
217 
223  uint linkId() const;
224 
226 
228  int refCount() const;
229 
232  bool isFolder() const;
233 
238  bool isProvider() const;
239 
241 
243  Arn::DataType type() const;
244 
246 
248  void setIgnoreSameValue( bool isIgnore = true);
249 
253  bool isIgnoreSameValue() const;
254 
256 
264  void addMode( Arn::ObjectMode mode);
265 
270  Arn::ObjectMode getMode() const;
271 
276 
278 
283 
289  bool isBiDirMode() const;
290 
292 
297 
303  bool isPipeMode() const;
304 
306 
312 
318  bool isSaveMode() const;
319 
321 
326 
331  bool isMaster() const;
332 
334 
338 
342  bool isAutoDestroy() const;
343 
345 
352  void arnImport( const QByteArray& data, int ignoreSame = Arn::SameValue::DefaultAction);
353 
357  QByteArray arnExport() const;
358 
363  int toInt( bool* isOk = arnNullptr) const;
364 
369  double toDouble( bool* isOk = arnNullptr) const;
370 
375  ARNREAL toReal( bool* isOk = arnNullptr) const;
376 
381  QString toString( bool* isOk = arnNullptr) const;
382 
387  QByteArray toByteArray( bool* isOk = arnNullptr) const;
388 
393  QVariant toVariant( bool* isOk = arnNullptr) const;
394 
400  bool toBool( bool* isOk = arnNullptr) const;
401 
407  uint toUInt( bool* isOk = arnNullptr) const;
408 
414  qint64 toInt64( bool* isOk = arnNullptr) const;
415 
421  quint64 toUInt64( bool* isOk = arnNullptr) const;
422 
423  ArnAdaptItem& operator=( const ArnAdaptItem& other);
424  ArnAdaptItem& operator=( int val);
426  ArnAdaptItem& operator=( const QString& val);
427  ArnAdaptItem& operator=( const QByteArray& val);
428  ArnAdaptItem& operator=( const QVariant& val);
429  ArnAdaptItem& operator=( const char* val);
430  ArnAdaptItem& operator=( uint val);
431  ArnAdaptItem& operator=( qint64 val);
432  ArnAdaptItem& operator=( quint64 val);
433 
434  ArnAdaptItem& operator+=( int val);
436 
437  void setValue( const ArnAdaptItem& other, int ignoreSame = Arn::SameValue::DefaultAction);
438 
440 
444  void setValue( int value, int ignoreSame = Arn::SameValue::DefaultAction);
445 
447 
451  void setValue( ARNREAL value, int ignoreSame = Arn::SameValue::DefaultAction);
452 
454 
458  void setValue( bool value, int ignoreSame = Arn::SameValue::DefaultAction);
459 
461 
465  void setValue( const QString& value, int ignoreSame = Arn::SameValue::DefaultAction);
466 
468 
472  void setValue( const QByteArray& value, int ignoreSame = Arn::SameValue::DefaultAction);
473 
475 
479  void setValue( const QVariant& value, int ignoreSame = Arn::SameValue::DefaultAction);
480 
482 
486  void setValue( const char* value, int ignoreSame = Arn::SameValue::DefaultAction);
487 
489 
494  void setValue( uint value, int ignoreSame = Arn::SameValue::DefaultAction);
495 
497 
502  void setValue( qint64 value, int ignoreSame = Arn::SameValue::DefaultAction);
503 
505 
510  void setValue( quint64 value, int ignoreSame = Arn::SameValue::DefaultAction);
511 
513 
521  void setBits( int mask, int value, int ignoreSame = Arn::SameValue::DefaultAction);
522 
524 
529  void addValue( int value);
530 
532 
537  void addValue( ARNREAL value);
538 
540 
545  ARN_RecursiveMutex& mutex() const;
546 
548 
552  QThread* thread() const;
553 
555 
562  void setChangedCallback( ChangedCB changedCB);
563 
565 
569  ChangedCB ChangedCallback() const;
570 
572 
579  void setLinkDestroyedCallback( LinkDestroyedCB linkDestroyedCB);
580 
582 
586  LinkDestroyedCB linkDestroyedCallback() const;
587 
589 
595  void setArnEventCallback( ArnEventCB evCB);
596 
598 
602  ArnEventCB arnEventCallback() const;
603 
605 
612  void setUncrossed( bool isUncrossed = true);
613 
615 
621  bool isUncrossed() const;
622 
624  bool sendArnEventLink( ArnEvent* ev);
625  void sendArnEventItem( ArnEvent* ev, bool isAlienThread, bool isLocked = false);
626 
627 protected:
628  virtual void arnEvent( QEvent* ev, bool isAlienThread);
629 
631  void errorLog( const QString& errText, ArnError err = ArnError::Undef, void* reference = arnNullptr) const;
632 
633  ArnAdaptItem( ArnAdaptItemPrivate& dd);
635 
636 private:
637  void init();
638 
640  void setValue( const QByteArray& value, int ignoreSame, ArnLinkHandle& handleData);
641  void arnImport( const QByteArray& data, int ignoreSame, ArnLinkHandle& handleData);
644  using ArnBasicItem::openWithFlags;
645  using ArnBasicItem::getMode;
646  using ArnBasicItem::addSyncMode;
647  using ArnBasicItem::resetOnlyEcho;
648  using ArnBasicItem::addIsOnlyEcho;
649  using ArnBasicItem::isOnlyEcho;
650  using ArnBasicItem::retireType;
651  using ArnBasicItem::childItemsMain;
652 };
653 
654 #endif // ARNADAPTITEM_HPP
Data type of an Arn Data Object
Definition: Arn.hpp:74
bool isUncrossed() const
Get the Uncrossed state of an object.
QString toString(bool *isOk=arnNullptr) const
void destroyLink(bool isGlobal=true)
Destroy the Arn Data Object
QThread * thread() const
Get the thread affinity of this ArnBasicItem.
void setValue(const ArnBasicItem &other, int ignoreSame=Arn::SameValue::DefaultAction)
ArnBasicItem & setPipeMode()
Set general mode as Pipe for this Arn Data Object
quint64 toUInt64(bool *isOk=arnNullptr) const
bool isMaster() const
void destroyLinkLocal()
Destroy the local Arn Data Object
Arn::ObjectSyncMode syncMode() const
bool toBool(bool *isOk=arnNullptr) const
Path: "/@/test" ==> "//test", Item: "@" ==> "".
Definition: Arn.hpp:189
void close()
Close the handle.
bool open(const QString &path)
Open a handle to an Arn Data Object
void setReference(void *reference)
Set an associated external reference.
ArnBasicItem & setSaveMode()
Set general mode as Save for this Arn Data Object
int refCount() const
Get the number of refs to this Arn Data Object
uint toUInt(bool *isOk=arnNullptr) const
! Non Qt and threadsafe handle for an Arn Data Object.
void setIgnoreSameValue(bool isIgnore=true)
Set skipping of equal value.
void setUncrossed(bool isUncrossed=true)
Set a Bidirectional item as Uncrossed.
Arn::ObjectMode getMode() const
Use with care, link must be "referenced" before use, otherwise it might have been deleted...
int toInt(bool *isOk=arnNullptr) const
uint itemId() const
Get the id for this ArnItem.
bool isIgnoreSameValue() const
ARNREAL toReal(bool *isOk=arnNullptr) const
QByteArray toByteArray(bool *isOk=arnNullptr) const
void addValue(int value)
AtomicOp adds an integer to an Arn Data Object
void * reference() const
Get the stored external reference.
void setBits(int mask, int value, int ignoreSame=Arn::SameValue::DefaultAction)
AtomicOp assign an integer to specified bits in an Arn Data Object
void arnImport(const QByteArray &data, int ignoreSame=Arn::SameValue::DefaultAction)
Import data to an Arn Data Object
#define ARN_RecursiveMutex
Definition: ArnCompat.hpp:73
Assigning same value gives default action set in ArnM or ArnItem.
Definition: Arn.hpp:68
ArnBasicItem & operator+=(int val)
QVariant toVariant(bool *isOk=arnNullptr) const
bool isOpen() const
State of the handle.
QString path(Arn::NameF nameF=Arn::NameF::EmptyOk) const
Path of the Arn Data Object
ArnBasicItem & setBiDirMode()
Set general mode as Bidirectional for this Arn Data Object
void addMode(Arn::ObjectMode mode)
Add general mode settings for this Arn Data Object
Arn::DataType type() const
The type stored in the Arn Data Object
#define ARNREAL
Definition: Arn.hpp:44
bool isAutoDestroy() const
ArnBasicItem & setAutoDestroy()
Set client session sync mode as AutoDestroy for this ArnItem.
double toDouble(bool *isOk=arnNullptr) const
bool isFolder() const
uint linkId() const
Get the id for this Arn Data Object
qint64 toInt64(bool *isOk=arnNullptr) const
bool isSaveMode() const
bool isBiDirMode() const
#define ARNLIBSHARED_EXPORT
QString name(Arn::NameF nameF) const
Name of the Arn Data Object
QByteArray arnExport() const
ArnBasicItem & setMaster()
Set client session sync mode as Master for this ArnItem.
ArnBasicItem & operator=(const ArnBasicItem &other)
QObject * eventHandler() const
Get the event handler of this ArnBasicItem.
bool isProvider() const
void setEventHandler(QObject *eventHandler)
Set event handler for this ArnBasicItem.
bool isPipeMode() const
Base class handle for an Arn Data Object.