|
||||
File indexing completed on 2025-01-19 10:11:00
0001 //------------------------------------------------------------------------------ 0002 // Copyright (c) 2014 by European Organization for Nuclear Research (CERN) 0003 // Author: Lukasz Janyst <ljanyst@cern.ch> 0004 //------------------------------------------------------------------------------ 0005 // This file is part of the XRootD software suite. 0006 // 0007 // XRootD is free software: you can redistribute it and/or modify 0008 // it under the terms of the GNU Lesser General Public License as published by 0009 // the Free Software Foundation, either version 3 of the License, or 0010 // (at your option) any later version. 0011 // 0012 // XRootD is distributed in the hope that it will be useful, 0013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 // GNU General Public License for more details. 0016 // 0017 // You should have received a copy of the GNU Lesser General Public License 0018 // along with XRootD. If not, see <http://www.gnu.org/licenses/>. 0019 // 0020 // In applying this licence, CERN does not waive the privileges and immunities 0021 // granted to it by virtue of its status as an Intergovernmental Organization 0022 // or submit itself to any jurisdiction. 0023 //------------------------------------------------------------------------------ 0024 0025 #ifndef __XRD_CL_PLUGIN_MANAGER__ 0026 #define __XRD_CL_PLUGIN_MANAGER__ 0027 0028 #include "XrdCl/XrdClPlugInInterface.hh" 0029 #include "XrdOuc/XrdOucPinLoader.hh" 0030 #include "XrdSys/XrdSysPthread.hh" 0031 0032 #include <map> 0033 #include <string> 0034 #include <utility> 0035 0036 namespace XrdCl 0037 { 0038 //---------------------------------------------------------------------------- 0039 //! Manage client-side plug-ins and match them agains URLs 0040 //---------------------------------------------------------------------------- 0041 class PlugInManager 0042 { 0043 public: 0044 //------------------------------------------------------------------------ 0045 //! Constructor 0046 //------------------------------------------------------------------------ 0047 PlugInManager(); 0048 0049 //------------------------------------------------------------------------ 0050 //! Destructor 0051 //------------------------------------------------------------------------ 0052 ~PlugInManager(); 0053 0054 //------------------------------------------------------------------------ 0055 //! Register a plug-in factory for the given url, registering a 0 pointer 0056 //! removes the factory for the url 0057 //------------------------------------------------------------------------ 0058 bool RegisterFactory( const std::string &url, 0059 PlugInFactory *factory ); 0060 0061 //------------------------------------------------------------------------ 0062 //! Register a plug-in factory applying to all URLs, registering 0063 //! a 0 pointer removes the factory 0064 //------------------------------------------------------------------------ 0065 bool RegisterDefaultFactory( PlugInFactory *factory ); 0066 0067 //------------------------------------------------------------------------ 0068 //! Retrieve the plug-in factory for the given URL 0069 //! 0070 //! @return you do not own the returned memory 0071 //------------------------------------------------------------------------ 0072 PlugInFactory *GetFactory( const std::string url ); 0073 0074 //------------------------------------------------------------------------ 0075 //! Process user environment to load plug-in settings. 0076 //! 0077 //! This will try to load a default plug-in from a library pointed to 0078 //! by the XRD_PLUGIN envvar. If this fails it will scan the configuration 0079 //! files located in: 0080 //! 0081 //! 1) system directory: /etc/xrootd/client.plugins.d/ 0082 //! 2) user direvtory: ~/.xrootd/client.plugins.d/ 0083 //! 3) directory pointed to by XRD_PLUGINCONFDIR envvar 0084 //! 0085 //! In that order. 0086 //! 0087 //! The configuration files contain lines with key-value pairs in the 0088 //! form of 'key=value'. 0089 //! 0090 //! Mandatory keys are: 0091 //! url - a semicolon separated list of URLs the plug-in applies to 0092 //! lib - plugin library to be loaded 0093 //! enabled - determines whether the plug-in should be enabled or not 0094 //! 0095 //! You may use any other keys for your own purposes. 0096 //! 0097 //! The config files are processed in alphabetic order, any satteing 0098 //! found later superseeds the previous one. Any setting applied via 0099 //! environment or config files superseeds any setting done 0100 //! programatically. 0101 //! 0102 //! The plug-in library must implement the following C function: 0103 //! 0104 //! @code{.cpp} 0105 //! extern "C" 0106 //! { 0107 //! void *XrdClGetPlugIn( const void *arg ) 0108 //! { 0109 //! return __your_plug_in_factory__; 0110 //! } 0111 //! } 0112 //! @endcode 0113 //! 0114 //! where arg is a const pointer to std::map<std::string, std::string> 0115 //! containing the plug-in configuration. 0116 //------------------------------------------------------------------------ 0117 void ProcessEnvironmentSettings(); 0118 0119 private: 0120 typedef void *(*PlugInFunc_t)( const void *arg ); 0121 0122 struct FactoryHelper 0123 { 0124 FactoryHelper(): plugin(0), factory(0), isEnv(false), counter(0) {} 0125 ~FactoryHelper() 0126 { 0127 delete factory; 0128 if(plugin) plugin->Unload(); 0129 delete plugin; 0130 } 0131 XrdOucPinLoader *plugin; 0132 PlugInFactory *factory; 0133 bool isEnv; 0134 uint32_t counter; 0135 }; 0136 0137 //------------------------------------------------------------------------ 0138 //! Process the configuration directory and load plug in definitions 0139 //------------------------------------------------------------------------ 0140 void ProcessConfigDir( const std::string &dir ); 0141 0142 //------------------------------------------------------------------------ 0143 //! Process a plug-in config file and load the plug-in if possible 0144 //------------------------------------------------------------------------ 0145 void ProcessPlugInConfig( const std::string &confFile ); 0146 0147 //------------------------------------------------------------------------ 0148 //! Load the plug-in and create the factory 0149 //------------------------------------------------------------------------ 0150 std::pair<XrdOucPinLoader*,PlugInFactory*> LoadFactory( 0151 const std::string &lib, 0152 const std::map<std::string, std::string> &config ); 0153 0154 //------------------------------------------------------------------------ 0155 //! Register factory, if successful it actuires ownership of the objects 0156 //! @return true if successfully registered 0157 //------------------------------------------------------------------------ 0158 bool RegisterFactory( const std::string &urlString, 0159 const std::string &lib, 0160 PlugInFactory *factory, 0161 XrdOucPinLoader *plugin ); 0162 0163 //------------------------------------------------------------------------ 0164 //! Normalize a URL 0165 //------------------------------------------------------------------------ 0166 std::string NormalizeURL( const std::string url ); 0167 0168 std::map<std::string, FactoryHelper*> pFactoryMap; 0169 FactoryHelper *pDefaultFactory; 0170 XrdSysMutex pMutex; 0171 }; 0172 } 0173 0174 #endif // __XRD_CL_PLUGIN_MANAGER__
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |