OpendTect  6.6
networkcommon.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: A. Huck
8  Date: November 2019
9  RCS: $Id$
10 ________________________________________________________________________
11 
12 -*/
13 
14 #include "networkmod.h"
15 
16 #include "bufstring.h"
17 #include "notify.h"
18 #include "uistring.h"
19 
20 mFDQtclass(QString)
21 mFDQtclass(QHostAddress)
22 
23 class CommandLineParser;
24 class uiRetVal;
25 namespace OS { class MachineCommand; }
26 
27 
28 namespace Network
29 {
30 
31 class Socket;
32 
34 
35 
37  int maxportstotry=100);
39 
41 mGlobal(Network) bool isPortFree(PortNr_Type port,uiString* errmsg=nullptr);
43 
44 
45 /*\brief
46  Network authority, containing all necessary information to connect
47  to a local or remote host if that one has a listening socket
48  authority = [ userinfo "@" ] host [ ":" port ]
49 
50  See RFC 3986 for more details:
51  https://www.rfc-editor.org/rfc/rfc3986.html#section-3.2
52 
53 */
54 
57 public:
58  explicit Authority(const BufferString& servernm);
59  Authority(const char* host=nullptr,
60  PortNr_Type=0,bool resolveipv6=false);
63 
65  bool operator==(const Authority&) const;
66 
67  bool isOK() const;
68 
69  bool isLocal() const { return !servernm_.isEmpty(); }
72 
74  BufferString getUserInfo() const { return userinfo_; }
76  PortNr_Type getPort() const { return port_; }
77  bool addressIsValid() const;
78  bool isUsable() const;
79  //<! Also checks if already in use
80  bool portIsFree(uiString* errmsg =nullptr) const;
81 
82  void fromString(const char*,bool resolveipv6=false);
83  Authority& localFromString(const char*);
84  Authority& setUserInfo(const char*);
85  Authority& setHost(const char*,bool resolveipv6=false);
88 
90  const char* defservnm=nullptr,
91  const char* defhostnm=nullptr,
92  PortNr_Type defport=0);
93 
95  const char* ky=nullptr) const;
96 
97  static BufferString getAppServerName(const char* nm=nullptr);
98 
99 private:
100  void setHostAddress(const char*,bool resolveipv6=false);
101 
104 
106  mQtclass(QHostAddress)& qhostaddr_;
107  mQtclass(QString)& qhost_;
108 
110 
111  bool hasAssignedPort() const { return port_ > 0; }
112 
113 
114  friend class Socket;
115 
116 };
117 
118 
119 } // namespace Network
Network::Authority::servernm_
BufferString servernm_
Definition: networkcommon.h:109
Network::Authority::addressIsValid
bool addressIsValid() const
uistring.h
Network::Authority::getHost
BufferString getHost() const
Network::Authority::Authority
Authority(const char *host=nullptr, PortNr_Type=0, bool resolveipv6=false)
mGlobal
#define mGlobal(module)
Definition: commondefs.h:180
notify.h
Network::getUsablePort
PortNr_Type getUsablePort(uiRetVal &, PortNr_Type firstport=0, int maxportstotry=100)
Returns 0 if none found.
Network::Authority::Authority
Authority(const Authority &)
Network::Authority::mQtclass
mQtclass(QString) &qhost_
Network::Authority::fromString
void fromString(const char *, bool resolveipv6=false)
Network::getNextCandidatePort
PortNr_Type getNextCandidatePort()
Network::Authority::setPort
Authority & setPort(PortNr_Type)
Network::Authority::setUserInfo
Authority & setUserInfo(const char *)
Network::Authority::setFrom
Authority & setFrom(const CommandLineParser &, const char *defservnm=nullptr, const char *defhostnm=nullptr, PortNr_Type defport=0)
Network::Authority::~Authority
~Authority()
Network::IPv4
@ IPv4
Definition: networkcommon.h:33
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
Network::Authority::mODTextTranslationClass
mODTextTranslationClass(Authority)
Network
Definition: jobcommunic.h:22
Network::Authority
Definition: networkcommon.h:56
uiRetVal
Definition: uistringset.h:105
Network::LocalIPv6
@ LocalIPv6
Definition: networkcommon.h:33
mFDQtclass
mFDQtclass(QString) mFDQtclass(QHostAddress) class CommandLineParser
CommandLineParser
Definition: commandlineparser.h:53
Network::Authority::getServerName
BufferString getServerName() const
bufstring.h
Network::Authority::isLocal
bool isLocal() const
Definition: networkcommon.h:69
Network::LocalIPv4
@ LocalIPv4
Definition: networkcommon.h:33
Network::Authority::setFreePort
void setFreePort(uiRetVal &)
Network::Authority::localFromString
Authority & localFromString(const char *)
Network::Authority::setHostAddress
void setHostAddress(const char *, bool resolveipv6=false)
Network::Authority::userinfo_
BufferString userinfo_
Definition: networkcommon.h:102
Network::Authority::toString
BufferString toString() const
Network::Authority::isOK
bool isOK() const
Network::Authority::Authority
Authority(const BufferString &servernm)
Network::SpecAddr
SpecAddr
Definition: networkcommon.h:33
Network::Authority::port_
PortNr_Type port_
Definition: networkcommon.h:103
OS
Definition: od_stream.h:23
Network::Authority::hasAssignedPort
bool hasAssignedPort() const
Definition: networkcommon.h:111
Network::Authority::getUserInfo
BufferString getUserInfo() const
Definition: networkcommon.h:74
Network::Any
@ Any
Definition: networkcommon.h:33
BufferString
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size.
Definition: bufstring.h:40
Network::Authority::isUsable
bool isUsable() const
Network::None
@ None
Definition: networkcommon.h:33
Network::Authority::mQtclass
mQtclass(QHostAddress) &qhostaddr_
Network::Authority::hostisaddress_
bool hostisaddress_
Definition: networkcommon.h:105
uiString
String that is able to hold international (UTF-8) strings for the user interface.
Definition: uistring.h:121
Network::Authority::getAppServerName
static BufferString getAppServerName(const char *nm=nullptr)
Network::Authority::portIsFree
bool portIsFree(uiString *errmsg=nullptr) const
OS::MachineCommand
Encapsulates an actual command to execute + the machine to run it on.
Definition: oscommand.h:94
Network::isPortFree
bool isPortFree(PortNr_Type port, uiString *errmsg=nullptr)
Network::Authority::addTo
void addTo(OS::MachineCommand &, const char *ky=nullptr) const
Network::Authority::setHost
Authority & setHost(const char *, bool resolveipv6=false)
Network::Broadcast
@ Broadcast
Definition: networkcommon.h:33
Network::Authority::operator==
bool operator==(const Authority &) const
Network::Authority::operator=
Authority & operator=(const Authority &)
Network::IPv6
@ IPv6
Definition: networkcommon.h:33
Network::Authority::getPort
PortNr_Type getPort() const
Definition: networkcommon.h:76
PortNr_Type
unsigned short PortNr_Type
Definition: commontypes.h:37
Network::Authority::serverAddress
SpecAddr serverAddress() const

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B.V. 1995-2021