00001 // ===================================================================================== 00002 // Filename: InputArbitrator.cpp 00003 // Description: 00004 // Created: 02/15/2007 08:47:46 PM EST 00005 // Revision: none 00006 // Compiler: gcc 3.4.6 00007 // 00008 // Author: John P. Feltz // Email: jfeltz@gmail.com 00009 // License: Copyright (c) 2006-2007, John P. Feltz 00010 // This program is free software; you can redistribute it and/or 00011 // modify it under the terms of the GNU General Public License as 00012 // published by the Free Software Foundation, version 2 of the 00013 // License. 00014 // This program is distributed in the hope that it will be 00015 // useful, but WITHOUT ANY WARRANTY; without even the implied 00016 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00017 // PURPOSE. 00018 // See the GNU General Public License version 2 for more details. 00019 // 00020 // ===================================================================================== 00021 00022 00023 #include <iostream> 00024 #include <map> 00025 #include <vector> 00026 #include <sstream> 00027 00028 #include <util/Singleton.h> 00029 #include <util/Logger.h> 00030 00031 #include <InputAction.h> 00032 #include <InputData.h> 00033 #include <InputEv.h> 00034 00035 #include <InputActor.h> 00036 #include <InputDevice.h> 00037 #include <InputArbitrator.h> 00038 00039 namespace cmil { 00040 using std::string; 00041 00042 string InputArbitrator::getDefaultDevice() const { 00043 return m_registry->getDefaultDevice(); 00044 } 00045 00046 InputData* const InputArbitrator::getData(int id) const { 00047 return m_registry->getData(id); 00048 } 00049 00050 InputData* const InputArbitrator::getData(const Ev& event) const { 00051 return m_registry->getData(event); 00052 } 00053 00054 const int InputArbitrator::getID(const Ev& event) const { 00055 return m_registry->getID(event); 00056 } 00057 00058 int InputArbitrator::getSize() const { 00059 return m_registry->getSize(); 00060 } 00061 00062 const bool InputArbitrator::isActionCompatible(int id, InputAction* action) const { 00063 std::ostringstream debug_ss; 00064 debug_ss << "isActionCompatible() deferring to data with id: " << id << "and name: " << getData(id)->getName(); 00065 log_debug(debug_ss.str() ); 00066 return getData(id)->isActionCompatible(action); 00067 } 00068 00069 void InputArbitrator::attach(InputActor* actor) { 00070 m_pActor = actor; 00071 } 00072 00073 void InputArbitrator::registerDevices(DeviceRegistry& dev) { 00074 log_debug("registerDevices()"); 00075 m_registry->mergeRegistry(dev); 00076 } 00077 00078 void InputArbitrator::registerDevice(InputDevice& dev) { 00079 m_registry->registerDevice(dev); 00080 } 00081 00082 void InputArbitrator::update(const ModData& input) { 00083 if(m_pActor) 00084 m_pActor->update(input); 00085 else 00086 log_debug("update() no InputActor set, can't update." ); 00087 } 00088 00089 void InputArbitrator::update(const InputData& input) { 00090 if(m_pActor) 00091 m_pActor->update(input); 00092 else 00093 log_debug( "update() no InputActor set, can't update." ); 00094 } 00095 00096 void InputArbitrator::quit() { 00097 if(m_pActor) 00098 m_pActor->quit(); 00099 else 00100 log_debug( "update() no InputActor set, can't send quit signal." ); 00101 } 00102 }