KDELibs4Support

k3resolverworkerbase.h
1 /* -*- C++ -*-
2  * Copyright (C) 2003-2005 Thiago Macieira <[email protected]>
3  *
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining
6  * a copy of this software and associated documentation files (the
7  * "Software"), to deal in the Software without restriction, including
8  * without limitation the rights to use, copy, modify, merge, publish,
9  * distribute, sublicense, and/or sell copies of the Software, and to
10  * permit persons to whom the Software is furnished to do so, subject to
11  * the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 #ifndef KRESOLVERWORKERBASE_H
26 #define KRESOLVERWORKERBASE_H
27 
28 #include "k3resolver.h"
29 
30 // forward declarations
31 class QString;
32 template <class T> class QValueList;
33 
34 namespace KNetwork
35 {
36 
37 namespace Internal
38 {
39 class KResolverThread;
40 struct InputData;
41 }
42 
66 {
67 public:
68 
76  {
77  public:
82  : parent(parent)
83  {
84  parent->acquireResolver();
85  }
86 
91  {
92  parent->releaseResolver();
93  }
94 
100  void openClose()
101  {
102  parent->releaseResolver();
103  parent->acquireResolver();
104  }
105 
106  private:
108  KResolverWorkerBase *parent;
109  };
110 private:
111  // this will be like our d pointer
112  KNetwork::Internal::KResolverThread *th;
113  const KNetwork::Internal::InputData *input;
114  friend class KNetwork::Internal::KResolverThread;
115  friend class KNetwork::Internal::KResolverManager;
117 
118  int m_finished : 1;
119  int m_reserved : 31; // reserved
120 
121 public:
130 
131 public:
132  // default constructor
134 
135  // virtual destructor
136  virtual ~KResolverWorkerBase();
137 
141  QString nodeName() const;
142 
146  QString serviceName() const;
147 
151  int flags() const;
152 
156  int familyMask() const;
157 
161  int socketType() const;
162 
166  int protocol() const;
167 
171  QByteArray protocolName() const;
172 
179  void finished();
180 
181 protected:
182  // like a QThread
195  virtual bool run() = 0;
196 
216  virtual bool preprocess() = 0;
217 
226  virtual bool postprocess();
227 
231  inline void setError(int errorcode, int syserror = 0)
232  {
233  results.setError(errorcode, syserror);
234  }
235 
251  bool enqueue(KResolver *other);
252 
256  bool enqueue(KResolverWorkerBase *worker);
257 
264  bool checkResolver();
265 
275  void acquireResolver();
276 
281  void releaseResolver();
282 
283 };
284 
295 {
296 public:
297  virtual ~KResolverWorkerFactoryBase() {}
298  virtual KResolverWorkerBase *create() const = 0;
304  static void registerNewWorker(KResolverWorkerFactoryBase *factory);
305 };
306 
316 template<class Worker>
318 {
319 public:
320  KResolverWorkerBase *create() const override
321  {
322  return new Worker;
323  }
324 };
325 
326 } // namespace KNetwork
327 
328 #endif
Name and service resolution class.
Definition: k3resolver.h:312
KResolverResults results
Derived classes will put their resolved data in this list, or will leave it empty in case of error...
Helper class for locking the resolver subsystem.
Name and service resolution results.
Definition: k3resolver.h:212
void setError(int errorcode, int syserror=0)
Sets the error.
A namespace to store all networking-related (socket) classes.
ResolverLocker(KResolverWorkerBase *parent)
Constructor.
void openClose()
Releases the lock and then reacquires it.
void acquireResolver()
This function has to be called from the resolver workers that require use of the DNS resolver code (i...
void setError(int errorcode, int systemerror=0)
Sets the error codes.
Definition: k3resolver.cpp:239
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 14 2020 22:58:18 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.