SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
soloader.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 /*
30  *@file soloader.h
31  *@brief These functions are used to abstract the interface for
32  *accessing shared libraries (.so for unix and .dll for windows)
33  *
34  *@author Chris Moulding
35  *@Date Nov 1998
36  */
37 
38 #ifndef SOLOADER_H_
39 #define SOLOADER_H_
40 
41 
42 #include <string>
43 
44 
45 #ifdef _WIN32
46 # define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */
47 # include <windows.h> // for LoadLibrary(), GetProcAddress() and HINSTANCE
48  typedef HINSTANCE LIBRARY_HANDLE;
49 #else
50 # include <dlfcn.h> // for dlopen() and dlsym()
51  typedef void* LIBRARY_HANDLE;
52 #endif
53 
55 /////////////////////////////////////////////////////////////////
56 /// GetLibrarySymbolAddress()
57 /// returns a pointer to the data or function called "symbolname"
58 /// from within the shared library called "libname"
59 
60 SCISHARE void* GetLibrarySymbolAddress(const std::string libname, const std::string symbolname, std::string& errormsg);
61 
62 inline void* GetLibrarySymbolAddress(const std::string libname, const std::string symbolname)
63 {
64  std::string errormsg;
65  return (GetLibrarySymbolAddress(libname,symbolname,errormsg));
66 }
67 
68 
69 /////////////////////////////////////////////////////////////////
70 /// GetLibraryHandle()
71 /// opens, and returns the handle to, the library module
72 /// called "libname"
73 
74 SCISHARE LIBRARY_HANDLE GetLibraryHandle(const std::string libname, std::string& errormsg);
75 
76 inline LIBRARY_HANDLE GetLibraryHandle(const std::string libname)
77 {
78  std::string errormsg;
79  return (GetLibraryHandle(libname,errormsg));
80 }
81 
83 {
84  std::string errormsg;
85  return (GetLibraryHandle("",errormsg));
86 }
87 
88 /////////////////////////////////////////////////////////////////
89 /// GetHandleSymbolAddress()
90 /// returns a pointer to the data or function called "symbolname"
91 /// from within the shared library with handle "handle"
92 
93 SCISHARE void* GetHandleSymbolAddress(LIBRARY_HANDLE handle, const std::string symbolname, std::string& errormsg);
94 
95 /////////////////////////////////////////////////////////////////
96 /// CloseLibrary()
97 ///
98 /// disassociates the given library handle from the calling process.
99 
101 
102 
103 ////////////////////////////////////////////////////////////////
104 /// SOError()
105 /// returns the last error generated by one of the above functions.
106 /// SCISHARE const char* SOError();
107 
108 SCISHARE LIBRARY_HANDLE findLib(std::string lib, std::string& errormsg);
109 
110 inline LIBRARY_HANDLE findLib(std::string lib)
111 {
112  std::string errormsg;
113  return (findLib(lib,errormsg));
114 }
115 
116 SCISHARE LIBRARY_HANDLE FindLibInPath(const std::string& lib, const std::string& path,std::string& errormsg);
117 
118 inline SCISHARE LIBRARY_HANDLE FindLibInPath(const std::string& lib, const std::string& path)
119 {
120  std::string errormsg;
121  return (FindLibInPath(lib,path,errormsg));
122 }
123 
124 #endif
SCISHARE void * GetLibrarySymbolAddress(const std::string libname, const std::string symbolname, std::string &errormsg)
#define SCISHARE
Definition: share.h:39
void * LIBRARY_HANDLE
Definition: soloader.h:51
SCISHARE LIBRARY_HANDLE GetLibraryHandle(const std::string libname, std::string &errormsg)
SCISHARE void * GetHandleSymbolAddress(LIBRARY_HANDLE handle, const std::string symbolname, std::string &errormsg)
SCISHARE void CloseLibrary(LIBRARY_HANDLE)
SCISHARE LIBRARY_HANDLE findLib(std::string lib, std::string &errormsg)
SCISHARE LIBRARY_HANDLE FindLibInPath(const std::string &lib, const std::string &path, std::string &errormsg)