comparison Plugins/Engine/PluginsManager.cpp @ 893:f57802f8b4dc plugins

plugins for windows
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 16 Jun 2014 16:14:56 +0200
parents d2a393061eb6
children 690aeb4cb899
comparison
equal deleted inserted replaced
892:517e28b420af 893:f57802f8b4dc
51 static void CallInitialize(SharedLibrary& plugin, 51 static void CallInitialize(SharedLibrary& plugin,
52 const OrthancPluginContext& context) 52 const OrthancPluginContext& context)
53 { 53 {
54 typedef int32_t (*Initialize) (const OrthancPluginContext*); 54 typedef int32_t (*Initialize) (const OrthancPluginContext*);
55 55
56 #if defined(_WIN32)
57 Initialize initialize = (Initialize) plugin.GetFunction("OrthancPluginInitialize");
58 #else
56 /** 59 /**
57 * gcc would complain about "ISO C++ forbids casting between 60 * gcc would complain about "ISO C++ forbids casting between
58 * pointer-to-function and pointer-to-object" without the trick 61 * pointer-to-function and pointer-to-object" without the trick
59 * below, that is known as "the POSIX.1-2003 (Technical Corrigendum 62 * below, that is known as "the POSIX.1-2003 (Technical Corrigendum
60 * 1) workaround". See the man page of "dlsym()". 63 * 1) workaround". See the man page of "dlsym()".
62 * http://stackoverflow.com/a/14543811/881731 65 * http://stackoverflow.com/a/14543811/881731
63 **/ 66 **/
64 67
65 Initialize initialize; 68 Initialize initialize;
66 *(void **) (&initialize) = plugin.GetFunction("OrthancPluginInitialize"); 69 *(void **) (&initialize) = plugin.GetFunction("OrthancPluginInitialize");
70 #endif
71
67 assert(initialize != NULL); 72 assert(initialize != NULL);
68
69 int32_t error = initialize(&context); 73 int32_t error = initialize(&context);
70 74
71 if (error != 0) 75 if (error != 0)
72 { 76 {
73 LOG(ERROR) << "Error while initializing plugin " << plugin.GetPath() 77 LOG(ERROR) << "Error while initializing plugin " << plugin.GetPath()
79 83
80 static void CallFinalize(SharedLibrary& plugin) 84 static void CallFinalize(SharedLibrary& plugin)
81 { 85 {
82 typedef void (*Finalize) (); 86 typedef void (*Finalize) ();
83 87
88 #if defined(_WIN32)
89 Finalize finalize = (Finalize) plugin.GetFunction("OrthancPluginFinalize");
90 #else
84 Finalize finalize; 91 Finalize finalize;
85 *(void **) (&finalize) = plugin.GetFunction("OrthancPluginFinalize"); 92 *(void **) (&finalize) = plugin.GetFunction("OrthancPluginFinalize");
93 #endif
94
86 assert(finalize != NULL); 95 assert(finalize != NULL);
87
88 finalize(); 96 finalize();
89 } 97 }
90 98
91 99
92 static const char* CallGetName(SharedLibrary& plugin) 100 static const char* CallGetName(SharedLibrary& plugin)
93 { 101 {
94 typedef const char* (*GetName) (); 102 typedef const char* (*GetName) ();
95 103
104 #if defined(_WIN32)
105 GetName getName = (GetName) plugin.GetFunction("OrthancPluginGetName");
106 #else
96 GetName getName; 107 GetName getName;
97 *(void **) (&getName) = plugin.GetFunction("OrthancPluginGetName"); 108 *(void **) (&getName) = plugin.GetFunction("OrthancPluginGetName");
109 #endif
110
98 assert(getName != NULL); 111 assert(getName != NULL);
99
100 return getName(); 112 return getName();
101 } 113 }
102 114
103 115
104 static const char* CallGetVersion(SharedLibrary& plugin) 116 static const char* CallGetVersion(SharedLibrary& plugin)
105 { 117 {
106 typedef const char* (*GetVersion) (); 118 typedef const char* (*GetVersion) ();
107 119
120 #if defined(_WIN32)
121 GetVersion getVersion = (GetVersion) plugin.GetFunction("OrthancPluginGetVersion");
122 #else
108 GetVersion getVersion; 123 GetVersion getVersion;
109 *(void **) (&getVersion) = plugin.GetFunction("OrthancPluginGetVersion"); 124 *(void **) (&getVersion) = plugin.GetFunction("OrthancPluginGetVersion");
125 #endif
126
110 assert(getVersion != NULL); 127 assert(getVersion != NULL);
111
112 return getVersion(); 128 return getVersion();
113 } 129 }
114 130
115 131
116 static void LogError(const char* str) 132 static void LogError(const char* str)
148 { 164 {
149 for (Plugins::iterator it = plugins_.begin(); it != plugins_.end(); it++) 165 for (Plugins::iterator it = plugins_.begin(); it != plugins_.end(); it++)
150 { 166 {
151 if (it->second != NULL) 167 if (it->second != NULL)
152 { 168 {
169 LOG(WARNING) << "Unregistering plugin '" << CallGetName(*it->second)
170 << "' (version " << CallGetVersion(*it->second) << ")";
171
153 CallFinalize(*(it->second)); 172 CallFinalize(*(it->second));
154 delete it->second; 173 delete it->second;
155 } 174 }
156 } 175 }
157 } 176 }