2003-02-21 10:04:08 +00:00
|
|
|
/**
|
|
|
|
* \file LoaderQueue.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Alfredo Braunstein
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-02-21 10:04:08 +00:00
|
|
|
*/
|
|
|
|
|
2003-05-06 20:34:12 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2003-02-21 10:04:08 +00:00
|
|
|
#include "LoaderQueue.h"
|
2003-09-04 00:35:07 +00:00
|
|
|
#include "GraphicsCacheItem.h"
|
2003-02-21 10:04:08 +00:00
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
|
|
|
#include <boost/bind.hpp>
|
|
|
|
|
|
|
|
using std::endl;
|
|
|
|
using std::list;
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace graphics {
|
2003-02-21 10:04:08 +00:00
|
|
|
|
2003-02-25 11:20:59 +00:00
|
|
|
int LoaderQueue::s_numimages_ = 5;
|
|
|
|
int LoaderQueue::s_millisecs_ = 500;
|
2003-02-21 10:04:08 +00:00
|
|
|
|
2003-02-25 15:17:53 +00:00
|
|
|
|
2003-02-21 10:04:08 +00:00
|
|
|
LoaderQueue & LoaderQueue::get()
|
|
|
|
{
|
|
|
|
static LoaderQueue singleton;
|
|
|
|
return singleton;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-25 12:33:33 +00:00
|
|
|
void LoaderQueue::loadNext()
|
2003-02-21 10:04:08 +00:00
|
|
|
{
|
|
|
|
lyxerr[Debug::GRAPHICS] << "LoaderQueue: "
|
|
|
|
<< cache_queue_.size()
|
2003-02-25 12:33:33 +00:00
|
|
|
<< " items in the queue" << endl;
|
2003-02-25 11:20:59 +00:00
|
|
|
int counter = s_numimages_;
|
2003-02-21 10:04:08 +00:00
|
|
|
while (cache_queue_.size() && counter--) {
|
2003-02-25 15:17:53 +00:00
|
|
|
Cache::ItemPtr ptr = cache_queue_.front();
|
|
|
|
cache_set_.erase(ptr);
|
2003-02-21 10:04:08 +00:00
|
|
|
cache_queue_.pop_front();
|
2003-02-25 15:17:53 +00:00
|
|
|
if (ptr->status() == WaitingToLoad)
|
|
|
|
ptr->startLoading();
|
2003-02-21 10:04:08 +00:00
|
|
|
}
|
2003-02-25 15:17:53 +00:00
|
|
|
if (cache_queue_.size()) {
|
2003-02-21 10:04:08 +00:00
|
|
|
startLoader();
|
|
|
|
} else {
|
|
|
|
stopLoader();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-25 11:20:59 +00:00
|
|
|
void LoaderQueue::setPriority(int numimages , int millisecs)
|
|
|
|
{
|
|
|
|
s_numimages_ = numimages;
|
|
|
|
s_millisecs_ = millisecs;
|
|
|
|
lyxerr[Debug::GRAPHICS] << "LoaderQueue: priority set to "
|
|
|
|
<< s_numimages_ << " images at a time, "
|
2003-02-25 12:33:33 +00:00
|
|
|
<< s_millisecs_ << " milliseconds between calls"
|
2003-02-25 11:20:59 +00:00
|
|
|
<< endl;
|
|
|
|
}
|
|
|
|
|
2003-02-25 12:33:33 +00:00
|
|
|
|
|
|
|
LoaderQueue::LoaderQueue() : timer(s_millisecs_, Timeout::ONETIME),
|
2003-02-21 10:04:08 +00:00
|
|
|
running_(false)
|
|
|
|
{
|
|
|
|
timer.timeout.connect(boost::bind(&LoaderQueue::loadNext, this));
|
|
|
|
}
|
|
|
|
|
2003-02-25 12:33:33 +00:00
|
|
|
|
2003-02-21 10:04:08 +00:00
|
|
|
void LoaderQueue::startLoader()
|
|
|
|
{
|
|
|
|
lyxerr[Debug::GRAPHICS] << "LoaderQueue: waking up" << endl;
|
|
|
|
running_ = true ;
|
2003-02-25 11:20:59 +00:00
|
|
|
timer.setTimeout(s_millisecs_);
|
2003-02-21 10:04:08 +00:00
|
|
|
timer.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LoaderQueue::stopLoader()
|
|
|
|
{
|
|
|
|
timer.stop();
|
|
|
|
running_ = false ;
|
|
|
|
lyxerr[Debug::GRAPHICS] << "LoaderQueue: I'm going to sleep" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool LoaderQueue::running() const
|
|
|
|
{
|
|
|
|
return running_ ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LoaderQueue::touch(Cache::ItemPtr const & item)
|
|
|
|
{
|
|
|
|
if (! cache_set_.insert(item).second) {
|
2003-02-25 12:33:33 +00:00
|
|
|
list<Cache::ItemPtr>::iterator
|
2003-02-21 10:04:08 +00:00
|
|
|
it = cache_queue_.begin();
|
2003-02-25 12:33:33 +00:00
|
|
|
list<Cache::ItemPtr>::iterator
|
2003-02-21 10:04:08 +00:00
|
|
|
end = cache_queue_.end();
|
2003-02-25 12:33:33 +00:00
|
|
|
|
2003-02-21 10:04:08 +00:00
|
|
|
it = std::find(it, end, item);
|
|
|
|
if (it != end)
|
|
|
|
cache_queue_.erase(it);
|
2003-02-25 12:33:33 +00:00
|
|
|
}
|
2003-02-21 10:04:08 +00:00
|
|
|
cache_queue_.push_front(item);
|
2003-02-25 15:17:53 +00:00
|
|
|
if (!running_)
|
|
|
|
startLoader();
|
2003-02-21 10:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-04 08:23:23 +00:00
|
|
|
} // namespace graphics
|
|
|
|
} // namespace lyx
|