2 Copyright (c) 2002-2009 Tampere University.
4 This file is part of TTA-Based Codesign Environment (TCE).
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:
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
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.
25 * @file CostEstimationPluginRegistry.icc
27 * Implementations of templated CostEstimationPluginRegistry class
29 * @author Pekka Jääskeläinen 2005 (pjaaskel-no.spam-cs.tut.fi)
33 #include "boost/format.hpp"
35 #include "AssocTools.hh"
36 #include "FileSystem.hh"
37 #include "Exception.hh"
38 #include "Application.hh"
40 namespace CostEstimator {
42 /// the prefix of the function in the plugin file that is used to create new
43 /// estimator plugin instances
44 const std::string PLUGIN_CREATOR_FUNCTION_PREFIX =
45 "create_estimator_plugin_";
51 CostEstimationPluginRegistry<T>::CostEstimationPluginRegistry() {
52 pluginTools_.addSearchPath(FileSystem::currentWorkingDir());
59 CostEstimationPluginRegistry<T>::~CostEstimationPluginRegistry() {
60 /// @todo call the deletion function in the plugin instead, just in case
61 /// delete is overloaded in the plugin
62 AssocTools::deleteAllValues(registry_);
66 * Returns the plugin that is stored in the given path.
68 * In case the plugin is not found, tries to open it.
70 * @param pluginFileName The path of the plugin.
71 * @param pluginName The (class) name of the plugin.
72 * @param sourceHDB The HDB from which the plugin should fetch its data.
73 * @param pluginID The id of the plugin in the sourceHDB.
75 * @exception IOException In case an I/O error occured.
76 * @exception FileNotfound In case the plugin file was not found.
77 * @exception DynamicLibraryException In case the plugin interface is broken.
78 * @exception WrongSubClass In case the plugin is of wrong estimation plugin
83 CostEstimationPluginRegistry<T>::plugin(
84 const std::string& pluginFileName,
85 const std::string& pluginName)
88 T* pluginInstance = NULL;
90 if (AssocTools::containsKey(registry_, pluginFileName)) {
91 pluginInstance = registry_[pluginFileName];
93 /// try to load the plugin
95 std::string pluginFile = FileSystem::findFileInSearchPaths(
96 Environment::estimatorPluginPaths(), pluginFileName);
98 pluginTools_.importSymbol(
99 PLUGIN_CREATOR_FUNCTION_PREFIX + pluginName, creator,
101 pluginInstance = creator();
102 } catch (const FileNotFound& e) {
104 __FILE__, __LINE__, __func__,
105 (boost::format("Plugin file '%s' not found.") %
106 pluginFileName).str());
107 } catch (const Exception& e) {
108 throw DynamicLibraryException(
109 __FILE__, __LINE__, __func__,
110 std::string("Error while trying to import plugin. ") +
113 registry_[pluginFileName] = pluginInstance;
116 return *pluginInstance;