2003-02-21 10:04:08 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2003-08-23 00:17:00 +00:00
|
|
|
* \file LoaderQueue.h
|
2003-02-21 10:04:08 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Alfredo Braunstein
|
2003-02-21 10:04:08 +00:00
|
|
|
*
|
2003-02-25 12:33:33 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-02-21 10:04:08 +00:00
|
|
|
*
|
|
|
|
* This implements a threaded service queue which loads images on background.
|
|
|
|
* In order to request an image loading you call touch() with the pointer to
|
2003-02-25 12:33:33 +00:00
|
|
|
* the cached image. Then it will try to satisfy the request as soon as
|
2003-02-21 10:04:08 +00:00
|
|
|
* posible (that's it: after finishing an eventual loading on progress)
|
|
|
|
* touch() returns inmediately, in order not tu disrupt the flow of the main
|
|
|
|
* thread.
|
|
|
|
* The service thread is the method loadNext(). It's actually not a thread,
|
|
|
|
* but implemented with a timer that comes back every x msec.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef LOADERQUEUE_H
|
|
|
|
#define LOADERQUEUE_H
|
|
|
|
|
|
|
|
#include "GraphicsCache.h"
|
|
|
|
#include "frontends/Timeout.h"
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <queue>
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace graphics {
|
2003-02-21 10:04:08 +00:00
|
|
|
|
|
|
|
class LoaderQueue {
|
|
|
|
public:
|
2003-02-25 11:20:59 +00:00
|
|
|
/// Use this to request that the item is loaded.
|
2003-02-21 10:04:08 +00:00
|
|
|
void touch(Cache::ItemPtr const & item);
|
2003-02-25 11:20:59 +00:00
|
|
|
/// Query whether the clock is ticking.
|
2003-02-21 10:04:08 +00:00
|
|
|
bool running() const;
|
2003-02-25 11:20:59 +00:00
|
|
|
///get the and only instance of the class
|
2003-02-21 10:04:08 +00:00
|
|
|
static LoaderQueue & get();
|
2003-02-25 11:20:59 +00:00
|
|
|
/** Adjusts the queue priority:
|
|
|
|
* numimages is the number of images loaded in a particular call
|
|
|
|
* from the timer.
|
|
|
|
* millisecs is the time interval between calls.
|
|
|
|
* Higher numimages, lower millisecs means higher priority.
|
|
|
|
*/
|
|
|
|
static void setPriority(int numimages , int millisecs);
|
2003-02-21 10:04:08 +00:00
|
|
|
private:
|
2003-02-25 11:20:59 +00:00
|
|
|
/// This class is a singleton class... use LoaderQueue::get() instead
|
2003-02-21 10:04:08 +00:00
|
|
|
LoaderQueue();
|
2003-02-25 11:20:59 +00:00
|
|
|
/// The in-progress loading queue (elements are unique here).
|
2003-02-21 10:04:08 +00:00
|
|
|
std::list<Cache::ItemPtr> cache_queue_;
|
2003-02-25 11:20:59 +00:00
|
|
|
/// Used to make the insertion of new elements faster.
|
2003-02-21 10:04:08 +00:00
|
|
|
std::set<Cache::ItemPtr> cache_set_;
|
2003-02-25 11:20:59 +00:00
|
|
|
/// Newly touched elements go here. loadNext moves them to cache_queue_
|
2003-02-21 10:04:08 +00:00
|
|
|
std::queue<Cache::ItemPtr> bucket_;
|
2003-02-25 11:20:59 +00:00
|
|
|
///
|
2003-02-21 10:04:08 +00:00
|
|
|
Timeout timer;
|
2003-02-25 11:20:59 +00:00
|
|
|
///
|
2003-02-21 10:04:08 +00:00
|
|
|
bool running_;
|
2003-02-25 11:20:59 +00:00
|
|
|
///
|
|
|
|
static int s_numimages_ ;
|
|
|
|
///
|
|
|
|
static int s_millisecs_ ;
|
|
|
|
|
|
|
|
/** This is the 'threaded' method, that does the loading in the
|
|
|
|
* background.
|
|
|
|
*/
|
2003-02-21 10:04:08 +00:00
|
|
|
void loadNext();
|
2003-02-25 11:20:59 +00:00
|
|
|
///
|
2003-02-21 10:04:08 +00:00
|
|
|
void startLoader();
|
2003-02-25 11:20:59 +00:00
|
|
|
///
|
2003-02-21 10:04:08 +00:00
|
|
|
void stopLoader();
|
|
|
|
};
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
} // namespace graphics
|
|
|
|
} // namespace lyx
|
2003-02-21 10:04:08 +00:00
|
|
|
|
|
|
|
#endif // LOADERQUEUE_H
|