From ksecretservice-devel Sun Sep 04 15:26:47 2011 From: Michael Leupold Date: Sun, 04 Sep 2011 15:26:47 +0000 To: ksecretservice-devel Subject: [Ksecretservice-devel] [kdelibs/ksecretsservice] /: Force kdelibs Message-Id: <20110904152647.A6292A60E0 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=ksecretservice-devel&m=131515005126893 Git commit 16b382be0f75560de58e1bf9baf04fa26430eb5c by Michael Leupold. Committed on 30/10/2010 at 10:32. Pushed by vrusu into branch 'ksecretsservice'. Force kdelibs style using the parameters from kdesdk and astyle. CCMAIL: ksecretservice-devel@kde.org svn path=/trunk/playground/base/ksecretservice/; revision=1191239 M +55 -55 peer.h M +38 -38 jobqueue.cpp M +57 -57 tests/queuedjobtest.cpp M +33 -33 jobqueue_p.h M +88 -88 jobinfostructs.h M +1 -1 secrettool.cpp M +73 -73 queuedjob.h M +22 -22 queuedjob.cpp M +20 -20 jobqueue.h M +45 -45 peer.cpp M +21 -21 tests/queuedjobtest.h http://commits.kde.org/kdelibs/16b382be0f75560de58e1bf9baf04fa26430eb5c diff --git a/jobinfostructs.h b/jobinfostructs.h index 3b65351..e6ab4ff 100644 --- a/jobinfostructs.h +++ b/jobinfostructs.h @@ -25,7 +25,7 @@ * * This file contain a collection of data objects exchanged by the various * asynchronous jobs used by the frontend and backend layer to interact. - * We opted for structs and not classes as these data objects are not + * We opted for structs and not classes as these data objects are not * real full-fledget objets. They only need to transport the various contextual * parameters needed for the jobs to perform. * @@ -33,7 +33,7 @@ * information about the d-bus peer that originated the various operations * the jobs are requested to do. * - * Some of the structures do not have any members. That is on purpose, as + * Some of the structures do not have any members. That is on purpose, as * defining ans using them would allow easy addition of new data pieces to * exchange on the job chain path. */ @@ -49,14 +49,14 @@ * It takes ownership of the Peer pointer and deletes it * when it's destructor is called. */ -struct JobBaseInfo -{ - /** - * The peer that requested the delete operation. - */ - const Peer m_peer; - JobBaseInfo(const Peer &peer) : m_peer(peer) - { /* nothing */ } +struct JobBaseInfo { + /** + * The peer that requested the delete operation. + */ + const Peer m_peer; + JobBaseInfo(const Peer &peer) : m_peer(peer) { + /* nothing */ + } }; class BackendCollection; @@ -65,112 +65,112 @@ class BackendCollection; * This job value object holds information needed when creating * a new collection. */ -struct CollectionCreateInfo : public JobBaseInfo -{ - const QString m_label; /*!< new collection label */ - bool m_locked; /*!< if true, the collection will be locked after creation */ - - /** - * Collection creation job value object constructor - * - * @param label New collection's label - * @param peer Information about the d-bus peer which requests collection creation - */ - CollectionCreateInfo(const QString& label, const Peer &peer) : - JobBaseInfo(peer), m_label(label), m_locked(false) - { /* nothing */ } +struct CollectionCreateInfo : public JobBaseInfo { + const QString m_label; /*!< new collection label */ + bool m_locked; /*!< if true, the collection will be locked after creation */ + + /** + * Collection creation job value object constructor + * + * @param label New collection's label + * @param peer Information about the d-bus peer which requests collection creation + */ + CollectionCreateInfo(const QString& label, const Peer &peer) : + JobBaseInfo(peer), m_label(label), m_locked(false) { + /* nothing */ + } }; /** * This job value object holds information needed during collection deletion */ -struct CollectionDeleteInfo : public JobBaseInfo -{ - mutable BackendCollection *m_collection; /*!< the collection to be deleted */ - /** - * Collection delete job value object constructor - * - * @param peer Information about the d-bus peer which requests collection delete - * @param collection The collection to be deleted. If NULL, it must be specified later - */ - CollectionDeleteInfo(const Peer &peer) : JobBaseInfo(peer), m_collection(0) - { /* nothing */ } +struct CollectionDeleteInfo : public JobBaseInfo { + mutable BackendCollection *m_collection; /*!< the collection to be deleted */ + /** + * Collection delete job value object constructor + * + * @param peer Information about the d-bus peer which requests collection delete + * @param collection The collection to be deleted. If NULL, it must be specified later + */ + CollectionDeleteInfo(const Peer &peer) : JobBaseInfo(peer), m_collection(0) { + /* nothing */ + } }; /** * This job value object holds information neede during collection unlocking */ -struct CollectionUnlockInfo : public JobBaseInfo -{ - mutable BackendCollection *m_collection; // collection may be changed on the job path - /** - * Collection unlock job value object constructor - * - * @param peer Information about the d-bus peer which requests collection unlocking - * @param collection The collection to be unkocked. If NULL, it must be specified later. - */ - CollectionUnlockInfo(const Peer &peer) : JobBaseInfo(peer), m_collection(0) - { /* nothing */ } +struct CollectionUnlockInfo : public JobBaseInfo { + mutable BackendCollection *m_collection; // collection may be changed on the job path + /** + * Collection unlock job value object constructor + * + * @param peer Information about the d-bus peer which requests collection unlocking + * @param collection The collection to be unkocked. If NULL, it must be specified later. + */ + CollectionUnlockInfo(const Peer &peer) : JobBaseInfo(peer), m_collection(0) { + /* nothing */ + } }; class BackendItem; -struct ItemCreateInfo : public JobBaseInfo -{ - const QString m_label; /*!< Item label */ - const QMap m_attributes; /*!< Collection of attributes to set for the new item */ - const QCA::SecureArray m_secret; /*!< The secret to store */ - bool m_replace; /*!< If true, replace an item with the same attributes if it already exists */ - bool m_locked; /*!< true if the item should be locked after creation, false else */ - - /** - * @param label human-readable label for the new item - * @param attributes attributes to set for the new item - * @param secret the secret to store - * @param locked true if the item should be locked after creation, false else - * @param replace if true, replace an item with the same attributes if it already exists - * @param peer the d-bus peer that initiated the item creation operation - */ - ItemCreateInfo( const QString &label, +struct ItemCreateInfo : public JobBaseInfo { + const QString m_label; /*!< Item label */ + const QMap m_attributes; /*!< Collection of attributes to set for the new item */ + const QCA::SecureArray m_secret; /*!< The secret to store */ + bool m_replace; /*!< If true, replace an item with the same attributes if it already exists */ + bool m_locked; /*!< true if the item should be locked after creation, false else */ + + /** + * @param label human-readable label for the new item + * @param attributes attributes to set for the new item + * @param secret the secret to store + * @param locked true if the item should be locked after creation, false else + * @param replace if true, replace an item with the same attributes if it already exists + * @param peer the d-bus peer that initiated the item creation operation + */ + ItemCreateInfo(const QString &label, const QMap &attributes, const QCA::SecureArray &secret, bool replace, bool locked, const Peer &peer) : - JobBaseInfo(peer), - m_label(label), m_attributes(attributes), m_secret(secret), - m_replace(replace), m_locked(locked) - { /* nothing */ } + JobBaseInfo(peer), + m_label(label), m_attributes(attributes), m_secret(secret), + m_replace(replace), m_locked(locked) { + /* nothing */ + } }; /** - * Item delete job value object + * Item delete job value object */ -struct ItemDeleteInfo : public JobBaseInfo -{ - mutable BackendItem* m_item; // item information may be added on the job path so let it be mutable - /** - * Item delete job value object constructor - * @param peer the d-bus peer that initiated the item delete operation - * @param item the item to be deleted. If NULL, it must be specified later. - */ - ItemDeleteInfo( const Peer &peer) : JobBaseInfo(peer), m_item(0) - { /* nothing */ } +struct ItemDeleteInfo : public JobBaseInfo { + mutable BackendItem* m_item; // item information may be added on the job path so let it be mutable + /** + * Item delete job value object constructor + * @param peer the d-bus peer that initiated the item delete operation + * @param item the item to be deleted. If NULL, it must be specified later. + */ + ItemDeleteInfo(const Peer &peer) : JobBaseInfo(peer), m_item(0) { + /* nothing */ + } }; /** * Value object used by item unlocking jobs */ -struct ItemUnlockInfo : public JobBaseInfo -{ - mutable BackendItem *m_item; // item information may be added on the job path so let it be mutable - /** - * Item unlock value object constructor - * @param peer the d-bus peer that initiated the item delete operation - * @param item the item to be deleted. If NULL, it must be specified later. - */ - ItemUnlockInfo( const Peer &peer) : JobBaseInfo(peer), m_item(0) - { /* nothing */ } +struct ItemUnlockInfo : public JobBaseInfo { + mutable BackendItem *m_item; // item information may be added on the job path so let it be mutable + /** + * Item unlock value object constructor + * @param peer the d-bus peer that initiated the item delete operation + * @param item the item to be deleted. If NULL, it must be specified later. + */ + ItemUnlockInfo(const Peer &peer) : JobBaseInfo(peer), m_item(0) { + /* nothing */ + } }; #endif // JOBINFOSTRUCTS_H diff --git a/jobqueue.cpp b/jobqueue.cpp index e0bfb0a..c211f21 100644 --- a/jobqueue.cpp +++ b/jobqueue.cpp @@ -30,54 +30,54 @@ JobQueuePrivate::JobQueuePrivate() JobQueuePrivate::~JobQueuePrivate() { - // TODO: make sure there's no jobs left running when we go down + // TODO: make sure there's no jobs left running when we go down } void JobQueuePrivate::enqueue(QueuedJob *job, bool inFront) { - Q_ASSERT(job); - if (inFront) { - m_jobs.prepend(job); - } else { - m_jobs.enqueue(job); - } - - if (m_currentJob.isNull()) { - QTimer::singleShot(0, this, SLOT(process())); - } + Q_ASSERT(job); + if(inFront) { + m_jobs.prepend(job); + } else { + m_jobs.enqueue(job); + } + + if(m_currentJob.isNull()) { + QTimer::singleShot(0, this, SLOT(process())); + } } void JobQueuePrivate::process() { - // check if already processing - if (!m_currentJob.isNull()) { - return; - } - - // get a job to execute - // as the job queue consists of QPointers, jobs which have been dismissed - // (deleted) are automatically weeded out. - while (m_currentJob.isNull()) { - if (m_jobs.isEmpty()) { - return; - } - m_currentJob = m_jobs.dequeue(); - } - - connect(m_currentJob.data(), SIGNAL(result(QueuedJob*)), - SLOT(jobFinished(QueuedJob*))); - m_currentJob->start(); + // check if already processing + if(!m_currentJob.isNull()) { + return; + } + + // get a job to execute + // as the job queue consists of QPointers, jobs which have been dismissed + // (deleted) are automatically weeded out. + while(m_currentJob.isNull()) { + if(m_jobs.isEmpty()) { + return; + } + m_currentJob = m_jobs.dequeue(); + } + + connect(m_currentJob.data(), SIGNAL(result(QueuedJob*)), + SLOT(jobFinished(QueuedJob*))); + m_currentJob->start(); } void JobQueuePrivate::jobFinished(QueuedJob *job) { - Q_UNUSED(job); - Q_ASSERT(job == m_currentJob); - m_currentJob = 0; - // keep processing if there's more jobs - if (!m_jobs.isEmpty()) { - QTimer::singleShot(0, this, SLOT(process())); - } + Q_UNUSED(job); + Q_ASSERT(job == m_currentJob); + m_currentJob = 0; + // keep processing if there's more jobs + if(!m_jobs.isEmpty()) { + QTimer::singleShot(0, this, SLOT(process())); + } } JobQueue::JobQueue() : d(new JobQueuePrivate) @@ -86,12 +86,12 @@ JobQueue::JobQueue() : d(new JobQueuePrivate) JobQueue::~JobQueue() { - delete d; + delete d; } void JobQueue::enqueue(QueuedJob *job, bool inFront) { - d->enqueue(job, inFront); + d->enqueue(job, inFront); } #include "jobqueue_p.moc" diff --git a/jobqueue.h b/jobqueue.h index 9275906..3ac954f 100644 --- a/jobqueue.h +++ b/jobqueue.h @@ -35,27 +35,27 @@ class JobQueuePrivate; class JobQueue { public: - /** - * Constructor. - */ - JobQueue(); - - /** - * Destructor. - */ - virtual ~JobQueue(); - - /** - * Enqueue a job for processing. - * - * @param job the job to enqueue - * @param inFront true to enqueue the job in front so it is the next - * job to be processed - */ - void enqueue(QueuedJob *job, bool inFront = false); - + /** + * Constructor. + */ + JobQueue(); + + /** + * Destructor. + */ + virtual ~JobQueue(); + + /** + * Enqueue a job for processing. + * + * @param job the job to enqueue + * @param inFront true to enqueue the job in front so it is the next + * job to be processed + */ + void enqueue(QueuedJob *job, bool inFront = false); + private: - JobQueuePrivate *d; + JobQueuePrivate *d; }; #endif // JOBQUEUE_H diff --git a/jobqueue_p.h b/jobqueue_p.h index 77f1a79..58ba1cc 100644 --- a/jobqueue_p.h +++ b/jobqueue_p.h @@ -33,44 +33,44 @@ class QueuedJob; */ class JobQueuePrivate : public QObject { - Q_OBJECT + Q_OBJECT public: - /** - * Constructor. - */ - JobQueuePrivate(); - - /** - * Destructor. - */ - ~JobQueuePrivate(); - - /** - * Enqueue a job for processing. - * - * @param job the job to enqueue - * @param inFront true to enqueue the job in front so it is the next - * job to be processed - */ - void enqueue(QueuedJob *job, bool inFront); + /** + * Constructor. + */ + JobQueuePrivate(); + + /** + * Destructor. + */ + ~JobQueuePrivate(); + + /** + * Enqueue a job for processing. + * + * @param job the job to enqueue + * @param inFront true to enqueue the job in front so it is the next + * job to be processed + */ + void enqueue(QueuedJob *job, bool inFront); private Q_SLOTS: - /** - * Start processing jobs. - */ - void process(); - - /** - * Used to receive result() signals of the current QueuedJob. - * - * @param job the job that sends its result - */ - void jobFinished(QueuedJob *job); - + /** + * Start processing jobs. + */ + void process(); + + /** + * Used to receive result() signals of the current QueuedJob. + * + * @param job the job that sends its result + */ + void jobFinished(QueuedJob *job); + private: - QQueue > m_jobs; - QPointer m_currentJob; + QQueue > m_jobs; + QPointer m_currentJob; }; #endif // JOBQUEUE_P_H diff --git a/peer.cpp b/peer.cpp index fe119c4..6e09887 100644 --- a/peer.cpp +++ b/peer.cpp @@ -28,16 +28,16 @@ class PeerData : public QSharedData { public: - PeerData() : m_valid(false), m_pid(0) {} - PeerData(const PeerData &other) : QSharedData(other), m_pid(other.m_pid) {} - ~PeerData() {} - - // designates whether this Peer is valid as it's not certain that - // a pid of 0 can always denote an invalid peer. - bool m_valid; - - // peer process pid - uint m_pid; + PeerData() : m_valid(false), m_pid(0) {} + PeerData(const PeerData &other) : QSharedData(other), m_pid(other.m_pid) {} + ~PeerData() {} + + // designates whether this Peer is valid as it's not certain that + // a pid of 0 can always denote an invalid peer. + bool m_valid; + + // peer process pid + uint m_pid; }; Peer::Peer() : d(new PeerData) @@ -50,18 +50,18 @@ Peer::Peer(const Peer &other) : d(other.d) Peer &Peer::operator=(const Peer &other) { - d = other.d; - return *this; + d = other.d; + return *this; } Peer::Peer(uint pid) : d(new PeerData) { - d->m_valid = true; - d->m_pid = pid; - - kDebug() << "Peer " << pid; - kDebug() << " cmdLine = " << cmdLine(); - kDebug() << " exePath = " << exePath(); + d->m_valid = true; + d->m_pid = pid; + + kDebug() << "Peer " << pid; + kDebug() << " cmdLine = " << cmdLine(); + kDebug() << " exePath = " << exePath(); } Peer::~Peer() @@ -70,46 +70,46 @@ Peer::~Peer() QString Peer::procFileName() const { - Q_ASSERT(d->m_valid); - return QString("/proc/%1").arg(d->m_pid); + Q_ASSERT(d->m_valid); + return QString("/proc/%1").arg(d->m_pid); } QByteArray Peer::cmdLine() const { - if (!d->m_valid) { - return QByteArray(); - } else { - QFile procFile(QString("%1/cmd").arg(procFileName())); - if (!procFile.open(QIODevice::ReadOnly | QIODevice::Text) || - procFile.atEnd()) { - // file doesn't exist or is empty - return QByteArray(); - } else { - return procFile.readLine(); - } - } + if(!d->m_valid) { + return QByteArray(); + } else { + QFile procFile(QString("%1/cmd").arg(procFileName())); + if(!procFile.open(QIODevice::ReadOnly | QIODevice::Text) || + procFile.atEnd()) { + // file doesn't exist or is empty + return QByteArray(); + } else { + return procFile.readLine(); + } + } } bool Peer::isValid() const { - return d->m_valid; + return d->m_valid; } bool Peer::isStillRunning() const { - if (!d->m_valid) { - return false; - } else { - return QFile::exists(procFileName()); - } + if(!d->m_valid) { + return false; + } else { + return QFile::exists(procFileName()); + } } -QString Peer::exePath() const +QString Peer::exePath() const { - if (!d->m_valid) { - return QString(); - } else { - // TODO: add a watch an trigger signal when the peer process ends - return QFile::symLinkTarget(QString("%1/exe").arg(procFileName())); - } + if(!d->m_valid) { + return QString(); + } else { + // TODO: add a watch an trigger signal when the peer process ends + return QFile::symLinkTarget(QString("%1/exe").arg(procFileName())); + } } diff --git a/peer.h b/peer.h index a16adaf..959f82b 100644 --- a/peer.h +++ b/peer.h @@ -34,62 +34,62 @@ class PeerData; class Peer { public: - /** - * Construct an invalid (non-existant) Peer. - */ - Peer(); - - /** - * Copy constructor. - */ - Peer(const Peer &other); - - /** - * Copy operator. - */ - Peer &operator=(const Peer &other); - - /** - * Construct a valid Peer representing the process with the given pid. - */ - explicit Peer(uint pid); - - /** - * Destructor. - */ - ~Peer(); - - /** - * Get the running state of the peer process - */ - bool isStillRunning() const; - - /** - * Get the executable path of the running process - */ - QString exePath() const; - - /** - * Get the command line used to launch the running process - */ - QByteArray cmdLine() const; - - /** - * Check if the peer is valid. An invalid peer identifies test applications - * or requests sent in-process. - */ - bool isValid() const; - + /** + * Construct an invalid (non-existant) Peer. + */ + Peer(); + + /** + * Copy constructor. + */ + Peer(const Peer &other); + + /** + * Copy operator. + */ + Peer &operator=(const Peer &other); + + /** + * Construct a valid Peer representing the process with the given pid. + */ + explicit Peer(uint pid); + + /** + * Destructor. + */ + ~Peer(); + + /** + * Get the running state of the peer process + */ + bool isStillRunning() const; + + /** + * Get the executable path of the running process + */ + QString exePath() const; + + /** + * Get the command line used to launch the running process + */ + QByteArray cmdLine() const; + + /** + * Check if the peer is valid. An invalid peer identifies test applications + * or requests sent in-process. + */ + bool isValid() const; + private: - /** - * Helper method witch returns the /proc/pid path for the - * peer process. - * - * @note Must only be called on valid peers. - */ - QString procFileName() const; - - QSharedDataPointer d; + /** + * Helper method witch returns the /proc/pid path for the + * peer process. + * + * @note Must only be called on valid peers. + */ + QString procFileName() const; + + QSharedDataPointer d; }; #endif // DEAMON_PEER_H diff --git a/queuedjob.cpp b/queuedjob.cpp index a6d8828..ecfe495 100644 --- a/queuedjob.cpp +++ b/queuedjob.cpp @@ -24,52 +24,52 @@ class QueuedJobPrivate { public: - JobQueue *m_queue; - bool m_finished; - bool m_enqueued; + JobQueue *m_queue; + bool m_finished; + bool m_enqueued; }; QueuedJob::QueuedJob(JobQueue *queue) - : d(new QueuedJobPrivate) + : d(new QueuedJobPrivate) { - Q_ASSERT(queue); - - d->m_queue = queue; - d->m_finished = false; - d->m_enqueued = false; + Q_ASSERT(queue); + + d->m_queue = queue; + d->m_finished = false; + d->m_enqueued = false; } QueuedJob::~QueuedJob() { - delete d; + delete d; } bool QueuedJob::isImmediate() const { - return false; + return false; } bool QueuedJob::isFinished() const { - return d->m_finished; + return d->m_finished; } void QueuedJob::enqueue(bool inFront) { - // if the job has already been finished or enqueued, handle this - // gracefully. - if (d->m_enqueued || d->m_finished) { - return; - } - d->m_queue->enqueue(this, inFront); - d->m_enqueued = true; + // if the job has already been finished or enqueued, handle this + // gracefully. + if(d->m_enqueued || d->m_finished) { + return; + } + d->m_queue->enqueue(this, inFront); + d->m_enqueued = true; } void QueuedJob::emitResult() { - d->m_finished = true; - emit result(this); - deleteLater(); + d->m_finished = true; + emit result(this); + deleteLater(); } #include "queuedjob.moc" diff --git a/queuedjob.h b/queuedjob.h index 25f2630..81c5456 100644 --- a/queuedjob.h +++ b/queuedjob.h @@ -37,85 +37,85 @@ class QueuedJobPrivate; */ class QueuedJob : public QObject { - Q_OBJECT - + Q_OBJECT + public: - /** - * Constructor. - * - * @param queue queue the job will be enqueued into - */ - explicit QueuedJob(JobQueue *queue); - - /** - * Destructor. - */ - virtual ~QueuedJob(); - - /** - * Checks if this call can be made immediately/synchronously. - * - * @return true if the call can be made immediately, false if it needs to - * be queued - * @note The base implementation always returns false, so if your job class - * isn't immediate, you don't have to reimplement this method. - */ - virtual bool isImmediate() const; - - /** - * Check whether this job is finished. - * - * @return true if the job is finished, false else - */ - bool isFinished() const; - - /** - * Enqueue this job into the JobQueue passed in its constructor. - * - * @param inFront true to enqueue the job in front so it is the next job - * to be processed - */ - void enqueue(bool inFront = false); - - /** - * Execute this job synchronously. Implementation of this method should - * not involve an event-loop and it should only be available if the job - * advertised that it can be called immediately. - * - * @note This method has to call emitResult() before returning. Even if - * noone is interested in the signal it's used to mark this job - * as finished and call deleteLater(). - */ - virtual void exec() = 0; + /** + * Constructor. + * + * @param queue queue the job will be enqueued into + */ + explicit QueuedJob(JobQueue *queue); + + /** + * Destructor. + */ + virtual ~QueuedJob(); + + /** + * Checks if this call can be made immediately/synchronously. + * + * @return true if the call can be made immediately, false if it needs to + * be queued + * @note The base implementation always returns false, so if your job class + * isn't immediate, you don't have to reimplement this method. + */ + virtual bool isImmediate() const; + + /** + * Check whether this job is finished. + * + * @return true if the job is finished, false else + */ + bool isFinished() const; + + /** + * Enqueue this job into the JobQueue passed in its constructor. + * + * @param inFront true to enqueue the job in front so it is the next job + * to be processed + */ + void enqueue(bool inFront = false); + + /** + * Execute this job synchronously. Implementation of this method should + * not involve an event-loop and it should only be available if the job + * advertised that it can be called immediately. + * + * @note This method has to call emitResult() before returning. Even if + * noone is interested in the signal it's used to mark this job + * as finished and call deleteLater(). + */ + virtual void exec() = 0; protected: - /** - * Start the job asynchronously. - * - * When the job is finished, result() is emitted. - */ - virtual void start() = 0; + /** + * Start the job asynchronously. + * + * When the job is finished, result() is emitted. + */ + virtual void start() = 0; + + /** + * Emit the result of this job, notifying every object listening that + * it's finished. + */ + void emitResult(); - /** - * Emit the result of this job, notifying every object listening that - * it's finished. - */ - void emitResult(); - Q_SIGNALS: - /** - * Emit the result of this job. - * - * As this signal can't be emitted directly from derived classes, use - * emitResult() to mark the job as finished and emit this signal. - * - * @param job The job that finished (this object) - */ - void result(QueuedJob *job); - + /** + * Emit the result of this job. + * + * As this signal can't be emitted directly from derived classes, use + * emitResult() to mark the job as finished and emit this signal. + * + * @param job The job that finished (this object) + */ + void result(QueuedJob *job); + private: - friend class JobQueuePrivate; - QueuedJobPrivate *d; + friend class JobQueuePrivate; + QueuedJobPrivate *d; }; #endif // QUEUEDJOB_H diff --git a/secrettool.cpp b/secrettool.cpp index 41ee316..c30d867 100644 --- a/secrettool.cpp +++ b/secrettool.cpp @@ -25,5 +25,5 @@ QString createId() { - return QUuid::createUuid().toString().remove(QRegExp("[\\{\\}-]")); + return QUuid::createUuid().toString().remove(QRegExp("[\\{\\}-]")); } diff --git a/tests/queuedjobtest.cpp b/tests/queuedjobtest.cpp index a61ecec..610b161 100644 --- a/tests/queuedjobtest.cpp +++ b/tests/queuedjobtest.cpp @@ -34,98 +34,98 @@ TestJob::~TestJob() bool TestJob::isImmediate() const { - return true; + return true; } void TestJob::exec() { - doWork(); + doWork(); } void TestJob::start() { - QTimer::singleShot(0, this, SLOT(doWork())); + QTimer::singleShot(0, this, SLOT(doWork())); } - + void TestJob::doWork() { - // nothing to do really - emitResult(); + // nothing to do really + emitResult(); } void QueuedJobTest::initTestCase() { - m_queue = new JobQueue; + m_queue = new JobQueue; } void QueuedJobTest::testSync() { - QPointer job = new TestJob(m_queue); - QVERIFY(job->isImmediate()); - QVERIFY(!job->isFinished()); - job->exec(); - QVERIFY(job->isFinished()); - - // make sure the job gets deleted - QEventLoop loop; - QTimer::singleShot(0, &loop, SLOT(quit())); - loop.exec(); - QVERIFY(job.isNull()); + QPointer job = new TestJob(m_queue); + QVERIFY(job->isImmediate()); + QVERIFY(!job->isFinished()); + job->exec(); + QVERIFY(job->isFinished()); + + // make sure the job gets deleted + QEventLoop loop; + QTimer::singleShot(0, &loop, SLOT(quit())); + loop.exec(); + QVERIFY(job.isNull()); } void QueuedJobTest::testAsync() { - QPointer job = new TestJob(m_queue); - QEventLoop loop; - loop.connect(job, SIGNAL(result(QueuedJob*)), SLOT(quit())); - QVERIFY(!job->isFinished()); - job->enqueue(); - loop.exec(); - // if we end up here, the job will already be deleted - QVERIFY(job.isNull() || job->isFinished()); - if (!job.isNull()) { - // if the job wasn't deleted yet, make sure it's getting deleted - QTimer::singleShot(0, &loop, SLOT(quit())); - loop.exec(); - QVERIFY(job.isNull()); - } + QPointer job = new TestJob(m_queue); + QEventLoop loop; + loop.connect(job, SIGNAL(result(QueuedJob*)), SLOT(quit())); + QVERIFY(!job->isFinished()); + job->enqueue(); + loop.exec(); + // if we end up here, the job will already be deleted + QVERIFY(job.isNull() || job->isFinished()); + if(!job.isNull()) { + // if the job wasn't deleted yet, make sure it's getting deleted + QTimer::singleShot(0, &loop, SLOT(quit())); + loop.exec(); + QVERIFY(job.isNull()); + } } void QueuedJobTest::testAsyncOrder() { - QPointer job1 = new TestJob(m_queue); - QPointer job2 = new TestJob(m_queue); - QEventLoop loop1; - QEventLoop loop2; - loop1.connect(job1, SIGNAL(result(QueuedJob*)), SLOT(quit())); - loop2.connect(job2, SIGNAL(result(QueuedJob*)), SLOT(quit())); - job1->enqueue(); - job2->enqueue(); - loop1.exec(); - loop2.exec(); - QVERIFY(job1.isNull() || job1->isFinished()); - QVERIFY(job2.isNull() || job2->isFinished()); + QPointer job1 = new TestJob(m_queue); + QPointer job2 = new TestJob(m_queue); + QEventLoop loop1; + QEventLoop loop2; + loop1.connect(job1, SIGNAL(result(QueuedJob*)), SLOT(quit())); + loop2.connect(job2, SIGNAL(result(QueuedJob*)), SLOT(quit())); + job1->enqueue(); + job2->enqueue(); + loop1.exec(); + loop2.exec(); + QVERIFY(job1.isNull() || job1->isFinished()); + QVERIFY(job2.isNull() || job2->isFinished()); } void QueuedJobTest::testAsyncOrderInFront() { - QPointer job1 = new TestJob(m_queue); - QPointer job2 = new TestJob(m_queue); - QEventLoop loop1; - QEventLoop loop2; - loop1.connect(job1, SIGNAL(result(QueuedJob*)), SLOT(quit())); - loop2.connect(job2, SIGNAL(result(QueuedJob*)), SLOT(quit())); - job1->enqueue(); - job2->enqueue(true); - loop2.exec(); - loop1.exec(); - QVERIFY(job1.isNull() || job1->isFinished()); - QVERIFY(job2.isNull() || job2->isFinished()); + QPointer job1 = new TestJob(m_queue); + QPointer job2 = new TestJob(m_queue); + QEventLoop loop1; + QEventLoop loop2; + loop1.connect(job1, SIGNAL(result(QueuedJob*)), SLOT(quit())); + loop2.connect(job2, SIGNAL(result(QueuedJob*)), SLOT(quit())); + job1->enqueue(); + job2->enqueue(true); + loop2.exec(); + loop1.exec(); + QVERIFY(job1.isNull() || job1->isFinished()); + QVERIFY(job2.isNull() || job2->isFinished()); } void QueuedJobTest::cleanupTestCase() { - delete m_queue; + delete m_queue; } QTEST_MAIN(QueuedJobTest) diff --git a/tests/queuedjobtest.h b/tests/queuedjobtest.h index 3729666..4e2cfc7 100644 --- a/tests/queuedjobtest.h +++ b/tests/queuedjobtest.h @@ -28,35 +28,35 @@ class JobQueue; class TestJob : public QueuedJob { - Q_OBJECT - + Q_OBJECT + public: - TestJob(JobQueue *queue); - virtual ~TestJob(); - virtual bool isImmediate() const; - virtual void exec(); - virtual void start(); - + TestJob(JobQueue *queue); + virtual ~TestJob(); + virtual bool isImmediate() const; + virtual void exec(); + virtual void start(); + protected Q_SLOTS: - void doWork(); + void doWork(); }; class QueuedJobTest : public QObject { - Q_OBJECT - + Q_OBJECT + private Q_SLOTS: - void initTestCase(); - - void testSync(); - void testAsync(); - void testAsyncOrder(); - void testAsyncOrderInFront(); - - void cleanupTestCase(); - + void initTestCase(); + + void testSync(); + void testAsync(); + void testAsyncOrder(); + void testAsyncOrderInFront(); + + void cleanupTestCase(); + private: - JobQueue *m_queue; + JobQueue *m_queue; }; #endif // QUEUEDJOBTEST_H _______________________________________________ Ksecretservice-devel mailing list Ksecretservice-devel@kde.org https://mail.kde.org/mailman/listinfo/ksecretservice-devel