00001 #ifndef __XRDOUCPINKING_HH__ 00002 #define __XRDOUCPINKING_HH__ 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d O u c P i n K i n g . h h */ 00006 /* */ 00007 /* (c) 2020 by the Board of Trustees of the Leland Stanford, Jr., University */ 00008 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 00009 /* DE-AC02-76-SFO0515 with the Department of Energy */ 00010 /* */ 00011 /* This file is part of the XRootD software suite. */ 00012 /* */ 00013 /* XRootD is free software: you can redistribute it and/or modify it under */ 00014 /* the terms of the GNU Lesser General Public License as published by the */ 00015 /* Free Software Foundation, either version 3 of the License, or (at your */ 00016 /* option) any later version. */ 00017 /* */ 00018 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 00019 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 00020 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 00021 /* License for more details. */ 00022 /* */ 00023 /* You should have received a copy of the GNU Lesser General Public License */ 00024 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 00025 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 00026 /* */ 00027 /* The copyright holder's institutional names and contributor's names may not */ 00028 /* be used to endorse or promote products derived from this software without */ 00029 /* specific prior written permission of the institution or contributor. */ 00030 /******************************************************************************/ 00031 00032 #include <string> 00033 #include <vector> 00034 00035 #include "XrdOuc/XrdOucPinLoader.hh" 00036 #include "XrdOuc/XrdOucPinObject.hh" 00037 #include "XrdSys/XrdSysError.hh" 00038 00039 //------------------------------------------------------------------------------ 00043 //------------------------------------------------------------------------------ 00044 00045 class XrdOucEnv; 00046 struct XrdVersionInfo; 00047 00048 template<class T> 00049 class XrdOucPinKing 00050 { 00051 public: 00052 00053 //------------------------------------------------------------------------------ 00060 //------------------------------------------------------------------------------ 00061 00062 void Add(const char *path, 00063 const char *parms, 00064 bool push=false) 00065 {if (push) pinVec.push_back(pinInfo(path, parms)); 00066 else pinVec[0] = pinInfo(path, parms); 00067 } 00068 00069 //------------------------------------------------------------------------------ 00075 //------------------------------------------------------------------------------ 00076 00077 T *Load(const char *Symbol); 00078 00079 //------------------------------------------------------------------------------ 00089 //------------------------------------------------------------------------------ 00090 00091 XrdOucPinKing(const char *drctv, 00092 XrdOucEnv &envR, 00093 XrdSysError &errR, 00094 XrdVersionInfo *vinfo=0) 00095 : Drctv(drctv), eInfo(envR), eMsg(errR), vInfo(vinfo) 00096 {pinVec.push_back(pinInfo(0,0));} 00097 00098 //------------------------------------------------------------------------------ 00102 //------------------------------------------------------------------------------ 00103 00104 ~XrdOucPinKing() {} 00105 00106 private: 00107 00108 const char *Drctv; 00109 XrdOucEnv &eInfo; 00110 XrdSysError &eMsg; 00111 XrdVersionInfo *vInfo; 00112 00113 struct pinInfo 00114 { 00115 std::string path; 00116 std::string parm; 00117 XrdOucPinLoader *pinP; 00118 00119 pinInfo(const char *pth, const char *prm) 00120 : path(pth ? pth : ""), parm(prm ? prm : ""), pinP(0) {} 00121 00122 ~pinInfo() {delete pinP;} 00123 }; 00124 00125 std::vector<pinInfo> pinVec; 00126 }; 00127 00128 00129 template<class T> 00130 T *XrdOucPinKing<T>::Load(const char *Symbol) 00131 { 00132 XrdOucPinObject<T> *objPIN; 00133 T *lastPIN = 0; 00134 typename std::vector<pinInfo>::iterator it; 00135 00136 for (it = pinVec.begin(); it != pinVec.end(); it++) 00137 {if (it->path.size() == 0) continue; 00138 it->pinP = new XrdOucPinLoader(&eMsg, vInfo, Drctv, it->path.c_str()); 00139 objPIN = (XrdOucPinObject<T> *)(it->pinP->Resolve(Symbol)); 00140 if (!objPIN 00141 || !(lastPIN = objPIN->getInstance(it->parm.c_str(), eInfo, 00142 *(eMsg.logger()), lastPIN))) 00143 return 0; 00144 } 00145 return lastPIN; 00146 } 00147 #endif