ArnLib  4.0.x
Active Registry Network
ArnClient.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 ARNCLIENT_HPP
33 #define ARNCLIENT_HPP
34 
35 #include "ArnLib_global.hpp"
36 #include "ArnM.hpp"
37 #include "XStringMap.hpp"
38 #include "MQFlags.hpp"
39 #include <QObject>
40 #include <QAbstractSocket>
41 #include <QStringList>
42 #include <QList>
43 
44 class ArnClientPrivate;
45 class ArnItemNet;
46 class ArnItemNetEar;
47 
48 
50  Q_GADGET
51  Q_ENUMS(E)
52 public:
53  enum E {
55  Init = 0,
70  };
72 
73  enum NS {NsEnum, NsHuman};
75  { NsHuman, Init, "Initialized" },
76  { NsHuman, Error, "Connect error" },
78  )
79 };
80 
81 
83 
104 class ARNLIBSHARED_EXPORT ArnClient : public QObject
105 {
106  Q_OBJECT
107  Q_DECLARE_PRIVATE(ArnClient)
108 
109 public:
112 
113  struct HostAddrPort {
114  QString addr;
115  quint16 port;
116 
118  port = Arn::defaultTcpPort;
119  }
120  };
121  typedef QList<HostAddrPort> HostList;
122 
123  explicit ArnClient(QObject *parent = arnNullptr);
124  ~ArnClient();
125 
127 
131  void clearArnList( int prioFilter = -1);
132 
134 
138  HostList arnList( int prioFilter = -1) const;
139 
141 
148  void addToArnList( const QString& arnHost, quint16 port = 0, int prio = 0);
149 
151 
155  void connectToArnList();
156 
158 
163  void connectToArn( const QString& arnHost, quint16 port = 0);
164 
166 
176  void disconnectFromArn();
177 
179 
192  void loginToArn( const QString& userName, const QString& password,
193  Arn::Allow allow = Arn::Allow::All);
194 
196 
206  void loginToArnHashed( const QString& userName, const QString& passwordHashed,
207  Arn::Allow allow = Arn::Allow::All);
208 
210 
220  void close();
221 
223 
231  bool setMountPoint( const QString& path);
232 
234 
247  bool addMountPoint( const QString& localPath, const QString& remotePath = QString());
248 
250 
258  bool removeMountPoint( const QString& localPath);
259 
261 
263  ConnectStat connectStatus() const;
264 
266 
274  void setAutoConnect( bool isAuto, int retryTime = 2);
275 
277 
286  void registerClient( const QString& id);
287 
289 
293  static ArnClient* getClient( const QString& id);
294 
296 
299  QString id() const;
300 
302 
305  int receiveTimeout() const;
306 
308 
318  void setReceiveTimeout( int receiveTimeout);
319 
321 
325  bool isDemandLogin() const;
326 
328 
332  void setDemandLogin( bool isDemandLogin);
333 
335 
340  SyncMode syncMode() const;
341 
343 
348  void setSyncMode( SyncMode syncMode);
349 
351 
354  static QString passwordHash( const QString& password);
355 
357 
366  QStringList freePaths() const;
367 
369 
383  void setWhoIAm( const Arn::XStringMap& whoIAmXsm);
384 
386 
390  Arn::XStringMap remoteWhoIAm() const;
391 
393 
401  bool isReContact() const;
402 
404 
412  bool isReConnect() const;
413 
415 
420  void chatSend( const QString& text, int prioType);
421 
423 
428  void abortKillRequest();
429 
431 
435  bool getTraffic( quint64& in, quint64& out) const;
436 
438  int curPrio() const;
439 
440  void commandGet( const QString& path);
441  void commandSet( const QString& path, const QString& data);
442  void commandLs( const QString& path);
443  void commandInfo( int type, const QByteArray& data = QByteArray());
444  void commandVersion();
445  bool getLocalRemotePath( const QString& path,
446  QString& localMountPath, QString& remoteMountPath);
447  ArnItemNet* newNetItem( const QString& path,
449  bool* isNewPtr = arnNullptr);
451 
452 signals:
454 
457  void tcpError( const QString& errorText, QAbstractSocket::SocketError socketError);
458 
460 
463  void tcpConnected( const QString& arnHost, quint16 port);
464 
466  void tcpDisConnected();
467 
469 
473  void connectionStatusChanged( int status, int curPrio);
474 
476 
486  void loginRequired( int contextCode);
487 
489 
493  void killRequested();
494 
496 
500  void chatReceived( const QString& text, int prioType);
501 
503  void replyRecord( Arn::XStringMap& replyMap);
504  void replyGet( const QString& data, const QString& path);
505  void replyLs( const QStringList& subItems, const QString& path);
506  void replyInfo( int type, const QByteArray& data);
507  void replyVer( const QString& version);
508 
509 protected:
510  ArnClient( ArnClientPrivate& dd, QObject* parent);
511  ArnClientPrivate* const d_ptr;
513 
514 private slots:
515  void newNetItemProxy( ArnThreadCom* threadCom,
516  const QString& path, int syncMode = 0, void* isNewPtr = arnNullptr);
517  void createNewItem( const QString& path);
518  void doCreateArnTree( const QString& path);
519  void doDestroyArnTree( const QString& path, bool isGlobal);
520  void doReplyRecord( Arn::XStringMap& replyMap);
521  void doLoginRequired( int contextCode);
522  void onConnectWaitDone();
523  void doTcpConnected();
524  void doTcpError( QAbstractSocket::SocketError socketError);
525  void doTcpError( int socketError);
526  void doTcpDisconnected();
527  void doSyncStateChanged( int state);
528  void doRecNotified();
529  void doRecTimeout();
530  void onCommandDelete( const QString& remotePath);
531  void onMessageReceived( int type, const QByteArray& data);
532 
533 private:
534  struct MountPointSlot {
535  ArnItemNetEar* arnMountPoint;
536  QString localPath;
537  QString remotePath;
538 
539  MountPointSlot()
540  {
541  arnMountPoint = arnNullptr;
542  }
543  };
544 
545  void init();
546  void startConnectArn();
547  void reConnectArn();
548  void doConnectArnLogic();
549  static QString toRemotePathCB( void* context, const QString& path);
550 
551  QStringList makeItemList( Arn::XStringMap& xsMap);
552 
554  bool addMountPointNL( const QString& localPath, const QString& remotePath);
555  bool removeMountPointNL( const QString& localPath);
556 };
557 
558 #endif // ARNCLIENT_HPP
No data flow within set timeout (still connected)
Definition: ArnClient.hpp:63
Unsuccessfull when trying to connect to an Arn host.
Definition: ArnClient.hpp:65
Successfully connected to an Arn host.
Definition: ArnClient.hpp:61
#define MQ_DECLARE_ENUM_NSTXT(...)
Definition: MQFlags.hpp:113
#define MQ_NSTXT_FILL_MISSING_FROM(FromNs)
Definition: MQFlags.hpp:53
QList< HostAddrPort > HostList
Definition: ArnClient.hpp:121
Unsuccessfully tried to connect to all hosts in the Arn connection List.
Definition: ArnClient.hpp:69
Container class with string representation for serialized data.
Definition: XStringMap.hpp:107
TCP connection is broken (has been successfull)
Definition: ArnClient.hpp:67
The Client session Sync mode at connect & reconnect.
Definition: Arn.hpp:155
const quint16 defaultTcpPort
Definition: Arn.hpp:50
Negotiating terms and compatibility with an Arn host.
Definition: ArnClient.hpp:59
Convenience, allow all.
Definition: Arn.hpp:226
Class for connecting to an Arn Server.
Definition: ArnClient.hpp:104
Trying to connect to an Arn host.
Definition: ArnClient.hpp:57
Arn::ClientSyncMode SyncMode
Definition: ArnClient.hpp:111
ArnClientConnectStat ConnectStat
Definition: ArnClient.hpp:110
Initialized, not yet any result of trying to connect ...
Definition: ArnClient.hpp:55
#define MQ_DECLARE_ENUMTXT(EStruct)
Enums text.
Definition: MQFlags.hpp:102
#define ARNLIBSHARED_EXPORT