xrootd
XrdClEnv.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
3 // Author: Lukasz Janyst <ljanyst@cern.ch>
4 //------------------------------------------------------------------------------
5 // XRootD is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // XRootD is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
17 //------------------------------------------------------------------------------
18 
19 #ifndef __XRD_CL_ENV_HH__
20 #define __XRD_CL_ENV_HH__
21 
22 #include <map>
23 #include <string>
24 #include <utility>
25 
26 #include "XrdSys/XrdSysPthread.hh"
27 
28 namespace XrdCl
29 {
30  //----------------------------------------------------------------------------
35  //----------------------------------------------------------------------------
36  class Env
37  {
38  public:
39  //------------------------------------------------------------------------
41  //------------------------------------------------------------------------
42  virtual ~Env() {}
43 
44  //------------------------------------------------------------------------
48  //------------------------------------------------------------------------
49  bool GetString( const std::string &key, std::string &value );
50 
51  //------------------------------------------------------------------------
56  //------------------------------------------------------------------------
57  bool PutString( const std::string &key, const std::string &value );
58 
59  //------------------------------------------------------------------------
63  //------------------------------------------------------------------------
64  bool GetInt( const std::string &key, int &value );
65 
66  //------------------------------------------------------------------------
71  //------------------------------------------------------------------------
72  bool PutInt( const std::string &key, int value );
73 
74  //------------------------------------------------------------------------
79  //------------------------------------------------------------------------
80  bool ImportInt( const std::string &key, const std::string &shellKey );
81 
82  //------------------------------------------------------------------------
87  //------------------------------------------------------------------------
88  bool ImportString( const std::string &key, const std::string &shellKey );
89 
90  //------------------------------------------------------------------------
91  // Lock the environment for writing
92  //------------------------------------------------------------------------
93  void WriteLock()
94  {
95  pLock.WriteLock();
96  }
97 
98  //------------------------------------------------------------------------
99  // Unlock the environment
100  //------------------------------------------------------------------------
101  void UnLock()
102  {
103  pLock.UnLock();
104  }
105 
106  //------------------------------------------------------------------------
107  // Re-initialize the lock
108  //------------------------------------------------------------------------
110  {
111  // this is really shaky, but seems to work on linux and fork safety
112  // is probably not required anywhere else
113  pLock.UnLock();
115  }
116 
117  //------------------------------------------------------------------------
118  // Re-create the lock in the same memory
119  //------------------------------------------------------------------------
121  {
122  new( &pLock )XrdSysRWLock();
123  }
124 
125  private:
126 
127  std::string GetEnv( const std::string &key );
128  typedef std::map<std::string, std::pair<std::string, bool> > StringMap;
129  typedef std::map<std::string, std::pair<int, bool> > IntMap;
130 
134  };
135 }
136 
137 #endif // __XRD_CL_ENV_HH__
XrdCl::Env
Definition: XrdClEnv.hh:37
XrdCl::Env::GetEnv
std::string GetEnv(const std::string &key)
XrdCl::Env::PutInt
bool PutInt(const std::string &key, int value)
XrdSysPthread.hh
XrdSysRWLock::UnLock
void UnLock()
Definition: XrdSysPthread.hh:314
XrdCl::Env::pLock
XrdSysRWLock pLock
Definition: XrdClEnv.hh:131
XrdCl::Env::pStringMap
StringMap pStringMap
Definition: XrdClEnv.hh:132
XrdCl::Env::IntMap
std::map< std::string, std::pair< int, bool > > IntMap
Definition: XrdClEnv.hh:129
XrdSysRWLock::WriteLock
void WriteLock()
Definition: XrdSysPthread.hh:309
XrdSysRWLock
Definition: XrdSysPthread.hh:296
XrdCl::Env::GetString
bool GetString(const std::string &key, std::string &value)
XrdCl::Env::UnLock
void UnLock()
Definition: XrdClEnv.hh:101
XrdCl::Env::pIntMap
IntMap pIntMap
Definition: XrdClEnv.hh:133
XrdCl::Env::StringMap
std::map< std::string, std::pair< std::string, bool > > StringMap
Definition: XrdClEnv.hh:128
XrdCl::Env::WriteLock
void WriteLock()
Definition: XrdClEnv.hh:93
XrdCl::Env::ImportInt
bool ImportInt(const std::string &key, const std::string &shellKey)
XrdCl::Env::~Env
virtual ~Env()
Destructor.
Definition: XrdClEnv.hh:42
XrdCl
Definition: XrdClAnyObject.hh:26
XrdSysRWLock::ReInitialize
void ReInitialize()
Definition: XrdSysPthread.hh:319
XrdCl::Env::ImportString
bool ImportString(const std::string &key, const std::string &shellKey)
XrdCl::Env::ReInitializeLock
void ReInitializeLock()
Definition: XrdClEnv.hh:109
XrdCl::Env::PutString
bool PutString(const std::string &key, const std::string &value)
XrdCl::Env::GetInt
bool GetInt(const std::string &key, int &value)
XrdCl::Env::RecreateLock
void RecreateLock()
Definition: XrdClEnv.hh:120