XRootD
Loading...
Searching...
No Matches
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#include <algorithm>
26
28
29namespace XrdCl
30{
31 //----------------------------------------------------------------------------
36 //----------------------------------------------------------------------------
37 class Env
38 {
39 public:
40 //------------------------------------------------------------------------
42 //------------------------------------------------------------------------
43 virtual ~Env() {}
44
45 //------------------------------------------------------------------------
49 //------------------------------------------------------------------------
50 bool GetString( const std::string &key, std::string &value );
51
52 //------------------------------------------------------------------------
57 //------------------------------------------------------------------------
58 bool PutString( const std::string &key, const std::string &value );
59
60 //------------------------------------------------------------------------
64 //------------------------------------------------------------------------
65 bool GetInt( const std::string &key, int &value );
66
67 //------------------------------------------------------------------------
72 //------------------------------------------------------------------------
73 bool PutInt( const std::string &key, int value );
74
75 //------------------------------------------------------------------------
80 //------------------------------------------------------------------------
81 bool ImportInt( const std::string &key, const std::string &shellKey );
82
83 //------------------------------------------------------------------------
88 //------------------------------------------------------------------------
89 bool ImportString( const std::string &key, const std::string &shellKey );
90
91 //------------------------------------------------------------------------
98 //------------------------------------------------------------------------
99 bool GetDefaultIntValue( const std::string &key, int &value );
100
101 //------------------------------------------------------------------------
108 //------------------------------------------------------------------------
109 bool GetDefaultStringValue( const std::string &key, std::string &value );
110
111 //------------------------------------------------------------------------
112 // Lock the environment for writing
113 //------------------------------------------------------------------------
115 {
116 pLock.WriteLock();
117 }
118
119 //------------------------------------------------------------------------
120 // Unlock the environment
121 //------------------------------------------------------------------------
122 void UnLock()
123 {
124 pLock.UnLock();
125 }
126
127 //------------------------------------------------------------------------
128 // Re-initialize the lock
129 //------------------------------------------------------------------------
131 {
132 // this is really shaky, but seems to work on linux and fork safety
133 // is probably not required anywhere else
134 pLock.UnLock();
135 pLock.ReInitialize();
136 }
137
138 //------------------------------------------------------------------------
139 // Re-create the lock in the same memory
140 //------------------------------------------------------------------------
142 {
143 new( &pLock )XrdSysRWLock();
144 }
145
146 private:
147
148 //------------------------------------------------------------------------
149 // Unify the key, make sure it is not case sensitive and strip it of
150 // the XRD_ prefix if necessary
151 //------------------------------------------------------------------------
152 inline std::string UnifyKey( std::string key )
153 {
154 //----------------------------------------------------------------------
155 // Make the key lower case
156 //----------------------------------------------------------------------
157 std::transform( key.begin(), key.end(), key.begin(), ::tolower );
158
159 //----------------------------------------------------------------------
160 // Strip the `xrd_` prefix if necessary
161 //----------------------------------------------------------------------
162 static const char prefix[] = "xrd_";
163 if( key.compare( 0, sizeof( prefix ) - 1, prefix ) == 0 )
164 key = key.substr( sizeof( prefix ) - 1 );
165
166 return key;
167 }
168
169 std::string GetEnv( const std::string &key );
170 typedef std::map<std::string, std::pair<std::string, bool> > StringMap;
171 typedef std::map<std::string, std::pair<int, bool> > IntMap;
172
173 XrdSysRWLock pLock;
174 StringMap pStringMap;
175 IntMap pIntMap;
176 };
177}
178
179#endif // __XRD_CL_ENV_HH__
void RecreateLock()
Definition XrdClEnv.hh:141
bool PutInt(const std::string &key, int value)
Definition XrdClEnv.cc:110
bool PutString(const std::string &key, const std::string &value)
Definition XrdClEnv.cc:52
bool GetDefaultIntValue(const std::string &key, int &value)
Definition XrdClEnv.cc:195
bool ImportString(const std::string &key, const std::string &shellKey)
Definition XrdClEnv.cc:177
void ReInitializeLock()
Definition XrdClEnv.hh:130
void WriteLock()
Definition XrdClEnv.hh:114
bool ImportInt(const std::string &key, const std::string &shellKey)
Definition XrdClEnv.cc:148
bool GetString(const std::string &key, std::string &value)
Definition XrdClEnv.cc:31
void UnLock()
Definition XrdClEnv.hh:122
virtual ~Env()
Destructor.
Definition XrdClEnv.hh:43
bool GetInt(const std::string &key, int &value)
Definition XrdClEnv.cc:89
bool GetDefaultStringValue(const std::string &key, std::string &value)
Definition XrdClEnv.cc:207
void ReInitialize(PrefType)