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  //------------------------------------------------------------------------
78  //------------------------------------------------------------------------
79  bool ImportInt( const std::string &key, const std::string &shellKey );
80 
81  //------------------------------------------------------------------------
85  //------------------------------------------------------------------------
86  bool ImportString( const std::string &key, const std::string &shellKey );
87 
88  //------------------------------------------------------------------------
89  // Lock the environment for writing
90  //------------------------------------------------------------------------
91  void WriteLock()
92  {
93  pLock.WriteLock();
94  }
95 
96  //------------------------------------------------------------------------
97  // Unlock the environment
98  //------------------------------------------------------------------------
99  void UnLock()
100  {
101  pLock.UnLock();
102  }
103 
104  //------------------------------------------------------------------------
105  // Re-initialize the lock
106  //------------------------------------------------------------------------
108  {
109  // this is really shaky, but seems to work on linux and fork safety
110  // is probably not required anywhere else
111  pLock.UnLock();
113  }
114 
115  private:
116  std::string GetEnv( const std::string &key );
117  typedef std::map<std::string, std::pair<std::string, bool> > StringMap;
118  typedef std::map<std::string, std::pair<int, bool> > IntMap;
119 
123  };
124 }
125 
126 #endif // __XRD_CL_ENV_HH__