CommandScheduler Class Reference

#include <CommandScheduler.h>

List of all members.

Public Member Functions

void setServer (Server *myServer)
void queue (ICommand *cmd)

Static Public Member Functions

CommandSchedulergetInstance ()
void freeInstance ()

Private Attributes

ServermyServer
SDL_mutex * mxServer

Static Private Attributes

CommandSchedulerpUniqueInstance = NULL
SDL_mutex * mxInstance = SDL_CreateMutex()


Detailed Description

Schedules and executes commands.

Definition at line 15 of file CommandScheduler.h.


Member Function Documentation

void CommandScheduler::freeInstance  )  [static]
 

Deletes the class's instance.

Author:
stonedz
Since:
pre-alpha

Definition at line 17 of file CommandScheduler.cpp.

References mxInstance, and pUniqueInstance.

00017                                    {
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 }

CommandScheduler * CommandScheduler::getInstance  )  [static]
 

Returns class' instance.

Author:
stonedz
Since:
pre-alpha
Returns:
Class' instance.

Definition at line 8 of file CommandScheduler.cpp.

References mxInstance, and pUniqueInstance.

00008                                                {
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 }

void CommandScheduler::queue ICommand *  cmd  ) 
 

Queues commands and executes them.

In the final implementation this method will queue commands and then schedule them for execution. As for now, it executes the command.

Author:
stonedz
Since:
pre-alpha
Parameters:
cmd The ICommand to queue.
Todo:
TODO Finish the implementation.

Definition at line 32 of file CommandScheduler.cpp.

References Logger::getInstance(), and Logger::log().

Referenced by CommandManager::processCommand().

00032                                          {
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 }

void CommandScheduler::setServer Server myServer  ) 
 

Sets the Server the CommandScheduler refers to.

Author:
stonedz
Since:
pre-alpha
Parameters:
myServer A valid Server pointer.

Definition at line 26 of file CommandScheduler.cpp.

References mxServer.

Referenced by CommandManager::setServer().

00026                                                 {
00027         SDL_LockMutex(mxServer);
00028         this->myServer = myServer;              // Sets the CommandManager Server.
00029         SDL_UnlockMutex(mxServer);
00030 }


Member Data Documentation

SDL_mutex * CommandScheduler::mxInstance = SDL_CreateMutex() [static, private]
 

Instance mutex, for thread safetyness.

Definition at line 6 of file CommandScheduler.cpp.

Referenced by freeInstance(), and getInstance().

SDL_mutex* CommandScheduler::mxServer [private]
 

Server's mutex.

Definition at line 64 of file CommandScheduler.h.

Referenced by setServer().

Server* CommandScheduler::myServer [private]
 

Points to a valid Server.

Definition at line 63 of file CommandScheduler.h.

CommandScheduler * CommandScheduler::pUniqueInstance = NULL [static, private]
 

Reference to unique CommandScheduler instance.

Definition at line 5 of file CommandScheduler.cpp.

Referenced by freeInstance(), and getInstance().


The documentation for this class was generated from the following files:
Generated on Mon Dec 3 04:30:13 2007 for lo-testserver by  doxygen 1.3.9.1