KDECore
k3resolverworkerbase.cpp
Go to the documentation of this file.00001 /* -*- C++ -*- 00002 * Copyright (C) 2003,2004 Thiago Macieira <thiago@kde.org> 00003 * 00004 * 00005 * Permission is hereby granted, free of charge, to any person obtaining 00006 * a copy of this software and associated documentation files (the 00007 * "Software"), to deal in the Software without restriction, including 00008 * without limitation the rights to use, copy, modify, merge, publish, 00009 * distribute, sublicense, and/or sell copies of the Software, and to 00010 * permit persons to whom the Software is furnished to do so, subject to 00011 * the following conditions: 00012 * 00013 * The above copyright notice and this permission notice shall be included 00014 * in all copies or substantial portions of the Software. 00015 * 00016 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00017 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00018 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00019 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00020 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00021 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00022 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00023 */ 00024 00025 #include "k3resolverworkerbase.h" 00026 00027 #include <config.h> 00028 #include <config-network.h> 00029 00030 #include <assert.h> 00031 00032 #include <QByteArray> 00033 00034 00035 #include "k3resolver.h" 00036 #include "k3resolver_p.h" 00037 00038 using namespace KNetwork; 00039 using namespace KNetwork::Internal; 00040 00041 KResolverWorkerBase::KResolverWorkerBase() 00042 : th(0L), input(0L), m_finished(0), m_reserved(0) 00043 { 00044 } 00045 00046 KResolverWorkerBase::~KResolverWorkerBase() 00047 { 00048 } 00049 00050 QString KResolverWorkerBase::nodeName() const 00051 { 00052 if (input) 00053 return input->node; 00054 return QString(); 00055 } 00056 00057 QString KResolverWorkerBase::serviceName() const 00058 { 00059 if (input) 00060 return input->service; 00061 return QString(); 00062 } 00063 00064 int KResolverWorkerBase::flags() const 00065 { 00066 if (input) 00067 return input->flags; 00068 return 0; 00069 } 00070 00071 int KResolverWorkerBase::familyMask() const 00072 { 00073 if (input) 00074 return input->familyMask; 00075 return 0; 00076 } 00077 00078 int KResolverWorkerBase::socketType() const 00079 { 00080 if (input) 00081 return input->socktype; 00082 return 0; 00083 } 00084 00085 int KResolverWorkerBase::protocol() const 00086 { 00087 if (input) 00088 return input->protocol; 00089 return 0; 00090 } 00091 00092 QByteArray KResolverWorkerBase::protocolName() const 00093 { 00094 QByteArray res; 00095 if (input) 00096 res = input->protocolName; 00097 return res; 00098 } 00099 00100 void KResolverWorkerBase::finished() 00101 { 00102 m_finished = true; 00103 } 00104 00105 bool KResolverWorkerBase::postprocess() 00106 { 00107 return true; // no post-processing is a always successful postprocessing 00108 } 00109 00110 bool KResolverWorkerBase::enqueue(KResolver* res) 00111 { 00112 KResolverManager::manager()->enqueue(res, th->data); 00113 return true; 00114 } 00115 00116 bool KResolverWorkerBase::enqueue(KResolverWorkerBase* worker) 00117 { 00118 RequestData *myself = th->data; 00119 RequestData *newrequest = new RequestData; 00120 newrequest->obj = 0; 00121 newrequest->input = input; // same input 00122 newrequest->requestor = myself; 00123 newrequest->nRequests = 0; 00124 newrequest->worker = worker; 00125 myself->nRequests++; 00126 KResolverManager::manager()->dispatch(newrequest); 00127 return true; 00128 } 00129 00130 bool KResolverWorkerBase::checkResolver() 00131 { 00132 assert(th != 0L); 00133 return th->checkResolver(); 00134 } 00135 00136 void KResolverWorkerBase::acquireResolver() 00137 { 00138 assert(th != 0L); 00139 th->acquireResolver(); 00140 } 00141 00142 void KResolverWorkerBase::releaseResolver() 00143 { 00144 assert(th != 0L); 00145 th->releaseResolver(); 00146 } 00147 00148 void KResolverWorkerFactoryBase::registerNewWorker(KResolverWorkerFactoryBase* factory) 00149 { 00150 KResolverManager::manager()->registerNewWorker(factory); 00151 } 00152