Orocos Real-Time Toolkit
2.6.0
|
00001 /*************************************************************************** 00002 tag: Peter Soetens Mon Jun 26 13:25:56 CEST 2006 Typekit.cxx 00003 00004 Typekit.cxx - description 00005 ------------------- 00006 begin : Mon June 26 2006 00007 copyright : (C) 2006 Peter Soetens 00008 email : peter.soetens@fmtc.be 00009 00010 *************************************************************************** 00011 * This library is free software; you can redistribute it and/or * 00012 * modify it under the terms of the GNU General Public * 00013 * License as published by the Free Software Foundation; * 00014 * version 2 of the License. * 00015 * * 00016 * As a special exception, you may use this file as part of a free * 00017 * software library without restriction. Specifically, if other files * 00018 * instantiate templates or use macros or inline functions from this * 00019 * file, or you compile this file and link it with other files to * 00020 * produce an executable, this file does not by itself cause the * 00021 * resulting executable to be covered by the GNU General Public * 00022 * License. This exception does not however invalidate any other * 00023 * reasons why the executable file might be covered by the GNU General * 00024 * Public License. * 00025 * * 00026 * This library is distributed in the hope that it will be useful, * 00027 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00028 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00029 * Lesser General Public License for more details. * 00030 * * 00031 * You should have received a copy of the GNU General Public * 00032 * License along with this library; if not, write to the Free Software * 00033 * Foundation, Inc., 59 Temple Place, * 00034 * Suite 330, Boston, MA 02111-1307 USA * 00035 * * 00036 ***************************************************************************/ 00037 00038 00039 #include "TypekitRepository.hpp" 00040 #include "TypekitPlugin.hpp" 00041 #include "TransportPlugin.hpp" 00042 #include "../Logger.hpp" 00043 #include <algorithm> 00044 00045 namespace RTT { 00046 using namespace detail; 00047 using namespace std; 00048 00049 static std::vector<TypekitPlugin*> Typekits; 00050 static std::vector<TransportPlugin*> Transports; 00051 00052 void TypekitRepository::Import( TypekitPlugin* tkp ) 00053 { 00054 Logger::In in("TypekitRepository::Import"); 00055 for( vector<TypekitPlugin*>::iterator it = Typekits.begin(); it != Typekits.end(); ++it ) { 00056 if ( (*it)->getName() == tkp->getName() ) { 00057 log( Debug ) << "Typekit "<<tkp->getName() <<" already loaded: keeping old instance."<<Logger::endl; 00058 delete tkp; 00059 return; 00060 } 00061 } 00062 00063 log( Info) << "Loading Typekit "<<tkp->getName() <<"."<<Logger::endl; 00064 Typekits.push_back( tkp ); 00065 00066 if ( tkp->loadTypes() == false ) { 00067 log( Error) << "Typekit "<<tkp->getName() <<" failed to load types."<<Logger::endl; 00068 } 00069 00070 if ( tkp->loadConstructors() == false ) { 00071 log( Error) << "Typekit "<<tkp->getName() <<" failed to load type constructors."<<Logger::endl; 00072 } 00073 if ( tkp->loadOperators() == false ) { 00074 log( Error) << "Typekit "<<tkp->getName() <<" failed to load type operators."<<Logger::endl; 00075 } 00076 if ( tkp->loadGlobals() == false ) { 00077 log( Error) << "Typekit "<<tkp->getName() <<" failed to load global variables."<<Logger::endl; 00078 } 00079 } 00080 00081 void TypekitRepository::Import( TransportPlugin* trp ) 00082 { 00083 Logger::In in("TypekitRepository::Import"); 00084 for( vector<TransportPlugin*>::iterator it = Transports.begin(); it != Transports.end(); ++it ) { 00085 if ( (*it)->getName() == trp->getName() ) { 00086 log(Debug) << "Transport "<<trp->getTransportName() <<"://"<< trp->getTypekitName()<<" already loaded by plugin '"<<(*it)->getName()<<"': keeping old instance."<<Logger::endl; 00087 delete trp; 00088 return; 00089 } 00090 } 00091 00092 log(Info) << "Loading Transport "<<trp->getTransportName() <<"://"<<trp->getTypekitName() <<"."<<Logger::endl; 00093 Transports.push_back( trp ); 00094 00095 TypeInfoRepository::Instance()->registerTransport( trp ); 00096 } 00097 00098 std::vector<std::string> TypekitRepository::getTypekits() 00099 { 00100 std::vector<std::string> ret; 00101 for (std::vector<TypekitPlugin*>::const_iterator it = Typekits.begin(); 00102 it != Typekits.end(); ++it) 00103 ret.push_back( (*it)->getName() ); 00104 return ret; 00105 } 00106 00107 std::vector<std::string> TypekitRepository::getTransports() 00108 { 00109 std::vector<std::string> ret; 00110 for (std::vector<TransportPlugin*>::const_iterator it = Transports.begin(); 00111 it != Transports.end(); ++it) 00112 ret.push_back( (*it)->getTransportName() + "://" + (*it)->getTypekitName() ); 00113 return ret; 00114 } 00115 00116 bool TypekitRepository::hasTypekit( const std::string& toolname ) 00117 { 00118 for (std::vector<TypekitPlugin*>::const_iterator it = Typekits.begin(); 00119 it != Typekits.end(); ++it) 00120 if ((*it)->getName() == toolname) 00121 return true; 00122 return false; 00123 } 00124 00125 bool TypekitRepository::hasTransport( const std::string& transportname ) 00126 { 00127 for (std::vector<TransportPlugin*>::const_iterator it = Transports.begin(); 00128 it != Transports.end(); ++it) 00129 if ((*it)->getTransportName() + "://" + (*it)->getTypekitName() == transportname) 00130 return true; 00131 return false; 00132 } 00133 00134 void TypekitRepository::Release() { 00135 for (std::vector<TransportPlugin*>::const_iterator it = Transports.begin(); 00136 it != Transports.end(); ++it) 00137 delete *it; 00138 for (std::vector<TypekitPlugin*>::const_iterator it = Typekits.begin(); 00139 it != Typekits.end(); ++it) 00140 delete *it; 00141 } 00142 }