Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-10-31 09:35:26

0001 // Copyright (c) 2023 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _DE_PluginHolder_HeaderFile
0015 #define _DE_PluginHolder_HeaderFile
0016 
0017 #include <DE_Wrapper.hxx>
0018 
0019 #include <mutex>
0020 #include <tuple>
0021 
0022 //! Base class to work with DE_Wrapper global registration of components.
0023 //! Control life-time of current configuration node.
0024 //! In creating stage load into global configuration.
0025 //! On destroying stage unload from global configuration.
0026 //! Operation to load/unload are thread safety.
0027 template <class TheConfType>
0028 class DE_PluginHolder
0029 {
0030 public:
0031   DE_PluginHolder()
0032   {
0033     std::lock_guard<std::mutex> aLock(DE_Wrapper::GlobalLoadMutex());
0034     myInternalConfiguration = new TheConfType;
0035     myInternalConfiguration->Register(DE_Wrapper::GlobalWrapper());
0036   }
0037 
0038   ~DE_PluginHolder()
0039   {
0040     std::lock_guard<std::mutex> aLock(DE_Wrapper::GlobalLoadMutex());
0041     myInternalConfiguration->UnRegister(DE_Wrapper::GlobalWrapper());
0042   }
0043 
0044 private:
0045   occ::handle<TheConfType> myInternalConfiguration; //!< Wrapped object
0046 };
0047 
0048 //! Helper class for variadic plugin registration.
0049 //! Allows registration of multiple configuration node types simultaneously.
0050 template <typename... TheConfTypes>
0051 class DE_MultiPluginHolder
0052 {
0053 public:
0054   DE_MultiPluginHolder()
0055       : myHolders{}
0056   {
0057   }
0058 
0059 private:
0060   std::tuple<DE_PluginHolder<TheConfTypes>...> myHolders; //!< Tuple of individual plugin holders
0061 };
0062 
0063 //! Macro to define plugin factory function for DE_Wrapper configuration nodes.
0064 //! @param[in] theNodeType - first configuration node class to instantiate
0065 //! @param[in] ... - additional configuration node classes to instantiate (optional)
0066 //! Needs to be called after loading of the library to register configuration nodes.
0067 //!
0068 //! Example of usage:
0069 //! @code
0070 //! // Inside implementation of the configuration node source file:
0071 //! DEPLUGIN(DESTEP_ConfigurationNode)
0072 //!
0073 //! // For multiple node types:
0074 //! DEPLUGIN(DESTEP_ConfigurationNode, DEIGES_ConfigurationNode, DEVRML_ConfigurationNode)
0075 //! @endcode
0076 //!
0077 //! After loading of the library TKDESTEP:
0078 //! @code
0079 //! OSD_SharedLibrary aSharedLibrary("libTKDESTEP.so");
0080 //! if (!aSharedLibrary.DlOpen(OSD_RTLD_LAZY))
0081 //! {
0082 //!   // Error handling
0083 //!   return;
0084 //! }
0085 //!
0086 //! typedef void (*PluginFactoryFunc)();
0087 //! PluginFactoryFunc aFunc = (PluginFactoryFunc)aSharedLibrary.DlSymb("PLUGINFACTORY");
0088 //! if (aFunc == NULL)
0089 //! {
0090 //!   // Error handling
0091 //!   return;
0092 //! }
0093 //!
0094 //! aFunc(); // Call factory function to register configuration nodes
0095 //! @endcode
0096 //!
0097 //! Will create instances of all specified configuration nodes and set them to DE_Wrapper global
0098 //! configuration.
0099 //!
0100 //! Note: if OCCT_NO_PLUGINS is defined, macro does nothing.
0101 #ifdef OCCT_NO_PLUGINS
0102   #define DEPLUGIN(theNodeType, ...)
0103 #else
0104   #define DEPLUGIN(theNodeType, ...)                                                               \
0105     extern "C" Standard_EXPORT void PLUGINFACTORY()                                                \
0106     {                                                                                              \
0107       static DE_MultiPluginHolder<theNodeType, ##__VA_ARGS__> aMultiHolder;                        \
0108     }
0109 #endif
0110 
0111 #endif // _DE_PluginHolder_HeaderFile