pdf_render_requests.cpp

Go to the documentation of this file.
00001 /*
00002  * File Name: pdf_render_requests.cpp
00003  */
00004 
00005 /*
00006  * This file is part of uds-plugin-pdf.
00007  *
00008  * uds-plugin-pdf is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * uds-plugin-pdf is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 #include "pdf_render_requests.h"
00028 
00029 namespace pdf
00030 {
00031 
00032 static const int PRIORITY_MIN = 0xFFFF;
00033 
00034 PDFRenderRequests::PDFRenderRequests()
00035 {
00036 }
00037 
00038 PDFRenderRequests::~PDFRenderRequests()
00039 {
00040 }
00041 
00042 void PDFRenderRequests::add_request(const size_t page_number, const int priority)
00043 {
00044     ScopeMutex m(&queue_mutex);
00045     queue[page_number] = priority;
00046 }
00047 
00048 void PDFRenderRequests::append_request(const size_t page_number)
00049 {
00050     ScopeMutex m(&queue_mutex);
00051     // the request is appeneded with the lowest priority in the queue
00052     if (queue.find(page_number) != queue.end())
00053     {
00054         // if the page is in the request list, stop appending
00055         return;
00056     }
00057 
00058     int priority = -1;
00059     QueueIter iter = queue.begin();
00060     for (; iter != queue.end(); ++iter)
00061     {
00062         if (iter->second > priority)
00063         {
00064             priority = iter->second;
00065         }
00066     }
00067 
00068     queue[page_number] = (priority + 1);
00069 }
00070 
00071 void PDFRenderRequests::remove_request(const size_t page_number)
00072 {
00073     ScopeMutex m(&queue_mutex);
00074     QueueIter iter = queue.find(page_number);
00075     if (iter != queue.end())
00076     {
00077         queue.erase(iter);
00078     }
00079 }
00080 
00081 void PDFRenderRequests::clear()
00082 {
00083     ScopeMutex m(&queue_mutex);
00084     queue.clear();
00085 }
00086 
00087 int PDFRenderRequests::get_priority(const size_t page_number)
00088 {
00089     ScopeMutex m(&queue_mutex);
00090     QueueIter iter = queue.find(page_number);
00091     if (iter == queue.end())
00092     {
00093         return PRIORITY_MIN;
00094     }
00095     return queue[page_number];
00096 }
00097 
00098 void PDFRenderRequests::update(const std::vector<size_t> & requests)
00099 {
00100     ScopeMutex m(&queue_mutex);
00101     queue.clear();
00102     for (size_t idx = 0; idx < requests.size(); ++idx)
00103     {
00104         queue[requests.at(idx)] = idx;
00105     }
00106 }
00107 
00108 bool PDFRenderRequests::contains(const size_t page_number)
00109 {
00110     ScopeMutex m(&queue_mutex);
00111     return (queue.find(page_number) != queue.end());
00112 }
00113 
00114 }
Generated by  doxygen 1.6.2-20100208