OpenASIP  2.0
PluginTools.hh
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file PluginTools.hh
26  *
27  * Declaration of PluginTools class.
28  *
29  * @author Jussi Nykänen 2004 (nykanen-no.spam-cs.tut.fi)
30  * @note reviewed 19 May 2004 by ml, jn, ao, am
31  * @note rating: green
32  */
33 
34 #ifndef TTA_PLUGIN_TOOLS_HH
35 #define TTA_PLUGIN_TOOLS_HH
36 
37 #include <string>
38 #include <vector>
39 #include <map>
40 
41 #include "Exception.hh"
42 
43 
44 /**
45  * Class that handles accessing of dynamic modules for providing run-time
46  * plug-in functionality.
47  *
48  * Class allows defining search paths, in which modules are searched. This
49  * enables registering modules without absolut paths to modules. Symbols
50  * (variables, functions) are loaded from modules and automatically cast
51  * to correct types by means of the template mechanism.
52  */
53 class PluginTools {
54 public:
55  PluginTools(bool lazyResolution = true, bool local = false);
56  virtual ~PluginTools();
57 
58  void addSearchPath(const std::string& searchPath);
59  void removeSearchPath(const std::string& searchPath);
60  void clearSearchPaths();
61 
62  void registerModule(const std::string& module);
63  void unregisterModule(const std::string& module);
64  void unregisterAllModules();
65 
66  template <typename T>
67  void importSymbol(
68  const std::string& symbolName, T*& target, const std::string& module);
69 
70  template <typename T>
71  void importSymbol(const std::string& symbolName, T*& target);
72 
73 private:
74  typedef std::vector<std::string>::iterator VecIter;
75  typedef std::map<std::string, void*>::iterator MapIter;
76  typedef std::map<std::string, void*>::value_type ValType;
77 
78  void* loadSym(
79  const std::string& symbolName, const std::string& module = "");
80 
81  std::string findModule(const std::string& module);
82 
83  /// Copying not allowed.
84  PluginTools(const PluginTools&);
85  /// Assignment not allowed.
87 
88  /// Search paths of dynamic modules.
89  std::vector<std::string> searchPaths_;
90  /// Map containing opened module handles.
91  std::map<std::string, void*> modules_;
92 
93  /// True if all undefined symbols should be resolved only when needed.
95  /// True if the symbols defined in the loaded library should be made
96  /// available for symbol resolution of subsequently loaded libraries.
98 
99 };
100 
101 #include "PluginTools.icc"
102 
103 #endif
PluginTools::ValType
std::map< std::string, void * >::value_type ValType
Definition: PluginTools.hh:76
PluginTools::findModule
std::string findModule(const std::string &module)
Definition: PluginTools.cc:346
Exception.hh
PluginTools
Definition: PluginTools.hh:53
PluginTools::searchPaths_
std::vector< std::string > searchPaths_
Search paths of dynamic modules.
Definition: PluginTools.hh:89
PluginTools::removeSearchPath
void removeSearchPath(const std::string &searchPath)
Definition: PluginTools.cc:110
PluginTools::localResolution_
bool localResolution_
True if the symbols defined in the loaded library should be made available for symbol resolution of s...
Definition: PluginTools.hh:97
PluginTools::PluginTools
PluginTools(bool lazyResolution=true, bool local=false)
Definition: PluginTools.cc:73
PluginTools::loadSym
void * loadSym(const std::string &symbolName, const std::string &module="")
Definition: PluginTools.cc:271
PluginTools::unregisterModule
void unregisterModule(const std::string &module)
Definition: PluginTools.cc:207
PluginTools::importSymbol
void importSymbol(const std::string &symbolName, T *&target, const std::string &module)
PluginTools::~PluginTools
virtual ~PluginTools()
Definition: PluginTools.cc:83
PluginTools::registerModule
void registerModule(const std::string &module)
Definition: PluginTools.cc:138
PluginTools::VecIter
std::vector< std::string >::iterator VecIter
Definition: PluginTools.hh:74
PluginTools.icc
PluginTools::modules_
std::map< std::string, void * > modules_
Map containing opened module handles.
Definition: PluginTools.hh:91
PluginTools::addSearchPath
void addSearchPath(const std::string &searchPath)
Definition: PluginTools.cc:95
PluginTools::clearSearchPaths
void clearSearchPaths()
Definition: PluginTools.cc:119
PluginTools::operator=
PluginTools & operator=(const PluginTools &)
Assignment not allowed.
PluginTools::MapIter
std::map< std::string, void * >::iterator MapIter
Definition: PluginTools.hh:75
PluginTools::lazyResolution_
bool lazyResolution_
True if all undefined symbols should be resolved only when needed.
Definition: PluginTools.hh:94
PluginTools::unregisterAllModules
void unregisterAllModules()
Definition: PluginTools.cc:236