ServerWebServerQueue.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2003
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <webserver/ServerWebServer.h>
00022 
00023 ServerWebServerQueueEntry::ServerWebServerQueueEntry(
00024         unsigned int destinationId,
00025         unsigned int sid,
00026         const char *url,
00027         ServerWebServerI *handler,
00028         std::map<std::string, std::string> &fields,
00029         std::map<std::string, NetMessage *> &parts) :
00030         destinationId_(destinationId),
00031         sid_(sid), 
00032         request_(url, fields, parts),
00033         handler_(handler)
00034 {
00035 }
00036 
00037 ServerWebServerQueueEntry::~ServerWebServerQueueEntry()
00038 {
00039         delete handler_;
00040 }
00041 
00042 ServerWebServerQueue::ServerWebServerQueue() 
00043 {
00044         queueMutex_ = SDL_CreateMutex();
00045 }
00046 
00047 ServerWebServerQueue::~ServerWebServerQueue()
00048 {
00049 }
00050 
00051 void ServerWebServerQueue::addEntry(ServerWebServerQueueEntry *entry)
00052 {
00053         SDL_LockMutex(queueMutex_);
00054         entries_.push_back(entry);
00055         SDL_UnlockMutex(queueMutex_);
00056 }
00057 
00058 ServerWebServerQueueEntry *ServerWebServerQueue::getEntry()
00059 {
00060         ServerWebServerQueueEntry *result = 0;
00061         SDL_LockMutex(queueMutex_);
00062         if (!entries_.empty())
00063         {
00064                 result = entries_.front();
00065                 entries_.pop_front();
00066         }
00067         SDL_UnlockMutex(queueMutex_);
00068         return result;
00069 }
00070 
00071 void ServerWebServerQueue::removeEntry(unsigned int destinationId)
00072 {
00073         SDL_LockMutex(queueMutex_);
00074         std::list<ServerWebServerQueueEntry *>::iterator itor;
00075         for (itor = entries_.begin();
00076                 itor != entries_.end();
00077                 itor++)
00078         {
00079                 ServerWebServerQueueEntry *entry = *itor;
00080                 if (entry->getDestinationId() == destinationId)
00081                 {
00082                         entries_.erase(itor);
00083                         delete entry;
00084                         break;
00085                 }
00086         }
00087         SDL_UnlockMutex(queueMutex_);
00088 }
00089 
00090 bool ServerWebServerQueue::hasEntry(unsigned int destinationId)
00091 {
00092         bool result = false;
00093 
00094         SDL_LockMutex(queueMutex_);
00095         std::list<ServerWebServerQueueEntry *>::iterator itor;
00096         for (itor = entries_.begin();
00097                 itor != entries_.end();
00098                 itor++)
00099         {
00100                 ServerWebServerQueueEntry *entry = *itor;
00101                 if (entry->getDestinationId() == destinationId)
00102                 {
00103                         result = true;
00104                         break;
00105                 }
00106         }
00107         SDL_UnlockMutex(queueMutex_);
00108 
00109         return result;
00110 }

Generated on Mon Feb 16 15:14:53 2009 for Scorched3D by  doxygen 1.5.3