00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <SDL/SDL.h>
00026 #include <SDLSystem.h>
00027
00028 namespace cmil {
00029 namespace SDL {
00030 bool SDLSystem::Parameters::add(const Supported device_type) {
00031 return SDLSystem::Parameters::add(device_type, NULL);
00032 }
00033
00037
00038 bool SDLSystem::Parameters::add(const Supported dev_type, InputDevice* custom) {
00040 MapList::iterator i;
00041
00042 if( (i = m_index.find(dev_type)) == m_index.end() ) {
00043 m_index.insert( MapListPair(dev_type, InputDeviceList(1, custom)) ) ;
00044 }
00045 else {
00047 (i->second).push_back(custom);
00048 }
00049
00050 return false;
00051 }
00052
00053 SDLSystem::SDLSystem() : m_default_translator(new SDLTranslator(this)) { init(); }
00054
00055 SDLSystem::SDLSystem(const SDLSystem::Parameters& params, InputArbitrator* const arbitrator) :
00056 System(arbitrator),
00057 m_default_translator(new SDLTranslator(this))
00058 { init(params); }
00059
00060 SDLSystem::SDLSystem(const SDLSystem::Parameters& params) :
00061 m_default_translator(new SDLTranslator(this))
00062 { init(params); }
00063
00064 void SDLSystem::init() {
00065 m_translators.addTranslator(m_default_translator);
00066
00067 m_default_translator->addTranslated(SupportedFactory::create(Mice, this));
00068
00069
00070 m_default_translator->addTranslated(SupportedFactory::create(Keyboards, this));
00071
00072
00073
00074
00075 registerDevices(m_default_translator->getDevices());
00076 }
00077
00080
00081 void SDLSystem::init(const SDLSystem::Parameters& params) {
00082 DeviceTranslator* dev_translated = NULL;
00083 bool valid_param = false;
00084
00085 for(Parameters::MapList::const_iterator i = params.m_index.begin(); i != params.m_index.end(); ++i) {
00086 dev_translated = SupportedFactory::create(i->first, this);
00087
00088 if(dev_translated) {
00089 valid_param = true;
00091
00092 if(!(i->second.empty()))
00094 for(Parameters::InputDeviceList::const_iterator j = i->second.begin() ; j != i->second.end() ; ++j) {
00095 if (*j) {
00096 log_debug(std::string("init() attempted to add custom device named: ").append((*j)->getName())
00097 .append(" to device translator. "));
00098 dev_translated->addCustomDevice(*j);
00099 }
00100 else
00101 log_debug("init() Null custom device set in parameter device translator, no custom device will be provided for this iteration.");
00102 }
00103
00104 log_debug("init() adding device translator ");
00105 m_default_translator->addTranslated(dev_translated);
00106 }
00107 else
00108 log_error("init() invalid translated device type passed to init()");
00109 }
00110
00111 if(valid_param) {
00112 m_translators.addTranslator(m_default_translator);
00113 registerDevices(m_default_translator->getDevices());
00114 }
00115 else {
00117 init();
00118 }
00119 }
00120
00121 void SDLSystem::poll() {
00122 m_default_translator->poll();
00123 }
00124 }
00125 }