KDELibs4Support

k3resolverworkerbase.cpp
1 /* -*- C++ -*-
2  * Copyright (C) 2003,2004 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 #include "k3resolverworkerbase.h"
26 
27 #include <config-network.h>
28 
29 #include <assert.h>
30 
31 #include <QByteArray>
32 
33 #include "k3resolver.h"
34 #include "k3resolver_p.h"
35 
36 using namespace KNetwork;
37 using namespace KNetwork::Internal;
38 
39 KResolverWorkerBase::KResolverWorkerBase()
40  : th(nullptr), input(nullptr), m_finished(0), m_reserved(0)
41 {
42 }
43 
44 KResolverWorkerBase::~KResolverWorkerBase()
45 {
46 }
47 
49 {
50  if (input) {
51  return input->node;
52  }
53  return QString();
54 }
55 
57 {
58  if (input) {
59  return input->service;
60  }
61  return QString();
62 }
63 
65 {
66  if (input) {
67  return input->flags;
68  }
69  return 0;
70 }
71 
73 {
74  if (input) {
75  return input->familyMask;
76  }
77  return 0;
78 }
79 
81 {
82  if (input) {
83  return input->socktype;
84  }
85  return 0;
86 }
87 
89 {
90  if (input) {
91  return input->protocol;
92  }
93  return 0;
94 }
95 
97 {
98  QByteArray res;
99  if (input) {
100  res = input->protocolName;
101  }
102  return res;
103 }
104 
106 {
107  m_finished = true;
108 }
109 
111 {
112  return true; // no post-processing is a always successful postprocessing
113 }
114 
116 {
117  KResolverManager::manager()->enqueue(res, th->data);
118  return true;
119 }
120 
122 {
123  RequestData *myself = th->data;
124  RequestData *newrequest = new RequestData;
125  newrequest->obj = nullptr;
126  newrequest->input = input; // same input
127  newrequest->requestor = myself;
128  newrequest->nRequests = 0;
129  newrequest->worker = worker;
130  myself->nRequests++;
131  KResolverManager::manager()->dispatch(newrequest);
132  return true;
133 }
134 
136 {
137  assert(th != nullptr);
138  return th->checkResolver();
139 }
140 
142 {
143  assert(th != nullptr);
144  th->acquireResolver();
145 }
146 
148 {
149  assert(th != nullptr);
150  th->releaseResolver();
151 }
152 
154 {
155  KResolverManager::manager()->registerNewWorker(factory);
156 }
157 
QString serviceName() const
And this is the service name.
bool checkResolver()
Checks the resolver subsystem status.
bool enqueue(KResolver *other)
Enqueue the given resolver for post-processing.
int protocol() const
gets the protocol number
Name and service resolution class.
Definition: k3resolver.h:312
void finished()
Call this function to indicate that processing has finished.
int flags() const
gets the flags
A namespace to store all networking-related (socket) classes.
QString nodeName() const
This is the hostname to be looked for.
int familyMask() const
gets the family mask
int socketType() const
gets the socket type
void acquireResolver()
This function has to be called from the resolver workers that require use of the DNS resolver code (i...
virtual bool postprocess()
This function gets called during post processing for this class.
static void registerNewWorker(KResolverWorkerFactoryBase *factory)
Wrapper call to register workers.
void releaseResolver()
This function is the counterpart for acquireResolver() - the worker thread indicates that it&#39;s done w...
QByteArray protocolName() const
gets the protocol name, if applicable
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Aug 7 2020 22:56:37 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.