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  private:
118  std::string GetEnv( const std::string &key );
119  typedef std::map<std::string, std::pair<std::string, bool> > StringMap;
120  typedef std::map<std::string, std::pair<int, bool> > IntMap;
121 
125  };
126 }
127 
128 #endif // __XRD_CL_ENV_HH__
Definition: XrdSysPthread.hh:224
bool GetInt(const std::string &key, int &value)
XrdSysRWLock pLock
Definition: XrdClEnv.hh:122
bool ImportString(const std::string &key, const std::string &shellKey)
IntMap pIntMap
Definition: XrdClEnv.hh:124
void ReInitialize()
Definition: XrdSysPthread.hh:248
std::string GetEnv(const std::string &key)
bool ImportInt(const std::string &key, const std::string &shellKey)
bool PutString(const std::string &key, const std::string &value)
void WriteLock()
Definition: XrdSysPthread.hh:238
std::map< std::string, std::pair< int, bool > > IntMap
Definition: XrdClEnv.hh:120
bool PutInt(const std::string &key, int value)
virtual ~Env()
Destructor.
Definition: XrdClEnv.hh:42
Definition: XrdClEnv.hh:36
void ReInitializeLock()
Definition: XrdClEnv.hh:109
StringMap pStringMap
Definition: XrdClEnv.hh:123
void UnLock()
Definition: XrdClEnv.hh:101
void UnLock()
Definition: XrdSysPthread.hh:243
void WriteLock()
Definition: XrdClEnv.hh:93
bool GetString(const std::string &key, std::string &value)
std::map< std::string, std::pair< std::string, bool > > StringMap
Definition: XrdClEnv.hh:119