Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# Tools/Module/ModuleSelector.cpp

Go to the documentation of this file.

    00001 /**
    00002 * @file ModuleSelector.cpp
    00003 *
    00004 * Implementation of class ModuleSelector.
    00005 *
    00006 * @author Max Risler
    00007 * @author Martin Lötzsch
    00008 */
    00009
    00010 #include "ModuleSelector.h"
    00011 #include "Platform/GTAssert.h"
    00012 #include "Tools/Debugging/Debugging.h"
    00013
    00014 ModuleSelector::ModuleSelector(SolutionRequest::ModuleID id)
    00015 : moduleID(id), selectedSolution(0)
    00016 , maxRunTime(0), minRunTime(0xffffffff), averageRunTime(0), frameCounter(0)
    00017 {
    00018   selectedSolutionID = SolutionRequest::getDefaultSolution(id);
    00019 }
    00020
    00021 ModuleSelector::~ModuleSelector()
    00022 {
    00023   if (selectedSolution != 0) delete selectedSolution;
    00024 }
    00025
    00026 void ModuleSelector::selectSolution(SolutionRequest::ModuleSolutionID id)
    00027 {
    00028   ASSERT(id < solutionRequestMaxNumOfSolutions);
    00029   if (id != selectedSolutionID)
    00030   {
    00031     if (selectedSolution != 0)
    00032     {
    00033       delete selectedSolution;
    00034     }
    00035     selectedSolutionID=id;
    00036     init();
    00037   }
    00038 }
    00039
    00040 SolutionRequest::ModuleSolutionID ModuleSelector::getSelectedSolution() const
    00041 {
    00042   return selectedSolutionID;
    00043 }
    00044
    00045 void ModuleSelector::execute()
    00046 {
    00047   unsigned long time = SystemCall::getCurrentSystemTime();
    00048   if (selectedSolution != 0) selectedSolution->execute();
    00049   time = SystemCall::getTimeSince(time);
    00050   if (time > maxRunTime)
    00051   {
    00052     maxRunTime = time;
    00053   }
    00054   if (time < minRunTime)
    00055   {
    00056     minRunTime = time;
    00057   }
    00058   averageRunTime = averageRunTime*frameCounter + time;
    00059   frameCounter++;
    00060   averageRunTime /= frameCounter;
    00061 }
    00062
    00063 bool ModuleSelector::handleMessage(InMessage& message)
    00064 {
    00065   if (selectedSolution != 0)
    00066     return selectedSolution->handleMessage(message);
    00067   else
    00068     return false;
    00069 }
    00070
    00071 void ModuleSelector::init()
    00072 {
    00073   selectedSolution = this->createSolution(selectedSolutionID);
    00074   if ((selectedSolution == 0)&&(selectedSolutionID != SolutionRequest::disabled))
    00075   {
    00076     OUTPUT(idText,text,"ModuleSelector::init(): could not create default solution \""
    00077       << SolutionRequest::getModuleSolutionName(moduleID,selectedSolutionID)
    00078       << "\" of module \""
    00079       << SolutionRequest::getModuleName(moduleID) << "\".");
    00080   }
    00081 }