Mercurial > hg > orthanc
changeset 892:517e28b420af plugins
integration mainline -> plugins
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 16 Jun 2014 15:41:13 +0200 |
parents | d0a08d8881b7 (diff) 816dccaeb7cf (current diff) |
children | f57802f8b4dc |
files | CMakeLists.txt Core/Toolbox.cpp |
diffstat | 15 files changed, 768 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/CMakeLists.txt Mon Jun 16 15:39:16 2014 +0200 +++ b/CMakeLists.txt Mon Jun 16 15:41:13 2014 +0200 @@ -114,6 +114,9 @@ OrthancCppClient/Series.cpp OrthancCppClient/Instance.cpp OrthancCppClient/Patient.cpp + + Plugins/Engine/SharedLibrary.cpp + Plugins/Engine/PluginsManager.cpp ) @@ -168,6 +171,7 @@ UnitTestsSources/UnitTestsMain.cpp UnitTestsSources/ImageProcessingTests.cpp UnitTestsSources/JpegLossless.cpp + UnitTestsSources/PluginsTests.cpp )
--- a/Core/Enumerations.h Mon Jun 16 15:39:16 2014 +0200 +++ b/Core/Enumerations.h Mon Jun 16 15:41:13 2014 +0200 @@ -71,7 +71,8 @@ ErrorCode_InexistentTag, ErrorCode_ReadOnly, ErrorCode_IncompatibleImageFormat, - ErrorCode_IncompatibleImageSize + ErrorCode_IncompatibleImageSize, + ErrorCode_SharedLibrary }; /**
--- a/Core/OrthancException.cpp Mon Jun 16 15:39:16 2014 +0200 +++ b/Core/OrthancException.cpp Mon Jun 16 15:41:13 2014 +0200 @@ -121,6 +121,9 @@ case ErrorCode_IncompatibleImageFormat: return "Incompatible format of the images"; + case ErrorCode_SharedLibrary: + return "Error while using a shared library (plugin)"; + case ErrorCode_Custom: default: return "???";
--- a/Core/Toolbox.cpp Mon Jun 16 15:39:16 2014 +0200 +++ b/Core/Toolbox.cpp Mon Jun 16 15:41:13 2014 +0200 @@ -845,5 +845,12 @@ } } } + + + bool Toolbox::IsExistingFile(const std::string& path) + { + return boost::filesystem::exists(path); + } + }
--- a/Core/Toolbox.h Mon Jun 16 15:39:16 2014 +0200 +++ b/Core/Toolbox.h Mon Jun 16 15:41:13 2014 +0200 @@ -130,5 +130,7 @@ const std::string& source); void CreateDirectory(const std::string& path); + + bool IsExistingFile(const std::string& path); } }
--- a/OrthancServer/OrthancRestApi/OrthancRestArchive.cpp Mon Jun 16 15:39:16 2014 +0200 +++ b/OrthancServer/OrthancRestApi/OrthancRestArchive.cpp Mon Jun 16 15:41:13 2014 +0200 @@ -38,6 +38,7 @@ #include "../../Core/Uuid.h" #include <glog/logging.h> +#include <stdio.h> #if defined(_MSC_VER) #define snprintf _snprintf
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Plugins/Engine/PluginsManager.cpp Mon Jun 16 15:41:13 2014 +0200 @@ -0,0 +1,244 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, + * Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#include "PluginsManager.h" + +#include <glog/logging.h> +#include <cassert> +#include <memory> +#include <boost/filesystem.hpp> + +#ifdef WIN32 +#define PLUGIN_EXTENSION ".dll" +#elif defined(__linux) +#define PLUGIN_EXTENSION ".so" +#else +#error Support your platform here +#endif + + +namespace Orthanc +{ + static void CallInitialize(SharedLibrary& plugin, + const OrthancPluginContext& context) + { + typedef int32_t (*Initialize) (const OrthancPluginContext*); + + /** + * gcc would complain about "ISO C++ forbids casting between + * pointer-to-function and pointer-to-object" without the trick + * below, that is known as "the POSIX.1-2003 (Technical Corrigendum + * 1) workaround". See the man page of "dlsym()". + * http://www.trilithium.com/johan/2004/12/problem-with-dlsym/ + * http://stackoverflow.com/a/14543811/881731 + **/ + + Initialize initialize; + *(void **) (&initialize) = plugin.GetFunction("OrthancPluginInitialize"); + assert(initialize != NULL); + + int32_t error = initialize(&context); + + if (error != 0) + { + LOG(ERROR) << "Error while initializing plugin " << plugin.GetPath() + << " (code " << error << ")"; + throw OrthancException(ErrorCode_SharedLibrary); + } + } + + + static void CallFinalize(SharedLibrary& plugin) + { + typedef void (*Finalize) (); + + Finalize finalize; + *(void **) (&finalize) = plugin.GetFunction("OrthancPluginFinalize"); + assert(finalize != NULL); + + finalize(); + } + + + static const char* CallGetName(SharedLibrary& plugin) + { + typedef const char* (*GetName) (); + + GetName getName; + *(void **) (&getName) = plugin.GetFunction("OrthancPluginGetName"); + assert(getName != NULL); + + return getName(); + } + + + static const char* CallGetVersion(SharedLibrary& plugin) + { + typedef const char* (*GetVersion) (); + + GetVersion getVersion; + *(void **) (&getVersion) = plugin.GetFunction("OrthancPluginGetVersion"); + assert(getVersion != NULL); + + return getVersion(); + } + + + static void LogError(const char* str) + { + LOG(ERROR) << str; + } + + static void LogWarning(const char* str) + { + LOG(WARNING) << str; + } + + static void LogInfo(const char* str) + { + LOG(INFO) << str; + } + + static int32_t InvokeService(const char* serviceName, + const void* serviceParameters) + { + // TODO + return 0; + } + + PluginsManager::PluginsManager() + { + context_.orthancVersion = ORTHANC_VERSION; + context_.InvokeService = InvokeService; + context_.LogError = LogError; + context_.LogWarning = LogWarning; + context_.LogInfo = LogInfo; + } + + PluginsManager::~PluginsManager() + { + for (Plugins::iterator it = plugins_.begin(); it != plugins_.end(); it++) + { + if (it->second != NULL) + { + CallFinalize(*(it->second)); + delete it->second; + } + } + } + + + static bool IsOrthancPlugin(SharedLibrary& library) + { + return (library.HasFunction("OrthancPluginInitialize") && + library.HasFunction("OrthancPluginFinalize") && + library.HasFunction("OrthancPluginGetName") && + library.HasFunction("OrthancPluginGetVersion")); + } + + + void PluginsManager::RegisterPlugin(const std::string& path) + { + std::auto_ptr<SharedLibrary> plugin(new SharedLibrary(path)); + + if (!IsOrthancPlugin(*plugin)) + { + LOG(ERROR) << "Plugin " << plugin->GetPath() + << " does not declare the proper entry functions"; + throw OrthancException(ErrorCode_SharedLibrary); + } + + std::string name(CallGetName(*plugin)); + if (plugins_.find(name) != plugins_.end()) + { + LOG(ERROR) << "Plugin '" << name << "' already registered"; + throw OrthancException(ErrorCode_SharedLibrary); + } + + LOG(WARNING) << "Registering plugin '" << name + << "' (version " << CallGetVersion(*plugin) << ")"; + + CallInitialize(*plugin, context_); + + plugins_[name] = plugin.release(); + } + + + void PluginsManager::ScanFolderForPlugins(const std::string& folder, + bool isRecursive) + { + using namespace boost::filesystem; + + if (!exists(folder)) + { + return; + } + + LOG(INFO) << "Scanning folder " << folder << " for plugins"; + + directory_iterator end_it; // default construction yields past-the-end + for (directory_iterator it(folder); + it != end_it; + ++it) + { + std::string path = it->path().string(); + + if (is_directory(it->status())) + { + if (isRecursive) + { + ScanFolderForPlugins(path, true); + } + } + else + { + if (boost::filesystem::extension(it->path()) == PLUGIN_EXTENSION) + { + LOG(INFO) << "Found a shared library: " << it->path(); + + try + { + SharedLibrary plugin(path); + if (IsOrthancPlugin(plugin)) + { + RegisterPlugin(path); + } + } + catch (OrthancException&) + { + } + } + } + } + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Plugins/Engine/PluginsManager.h Mon Jun 16 15:41:13 2014 +0200 @@ -0,0 +1,60 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, + * Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + +#include "SharedLibrary.h" +#include "../OrthancCPlugin/OrthancCPlugin.h" + +#include <map> + +namespace Orthanc +{ + class PluginsManager : boost::noncopyable + { + private: + typedef std::map<std::string, SharedLibrary*> Plugins; + + OrthancPluginContext context_; + Plugins plugins_; + + public: + PluginsManager(); + + ~PluginsManager(); + + void RegisterPlugin(const std::string& path); + + void ScanFolderForPlugins(const std::string& path, + bool isRecursive); + }; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Plugins/Engine/SharedLibrary.cpp Mon Jun 16 15:41:13 2014 +0200 @@ -0,0 +1,133 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, + * Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#include "SharedLibrary.h" + +#include "../../Core/Toolbox.h" + +#if defined(_WIN32) +#include <windows.h> +#elif defined(__linux) +#include <dlfcn.h> +#else +#error Support your platform here +#endif + +#include <glog/logging.h> + +namespace Orthanc +{ + SharedLibrary::SharedLibrary(const std::string& path) : + path_(path), + handle_(NULL) + { +#if defined(_WIN32) + handle_ = ::LoadLibraryA(path.c_str()); + if (handle == NULL) + { + LOG(ERROR) << "LoadLibrary(" << path << ") failed: Error " << ::GetLastError(); + throw OrthancException(ErrorCode_SharedLibrary); + } + +#elif defined(__linux) + handle_ = ::dlopen(path.c_str(), RTLD_NOW); + if (handle_ == NULL) + { + std::string explanation; + const char *tmp = ::dlerror(); + if (tmp) + { + explanation = ": Error " + std::string(tmp); + } + + LOG(ERROR) << "dlopen(" << path << ") failed" << explanation; + throw OrthancException(ErrorCode_SharedLibrary); + } + +#else +#error Support your platform here +#endif + } + + SharedLibrary::~SharedLibrary() + { + if (handle_) + { +#if defined(_WIN32) + ::FreeLibrary((HMODULE)handle_); +#elif defined(__linux) + ::dlclose(handle_); +#else +#error Support your platform here +#endif + } + } + + + void* SharedLibrary::GetFunctionInternal(const std::string& name) + { + if (!handle_) + { + throw OrthancException(ErrorCode_InternalError); + } + +#if defined(_WIN32) + return ::GetProcAddress((HMODULE)handle_, name.c_str()); +#elif defined(__linux) + return ::dlsym(handle_, name.c_str()); +#else +#error Support your platform here +#endif + } + + + void* SharedLibrary::GetFunction(const std::string& name) + { + void* result = GetFunctionInternal(name); + + if (result == NULL) + { + LOG(ERROR) << "Shared library does not expose function \"" << name << "\""; + throw OrthancException(ErrorCode_SharedLibrary); + } + else + { + return result; + } + } + + + bool SharedLibrary::HasFunction(const std::string& name) + { + return GetFunctionInternal(name) != NULL; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Plugins/Engine/SharedLibrary.h Mon Jun 16 15:41:13 2014 +0200 @@ -0,0 +1,63 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, + * Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + +#include "../../Core/OrthancException.h" + +#include <boost/noncopyable.hpp> + +namespace Orthanc +{ + class SharedLibrary : boost::noncopyable + { + private: + std::string path_; + void *handle_; + + void* GetFunctionInternal(const std::string& name); + + public: + SharedLibrary(const std::string& path); + + ~SharedLibrary(); + + const std::string& GetPath() const + { + return path_; + } + + bool HasFunction(const std::string& name); + + void* GetFunction(const std::string& name); + }; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Plugins/OrthancCPlugin/OrthancCPlugin.h Mon Jun 16 15:41:13 2014 +0200 @@ -0,0 +1,92 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, + * Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#pragma once + + +#ifdef _MSC_VER +#include "../../Resources/VisualStudio/stdint.h" +#else +#include <stdint.h> +#endif + + +#ifdef WIN32 +#define ORTHANC_PLUGINS_API __declspec(dllexport) +#else +#define ORTHANC_PLUGINS_API +#endif + + +#include <stdlib.h> + + +#ifdef __cplusplus +extern "C" +{ +#endif + + typedef void (*OrthancPluginLogError) (const char* str); + + typedef void (*OrthancPluginLogWarning) (const char* str); + + typedef void (*OrthancPluginLogInfo) (const char* str); + + typedef int32_t (*OrthancPluginService) (const char* serviceName, + const void* serviceParameters); + + typedef struct OrthancPluginContext + { + const char* orthancVersion; + OrthancPluginService InvokeService; + OrthancPluginLogError LogError; + OrthancPluginLogWarning LogWarning; + OrthancPluginLogInfo LogInfo; + + /* TODO REGISTER */ + + } OrthancPluginContext; + + + /** + Each plugin must define 4 functions, whose signature is: + - int32_t OrthancPluginInitialize(const OrthancPluginContext*); + - void OrthancPluginFinalize(); + - const char* OrthancPluginGetName(); + - const char* OrthancPluginGetVersion(); + + nm -C -D --defined-only libPluginTest.so + **/ + +#ifdef __cplusplus +} +#endif
--- a/Resources/Configuration.json Mon Jun 16 15:39:16 2014 +0200 +++ b/Resources/Configuration.json Mon Jun 16 15:41:13 2014 +0200 @@ -33,6 +33,9 @@ "LuaScripts" : [ ], + "Plugins" : [ + + ], /**
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Samples/Plugins/Basic/CMakeLists.txt Mon Jun 16 15:41:13 2014 +0200 @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 2.8) + +project(Basic) + +add_library(PluginTest SHARED Plugin.c) + +if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux") + # Linking with "pthread" is necessary, otherwise the software crashes + # http://sourceware.org/bugzilla/show_bug.cgi?id=10652#c17 + target_link_libraries(PluginTest pthread dl) +endif()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/Samples/Plugins/Basic/Plugin.c Mon Jun 16 15:41:13 2014 +0200 @@ -0,0 +1,66 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, + * Belgium + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + **/ + + +#include "../../../../Plugins/OrthancCPlugin/OrthancCPlugin.h" + +#include <string.h> +#include <stdio.h> + +static const OrthancPluginContext* context = NULL; + + +ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(const OrthancPluginContext* c) +{ + context = c; + context->LogWarning("Plugin is initializing"); + + char info[1024]; + sprintf(info, "The version of Orthanc is '%s'", context->orthancVersion); + + context->LogInfo(info); + + return 0; +} + + +ORTHANC_PLUGINS_API void OrthancPluginFinalize() +{ + context->LogWarning("Plugin is finalizing"); +} + + +ORTHANC_PLUGINS_API const char* OrthancPluginGetName() +{ + return "sample"; +} + + +ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() +{ + return "1.0"; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UnitTestsSources/PluginsTests.cpp Mon Jun 16 15:41:13 2014 +0200 @@ -0,0 +1,77 @@ +/** + * Orthanc - A Lightweight, RESTful DICOM Store + * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, + * Belgium + * + * This program is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * In addition, as a special exception, the copyright holders of this + * program give permission to link the code of its release with the + * OpenSSL project's "OpenSSL" library (or with modified versions of it + * that use the same license as the "OpenSSL" library), and distribute + * the linked executables. You must obey the GNU General Public License + * in all respects for all of the code used other than "OpenSSL". If you + * modify file(s) with this exception, you may extend this exception to + * your version of the file(s), but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. If you delete this exception statement from all source files + * in the program, then also delete it here. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + **/ + + +#include "PrecompiledHeadersUnitTests.h" +#include "gtest/gtest.h" + +#include <glog/logging.h> + +#include "../Plugins/Engine/PluginsManager.h" + +using namespace Orthanc; + +TEST(SharedLibrary, Basic) +{ +#if defined(_WIN32) +#error Support your platform here + +#elif defined(__linux) + SharedLibrary l("libdl.so"); + ASSERT_THROW(l.GetFunction("world"), OrthancException); + ASSERT_TRUE(l.GetFunction("dlopen") != NULL); + ASSERT_TRUE(l.HasFunction("dlclose")); + ASSERT_FALSE(l.HasFunction("world")); + +#else +#error Support your platform here +#endif + +} + + +TEST(SharedLibrary, Development) +{ + PluginsManager manager; + +#if defined(_WIN32) +#error Support your platform here + +#elif defined(__linux) + //manager.RegisterPlugin("./libPluginTest.so"); + //ASSERT_THROW(manager.RegisterPlugin("./libPluginTest.so"), OrthancException); + + manager.ScanFolderForPlugins(".", true); + +#else +#error Support your platform here +#endif +}