F:/KPlato/koffice/libs/kofficecore/threadAction/KoExecutePolicy.cpp

Aller à la documentation de ce fichier.
00001 /*
00002  * Copyright (C) 2006 Thomas Zander <zander@kde.org>
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Library General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Library General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Library General Public License
00015  * along with this library; see the file COPYING.LIB.  If not, write to
00016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #include "KoExecutePolicy.h"
00021 #include "KoAction.h"
00022 #include "ActionJob_p.h"
00023 #include "KoJobsListPolicy.h"
00024 #include <WeaverInterface.h>
00025 
00026 using namespace ThreadWeaver;
00027 
00028 void KoOnlyLastPolicy::schedule(KoAction *action, KoJobsListPolicy *jobsList, QVariant *params) {
00029     if(action->weaver() == 0) {
00030         qWarning("Action has no weaver set, ignoring scheduling request");
00031         return;
00032     }
00033     jobsList->lock();
00034     foreach(Job *job, jobsList->jobs()) {
00035         ActionJob *aj = dynamic_cast<ActionJob*> (job);
00036         if(aj && aj->action() == action) {
00037             if(! aj->started()) {
00038                 action->weaver()->dequeue(aj);
00039                 jobsList->free(aj);
00040             }
00041         }
00042     }
00043     jobsList->unlock();
00044     ActionJob *job = new ActionJob(action, action->isEnabled() ? ActionJob::EnableOn :
00045             ActionJob::EnableOff, params);
00046     job->assignQueuePolicy(jobsList);
00047     jobsList->addJob(job);
00048     action->weaver()->enqueue(job);
00049 }
00050 
00051 void KoDirectPolicy::schedule(KoAction *action, KoJobsListPolicy *jobsList, QVariant *params) {
00052     Q_UNUSED(jobsList);
00053     ActionJob *job = new ActionJob(action, ActionJob::EnableNoChange, params);
00054     job->run();
00055 }
00056 
00057 void KoQueuedPolicy::schedule(KoAction *action, KoJobsListPolicy *jobsList, QVariant *params) {
00058     if(action->weaver() == 0) {
00059         qWarning("Action has no weaver set, ignoring scheduling request");
00060         return;
00061     }
00062     ActionJob *job = new ActionJob(action, action->isEnabled() ? ActionJob::EnableOn :
00063             ActionJob::EnableOff, params);
00064     job->assignQueuePolicy(jobsList);
00065     jobsList->addJob(job);
00066     action->setEnabled(false);
00067     action->weaver()->enqueue(job);
00068 }
00069 
00070 void KoSimpleQueuedPolicy::schedule(KoAction *action, KoJobsListPolicy *jobsList, QVariant *params) {
00071     if(action->weaver() == 0) {
00072         qWarning("Action has no weaver set, ignoring scheduling request");
00073         return;
00074     }
00075     ActionJob *job = new ActionJob(action, ActionJob::EnableNoChange, params);
00076     job->assignQueuePolicy(jobsList);
00077     jobsList->addJob(job);
00078     action->weaver()->enqueue(job);
00079 }
00080 
00081 // statics
00082 KoExecutePolicy *const KoExecutePolicy::onlyLastPolicy = new KoOnlyLastPolicy();
00083 KoExecutePolicy *const KoExecutePolicy::directPolicy = new KoDirectPolicy();
00084 KoExecutePolicy *const KoExecutePolicy::queuedPolicy = new KoQueuedPolicy();
00085 KoExecutePolicy *const KoExecutePolicy::simpleQueuedPolicy = new KoSimpleQueuedPolicy();

Généré le Wed Nov 22 23:41:04 2006 pour KPlato par  doxygen 1.5.1-p1