00001 //------------------------------------------------------------------------------ 00002 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN) 00003 // Author: Lukasz Janyst <ljanyst@cern.ch> 00004 //------------------------------------------------------------------------------ 00005 // XRootD is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU Lesser General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // XRootD is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with XRootD. If not, see <http://www.gnu.org/licenses/>. 00017 //------------------------------------------------------------------------------ 00018 00019 #ifndef __XRD_CL_ENV_HH__ 00020 #define __XRD_CL_ENV_HH__ 00021 00022 #include <map> 00023 #include <string> 00024 #include <utility> 00025 00026 #include "XrdSys/XrdSysPthread.hh" 00027 00028 namespace XrdCl 00029 { 00030 //---------------------------------------------------------------------------- 00035 //---------------------------------------------------------------------------- 00036 class Env 00037 { 00038 public: 00039 //------------------------------------------------------------------------ 00041 //------------------------------------------------------------------------ 00042 virtual ~Env() {} 00043 00044 //------------------------------------------------------------------------ 00048 //------------------------------------------------------------------------ 00049 bool GetString( const std::string &key, std::string &value ); 00050 00051 //------------------------------------------------------------------------ 00056 //------------------------------------------------------------------------ 00057 bool PutString( const std::string &key, const std::string &value ); 00058 00059 //------------------------------------------------------------------------ 00063 //------------------------------------------------------------------------ 00064 bool GetInt( const std::string &key, int &value ); 00065 00066 //------------------------------------------------------------------------ 00071 //------------------------------------------------------------------------ 00072 bool PutInt( const std::string &key, int value ); 00073 00074 //------------------------------------------------------------------------ 00079 //------------------------------------------------------------------------ 00080 bool ImportInt( const std::string &key, const std::string &shellKey ); 00081 00082 //------------------------------------------------------------------------ 00087 //------------------------------------------------------------------------ 00088 bool ImportString( const std::string &key, const std::string &shellKey ); 00089 00090 //------------------------------------------------------------------------ 00091 // Lock the environment for writing 00092 //------------------------------------------------------------------------ 00093 void WriteLock() 00094 { 00095 pLock.WriteLock(); 00096 } 00097 00098 //------------------------------------------------------------------------ 00099 // Unlock the environment 00100 //------------------------------------------------------------------------ 00101 void UnLock() 00102 { 00103 pLock.UnLock(); 00104 } 00105 00106 //------------------------------------------------------------------------ 00107 // Re-initialize the lock 00108 //------------------------------------------------------------------------ 00109 void ReInitializeLock() 00110 { 00111 // this is really shaky, but seems to work on linux and fork safety 00112 // is probably not required anywhere else 00113 pLock.UnLock(); 00114 pLock.ReInitialize(); 00115 } 00116 00117 private: 00118 std::string GetEnv( const std::string &key ); 00119 typedef std::map<std::string, std::pair<std::string, bool> > StringMap; 00120 typedef std::map<std::string, std::pair<int, bool> > IntMap; 00121 00122 XrdSysRWLock pLock; 00123 StringMap pStringMap; 00124 IntMap pIntMap; 00125 }; 00126 } 00127 00128 #endif // __XRD_CL_ENV_HH__