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

# Tools/Module/ModuleHandler.cpp

Go to the documentation of this file.

    00001 /**
    00002 * @file ModuleHandler.cpp
    00003 *
    00004 * Implementation of class ModuleHandler.
    00005 *
    00006 * @author Max Risler
    00007 * @author Martin Lötzsch
    00008 */
    00009
    00010 #include "ModuleHandler.h"
    00011 #include "Tools/Debugging/Debugging.h"
    00012
    00013 ModuleHandler::ModuleHandler()
    00014 {
    00015   for(int i = 0; i < SolutionRequest::numOfModules; i++)
    00016     pModuleSelectors[i] = 0;
    00017 }
    00018
    00019 ModuleSelector* ModuleHandler::pGetModuleSelector(SolutionRequest::ModuleID id) const
    00020 {
    00021   return pModuleSelectors[id];
    00022 }
    00023
    00024 bool ModuleHandler::handleMessage(InMessage& message)
    00025 {
    00026   bool handled = false;
    00027   for(int i = 0; i < SolutionRequest::numOfModules; i++)
    00028   {
    00029     if (pModuleSelectors[i] != 0)
    00030     {
    00031       if (pModuleSelectors[i]->handleMessage(message))
    00032       {
    00033         handled = true;
    00034         message.resetReadPosition();
    00035       }
    00036     }
    00037   }
    00038   return handled;
    00039 }
    00040
    00041 void ModuleHandler::setModuleSelector(SolutionRequest::ModuleID id, ModuleSelector *module)
    00042 {
    00043   pModuleSelectors[id] = module;
    00044   if (module!=0) module->init();
    00045 }
    00046
    00047 SolutionRequest::ModuleSolutionID ModuleHandler::getSelectedSolution(SolutionRequest::ModuleID id) const
    00048 {
    00049   if (pModuleSelectors[id] != 0)
    00050     return pModuleSelectors[id]->getSelectedSolution();
    00051   else
    00052     return SolutionRequest::disabled;
    00053 }
    00054
    00055 void ModuleHandler::selectSolution(SolutionRequest::ModuleID id, SolutionRequest::ModuleSolutionID solution)
    00056 {
    00057   if (pModuleSelectors[id] != 0 && pModuleSelectors[id]->getSelectedSolution()!=solution)
    00058   {
    00059     OUTPUT(idText, text, "ModuleHandler::selectSolution :" <<
    00060       " Switched solution for " << SolutionRequest::getModuleName(id) <<
    00061       " from " << SolutionRequest::getModuleSolutionName(id,pModuleSelectors[id]->getSelectedSolution()) <<
    00062       " to " << SolutionRequest::getModuleSolutionName(id,solution) );
    00063     pModuleSelectors[id]->selectSolution(solution);
    00064   }
    00065 }
    00066
    00067 void ModuleHandler::selectSolutions(SolutionRequest request)
    00068 {
    00069   for (int i=0; i < SolutionRequest::numOfModules; i++)
    00070     selectSolution((SolutionRequest::ModuleID)i,request.solutions[i]);
    00071 }