lookuphost.h
1 //------------------------------------------------------------------------------
2 // lookuphost.h
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2015 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #ifndef id98fdc6b8_d51c_4a3b_a61e_91ddc4105daf
24 #define id98fdc6b8_d51c_4a3b_a61e_91ddc4105daf
25 
26 #include "dptr.h"
27 
28 #include <QObject>
29 #include <QString>
30 #include <QThread>
31 
32 class QHostInfo;
33 
61 class LookupHost : public QObject
62 {
63 Q_OBJECT
64 
65 friend class LookupHostAborter;
66 friend class LookupHostWorker;
67 
68 public:
69  static void finalizeAndJoin();
70  static void lookupHost(const QString &name, QObject *receiver, const char *receiverSlot);
71 
72 private:
74 
75  static LookupHost *instance();
76  static LookupHost *inst;
77 
78  LookupHost();
79  virtual ~LookupHost();
80 
81  void finalizeAndJoin_();
82  void lookupHost_(const QString &name, QObject *receiver, const char *receiverSlot);
83 
84 private slots:
85  void derefWorkCounter();
86 };
87 
88 class LookupHostWorker : public QObject
89 {
90 Q_OBJECT
91 
92 public:
93  LookupHostWorker(const QString &hostName);
94 
95 signals:
96  void hostFound(const QHostInfo &);
97 
98 public slots:
99  void work();
100 
101 private:
102  QString hostName;
103 
104 private slots:
105  void hostFoundReceived(const QHostInfo&);
106 };
107 
108 
109 class LookupHostConsumerThread : public QThread
110 {
111 Q_OBJECT
112 
113 public:
114  void run();
115 };
116 
117 #endif