Mercurial > hg > orthanc
annotate OrthancFramework/Sources/SharedLibrary.cpp @ 5657:dedbf019a707
Improved parsing of multiple numerical values in DICOM tags
author | Alain Mazy <am@orthanc.team> |
---|---|
date | Thu, 06 Jun 2024 17:55:13 +0200 |
parents | f7adfb22e20e |
children |
rev | line source |
---|---|
884
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1032
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
5640
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
f7adfb22e20e
updated copyright, as Orthanc Team now replaces Osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5485
diff
changeset
|
6 * Copyright (C) 2024-2024 Orthanc Team SRL, Belgium |
5485
48b8dae6dc77
upgrade to year 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
5185
diff
changeset
|
7 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
884
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * |
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * This program is free software: you can redistribute it and/or |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
10 * modify it under the terms of the GNU Lesser General Public License |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
11 * as published by the Free Software Foundation, either version 3 of |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
12 * the License, or (at your option) any later version. |
884
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * |
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * This program is distributed in the hope that it will be useful, but |
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * WITHOUT ANY WARRANTY; without even the implied warranty of |
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
17 * Lesser General Public License for more details. |
884
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * |
4119
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
19 * You should have received a copy of the GNU Lesser General Public |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
20 * License along with this program. If not, see |
bf7b9edf6b81
re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4044
diff
changeset
|
21 * <http://www.gnu.org/licenses/>. |
884
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 **/ |
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
2463
be5c0f4155f6
move SharedLibrary into OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
25 #include "PrecompiledHeaders.h" |
885
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
26 #include "SharedLibrary.h" |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
27 |
2463
be5c0f4155f6
move SharedLibrary into OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
28 #include "Logging.h" |
be5c0f4155f6
move SharedLibrary into OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2447
diff
changeset
|
29 #include "OrthancException.h" |
885
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
30 |
1630
ffd23c0104af
"/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1625
diff
changeset
|
31 #include <boost/filesystem.hpp> |
ffd23c0104af
"/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1625
diff
changeset
|
32 |
885
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
33 #if defined(_WIN32) |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
34 #include <windows.h> |
2364 | 35 #elif defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__OpenBSD__) |
885
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
36 #include <dlfcn.h> |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
37 #else |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
38 #error Support your platform here |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
39 #endif |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
40 |
884
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 namespace Orthanc |
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 { |
1631 | 43 SharedLibrary::SharedLibrary(const std::string& path) : |
44 path_(path), | |
45 handle_(NULL) | |
885
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
46 { |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
47 #if defined(_WIN32) |
1630
ffd23c0104af
"/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1625
diff
changeset
|
48 handle_ = ::LoadLibraryA(path_.c_str()); |
893
f57802f8b4dc
plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
887
diff
changeset
|
49 if (handle_ == NULL) |
885
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
50 { |
1630
ffd23c0104af
"/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1625
diff
changeset
|
51 LOG(ERROR) << "LoadLibrary(" << path_ << ") failed: Error " << ::GetLastError(); |
4373
c601f48c7c80
Explicit error log if trying to load a 32bit (resp. 64bit) plugin into a 64bit (resp. 32bit) version of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
52 |
c601f48c7c80
Explicit error log if trying to load a 32bit (resp. 64bit) plugin into a 64bit (resp. 32bit) version of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
53 if (::GetLastError() == ERROR_BAD_EXE_FORMAT && |
c601f48c7c80
Explicit error log if trying to load a 32bit (resp. 64bit) plugin into a 64bit (resp. 32bit) version of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
54 sizeof(void*) == 4) |
c601f48c7c80
Explicit error log if trying to load a 32bit (resp. 64bit) plugin into a 64bit (resp. 32bit) version of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
55 { |
c601f48c7c80
Explicit error log if trying to load a 32bit (resp. 64bit) plugin into a 64bit (resp. 32bit) version of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
56 throw OrthancException(ErrorCode_SharedLibrary, |
c601f48c7c80
Explicit error log if trying to load a 32bit (resp. 64bit) plugin into a 64bit (resp. 32bit) version of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
57 "You are most probably trying to load a 64bit plugin into a 32bit version of Orthanc"); |
c601f48c7c80
Explicit error log if trying to load a 32bit (resp. 64bit) plugin into a 64bit (resp. 32bit) version of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
58 } |
c601f48c7c80
Explicit error log if trying to load a 32bit (resp. 64bit) plugin into a 64bit (resp. 32bit) version of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
59 else if (::GetLastError() == ERROR_BAD_EXE_FORMAT && |
c601f48c7c80
Explicit error log if trying to load a 32bit (resp. 64bit) plugin into a 64bit (resp. 32bit) version of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
60 sizeof(void*) == 8) |
c601f48c7c80
Explicit error log if trying to load a 32bit (resp. 64bit) plugin into a 64bit (resp. 32bit) version of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
61 { |
c601f48c7c80
Explicit error log if trying to load a 32bit (resp. 64bit) plugin into a 64bit (resp. 32bit) version of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
62 throw OrthancException(ErrorCode_SharedLibrary, |
c601f48c7c80
Explicit error log if trying to load a 32bit (resp. 64bit) plugin into a 64bit (resp. 32bit) version of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
63 "You are most probably trying to load a 32bit plugin into a 64bit version of Orthanc"); |
c601f48c7c80
Explicit error log if trying to load a 32bit (resp. 64bit) plugin into a 64bit (resp. 32bit) version of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
64 } |
c601f48c7c80
Explicit error log if trying to load a 32bit (resp. 64bit) plugin into a 64bit (resp. 32bit) version of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
65 else |
c601f48c7c80
Explicit error log if trying to load a 32bit (resp. 64bit) plugin into a 64bit (resp. 32bit) version of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
66 { |
c601f48c7c80
Explicit error log if trying to load a 32bit (resp. 64bit) plugin into a 64bit (resp. 32bit) version of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
67 throw OrthancException(ErrorCode_SharedLibrary); |
c601f48c7c80
Explicit error log if trying to load a 32bit (resp. 64bit) plugin into a 64bit (resp. 32bit) version of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4300
diff
changeset
|
68 } |
885
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
69 } |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
70 |
2364 | 71 #elif defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__OpenBSD__) |
3788
626d5f4a5afb
disable RTLD_DEEPBIND if loading plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3696
diff
changeset
|
72 |
3696
b7087f928050
use of RTLD_DEEPBIND in dlopen() while loading plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
73 /** |
b7087f928050
use of RTLD_DEEPBIND in dlopen() while loading plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
74 * "RTLD_LOCAL" is the default, and is only present to be |
b7087f928050
use of RTLD_DEEPBIND in dlopen() while loading plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
75 * explicit. "RTLD_DEEPBIND" was added in Orthanc 1.6.0, in order |
b7087f928050
use of RTLD_DEEPBIND in dlopen() while loading plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
76 * to avoid crashes while loading plugins from the LSB binaries of |
b7087f928050
use of RTLD_DEEPBIND in dlopen() while loading plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
77 * the Orthanc core. |
3788
626d5f4a5afb
disable RTLD_DEEPBIND if loading plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3696
diff
changeset
|
78 * |
626d5f4a5afb
disable RTLD_DEEPBIND if loading plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3696
diff
changeset
|
79 * BUT this had no effect, and this results in a crash if loading |
626d5f4a5afb
disable RTLD_DEEPBIND if loading plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3696
diff
changeset
|
80 * the Python 2.7 plugin => We disabled it again in Orthanc 1.6.1. |
3696
b7087f928050
use of RTLD_DEEPBIND in dlopen() while loading plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
81 **/ |
3788
626d5f4a5afb
disable RTLD_DEEPBIND if loading plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3696
diff
changeset
|
82 |
626d5f4a5afb
disable RTLD_DEEPBIND if loading plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3696
diff
changeset
|
83 #if 0 // && defined(RTLD_DEEPBIND) // This is a GNU extension |
626d5f4a5afb
disable RTLD_DEEPBIND if loading plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3696
diff
changeset
|
84 // Disabled in Orthanc 1.6.1 |
3696
b7087f928050
use of RTLD_DEEPBIND in dlopen() while loading plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
85 handle_ = ::dlopen(path_.c_str(), RTLD_NOW | RTLD_LOCAL | RTLD_DEEPBIND); |
b7087f928050
use of RTLD_DEEPBIND in dlopen() while loading plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
86 #else |
b7087f928050
use of RTLD_DEEPBIND in dlopen() while loading plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
87 handle_ = ::dlopen(path_.c_str(), RTLD_NOW | RTLD_LOCAL); |
b7087f928050
use of RTLD_DEEPBIND in dlopen() while loading plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
88 #endif |
b7087f928050
use of RTLD_DEEPBIND in dlopen() while loading plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
89 |
885
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
90 if (handle_ == NULL) |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
91 { |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
92 std::string explanation; |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
93 const char *tmp = ::dlerror(); |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
94 if (tmp) |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
95 { |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
96 explanation = ": Error " + std::string(tmp); |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
97 } |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
98 |
1630
ffd23c0104af
"/system" URI gives information about the plugins used for storage area and DB back-end
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1625
diff
changeset
|
99 LOG(ERROR) << "dlopen(" << path_ << ") failed" << explanation; |
885
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
100 throw OrthancException(ErrorCode_SharedLibrary); |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
101 } |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
102 |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
103 #else |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
104 #error Support your platform here |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
105 #endif |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
106 } |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
107 |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
108 SharedLibrary::~SharedLibrary() |
884
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 { |
885
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
110 if (handle_) |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
111 { |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
112 #if defined(_WIN32) |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
113 ::FreeLibrary((HMODULE)handle_); |
2364 | 114 #elif defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__OpenBSD__) |
885
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
115 ::dlclose(handle_); |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
116 #else |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
117 #error Support your platform here |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
118 #endif |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
119 } |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
120 } |
884
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 |
885
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
122 |
4300 | 123 const std::string &SharedLibrary::GetPath() const |
124 { | |
125 return path_; | |
126 } | |
127 | |
128 | |
893
f57802f8b4dc
plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
887
diff
changeset
|
129 SharedLibrary::FunctionPointer SharedLibrary::GetFunctionInternal(const std::string& name) |
885
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
130 { |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
131 if (!handle_) |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
132 { |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
133 throw OrthancException(ErrorCode_InternalError); |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
134 } |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
135 |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
136 #if defined(_WIN32) |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
137 return ::GetProcAddress((HMODULE)handle_, name.c_str()); |
2364 | 138 #elif defined(__linux__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD_kernel__) || defined(__FreeBSD__) || defined(__OpenBSD__) |
885
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
139 return ::dlsym(handle_, name.c_str()); |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
140 #else |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
141 #error Support your platform here |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
142 #endif |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
143 } |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
144 |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
145 |
893
f57802f8b4dc
plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
887
diff
changeset
|
146 SharedLibrary::FunctionPointer SharedLibrary::GetFunction(const std::string& name) |
885
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
147 { |
893
f57802f8b4dc
plugins for windows
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
887
diff
changeset
|
148 SharedLibrary::FunctionPointer result = GetFunctionInternal(name); |
885
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
149 |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
150 if (result == NULL) |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
151 { |
2954
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
152 throw OrthancException( |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
153 ErrorCode_SharedLibrary, |
d924f9bb61cc
taking advantage of details in OrthancException
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2463
diff
changeset
|
154 "Shared library does not expose function \"" + name + "\""); |
885
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
155 } |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
156 else |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
157 { |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
158 return result; |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
159 } |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
160 } |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
161 |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
162 |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
163 bool SharedLibrary::HasFunction(const std::string& name) |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
164 { |
0570a8c859cb
SharedLibrary class
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
884
diff
changeset
|
165 return GetFunctionInternal(name) != NULL; |
884
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 } |
cd8a69aa4093
creation of branch plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 } |