Orocos Real-Time Toolkit  2.9.0
TypekitRepository.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Mon Jun 26 13:25:56 CEST 2006 Typekit.cxx
3 
4  Typekit.cxx - description
5  -------------------
6  begin : Mon June 26 2006
7  copyright : (C) 2006 Peter Soetens
8  email : peter.soetens@fmtc.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 #include "TypekitRepository.hpp"
40 #include "TypekitPlugin.hpp"
41 #include "TransportPlugin.hpp"
42 #include "../Logger.hpp"
43 #include <algorithm>
44 
45 namespace RTT {
46  using namespace detail;
47  using namespace std;
48 
49  static std::vector<TypekitPlugin*> Typekits;
50  static std::vector<TransportPlugin*> Transports;
51 
53  {
54  Logger::In in("TypekitRepository::Import");
55  for( vector<TypekitPlugin*>::iterator it = Typekits.begin(); it != Typekits.end(); ++it ) {
56  if ( (*it)->getName() == tkp->getName() ) {
57  log( Debug ) << "Typekit "<<tkp->getName() <<" already loaded: keeping old instance."<<Logger::endl;
58  delete tkp;
59  return;
60  }
61  }
62 
63  log( Info) << "Loading Typekit "<<tkp->getName() <<"."<<Logger::endl;
64  Typekits.push_back( tkp );
65 
66  if ( tkp->loadTypes() == false ) {
67  log( Error) << "Typekit "<<tkp->getName() <<" failed to load types."<<Logger::endl;
68  }
69 
70  if ( tkp->loadConstructors() == false ) {
71  log( Error) << "Typekit "<<tkp->getName() <<" failed to load type constructors."<<Logger::endl;
72  }
73  if ( tkp->loadOperators() == false ) {
74  log( Error) << "Typekit "<<tkp->getName() <<" failed to load type operators."<<Logger::endl;
75  }
76  if ( tkp->loadGlobals() == false ) {
77  log( Error) << "Typekit "<<tkp->getName() <<" failed to load global variables."<<Logger::endl;
78  }
79  }
80 
82  {
83  Logger::In in("TypekitRepository::Import");
84  for( vector<TransportPlugin*>::iterator it = Transports.begin(); it != Transports.end(); ++it ) {
85  if ( (*it)->getName() == trp->getName() ) {
86  log(Debug) << "Transport "<<trp->getTransportName() <<"://"<< trp->getTypekitName()<<" already loaded by plugin '"<<(*it)->getName()<<"': keeping old instance."<<Logger::endl;
87  delete trp;
88  return;
89  }
90  }
91 
92  log(Info) << "Loading Transport "<<trp->getTransportName() <<"://"<<trp->getTypekitName() <<"."<<Logger::endl;
93  Transports.push_back( trp );
94 
95  TypeInfoRepository::Instance()->registerTransport( trp );
96  }
97 
98  std::vector<std::string> TypekitRepository::getTypekits()
99  {
100  std::vector<std::string> ret;
101  for (std::vector<TypekitPlugin*>::const_iterator it = Typekits.begin();
102  it != Typekits.end(); ++it)
103  ret.push_back( (*it)->getName() );
104  return ret;
105  }
106 
107  std::vector<std::string> TypekitRepository::getTransports()
108  {
109  std::vector<std::string> ret;
110  for (std::vector<TransportPlugin*>::const_iterator it = Transports.begin();
111  it != Transports.end(); ++it)
112  ret.push_back( (*it)->getTransportName() + "://" + (*it)->getTypekitName() );
113  return ret;
114  }
115 
116  bool TypekitRepository::hasTypekit( const std::string& toolname )
117  {
118  for (std::vector<TypekitPlugin*>::const_iterator it = Typekits.begin();
119  it != Typekits.end(); ++it)
120  if ((*it)->getName() == toolname)
121  return true;
122  return false;
123  }
124 
125  bool TypekitRepository::hasTransport( const std::string& transportname )
126  {
127  for (std::vector<TransportPlugin*>::const_iterator it = Transports.begin();
128  it != Transports.end(); ++it)
129  if ((*it)->getTransportName() + "://" + (*it)->getTypekitName() == transportname)
130  return true;
131  return false;
132  }
133 
135  for (std::vector<TransportPlugin*>::const_iterator it = Transports.begin();
136  it != Transports.end(); ++it)
137  delete *it;
138  for (std::vector<TypekitPlugin*>::const_iterator it = Typekits.begin();
139  it != Typekits.end(); ++it)
140  delete *it;
141  }
142 }
static bool hasTypekit(const std::string &typekitname)
Check if a typekit with given name was already imported.
static bool hasTransport(const std::string &transportname)
Check if a transport with given name was already imported.
static std::vector< std::string > getTransports()
Get the names of all imported transports.
virtual bool loadGlobals()
Implement this function to add global variables to the type system.
static void Release()
Removes all Typekits and transports from memory.
virtual std::string getTypekitName() const =0
Returns the intended typekit name of this plugin.
virtual std::string getName()=0
Each plugin must have a unique name.
STL namespace.
static void Import(TypekitPlugin *tkp)
Import a typekit plugin into the type system of this process.
This interface defines how additional typekits are loaded into Orocos.
A class which registers TypeTransporter instances to types.
virtual std::string getTransportName() const =0
Returns the (protocol) name of this transport.
static std::vector< std::string > getTypekits()
Get the names of all imported typekits.
static std::ostream & endl(std::ostream &__os)
Definition: Logger.cpp:383
Notify the Logger in which &#39;module&#39; the message occured.
Definition: Logger.hpp:159
virtual bool loadOperators()=0
Implement this method to load Scripting operators on types, such as &#39;+&#39;, &#39;*&#39;, ... ...
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52
virtual bool loadTypes()=0
Implement this method to add types to the Orocos type system.
virtual bool loadConstructors()=0
Implement this method to load Scripting constructors of types, such as in C++.
virtual std::string getName() const =0
Each plugin must have a unique name.