00001 //------------------------------------------------------------------------------ 00002 // Copyright (c) 2014 by European Organization for Nuclear Research (CERN) 00003 // Author: Lukasz Janyst <ljanyst@cern.ch> 00004 //------------------------------------------------------------------------------ 00005 // This file is part of the XRootD software suite. 00006 // 00007 // XRootD is free software: you can redistribute it and/or modify 00008 // it under the terms of the GNU Lesser General Public License as published by 00009 // the Free Software Foundation, either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // XRootD is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU Lesser General Public License 00018 // along with XRootD. If not, see <http://www.gnu.org/licenses/>. 00019 // 00020 // In applying this licence, CERN does not waive the privileges and immunities 00021 // granted to it by virtue of its status as an Intergovernmental Organization 00022 // or submit itself to any jurisdiction. 00023 //------------------------------------------------------------------------------ 00024 00025 #ifndef __XRD_CL_PLUGIN_MANAGER__ 00026 #define __XRD_CL_PLUGIN_MANAGER__ 00027 00028 #include "XrdCl/XrdClPlugInInterface.hh" 00029 #include "XrdOuc/XrdOucPinLoader.hh" 00030 #include "XrdSys/XrdSysPthread.hh" 00031 00032 #include <map> 00033 #include <string> 00034 #include <utility> 00035 00036 namespace XrdCl 00037 { 00038 //---------------------------------------------------------------------------- 00040 //---------------------------------------------------------------------------- 00041 class PlugInManager 00042 { 00043 public: 00044 //------------------------------------------------------------------------ 00046 //------------------------------------------------------------------------ 00047 PlugInManager(); 00048 00049 //------------------------------------------------------------------------ 00051 //------------------------------------------------------------------------ 00052 ~PlugInManager(); 00053 00054 //------------------------------------------------------------------------ 00057 //------------------------------------------------------------------------ 00058 bool RegisterFactory( const std::string &url, 00059 PlugInFactory *factory ); 00060 00061 //------------------------------------------------------------------------ 00064 //------------------------------------------------------------------------ 00065 bool RegisterDefaultFactory( PlugInFactory *factory ); 00066 00067 //------------------------------------------------------------------------ 00071 //------------------------------------------------------------------------ 00072 PlugInFactory *GetFactory( const std::string url ); 00073 00074 //------------------------------------------------------------------------ 00116 //------------------------------------------------------------------------ 00117 void ProcessEnvironmentSettings(); 00118 00119 private: 00120 typedef void *(*PlugInFunc_t)( const void *arg ); 00121 00122 struct FactoryHelper 00123 { 00124 FactoryHelper(): plugin(0), factory(0), isEnv(false), counter(0) {} 00125 ~FactoryHelper() 00126 { 00127 delete factory; 00128 if(plugin) plugin->Unload(); 00129 delete plugin; 00130 } 00131 XrdOucPinLoader *plugin; 00132 PlugInFactory *factory; 00133 bool isEnv; 00134 uint32_t counter; 00135 }; 00136 00137 //------------------------------------------------------------------------ 00139 //------------------------------------------------------------------------ 00140 void ProcessConfigDir( const std::string &dir ); 00141 00142 //------------------------------------------------------------------------ 00144 //------------------------------------------------------------------------ 00145 void ProcessPlugInConfig( const std::string &confFile ); 00146 00147 //------------------------------------------------------------------------ 00149 //------------------------------------------------------------------------ 00150 std::pair<XrdOucPinLoader*,PlugInFactory*> LoadFactory( 00151 const std::string &lib, 00152 const std::map<std::string, std::string> &config ); 00153 00154 //------------------------------------------------------------------------ 00157 //------------------------------------------------------------------------ 00158 bool RegisterFactory( const std::string &urlString, 00159 const std::string &lib, 00160 PlugInFactory *factory, 00161 XrdOucPinLoader *plugin ); 00162 00163 //------------------------------------------------------------------------ 00165 //------------------------------------------------------------------------ 00166 std::string NormalizeURL( const std::string url ); 00167 00168 std::map<std::string, FactoryHelper*> pFactoryMap; 00169 FactoryHelper *pDefaultFactory; 00170 XrdSysMutex pMutex; 00171 }; 00172 } 00173 00174 #endif // __XRD_CL_PLUGIN_MANAGER__