diff --git a/Applications/CoreApp/CMakeLists.txt b/Applications/CoreApp/CMakeLists.txt index 407a4b5cd5..adf226b3e0 100644 --- a/Applications/CoreApp/CMakeLists.txt +++ b/Applications/CoreApp/CMakeLists.txt @@ -1,35 +1,36 @@ project(CoreApp) set(_app_options) if(MITK_SHOW_CONSOLE_WINDOW) list(APPEND _app_options SHOW_CONSOLE) endif() +# Create a cache entry for the provisioning file which is used to export +# the file name in the MITKConfig.cmake file. This will keep external projects +# which rely on this file happy. +set(MITK_COREAPP_PROVISIONING_FILE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/CoreApp.provisioning" CACHE INTERNAL "CoreApp provisioning file" FORCE) + set(_plugins + org.blueberry.compat org.mitk.gui.qt.application ) # Plug-ins listed below will not be # - added as a build-time dependency to the executable # - listed in the provisioning file for the executable # - installed if they are external plug-ins set(_exclude_plugins ) FunctionCreateBlueBerryApplication( NAME CoreApp DESCRIPTION "MITK - CoreApp Application" PLUGINS ${_plugins} ${_app_options} ) -# Create a cache entry for the provisioning file which is used to export -# the file name in the MITKConfig.cmake file. This will keep external projects -# which rely on this file happy. -set(MITK_COREAPP_PROVISIONING_FILE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/CoreApp.provisioning" CACHE INTERNAL "CoreApp provisioning file" FORCE) - # subproject support ADD_DEPENDENCIES(MITK-CoreUI CoreApp) IF(MITK_ENABLE_GUI_TESTING) ADD_DEPENDENCIES(MITK-CoreUI solstice) ENDIF() diff --git a/Applications/CoreApp/CoreApp.cpp b/Applications/CoreApp/CoreApp.cpp index 77035f5c83..528b389506 100644 --- a/Applications/CoreApp/CoreApp.cpp +++ b/Applications/CoreApp/CoreApp.cpp @@ -1,86 +1,94 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/ for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include #include #include #include class QSafeApplication : public QApplication { public: QSafeApplication(int& argc, char** argv) : QApplication(argc, argv) {} /** * Reimplement notify to catch unhandled exceptions and open an error message. * * @param receiver * @param event * @return */ bool notify(QObject* receiver, QEvent* event) { QString msg; try { return QApplication::notify(receiver, event); } catch (Poco::Exception& e) { msg = QString::fromStdString(e.displayText()); } catch (std::exception& e) { msg = e.what(); } catch (...) { msg = "Unknown exception"; } QString text( "An error occurred. You should save all data and quit the program to prevent possible data loss.\nSee the error log for details.\n\n"); text += msg; QMessageBox::critical(0, "Error", text); return false; } }; int main(int argc, char** argv) { QSafeApplication safeApp(argc, argv); safeApp.setApplicationName("CoreApp"); safeApp.setOrganizationName("DKFZ"); // These paths replace the .ini file and are tailored for installation // packages created with CPack. If a .ini file is presented, it will // overwrite the settings in MapConfiguration Poco::Path basePath(argv[0]); basePath.setFileName(""); Poco::Path provFile(basePath); provFile.setFileName("CoreApp.provisioning"); Poco::Util::MapConfiguration* coreConfig(new Poco::Util::MapConfiguration()); coreConfig->setString(berry::Platform::ARG_PROVISIONING, provFile.toString()); coreConfig->setString(berry::Platform::ARG_APPLICATION, "org.mitk.qt.application"); + + // Preload the org.mitk.gui.qt.common plug-in (and hence also Qmitk) to speed + // up a clean-cache start. This also works around bugs in older gcc and glibc implementations, + // which have difficulties with multiple dynamic opening and closing of shared libraries with + // many global static initializers. It also helps if dependent libraries have weird static + // initialization methods and/or missing de-initialization code. + coreConfig->setString(berry::Platform::ARG_PRELOAD_LIBRARY, "liborg_mitk_gui_qt_common"); + return berry::Starter::Run(argc, argv, coreConfig); } diff --git a/Applications/ExtApp/CMakeLists.txt b/Applications/ExtApp/CMakeLists.txt index b531d10a5d..44c8d9db6c 100644 --- a/Applications/ExtApp/CMakeLists.txt +++ b/Applications/ExtApp/CMakeLists.txt @@ -1,35 +1,36 @@ project(ExtApp) set(_app_options) if(MITK_SHOW_CONSOLE_WINDOW) list(APPEND _app_options SHOW_CONSOLE) endif() +# Create a cache entry for the provisioning file which is used to export +# the file name in the MITKConfig.cmake file. This will keep external projects +# which rely on this file happy. +set(MITK_EXTAPP_PROVISIONING_FILE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ExtApp.provisioning" CACHE INTERNAL "ExtApp provisioning file" FORCE) + # Plug-ins listed below will not be # - added as a build-time dependency to the executable # - listed in the provisioning file for the executable # - installed if they are external plug-ins set(_exclude_plugins org.blueberry.test org.blueberry.uitest org.mitk.gui.qt.application org.mitk.gui.qt.diffusionimagingapp ) FunctionCreateBlueBerryApplication( NAME ExtApp DESCRIPTION "MITK - ExtApp Application" EXCLUDE_PLUGINS ${_exclude_plugins} ${_app_options} ) # Add a build time dependency to legacy BlueBerry bundles. if(MITK_MODULES_ENABLED_PLUGINS) add_dependencies(ExtApp ${MITK_MODULES_ENABLED_PLUGINS}) endif() -# Create a cache entry for the provisioning file which is used to export -# the file name in the MITKConfig.cmake file. This will keep external projects -# which rely on this file happy. -set(MITK_EXTAPP_PROVISIONING_FILE "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/ExtApp.provisioning" CACHE INTERNAL "ExtApp provisioning file" FORCE) diff --git a/Applications/ExtApp/ExtApp.cpp b/Applications/ExtApp/ExtApp.cpp index 99c7c0eb96..be576d189a 100644 --- a/Applications/ExtApp/ExtApp.cpp +++ b/Applications/ExtApp/ExtApp.cpp @@ -1,95 +1,103 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/ for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include #include #include #include class QtSafeApplication : public QApplication { public: QtSafeApplication(int& argc, char** argv) : QApplication(argc, argv) {} /** * Reimplement notify to catch unhandled exceptions and open an error message. * * @param receiver * @param event * @return */ bool notify(QObject* receiver, QEvent* event) { QString msg; try { return QApplication::notify(receiver, event); } catch (Poco::Exception& e) { msg = QString::fromStdString(e.displayText()); } catch (std::exception& e) { msg = e.what(); } catch (...) { msg = "Unknown exception"; } QString text("An error occurred. You should save all data and quit the program to " "prevent possible data loss.\nSee the error log for details.\n\n"); text += msg; QMessageBox::critical(0, "Error", text); return false; } }; int main(int argc, char** argv) { // Create a QApplication instance first QtSafeApplication qSafeApp(argc, argv); qSafeApp.setApplicationName("ExtApp"); qSafeApp.setOrganizationName("DKFZ"); // These paths replace the .ini file and are tailored for installation // packages created with CPack. If a .ini file is presented, it will // overwrite the settings in MapConfiguration Poco::Path basePath(argv[0]); basePath.setFileName(""); Poco::Path provFile(basePath); provFile.setFileName("ExtApp.provisioning"); Poco::Path extPath(basePath); extPath.pushDirectory("ExtBundles"); std::string pluginDirs = extPath.toString(); Poco::Util::MapConfiguration* extConfig(new Poco::Util::MapConfiguration()); extConfig->setString(berry::Platform::ARG_PLUGIN_DIRS, pluginDirs); extConfig->setString(berry::Platform::ARG_PROVISIONING, provFile.toString()); extConfig->setString(berry::Platform::ARG_APPLICATION, "org.mitk.qt.extapplication"); + + // Preload the org.mitk.gui.qt.ext plug-in (and hence also QmitkExt) to speed + // up a clean-cache start. This also works around bugs in older gcc and glibc implementations, + // which have difficulties with multiple dynamic opening and closing of shared libraries with + // many global static initializers. It also helps if dependent libraries have weird static + // initialization methods and/or missing de-initialization code. + extConfig->setString(berry::Platform::ARG_PRELOAD_LIBRARY, "liborg_mitk_gui_qt_ext"); + return berry::Starter::Run(argc, argv, extConfig); } diff --git a/BlueBerry/Bundles/org.blueberry.osgi/src/berryPlatform.cpp b/BlueBerry/Bundles/org.blueberry.osgi/src/berryPlatform.cpp index d93c699fc9..c28ea1141f 100644 --- a/BlueBerry/Bundles/org.blueberry.osgi/src/berryPlatform.cpp +++ b/BlueBerry/Bundles/org.blueberry.osgi/src/berryPlatform.cpp @@ -1,223 +1,224 @@ /*========================================================================= Program: BlueBerry Platform Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include #include "berryPlatform.h" #include "service/berryIExtensionPointService.h" #include "internal/berryInternalPlatform.h" namespace berry { int Platform::OS_FREE_BSD = BERRY_OS_FREE_BSD; int Platform::OS_AIX = BERRY_OS_AIX; int Platform::OS_HPUX = BERRY_OS_HPUX; int Platform::OS_TRU64 = BERRY_OS_TRU64; int Platform::OS_LINUX = BERRY_OS_LINUX; int Platform::OS_MAC_OS_X = BERRY_OS_MAC_OS_X; int Platform::OS_NET_BSD = BERRY_OS_NET_BSD; int Platform::OS_OPEN_BSD = BERRY_OS_OPEN_BSD; int Platform::OS_IRIX = BERRY_OS_IRIX; int Platform::OS_SOLARIS = BERRY_OS_SOLARIS; int Platform::OS_QNX = BERRY_OS_QNX; int Platform::OS_VXWORKS = BERRY_OS_VXWORKS; int Platform::OS_CYGWIN = BERRY_OS_CYGWIN; int Platform::OS_UNKNOWN_UNIX = BERRY_OS_UNKNOWN_UNIX; int Platform::OS_WINDOWS_NT = BERRY_OS_WINDOWS_NT; int Platform::OS_WINDOWS_CE = BERRY_OS_WINDOWS_CE; int Platform::OS_VMS = BERRY_OS_VMS; int Platform::ARCH_ALPHA = BERRY_ARCH_ALPHA; int Platform::ARCH_IA32 = BERRY_ARCH_IA32; int Platform::ARCH_IA64 = BERRY_ARCH_IA64; int Platform::ARCH_MIPS = BERRY_ARCH_MIPS; int Platform::ARCH_HPPA = BERRY_ARCH_HPPA; int Platform::ARCH_PPC = BERRY_ARCH_PPC; int Platform::ARCH_POWER = BERRY_ARCH_POWER; int Platform::ARCH_SPARC = BERRY_ARCH_SPARC; int Platform::ARCH_AMD64 = BERRY_ARCH_AMD64; int Platform::ARCH_ARM = BERRY_ARCH_ARM; std::string Platform::ARG_CLEAN = "BlueBerry.clean"; std::string Platform::ARG_APPLICATION = "BlueBerry.application"; std::string Platform::ARG_HOME = "BlueBerry.home"; std::string Platform::ARG_STORAGE_DIR = "BlueBerry.storageDir"; std::string Platform::ARG_PLUGIN_CACHE = "BlueBerry.plugin_cache_dir"; std::string Platform::ARG_PLUGIN_DIRS = "BlueBerry.plugin_dirs"; std::string Platform::ARG_FORCE_PLUGIN_INSTALL = "BlueBerry.forcePlugins"; +std::string Platform::ARG_PRELOAD_LIBRARY = "BlueBerry.preloadLibrary"; std::string Platform::ARG_PROVISIONING = "BlueBerry.provisioning"; std::string Platform::ARG_CONSOLELOG = "BlueBerry.consoleLog"; std::string Platform::ARG_TESTPLUGIN = "BlueBerry.testplugin"; std::string Platform::ARG_TESTAPPLICATION = "BlueBerry.testapplication"; std::string Platform::ARG_XARGS = "xargs"; const Poco::Path& Platform::GetConfigurationPath() { return InternalPlatform::GetInstance()->GetConfigurationPath(); } SmartPointer Platform::GetExtensionPointService() { return InternalPlatform::GetInstance()->GetExtensionPointService(); } PlatformEvents& Platform::GetEvents() { return InternalPlatform::GetInstance()->GetEvents(); } const Poco::Path& Platform::GetInstallPath() { return InternalPlatform::GetInstance()->GetInstallPath(); } const Poco::Path& Platform::GetInstancePath() { return InternalPlatform::GetInstance()->GetInstancePath(); } int Platform::GetOS() { return BERRY_OS; } int Platform::GetOSArch() { return BERRY_ARCH; } bool Platform::IsUnix() { #ifdef BERRY_OS_FAMILY_UNIX return true; #else return false; #endif } bool Platform::IsWindows() { #ifdef BERRY_OS_FAMILY_WINDOWS return true; #else return false; #endif } bool Platform::IsBSD() { #ifdef BERRY_OS_FAMILY_BSD return true; #else return false; #endif } bool Platform::IsLinux() { #ifdef BERRY_OS_FAMILY_LINUX return true; #else return false; #endif } bool Platform::IsVMS() { #ifdef BERRY_OS_FAMILY_VMS return true; #else return false; #endif } bool Platform::GetStatePath(Poco::Path& statePath, IBundle::Pointer bundle, bool create) { return InternalPlatform::GetInstance()->GetStatePath(statePath, bundle, create); } const Poco::Path& Platform::GetUserPath() { return InternalPlatform::GetInstance()->GetUserPath(); } std::string Platform::GetProperty(const std::string& /*key*/) { return ""; } bool Platform::IsRunning() { return InternalPlatform::GetInstance()->IsRunning(); } int& Platform::GetRawApplicationArgs(char**& argv) { return InternalPlatform::GetInstance()->GetRawApplicationArgs(argv); } std::vector Platform::GetApplicationArgs() { return InternalPlatform::GetInstance()->GetApplicationArgs(); } std::string Platform::GetExtendedApplicationArgs() { return InternalPlatform::GetInstance()->GetConfiguration().getString(ARG_XARGS, ""); } Poco::Util::LayeredConfiguration& Platform::GetConfiguration() { return InternalPlatform::GetInstance()->GetConfiguration(); } ServiceRegistry& Platform::GetServiceRegistry() { return InternalPlatform::GetInstance()->GetServiceRegistry(); } IBundle::Pointer Platform::GetBundle(const std::string& id) { return InternalPlatform::GetInstance()->GetBundle(id); } std::vector Platform::GetBundles() { return InternalPlatform::GetInstance()->GetBundles(); } QSharedPointer Platform::GetCTKPlugin(const QString& symbolicName) { QList > plugins = InternalPlatform::GetInstance()->GetCTKPluginFrameworkContext()->getPlugins(); foreach(QSharedPointer plugin, plugins) { if (plugin->getSymbolicName() == symbolicName) return plugin; } return QSharedPointer(0); } QSharedPointer Platform::GetCTKPlugin(long id) { return InternalPlatform::GetInstance()->GetCTKPluginFrameworkContext()->getPlugin(id); } } diff --git a/BlueBerry/Bundles/org.blueberry.osgi/src/berryPlatform.h b/BlueBerry/Bundles/org.blueberry.osgi/src/berryPlatform.h index 9ffdf2c84b..9ec83c92a1 100644 --- a/BlueBerry/Bundles/org.blueberry.osgi/src/berryPlatform.h +++ b/BlueBerry/Bundles/org.blueberry.osgi/src/berryPlatform.h @@ -1,356 +1,357 @@ /*========================================================================= Program: BlueBerry Platform Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef BERRY_Platform_INCLUDED #define BERRY_Platform_INCLUDED // // Platform Identification // #define BERRY_OS_FREE_BSD 0x0001 #define BERRY_OS_AIX 0x0002 #define BERRY_OS_HPUX 0x0003 #define BERRY_OS_TRU64 0x0004 #define BERRY_OS_LINUX 0x0005 #define BERRY_OS_MAC_OS_X 0x0006 #define BERRY_OS_NET_BSD 0x0007 #define BERRY_OS_OPEN_BSD 0x0008 #define BERRY_OS_IRIX 0x0009 #define BERRY_OS_SOLARIS 0x000a #define BERRY_OS_QNX 0x000b #define BERRY_OS_VXWORKS 0x000c #define BERRY_OS_CYGWIN 0x000d #define BERRY_OS_UNKNOWN_UNIX 0x00ff #define BERRY_OS_WINDOWS_NT 0x1001 #define BERRY_OS_WINDOWS_CE 0x1011 #define BERRY_OS_VMS 0x2001 #if defined(__FreeBSD__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS_FAMILY_BSD 1 #define BERRY_OS BERRY_OS_FREE_BSD #elif defined(_AIX) || defined(__TOS_AIX__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS BERRY_OS_AIX #elif defined(hpux) || defined(_hpux) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS BERRY_OS_HPUX #elif defined(__digital__) || defined(__osf__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS BERRY_OS_TRU64 #elif defined(linux) || defined(__linux) || defined(__linux__) || defined(__TOS_LINUX__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS BERRY_OS_LINUX #elif defined(__APPLE__) || defined(__TOS_MACOS__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS_FAMILY_BSD 1 #define BERRY_OS BERRY_OS_MAC_OS_X #elif defined(__NetBSD__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS_FAMILY_BSD 1 #define BERRY_OS BERRY_OS_NET_BSD #elif defined(__OpenBSD__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS_FAMILY_BSD 1 #define BERRY_OS BERRY_OS_OPEN_BSD #elif defined(sgi) || defined(__sgi) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS BERRY_OS_IRIX #elif defined(sun) || defined(__sun) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS BERRY_OS_SOLARIS #elif defined(__QNX__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS BERRY_OS_QNX #elif defined(unix) || defined(__unix) || defined(__unix__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS BERRY_OS_UNKNOWN_UNIX #elif defined(_WIN32_WCE) #define BERRY_OS_FAMILY_WINDOWS 1 #define BERRY_OS BERRY_OS_WINDOWS_CE #elif defined(_WIN32) || defined(_WIN64) #define BERRY_OS_FAMILY_WINDOWS 1 #define BERRY_OS BERRY_OS_WINDOWS_NT #elif defined(__CYGWIN__) #define BERRY_OS_FAMILY_UNIX 1 #define BERRY_OS BERRY_OS_CYGWIN #elif defined(__VMS) #define BERRY_OS_FAMILY_VMS 1 #define BERRY_OS BERRY_OS_VMS #endif // // Hardware Architecture and Byte Order // #define BERRY_ARCH_ALPHA 0x01 #define BERRY_ARCH_IA32 0x02 #define BERRY_ARCH_IA64 0x03 #define BERRY_ARCH_MIPS 0x04 #define BERRY_ARCH_HPPA 0x05 #define BERRY_ARCH_PPC 0x06 #define BERRY_ARCH_POWER 0x07 #define BERRY_ARCH_SPARC 0x08 #define BERRY_ARCH_AMD64 0x09 #define BERRY_ARCH_ARM 0x0a #if defined(__ALPHA) || defined(__alpha) || defined(__alpha__) || defined(_M_ALPHA) #define BERRY_ARCH BERRY_ARCH_ALPHA #define BERRY_ARCH_LITTLE_ENDIAN 1 #elif defined(i386) || defined(__i386) || defined(__i386__) || defined(_M_IX86) #define BERRY_ARCH BERRY_ARCH_IA32 #define BERRY_ARCH_LITTLE_ENDIAN 1 #elif defined(_IA64) || defined(__IA64__) || defined(__ia64__) || defined(__ia64) || defined(_M_IA64) #define BERRY_ARCH BERRY_ARCH_IA64 #if defined(hpux) || defined(_hpux) #define BERRY_ARCH_BIG_ENDIAN 1 #else #define BERRY_ARCH_LITTLE_ENDIAN 1 #endif #elif defined(__x86_64__) #define BERRY_ARCH BERRY_ARCH_AMD64 #define BERRY_ARCH_LITTLE_ENDIAN 1 #elif defined(_M_X64) #define BERRY_ARCH BERRY_ARCH_AMD64 #define BERRY_ARCH_LITTLE_ENDIAN 1 #elif defined(__mips__) || defined(__mips) || defined(__MIPS__) || defined(_M_MRX000) #define BERRY_ARCH BERRY_ARCH_MIPS #define BERRY_ARCH_BIG_ENDIAN 1 #elif defined(__hppa) || defined(__hppa__) #define BERRY_ARCH BERRY_ARCH_HPPA #define BERRY_ARCH_BIG_ENDIAN 1 #elif defined(__PPC) || defined(__POWERPC__) || defined(__powerpc) || defined(__PPC__) || \ defined(__powerpc__) || defined(__ppc__) || defined(_ARCH_PPC) || defined(_M_PPC) #define BERRY_ARCH BERRY_ARCH_PPC #define BERRY_ARCH_BIG_ENDIAN 1 #elif defined(_POWER) || defined(_ARCH_PWR) || defined(_ARCH_PWR2) || defined(_ARCH_PWR3) || \ defined(_ARCH_PWR4) || defined(__THW_RS6000) #define BERRY_ARCH BERRY_ARCH_POWER #define BERRY_ARCH_BIG_ENDIAN 1 #elif defined(__sparc__) || defined(__sparc) || defined(sparc) #define BERRY_ARCH BERRY_ARCH_SPARC #define BERRY_ARCH_BIG_ENDIAN 1 #elif defined(__arm__) || defined(__arm) || defined(ARM) || defined(_ARM_) || defined(__ARM__) || defined(_M_ARM) #define BERRY_ARCH BERRY_ARCH_ARM #if defined(__ARMEB__) #define BERRY_ARCH_BIG_ENDIAN 1 #else #define BERRY_ARCH_LITTLE_ENDIAN 1 #endif #endif #include #include "event/berryPlatformEvents.h" #include "service/berryServiceRegistry.h" #include namespace berry { struct IExtensionPointService; /** * The central class of the BlueBerry Platform Runtime. This class cannot * be instantiated or subclassed by clients; all functionality is provided * by static methods. Features include: *
    *
  • the platform registry of installed plug-ins
  • *
  • the platform adapter manager
  • *
  • the platform log
  • *
