OpenASIP  2.0
PluginTools.icc
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.icc
26  *
27  * Template method definitions of PluginTools.
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 #include <stdint.h>
35 
36 /**
37  * Loads a symbol from a module.
38  *
39  * The target symbol is cast to void* to make it possible to assign the
40  * loaded symbol to it.
41  *
42  * @param symbolName The symbol being loaded.
43  * @param target The target for loaded symbol.
44  * @param module The module where symbol is loaded from.
45  * @exception MultipleInstancesFound If multiple instances of module are
46  * found.
47  * @exception FileNotFound If module is not found.
48  * @exception DynamicLibraryException If occurs problems with dynamic
49  * libraries.
50  * @exception SymbolNotFound If symbol is not found.
51  */
52 template <typename T>
53 void
54 PluginTools::importSymbol(
55  const std::string& symbolName, T*& target, const std::string& module) {
56  /* This produces warnings with newer gcc's, but it seems it's
57  a known problem with dlsym():
58 
59  http://www.opengroup.org/onlinepubs/009695399/functions/dlsym.html
60  (see its rationale)
61 
62  http://stackoverflow.com/questions/1096341/function-pointers-casting-in-c
63  http://www.trilithium.com/johan/2004/12/problem-with-dlsym/
64  http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#573
65  */
66  target = (T*)(intptr_t)loadSym(symbolName, module);
67 }
68 
69 /**
70  * Loads a symbol.
71  *
72  * The target symbol is cast to void* to make it possible to assign the
73  * loaded symbol to it.
74  *
75  * @param symbolName The symbol being loaded.
76  * @param target The target where symbol is stored.
77  * @exception MultipleInstancesFound If multiple instances of module are
78  * found.
79  * @exception FileNotFound If module is not found.
80  * @exception DynamicLibraryException If occurs problems with dynamic
81  * libraries.
82  * @exception SymbolNotFound If symbol is not found.
83  */
84 template <typename T>
85 void
86 PluginTools::importSymbol(const std::string& symbolName, T*& target) {
87  target = (T*)(intptr_t)loadSym(symbolName);
88 }