/home/jpf/code/cc/project/cmil/src/SDLSystem.cpp

Go to the documentation of this file.
00001 // =====================================================================================
00002 //       Filename:  SDLSystem.cpp
00003 //    Description:  
00004 //        Version:  1.0
00005 //        Created:  03/29/2007 07:05:15 PM EDT
00006 //       Revision:  none
00007 //       Compiler:  gcc 3.4.6
00008 // 
00009 //         Author:  John P. Feltz 
00010 //          Email:  jfeltz@gmail.com
00011 //          License:  Copyright (c) 2006-2007, John P. Feltz 
00012 //                    This program is free software; you can redistribute it and/or
00013 //                    modify it under the terms of the GNU General Public License as
00014 //                    published by the Free Software Foundation, version 2 of the
00015 //                    License.
00016 //                    This program is distributed in the hope that it will be
00017 //                    useful, but WITHOUT ANY WARRANTY; without even the implied
00018 //                    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00019 //                    PURPOSE.
00020 //                    See the GNU General Public License version 2 for more details.
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       //TODO debug support for these
00073       //m_default_translator->addTranslated(SupportedFactory::create(Controllers, this));
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 }

(c) 2006-2007 John P. Feltz
Generated on Wed Jul 25 16:08:02 2007 for Common Media Input Layer by doxygen 1.4.7

SourceForge.net Logo