src/CommandScheduler.cpp

00001 #include "CommandScheduler.h"
00002 #include "cppsqlite3.h"
00003 #include "Logger.h"
00004 
00005 CommandScheduler* CommandScheduler::pUniqueInstance = NULL; // Reference to the unique instance.
00006 SDL_mutex* CommandScheduler::mxInstance = SDL_CreateMutex();                            // Reference to instance mutex.
00007 
00008 CommandScheduler* CommandScheduler::getInstance(){
00009         SDL_LockMutex(mxInstance);      // Locks the mutex...
00010         if (pUniqueInstance == NULL){ // No instance, create one.
00011         pUniqueInstance = new CommandScheduler();
00012     }
00013     SDL_UnlockMutex(mxInstance);        // Unlocks the mutex...
00014     return pUniqueInstance;
00015 }
00016 
00017 void CommandScheduler::freeInstance(){
00018         SDL_LockMutex(mxInstance);      // Locks the mutex...
00019         if (pUniqueInstance != NULL) {
00020         delete pUniqueInstance;
00021         pUniqueInstance = NULL;
00022     }
00023         SDL_UnlockMutex(mxInstance);    // Unlocks the mutex...
00024 }
00025 
00026 void CommandScheduler::setServer(Server* myServer){
00027         SDL_LockMutex(mxServer);
00028         this->myServer = myServer;              // Sets the CommandManager Server.
00029         SDL_UnlockMutex(mxServer);
00030 }
00031 
00032 void CommandScheduler::queue(ICommand* cmd){
00033     try{
00034         cmd->execute();
00035     }
00036     catch(CppSQLite3Exception& e){ // Database exception.
00037         delete cmd;
00038         std::string err = "Generic database error: ";
00039         err.append(e.errorMessage());
00040         err.append(".");
00041         std::cout << err << std::endl;
00042         Logger::getInstance()->log(err,LOGMODE_DB);
00043     }
00044 
00045         delete cmd;
00046 }
00047 
00048 CommandScheduler::CommandScheduler()
00049         :mxServer(SDL_CreateMutex())
00050 {
00051 }
00052 
00053 CommandScheduler::~CommandScheduler()
00054 {
00055         SDL_DestroyMutex(mxServer);
00056 }

Generated on Mon Dec 3 04:30:12 2007 for lo-testserver by  doxygen 1.3.9.1