• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • tools
  • osm-sisyphus
jobqueue.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2011 Dennis Nienhüser <earthwings@gentoo.org>
9 //
10 
11 #include "jobqueue.h"
12 #include "logger.h"
13 
14 #include <QDebug>
15 #include <QThreadPool>
16 
17 JobQueue::JobQueue(QObject *parent) :
18  QObject(parent), m_maxConcurrentJobs(1)
19 {
20  // nothing to do
21 }
22 
23 void JobQueue::addJob(Job *newJob)
24 {
25  QList<Job*> const allJobs = m_jobs + m_runningJobs;
26  foreach(Job* job, allJobs) {
27  if (*job == *newJob) {
28  qDebug() << "Ignoring job, still running";
29  return;
30  }
31  }
32 
33  connect(newJob, SIGNAL(finished(Job*)), this, SLOT(removeJob(Job*)));
34 
35  if (m_runningJobs.size()<m_maxConcurrentJobs) {
36  startJob(newJob);
37  } else {
38  Logger::instance().setStatus(newJob->region().id() + '_' + newJob->transport(), newJob->region().name() + QLatin1String( " (" ) + newJob->transport() + ')', "waiting", "Queued.");
39  m_jobs << newJob;
40  }
41 }
42 
43 void JobQueue::setMaxConcurrentJobs(int size)
44 {
45  m_maxConcurrentJobs = size;
46 }
47 
48 void JobQueue::removeJob(Job *job)
49 {
50  m_runningJobs.removeAll(job);
51 
52  while (m_runningJobs.size()<m_maxConcurrentJobs && !m_jobs.isEmpty()) {
53  Job* newJob = m_jobs.first();
54  m_jobs.removeFirst();
55  startJob(newJob);
56  }
57 }
58 
59 void JobQueue::startJob(Job *job)
60 {
61  m_runningJobs << job;
62  QThreadPool::globalInstance()->start(job);
63 }
64 
65 #include "jobqueue.moc"
JobQueue::JobQueue
JobQueue(QObject *parent=0)
Definition: jobqueue.cpp:17
Job::transport
QString transport() const
Definition: job.cpp:45
Job
Definition: job.h:21
QObject
jobqueue.h
Logger::setStatus
void setStatus(const QString &id, const QString &name, const QString &status, const QString &message)
Definition: logger.cpp:69
Region::id
QString id
Definition: region.h:24
JobQueue::addJob
void addJob(Job *job)
Definition: jobqueue.cpp:23
logger.h
Logger::instance
static Logger & instance()
Definition: logger.cpp:53
Job::region
Region region() const
Definition: job.cpp:35
JobQueue::setMaxConcurrentJobs
void setMaxConcurrentJobs(int size)
Definition: jobqueue.cpp:43
Region::name
QString name
Definition: region.h:22
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:50 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal