1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QHOSTINFO_H
5#define QHOSTINFO_H
6
7#include <QtNetwork/qtnetworkglobal.h>
8#include <QtCore/qlist.h>
9#include <QtCore/qscopedpointer.h>
10#include <QtNetwork/qhostaddress.h>
11
12QT_BEGIN_NAMESPACE
13
14
15class QObject;
16class QHostInfoPrivate;
17
18class Q_NETWORK_EXPORT QHostInfo
19{
20 Q_GADGET
21public:
22 enum HostInfoError {
23 NoError,
24 HostNotFound,
25 UnknownError
26 };
27
28 explicit QHostInfo(int lookupId = -1);
29 QHostInfo(const QHostInfo &d);
30 QHostInfo(QHostInfo &&other) noexcept : d_ptr(std::exchange(obj&: other.d_ptr, new_val: nullptr)) {}
31 QHostInfo &operator=(const QHostInfo &d);
32 QHostInfo &operator=(QHostInfo &&other) noexcept { swap(other); return *this; }
33 ~QHostInfo();
34
35 void swap(QHostInfo &other) noexcept { qt_ptr_swap(lhs&: d_ptr, rhs&: other.d_ptr); }
36
37 QString hostName() const;
38 void setHostName(const QString &name);
39
40 QList<QHostAddress> addresses() const;
41 void setAddresses(const QList<QHostAddress> &addresses);
42
43 HostInfoError error() const;
44 void setError(HostInfoError error);
45
46 QString errorString() const;
47 void setErrorString(const QString &errorString);
48
49 void setLookupId(int id);
50 int lookupId() const;
51
52#if QT_NETWORK_REMOVED_SINCE(6, 7)
53 static int lookupHost(const QString &name, QObject *receiver, const char *member);
54#endif
55 static int lookupHost(const QString &name, const QObject *receiver, const char *member);
56 static void abortHostLookup(int lookupId);
57
58 static QHostInfo fromName(const QString &name);
59 static QString localHostName();
60 static QString localDomainName();
61
62#ifdef Q_QDOC
63 template<typename Functor>
64 static int lookupHost(const QString &name, const QObject *context, Functor functor);
65#else
66 // lookupHost to a callable (with context)
67 template <typename Functor>
68 static inline int lookupHost(const QString &name,
69 const typename QtPrivate::ContextTypeForFunctor<Functor>::ContextType *receiver,
70 Functor &&func)
71 {
72 using Prototype = void(*)(QHostInfo);
73 QtPrivate::AssertCompatibleFunctions<Prototype, Functor>();
74 return lookupHostImpl(name, receiver,
75 slotObj: QtPrivate::makeCallableObject<Prototype>(std::forward<Functor>(func)),
76 member: nullptr);
77 }
78#endif // Q_QDOC
79
80#ifndef QT_NO_CONTEXTLESS_CONNECT
81 // lookupHost to a callable (without context)
82 template <typename Functor>
83 static inline int lookupHost(const QString &name, Functor &&slot)
84 {
85 return lookupHost(name, nullptr, std::forward<Functor>(slot));
86 }
87#endif // QT_NO_CONTEXTLESS_CONNECT
88
89private:
90 QHostInfoPrivate *d_ptr;
91 Q_DECLARE_PRIVATE(QHostInfo)
92
93 static int lookupHostImpl(const QString &name,
94 const QObject *receiver,
95 QtPrivate::QSlotObjectBase *slotObj,
96 const char *member);
97
98 friend QHostInfo Q_NETWORK_EXPORT qt_qhostinfo_lookup(const QString &name, QObject *receiver,
99 const char *member, bool *valid, int *id);
100};
101
102Q_DECLARE_SHARED(QHostInfo)
103
104QT_END_NAMESPACE
105
106QT_DECL_METATYPE_EXTERN(QHostInfo, Q_NETWORK_EXPORT)
107
108#endif // QHOSTINFO_H
109

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of qtbase/src/network/kernel/qhostinfo.h