00001 /*************** <auto-copyright.pl BEGIN do not edit this line> ************** 00002 * 00003 * VR Juggler is (C) Copyright 1998-2005 by Iowa State University 00004 * 00005 * Original Authors: 00006 * Allen Bierbaum, Christopher Just, 00007 * Patrick Hartling, Kevin Meinert, 00008 * Carolina Cruz-Neira, Albert Baker 00009 * 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Library General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 2 of the License, or (at your option) any later version. 00014 * 00015 * This library is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00018 * Library General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Library General Public 00021 * License along with this library; if not, write to the 00022 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00023 * Boston, MA 02111-1307, USA. 00024 * 00025 * ----------------------------------------------------------------- 00026 * File: $RCSfile$ 00027 * Date modified: $Date: 2005-01-01 14:59:16 -0600 (Sat, 01 Jan 2005) $ 00028 * Version: $Revision: 16524 $ 00029 * ----------------------------------------------------------------- 00030 * 00031 *************** <auto-copyright.pl END do not edit this line> ***************/ 00032 00033 #include <gadget/gadgetConfig.h> 00034 00035 #include <iomanip> 00036 #include <typeinfo> 00037 00038 #include <gadget/Type/AnalogProxy.h> 00039 #include <gadget/Type/DigitalProxy.h> 00040 #include <gadget/Type/PositionProxy.h> 00041 #include <gadget/Type/GloveProxy.h> 00042 #include <gadget/Type/GestureProxy.h> 00043 #include <gadget/Type/KeyboardMouseProxy.h> 00044 #include <gadget/Type/CommandProxy.h> 00045 #include <gadget/Type/StringProxy.h> 00046 #include <gadget/ProxyDepChecker.h> 00047 #include <gadget/ProxyFactory.h> 00048 #include <gadget/Util/Debug.h> 00049 #include <jccl/Config/ConfigElement.h> 00050 00051 00052 namespace gadget 00053 { 00054 00055 // Initialize the singleton ptr 00056 vprSingletonImpWithInitFunc( ProxyFactory, loadKnownProxies ); 00057 00058 template <class PROXY> 00059 ProxyConstructor<PROXY>::ProxyConstructor() 00060 { 00061 ProxyFactory::instance()->registerProxy(this); 00062 } 00063 00064 00065 // Register all the proxies that I know about 00066 void ProxyFactory::loadKnownProxies() 00067 { 00068 ProxyConstructor<AnalogProxy>* analog_proxy = new ProxyConstructor<AnalogProxy>; 00069 ProxyConstructor<DigitalProxy>* digital_proxy = new ProxyConstructor<DigitalProxy>; 00070 ProxyConstructor<PositionProxy>* pos_proxy = new ProxyConstructor<PositionProxy>; 00071 ProxyConstructor<GloveProxy>* glove_proxy = new ProxyConstructor<GloveProxy>; 00072 // ProxyConstructor<GestureProxy>* gesture_proxy = new ProxyConstructor<GestureProxy>; 00073 ProxyConstructor<KeyboardMouseProxy>* keyboard_mouse_proxy = new ProxyConstructor<KeyboardMouseProxy>; 00074 ProxyConstructor<CommandProxy>* command_proxy = new ProxyConstructor<CommandProxy>; 00075 ProxyConstructor<StringProxy>* string_proxy = new ProxyConstructor<StringProxy>; 00076 00077 if( (NULL == analog_proxy) || 00078 (NULL == digital_proxy) || 00079 (NULL == pos_proxy) || 00080 (NULL == glove_proxy) || 00081 // (NULL == gesture_proxy) || 00082 (NULL == keyboard_mouse_proxy) || 00083 (NULL == command_proxy) || 00084 (NULL == string_proxy) ) 00085 { 00086 vprDEBUG(vprDBG_ALL, vprDBG_CRITICAL_LVL) << "Error allocating proxy constructor.\n" << vprDEBUG_FLUSH; 00087 } 00088 00089 00090 jccl::DependencyManager::instance()->registerChecker(new ProxyDepChecker()); 00091 } 00092 00093 void ProxyFactory::registerProxy(ProxyConstructorBase* constructor) 00094 { 00095 mConstructors.push_back(constructor); // Add the constructor to the list 00096 vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL) 00097 << "gadget::ProxyFactory: Constructor registered for: " 00098 << std::setiosflags(std::ios::right) << std::setw(25) 00099 << std::setfill(' ') << constructor->getElementType() 00100 << std::resetiosflags(std::ios::right) 00101 //<< " :" << (void*)constructor 00102 << " type: " << typeid(*constructor).name() << std::endl 00103 << vprDEBUG_FLUSH; 00104 } 00105 00106 // Simply query all proxy constructors registered looking 00107 // for one that knows how to load the proxy 00108 bool ProxyFactory::recognizeProxy(jccl::ConfigElementPtr element) 00109 { 00110 return ! (findConstructor(element) == -1); 00111 } 00112 00116 Proxy* ProxyFactory::loadProxy(jccl::ConfigElementPtr element) 00117 { 00118 vprASSERT(recognizeProxy(element)); 00119 00120 int index = findConstructor(element); 00121 00122 Proxy* new_proxy; 00123 ProxyConstructorBase* constructor = mConstructors[index]; 00124 00125 vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL) 00126 << "[gadget::ProxyFactory::loadProxy] Loading proxy: " 00127 << element->getID() << " with: " 00128 << typeid(*constructor).name() << std::endl << vprDEBUG_FLUSH; 00129 new_proxy = constructor->createProxy(element); 00130 return new_proxy; 00131 } 00132 00133 int ProxyFactory::findConstructor(jccl::ConfigElementPtr element) 00134 { 00135 std::string element_type(element->getID()); 00136 00137 for(unsigned i=0;i<mConstructors.size();i++) 00138 { 00139 if(mConstructors[i]->getElementType() == element_type) 00140 { 00141 return i; 00142 } 00143 } 00144 00145 return -1; 00146 } 00147 00148 } // End of gadget namespace
1.5.1