kresolverworkerbase.h
/* -*- C++ -*-
* Copyright (C) 2003,2004 Thiago Macieira <thiago.macieira@kdemail.net>
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef KRESOLVERWORKERBASE_H
#define KRESOLVERWORKERBASE_H
#include "kresolver.h"
// forward declarations
class QString;
template <class T> class QValueList;
namespace KNetwork {
namespace Internal
{
class KResolverThread;
struct InputData;
}
class KResolverWorkerBase
{
public:
class ResolverLocker
{
public:
ResolverLocker(KResolverWorkerBase* parent)
: parent( parent )
{
parent->acquireResolver();
}
~ResolverLocker()
{
parent->releaseResolver();
}
void openClose()
{
parent->releaseResolver();
parent->acquireResolver();
}
private:
KResolverWorkerBase* parent;
};
private:
// this will be like our d pointer
KNetwork::Internal::KResolverThread *th;
const KNetwork::Internal::InputData *input;
friend class KNetwork::Internal::KResolverThread;
friend class KNetwork::Internal::KResolverManager;
friend class KResolverWorkerBase::ResolverLocker;
int m_finished : 1;
int m_reserved : 31; // reserved
public:
KResolverResults results;
public:
// default constructor
KResolverWorkerBase();
// virtual destructor
virtual ~KResolverWorkerBase();
QString nodeName() const;
QString serviceName() const;
int flags() const;
int familyMask() const;
int socketType() const;
int protocol() const;
QCString protocolName() const;
void finished();
protected:
// like a QThread
virtual bool run() = 0;
virtual bool preprocess() = 0;
virtual bool postprocess();
inline void setError(int errorcode, int syserror = 0)
{ results.setError(errorcode, syserror); }
bool enqueue(KResolver* other);
bool enqueue(KResolverWorkerBase* worker);
bool checkResolver();
void acquireResolver();
void releaseResolver();
};
class KResolverWorkerFactoryBase
{
public:
virtual KResolverWorkerBase* create() const = 0;
static void registerNewWorker(KResolverWorkerFactoryBase* factory);
};
template<class Worker>
class KResolverWorkerFactory: public KResolverWorkerFactoryBase
{
public:
virtual KResolverWorkerBase* create() const
{ return new Worker; }
};
} // namespace KNetwork
#endif
KNetwork::KResolverWorkerBase::ResolverLocker::~ResolverLocker
~ResolverLocker()
Destructor.
Definition: kresolverworkerbase.h:86
KNetwork::KResolverWorkerBase::ResolverLocker
Helper class for locking the resolver subsystem.
Definition: kresolverworkerbase.h:71
KNetwork::KResolverResults
Name and service resolution results.
Definition: kresolver.h:197
KStdAction::create
KAction * create(StdAction id, const char *name, const QObject *recvr, const char *slot, KActionCollection *parent)
KNetwork::KResolverWorkerBase::ResolverLocker::ResolverLocker
ResolverLocker(KResolverWorkerBase *parent)
Constructor.
Definition: kresolverworkerbase.h:77
KNetwork::KResolverWorkerBase::ResolverLocker::openClose
void openClose()
Releases the lock and then reacquires it.
Definition: kresolverworkerbase.h:96

KDE Home | KDE Accessibility Home | Description of Access Keys