*

* Most users don't have to worry about Platform's lifecycle. However, if your * code can call methods of this class when Platform is not running, it becomes * necessary to check {@link #IsRunning()} before making the call. A runtime * exception might be thrown or incorrect result might be returned if a method * from this class is called while Platform is not running. *

*/ class BERRY_OSGI Platform { public: static int OS_FREE_BSD; static int OS_AIX; static int OS_HPUX; static int OS_TRU64; static int OS_LINUX; static int OS_MAC_OS_X; static int OS_NET_BSD; static int OS_OPEN_BSD; static int OS_IRIX; static int OS_SOLARIS; static int OS_QNX; static int OS_VXWORKS; static int OS_CYGWIN; static int OS_UNKNOWN_UNIX; static int OS_WINDOWS_NT; static int OS_WINDOWS_CE; static int OS_VMS; static int ARCH_ALPHA; static int ARCH_IA32; static int ARCH_IA64; static int ARCH_MIPS; static int ARCH_HPPA; static int ARCH_PPC; static int ARCH_POWER; static int ARCH_SPARC; static int ARCH_AMD64; static int ARCH_ARM; static std::string ARG_CLEAN; static std::string ARG_APPLICATION; static std::string ARG_HOME; static std::string ARG_STORAGE_DIR; static std::string ARG_PLUGIN_CACHE; static std::string ARG_PLUGIN_DIRS; static std::string ARG_FORCE_PLUGIN_INSTALL; + static std::string ARG_PRELOAD_LIBRARY; static std::string ARG_PROVISIONING; static std::string ARG_CONSOLELOG; static std::string ARG_TESTPLUGIN; static std::string ARG_TESTAPPLICATION; static std::string ARG_XARGS; static SmartPointer GetExtensionPointService(); // static IPreferenceService GetPreferenceService(); static PlatformEvents& GetEvents(); /** * Returns the path of the configuration information * used to run this instance of the BlueBerry platform. * The configuration area typically * contains the list of plug-ins available for use, various settings * (those shared across different instances of the same configuration) * and any other such data needed by plug-ins. * An empty path is returned if the platform is running without a configuration location. * * @return the location of the platform's configuration data area */ static const Poco::Path& GetConfigurationPath(); /** * Returns the path of the base installation for the running platform * * @return the location of the platform's installation area or null if none */ static const Poco::Path& GetInstallPath(); /** * Returns the path of the platform's working directory (also known as the instance data area). * An empty path is returned if the platform is running without an instance location. * * @return the location of the platform's instance data area or null if none */ static const Poco::Path& GetInstancePath(); /** * Returns the path in the local file system of the * plug-in state area for the given bundle. * If the plug-in state area did not exist prior to this call, * it is created. *

* The plug-in state area is a file directory within the * platform's metadata area where a plug-in is free to create files. * The content and structure of this area is defined by the plug-in, * and the particular plug-in is solely responsible for any files * it puts there. It is recommended for plug-in preference settings and * other configuration parameters. *

* * @param bundle the bundle whose state location is returned * @return a local file system path * TODO Investigate the usage of a service factory */ static bool GetStatePath(Poco::Path& statePath, SmartPointer bundle, bool create = true); /** * Returns the path of the platform's user data area. The user data area is a location on the system * which is specific to the system's current user. By default it is located relative to the * location given by the System property "user.home". * An empty path is returned if the platform is running without an user location. * * @return the location of the platform's user data area or null if none */ static const Poco::Path& GetUserPath(); static int GetOS(); static int GetOSArch(); static bool IsUnix(); static bool IsWindows(); static bool IsBSD(); static bool IsLinux(); static bool IsVMS(); static std::string GetProperty(const std::string& key); static bool IsRunning(); static Poco::Util::LayeredConfiguration& GetConfiguration(); /** * Returns the unmodified, original command line arguments * */ static int& GetRawApplicationArgs(char**& argv); /** * Returns the applications command line arguments which * have not been consumed by the platform. The first * argument still is the application name */ static std::vector GetApplicationArgs(); /** * Returns the "extended" command line arguments. This is * just the string given as argument to the "--xargs" option. */ static std::string GetExtendedApplicationArgs(); static ServiceRegistry& GetServiceRegistry(); /** * Returns the resolved bundle with the specified symbolic name that has the * highest version. If no resolved bundles are installed that have the * specified symbolic name then null is returned. * * @param id the symbolic name of the bundle to be returned. * @return the bundle that has the specified symbolic name with the * highest version, or null if no bundle is found. */ static IBundle::Pointer GetBundle(const std::string& id); static std::vector GetBundles(); static QSharedPointer GetCTKPlugin(const QString& symbolicName); static QSharedPointer GetCTKPlugin(long id); private: Platform(); }; } // namespace #endif // BERRY_Platform_INCLUDED diff --git a/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryInternalPlatform.cpp b/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryInternalPlatform.cpp index 92683b103e..2969a20bec 100644 --- a/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryInternalPlatform.cpp +++ b/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryInternalPlatform.cpp @@ -1,573 +1,601 @@ /*========================================================================= Program: BlueBerry Platform Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "berryInternalPlatform.h" #include "berryLog.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "../berryPlatform.h" #include "../berryPlatformException.h" #include "../berryDebugUtil.h" #include "../event/berryPlatformEvents.h" #include "berryPlatformLogChannel.h" #include "../berryIBundle.h" #include "berryCodeCache.h" #include "../berryBundleLoader.h" #include "berrySystemBundle.h" #include "berryBundleDirectory.h" #include "berryProvisioningInfo.h" #include #include #include namespace berry { Poco::Mutex InternalPlatform::m_Mutex; InternalPlatform::InternalPlatform() : m_Initialized(false), m_Running(false), m_ConsoleLog(false), m_ServiceRegistry(0), m_CodeCache(0), m_BundleLoader(0), m_SystemBundle(0), m_PlatformLogger(0), m_ctkPluginFrameworkFactory(0), m_EventStarted(PlatformEvent::EV_PLATFORM_STARTED) { } InternalPlatform::~InternalPlatform() { } InternalPlatform* InternalPlatform::GetInstance() { Poco::Mutex::ScopedLock lock(m_Mutex); static InternalPlatform instance; return &instance; } bool InternalPlatform::ConsoleLog() const { return m_ConsoleLog; } ctkPluginContext* InternalPlatform::GetCTKPluginFrameworkContext() const { if (m_ctkPluginFrameworkFactory) { return m_ctkPluginFrameworkFactory->getFramework()->getPluginContext(); } return 0; } ServiceRegistry& InternalPlatform::GetServiceRegistry() { AssertInitialized(); return *m_ServiceRegistry; } void InternalPlatform::Initialize(int& argc, char** argv, Poco::Util::AbstractConfiguration* config) { // initialization Poco::Mutex::ScopedLock lock(m_Mutex); m_Argc = &argc; m_Argv = argv; try { this->init(argc, argv); } catch (const Poco::Util::UnknownOptionException& e) { BERRY_WARN << e.displayText(); } this->loadConfiguration(); if (config) { this->config().add(config, 50, false); } m_ServiceRegistry = new ServiceRegistry(); m_ConsoleLog = this->GetConfiguration().hasProperty(Platform::ARG_CONSOLELOG); m_ConfigPath.assign(this->GetConfiguration().getString("application.configDir")); m_InstancePath.assign(this->GetConfiguration().getString("application.dir")); try { m_InstallPath.assign(this->GetConfiguration().getString(Platform::ARG_HOME)); } catch (Poco::NotFoundException& ) { m_InstallPath.assign(m_InstancePath); } if (this->GetConfiguration().hasProperty(Platform::ARG_STORAGE_DIR)) { std::string dataLocation = this->GetConfiguration().getString(Platform::ARG_STORAGE_DIR, ""); if (dataLocation.at(dataLocation.size()-1) != '/') { dataLocation += '/'; } m_UserPath.assign(dataLocation); } else { // Append a hash value of the absolute path of the executable to the data location. // This allows to start the same application from different build or install trees. QString dataLocation = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + '_'; dataLocation += QString::number(qHash(QCoreApplication::applicationDirPath())) + "/"; m_UserPath.assign(dataLocation.toStdString()); } Poco::File userFile(m_UserPath); try { userFile.createDirectories(); userFile.canWrite(); } catch(const Poco::IOException& e) { BERRY_WARN << e.displayText(); m_UserPath.assign(Poco::Path::temp()); m_UserPath.pushDirectory("." + this->commandName()); userFile = m_UserPath; } // Initialize the CTK Plugin Framework ctkProperties fwProps; fwProps.insert(ctkPluginConstants::FRAMEWORK_STORAGE, QString::fromStdString(userFile.path())); #if defined(Q_CC_GNU) && ((__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 5))) fwProps.insert(ctkPluginConstants::FRAMEWORK_PLUGIN_LOAD_HINTS, QVariant::fromValue(QLibrary::ExportExternalSymbolsHint)); #endif if (this->GetConfiguration().hasProperty(Platform::ARG_CLEAN)) { fwProps.insert(ctkPluginConstants::FRAMEWORK_STORAGE_CLEAN, ctkPluginConstants::FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT); } if (this->GetConfiguration().hasProperty(Platform::ARG_CONSOLELOG)) { + fwProps.insert("org.commontk.pluginfw.debug.framework", true); fwProps.insert("org.commontk.pluginfw.debug.errors", true); fwProps.insert("org.commontk.pluginfw.debug.pluginfw", true); fwProps.insert("org.commontk.pluginfw.debug.lazy_activation", true); fwProps.insert("org.commontk.pluginfw.debug.resolve", true); } + if (this->GetConfiguration().hasProperty(Platform::ARG_PRELOAD_LIBRARY)) + { + QString preloadLibs = QString::fromStdString(this->GetConfiguration().getString(Platform::ARG_PRELOAD_LIBRARY)); + fwProps.insert(ctkPluginConstants::FRAMEWORK_PRELOAD_LIBRARIES, preloadLibs.split(',', QString::SkipEmptyParts)); + } m_ctkPluginFrameworkFactory = new ctkPluginFrameworkFactory(fwProps); QSharedPointer pfw = m_ctkPluginFrameworkFactory->getFramework(); pfw->init(); ctkPluginContext* pfwContext = pfw->getPluginContext(); std::string provisioningFile = this->GetConfiguration().getString(Platform::ARG_PROVISIONING); if (!provisioningFile.empty()) { + BERRY_INFO(m_ConsoleLog) << "Using provisioning file: " << provisioningFile; ProvisioningInfo provInfo(QString::fromStdString(provisioningFile)); foreach(QString pluginPath, provInfo.getPluginDirs()) { ctkPluginFrameworkLauncher::addSearchPath(pluginPath); } bool forcePluginOverwrite = this->GetConfiguration().hasOption(Platform::ARG_FORCE_PLUGIN_INSTALL); QList pluginsToStart = provInfo.getPluginsToStart(); foreach(QUrl pluginUrl, provInfo.getPluginsToInstall()) { if (forcePluginOverwrite) { uninstallPugin(pluginUrl, pfwContext); } try { + BERRY_INFO(m_ConsoleLog) << "Installing CTK plug-in from: " << pluginUrl.toString().toStdString(); QSharedPointer plugin = pfwContext->installPlugin(pluginUrl); if (pluginsToStart.contains(pluginUrl)) { m_CTKPluginsToStart << plugin->getPluginId(); } } catch (const ctkPluginException& e) { BERRY_ERROR << "Failed to install: " << pluginUrl.toString().toStdString() << ",\n" << e.what(); } } } + else + { + BERRY_INFO << "No provisioning file set."; + } m_BaseStatePath = m_UserPath; m_BaseStatePath.pushDirectory("bb-metadata"); m_BaseStatePath.pushDirectory("bb-plugins"); Poco::Path logPath(m_UserPath); logPath.setFileName(this->commandName() + ".log"); m_PlatformLogChannel = new PlatformLogChannel(logPath.toString()); m_PlatformLogger = &Poco::Logger::create("PlatformLogger", m_PlatformLogChannel, Poco::Message::PRIO_TRACE); try { m_CodeCache = new CodeCache(this->GetConfiguration().getString(Platform::ARG_PLUGIN_CACHE)); } catch (Poco::NotFoundException&) { Poco::Path cachePath(m_UserPath); cachePath.pushDirectory("bb-plugin_cache"); m_CodeCache = new CodeCache(cachePath.toString()); } m_BundleLoader = new BundleLoader(m_CodeCache, *m_PlatformLogger); // tell the BundleLoader about the installed CTK plug-ins QStringList installedCTKPlugins; foreach(QSharedPointer plugin, pfwContext->getPlugins()) { installedCTKPlugins << plugin->getSymbolicName(); } m_BundleLoader->SetCTKPlugins(installedCTKPlugins); m_Initialized = true; // Clear the CodeCache if (this->GetConfiguration().hasProperty(Platform::ARG_CLEAN)) m_CodeCache->Clear(); try { // assemble a list of base plugin-directories (which contain // the real plugins as directories) std::vector pluginBaseDirs; Poco::StringTokenizer tokenizer(this->GetConfiguration().getString(Platform::ARG_PLUGIN_DIRS, ""), ";", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM); for (Poco::StringTokenizer::Iterator token = tokenizer.begin(); token != tokenizer.end(); ++token) { pluginBaseDirs.push_back(*token); } std::vector pluginPaths; for (std::vector::iterator pluginBaseDir = pluginBaseDirs.begin(); pluginBaseDir != pluginBaseDirs.end(); ++pluginBaseDir) { BERRY_INFO(m_ConsoleLog) << "Plugin base directory: " << *pluginBaseDir; Poco::File pluginDir(*pluginBaseDir); if (!pluginDir.exists() || !pluginDir.isDirectory()) { BERRY_WARN(m_ConsoleLog) << *pluginBaseDir << " is not a direcotry or does not exist. SKIPPED.\n"; continue; } std::vector pluginList; pluginDir.list(pluginList); std::vector::iterator iter; for (iter = pluginList.begin(); iter != pluginList.end(); iter++) { Poco::Path pluginPath = Poco::Path::forDirectory(*pluginBaseDir); pluginPath.pushDirectory(*iter); Poco::File file(pluginPath); if (file.exists() && file.isDirectory()) { pluginPaths.push_back(pluginPath); } } } std::vector::iterator pathIter; for (pathIter = pluginPaths.begin(); pathIter != pluginPaths.end(); pathIter++) { try { Bundle::Pointer bundle = m_BundleLoader->LoadBundle(*pathIter); if (bundle) { BERRY_INFO(m_ConsoleLog) << "Bundle state (" << pathIter->toString() << "): " << bundle->GetStateString() << std::endl; } } catch (const BundleStateException& exc) { BERRY_WARN << exc.displayText() << std::endl; } } // resolve plugins m_BundleLoader->ResolveAllBundles(); } catch (Poco::Exception& exc) { this->logger().log(exc); } #ifdef BLUEBERRY_DEBUG_SMARTPOINTER DebugUtil::RestoreState(); #endif } void InternalPlatform::uninstallPugin(const QUrl& pluginUrl, ctkPluginContext* pfwContext) { QFileInfo libInfo(pluginUrl.toLocalFile()); QString libName = libInfo.baseName(); if (libName.startsWith("lib")) { libName = libName.mid(3); } QString symbolicName = libName.replace('_', '.'); foreach(QSharedPointer plugin, pfwContext->getPlugins()) { if (plugin->getSymbolicName() == symbolicName && plugin->getLocation() != pluginUrl.toString()) { BERRY_WARN << "A plug-in with the symbolic name " << symbolicName.toStdString() << " but different location is already installed. Trying to uninstall " << plugin->getLocation().toStdString(); plugin->uninstall(); return; } } } void InternalPlatform::Launch() { AssertInitialized(); if (m_Running) return; m_Running = true; this->run(); } void InternalPlatform::Shutdown() { QSharedPointer ctkPluginFW; { Poco::Mutex::ScopedLock lock(m_Mutex); AssertInitialized(); DebugUtil::SaveState(); ctkPluginFW = m_ctkPluginFrameworkFactory->getFramework(); m_Initialized = false; } ctkPluginFW->stop(); this->uninitialize(); // wait 10 seconds for the CTK plugin framework to stop - ctkPluginFW->waitForStop(30000); + ctkPluginFW->waitForStop(10000); { Poco::Mutex::ScopedLock lock(m_Mutex); delete m_ServiceRegistry; delete m_BundleLoader; delete m_CodeCache; } } void InternalPlatform::AssertInitialized() { if (!m_Initialized) throw Poco::SystemException("The Platform has not been initialized yet!"); } IExtensionPointService::Pointer InternalPlatform::GetExtensionPointService() { Poco::Mutex::ScopedLock lock(m_Mutex); this->AssertInitialized(); return m_ServiceRegistry->GetServiceById(IExtensionPointService::SERVICE_ID); } const Poco::Path& InternalPlatform::GetConfigurationPath() { return m_ConfigPath; } const Poco::Path& InternalPlatform::GetInstallPath() { return m_InstallPath; } const Poco::Path& InternalPlatform::GetInstancePath() { return m_InstancePath; } bool InternalPlatform::GetStatePath(Poco::Path& statePath, IBundle::Pointer bundle, bool create) { statePath = m_BaseStatePath; statePath.pushDirectory(bundle->GetSymbolicName()); try { Poco::File stateFile(statePath); if (!stateFile.exists() && create) stateFile.createDirectories(); } catch (Poco::FileException&) { return false; } return true; } PlatformEvents& InternalPlatform::GetEvents() { return m_Events; } const Poco::Path& InternalPlatform::GetUserPath() { return m_UserPath; } bool InternalPlatform::IsRunning() const { Poco::Mutex::ScopedLock lock(m_Mutex); return (m_Initialized && m_Running); } IBundle::Pointer InternalPlatform::GetBundle(const std::string& id) { Poco::Mutex::ScopedLock lock(m_Mutex); AssertInitialized(); return m_BundleLoader->FindBundle(id); } std::vector InternalPlatform::GetBundles() const { return m_BundleLoader->GetBundles(); } Poco::Logger* InternalPlatform::GetLogger() { return m_PlatformLogger; } Poco::Util::LayeredConfiguration& InternalPlatform::GetConfiguration() const { return this->config(); } std::vector InternalPlatform::GetApplicationArgs() const { return m_FilteredArgs; } int& InternalPlatform::GetRawApplicationArgs(char**& argv) { argv = m_Argv; return *m_Argc; } void InternalPlatform::defineOptions(Poco::Util::OptionSet& options) { Poco::Util::Option helpOption("help", "h", "print this help text"); helpOption.callback(Poco::Util::OptionCallback(this, &InternalPlatform::PrintHelp)); options.addOption(helpOption); Poco::Util::Option cleanOption(Platform::ARG_CLEAN, "", "cleans the plugin cache"); cleanOption.binding(Platform::ARG_CLEAN); options.addOption(cleanOption); Poco::Util::Option appOption(Platform::ARG_APPLICATION, "", "the id of the application extension to be executed"); appOption.argument("").binding(Platform::ARG_APPLICATION); options.addOption(appOption); Poco::Util::Option storageDirOption(Platform::ARG_STORAGE_DIR, "", "the location for storing persistent application data"); storageDirOption.argument("").binding(Platform::ARG_STORAGE_DIR); options.addOption(storageDirOption); Poco::Util::Option consoleLogOption(Platform::ARG_CONSOLELOG, "", "log messages to the console"); consoleLogOption.binding(Platform::ARG_CONSOLELOG); options.addOption(consoleLogOption); Poco::Util::Option forcePluginOption(Platform::ARG_FORCE_PLUGIN_INSTALL, "", "force installing plug-ins with same symbolic name"); forcePluginOption.binding(Platform::ARG_FORCE_PLUGIN_INSTALL); options.addOption(forcePluginOption); + Poco::Util::Option preloadLibsOption(Platform::ARG_PRELOAD_LIBRARY, "", "preload a library"); + preloadLibsOption.argument("").repeatable(true).callback(Poco::Util::OptionCallback(this, &InternalPlatform::handlePreloadLibraryOption)); + options.addOption(preloadLibsOption); + Poco::Util::Option testPluginOption(Platform::ARG_TESTPLUGIN, "", "the plug-in to be tested"); testPluginOption.argument("").binding(Platform::ARG_TESTPLUGIN); options.addOption(testPluginOption); Poco::Util::Option testAppOption(Platform::ARG_TESTAPPLICATION, "", "the application to be tested"); testAppOption.argument("").binding(Platform::ARG_TESTAPPLICATION); options.addOption(testAppOption); Poco::Util::Option xargsOption(Platform::ARG_XARGS, "", "Extended argument list"); xargsOption.argument("").binding(Platform::ARG_XARGS); options.addOption(xargsOption); Poco::Util::Application::defineOptions(options); } +void InternalPlatform::handlePreloadLibraryOption(const std::string& name, const std::string& value) +{ + std::string oldVal; + if (this->config().hasProperty(Platform::ARG_PRELOAD_LIBRARY)) + { + oldVal = this->config().getString(Platform::ARG_PRELOAD_LIBRARY); + } + this->config().setString(Platform::ARG_PRELOAD_LIBRARY, oldVal + "," + value); +} + int InternalPlatform::main(const std::vector& args) { m_FilteredArgs = args; //m_FilteredArgs.insert(m_FilteredArgs.begin(), this->config().getString("application.argv[0]")); ctkPluginContext* context = GetCTKPluginFrameworkContext(); QFileInfo storageDir = context->getDataFile(""); BundleDirectory::Pointer bundleStorage(new BundleDirectory(Poco::Path(storageDir.absolutePath().toStdString()))); SystemBundle::Pointer systemBundle(new SystemBundle(*m_BundleLoader, bundleStorage)); if (systemBundle == 0) throw PlatformException("Could not find the system bundle"); m_BundleLoader->m_SystemBundle = systemBundle; m_BundleLoader->LoadBundle(systemBundle); m_ctkPluginFrameworkFactory->getFramework()->start(); foreach(long pluginId, m_CTKPluginsToStart) { + BERRY_INFO(m_ConsoleLog) << "Starting CTK plug-in: " << context->getPlugin(pluginId)->getSymbolicName().toStdString() + << " [" << pluginId << "]"; // do not change the autostart setting of this plugin context->getPlugin(pluginId)->start(ctkPlugin::START_TRANSIENT | ctkPlugin::START_ACTIVATION_POLICY); } m_BundleLoader->StartSystemBundle(systemBundle); systemBundle->Resume(); return EXIT_OK; } void InternalPlatform::PrintHelp(const std::string&, const std::string&) { Poco::Util::HelpFormatter help(this->options()); help.setAutoIndent(); help.setCommand(this->commandName()); help.format(std::cout); exit(EXIT_OK); } } diff --git a/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryInternalPlatform.h b/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryInternalPlatform.h index e60e10c756..4181cfae9e 100644 --- a/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryInternalPlatform.h +++ b/BlueBerry/Bundles/org.blueberry.osgi/src/internal/berryInternalPlatform.h @@ -1,148 +1,151 @@ /*========================================================================= Program: BlueBerry Platform Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef BERRYINTERNALPLATFORM_H_ #define BERRYINTERNALPLATFORM_H_ #include #include #include #include #include #include "../event/berryPlatformEvents.h" #include "../service/berryServiceRegistry.h" #include "berryExtensionPointService.h" #include class ctkPluginFrameworkFactory; class ctkPluginContext; namespace berry { struct IBundle; class CodeCache; class BundleLoader; class PlatformLogChannel; class SystemBundle; class BERRY_OSGI InternalPlatform : private Poco::Util::Application { private: static Poco::Mutex m_Mutex; bool m_Initialized; bool m_Running; bool m_ConsoleLog; ServiceRegistry* m_ServiceRegistry; Poco::Path m_BaseStatePath; Poco::Path m_InstallPath; Poco::Path m_InstancePath; Poco::Path m_UserPath; Poco::Path m_ConfigPath; std::vector m_FilteredArgs; CodeCache* m_CodeCache; BundleLoader* m_BundleLoader; SystemBundle* m_SystemBundle; Poco::AutoPtr m_PlatformLogChannel; Poco::Logger* m_PlatformLogger; ctkPluginFrameworkFactory* m_ctkPluginFrameworkFactory; QList m_CTKPluginsToStart; PlatformEvents m_Events; PlatformEvent m_EventStarted; int* m_Argc; char** m_Argv; //std::map m_ArgMap; InternalPlatform(); //InternalPlatform(const InternalPlatform&) : m_EventStarted(PlatformEvent::EV_PLATFORM_STARTED) {}; void AssertInitialized(); // Poco::Application method overrides void defineOptions(Poco::Util::OptionSet& options); + + void handlePreloadLibraryOption(const std::string &name, const std::string &value); + int main(const std::vector& args); void uninstallPugin(const QUrl& pluginUrl, ctkPluginContext* pfwContext); public: virtual ~InternalPlatform(); void PrintHelp(const std::string& name, const std::string& value); static InternalPlatform* GetInstance(); void Initialize(int& argc, char** argv, Poco::Util::AbstractConfiguration* config = 0); void Launch(); void Shutdown(); ctkPluginContext* GetCTKPluginFrameworkContext() const; /// Returns a ServiceRegistry object for registering /// and accessing services from different plugins ServiceRegistry& GetServiceRegistry(); /// Convenience method to quickly get the extension /// point service, which is automatically started /// by the platform IExtensionPointService::Pointer GetExtensionPointService(); bool ConsoleLog() const; const Poco::Path& GetConfigurationPath(); const Poco::Path& GetInstallPath(); const Poco::Path& GetInstancePath(); bool GetStatePath(Poco::Path& statePath, SmartPointer bundle, bool create = true); const Poco::Path& GetUserPath(); PlatformEvents& GetEvents(); bool IsRunning() const; Poco::Util::LayeredConfiguration& GetConfiguration() const; std::vector GetApplicationArgs() const; int& GetRawApplicationArgs(char**& argv); IBundle::Pointer GetBundle(const std::string& id); std::vector GetBundles() const; Poco::Logger* GetLogger(); }; } // namespace berry #endif /*BERRYINTERNALPLATFORM_H_*/ diff --git a/BlueBerry/Bundles/org.blueberry.osgi/src/service/berryServiceRegistry.txx b/BlueBerry/Bundles/org.blueberry.osgi/src/service/berryServiceRegistry.txx index 0013b4ca8c..b821be76fc 100644 --- a/BlueBerry/Bundles/org.blueberry.osgi/src/service/berryServiceRegistry.txx +++ b/BlueBerry/Bundles/org.blueberry.osgi/src/service/berryServiceRegistry.txx @@ -1,76 +1,88 @@ /*========================================================================= Program: BlueBerry Platform Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __BERRY_SERVICE_REGISTRY_TXX__ #define __BERRY_SERVICE_REGISTRY_TXX__ #include "../internal/berryCTKPluginActivator.h" #include "../berryLog.h" #include namespace berry { template typename S::Pointer ServiceRegistry::GetServiceById(const std::string& id) { Poco::Mutex::ScopedLock lock(m_Mutex); Service::Pointer servicePtr; std::map::const_iterator serviceIt = m_ServiceMap.find(id); if (serviceIt != m_ServiceMap.end()) { servicePtr = serviceIt->second; } if (servicePtr.IsNull()) { // Try to get the service from the CTK Service Registry ctkPluginContext* context = CTKPluginActivator::getPluginContext(); + if (context == 0) + { + // The org.blueberry.osgi plug-in was not started by the CTK Plugin Framework. + // This is considered a fatal error. + BERRY_FATAL << "The org.blueberry.osgi plug-in is not started. " + "Check that your application loads the correct provisioning " + "file and that it contains an entry for the org.blueberry.osgi plug-in."; + return SmartPointer(); + } + try { ctkServiceReference serviceRef = context->getServiceReference(); + if (!serviceRef) return SmartPointer(); + S* service = context->getService(serviceRef); if (!service) { return SmartPointer(); } //BERRY_WARN << "Getting a CTK Service object through the BlueBerry service registry.\n" // "You should use a ctkPluginContext or ctkServiceTracker instance instead!"; return typename S::Pointer(service); } catch (const ctkServiceException& exc) { BERRY_INFO << exc.what(); } return SmartPointer(); } if (servicePtr->IsA(typeid(S))) { SmartPointer castService = servicePtr.Cast(); return castService; } else throw Poco::BadCastException("The service could not be cast to: ", typeid(S).name()); } } // namespace berry #endif // __BERRY_SERVICE_REGISTRY_TXX__ diff --git a/CMakeExternals/CTK.cmake b/CMakeExternals/CTK.cmake index 3a6cb007a2..4b99a27a56 100644 --- a/CMakeExternals/CTK.cmake +++ b/CMakeExternals/CTK.cmake @@ -1,61 +1,61 @@ #----------------------------------------------------------------------------- # CTK #----------------------------------------------------------------------------- IF(MITK_USE_CTK) # Sanity checks IF(DEFINED CTK_DIR AND NOT EXISTS ${CTK_DIR}) MESSAGE(FATAL_ERROR "CTK_DIR variable is defined but corresponds to non-existing directory") ENDIF() SET(proj CTK) SET(proj_DEPENDENCIES ) SET(CTK_DEPENDS ${proj}) IF(NOT DEFINED CTK_DIR) - SET(revision_tag 436795b904f69929149d3cdb7c4352516a1a85cd) + SET(revision_tag 6f26c34) IF(${proj}_REVISION_TAG) SET(revision_tag ${${proj}_REVISION_TAG}) ENDIF() SET(ctk_optional_cache_args ) IF(MITK_USE_Python) - LIST(APPEND ctk_optional_cache_args - -DCTK_LIB_Scripting/Python/Widgets:BOOL=ON - ) + LIST(APPEND ctk_optional_cache_args + -DCTK_LIB_Scripting/Python/Widgets:BOOL=ON + ) ENDIF() FOREACH(type RUNTIME ARCHIVE LIBRARY) IF(DEFINED CTK_PLUGIN_${type}_OUTPUT_DIRECTORY) LIST(APPEND mitk_optional_cache_args -DCTK_PLUGIN_${type}_OUTPUT_DIRECTORY:PATH=${CTK_PLUGIN_${type}_OUTPUT_DIRECTORY}) ENDIF() ENDFOREACH() ExternalProject_Add(${proj} GIT_REPOSITORY http://github.com/commontk/CTK.git GIT_TAG ${revision_tag} BINARY_DIR ${proj}-build UPDATE_COMMAND "" INSTALL_COMMAND "" CMAKE_GENERATOR ${gen} CMAKE_ARGS ${ep_common_args} ${ctk_optional_cache_args} -DDESIRED_QT_VERSION:STRING=4 -DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE} -DCTK_LIB_PluginFramework:BOOL=ON -DCTK_LIB_DICOM/Widgets:BOOL=ON -DCTK_PLUGIN_org.commontk.eventadmin:BOOL=ON -DCTK_USE_GIT_PROTOCOL:BOOL=OFF DEPENDS ${proj_DEPENDENCIES} ) SET(CTK_DIR ${CMAKE_CURRENT_BINARY_DIR}/${proj}-build) ELSE() mitkMacroEmptyExternalProject(${proj} "${proj_DEPENDENCIES}") ENDIF() ENDIF()