File indexing completed on 2023-09-24 04:04:39
0001 /* -*- C++ -*- 0002 * Copyright (C) 2003,2004 Thiago Macieira <thiago@kde.org> 0003 * 0004 * 0005 * Permission is hereby granted, free of charge, to any person obtaining 0006 * a copy of this software and associated documentation files (the 0007 * "Software"), to deal in the Software without restriction, including 0008 * without limitation the rights to use, copy, modify, merge, publish, 0009 * distribute, sublicense, and/or sell copies of the Software, and to 0010 * permit persons to whom the Software is furnished to do so, subject to 0011 * the following conditions: 0012 * 0013 * The above copyright notice and this permission notice shall be included 0014 * in all copies or substantial portions of the Software. 0015 * 0016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 0017 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 0018 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 0019 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 0020 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 0021 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 0022 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 0023 */ 0024 0025 #include "k3resolverworkerbase.h" 0026 0027 #include <config-network.h> 0028 0029 #include <assert.h> 0030 0031 #include <QByteArray> 0032 0033 #include "k3resolver_p.h" 0034 0035 using namespace KNetwork; 0036 using namespace KNetwork::Internal; 0037 0038 KResolverWorkerBase::KResolverWorkerBase() 0039 : th(nullptr), input(nullptr), m_finished(0), m_reserved(0) 0040 { 0041 } 0042 0043 KResolverWorkerBase::~KResolverWorkerBase() 0044 { 0045 } 0046 0047 QString KResolverWorkerBase::nodeName() const 0048 { 0049 if (input) { 0050 return input->node; 0051 } 0052 return QString(); 0053 } 0054 0055 QString KResolverWorkerBase::serviceName() const 0056 { 0057 if (input) { 0058 return input->service; 0059 } 0060 return QString(); 0061 } 0062 0063 int KResolverWorkerBase::flags() const 0064 { 0065 if (input) { 0066 return input->flags; 0067 } 0068 return 0; 0069 } 0070 0071 int KResolverWorkerBase::familyMask() const 0072 { 0073 if (input) { 0074 return input->familyMask; 0075 } 0076 return 0; 0077 } 0078 0079 int KResolverWorkerBase::socketType() const 0080 { 0081 if (input) { 0082 return input->socktype; 0083 } 0084 return 0; 0085 } 0086 0087 int KResolverWorkerBase::protocol() const 0088 { 0089 if (input) { 0090 return input->protocol; 0091 } 0092 return 0; 0093 } 0094 0095 QByteArray KResolverWorkerBase::protocolName() const 0096 { 0097 QByteArray res; 0098 if (input) { 0099 res = input->protocolName; 0100 } 0101 return res; 0102 } 0103 0104 void KResolverWorkerBase::finished() 0105 { 0106 m_finished = true; 0107 } 0108 0109 bool KResolverWorkerBase::postprocess() 0110 { 0111 return true; // no post-processing is a always successful postprocessing 0112 } 0113 0114 bool KResolverWorkerBase::enqueue(KResolver *res) 0115 { 0116 KResolverManager::manager()->enqueue(res, th->data); 0117 return true; 0118 } 0119 0120 bool KResolverWorkerBase::enqueue(KResolverWorkerBase *worker) 0121 { 0122 RequestData *myself = th->data; 0123 RequestData *newrequest = new RequestData; 0124 newrequest->obj = nullptr; 0125 newrequest->input = input; // same input 0126 newrequest->requestor = myself; 0127 newrequest->nRequests = 0; 0128 newrequest->worker = worker; 0129 myself->nRequests++; 0130 KResolverManager::manager()->dispatch(newrequest); 0131 return true; 0132 } 0133 0134 bool KResolverWorkerBase::checkResolver() 0135 { 0136 assert(th != nullptr); 0137 return th->checkResolver(); 0138 } 0139 0140 void KResolverWorkerBase::acquireResolver() 0141 { 0142 assert(th != nullptr); 0143 th->acquireResolver(); 0144 } 0145 0146 void KResolverWorkerBase::releaseResolver() 0147 { 0148 assert(th != nullptr); 0149 th->releaseResolver(); 0150 } 0151 0152 void KResolverWorkerFactoryBase::registerNewWorker(KResolverWorkerFactoryBase *factory) 0153 { 0154 KResolverManager::manager()->registerNewWorker(factory); 0155 } 0156