XRootD
Loading...
Searching...
No Matches
XrdCl::Env Class Reference

#include <XrdClEnv.hh>

Inheritance diagram for XrdCl::Env:
Collaboration diagram for XrdCl::Env:

Public Member Functions

virtual ~Env ()
 Destructor.
bool DelInt (const std::string &key)
bool DelString (const std::string &key)
bool GetDefaultIntValue (const std::string &key, int &value)
bool GetDefaultStringValue (const std::string &key, std::string &value)
bool GetInt (const std::string &key, int &value)
bool GetPtr (const std::string &key, void *&value)
bool GetString (const std::string &key, std::string &value)
bool ImportInt (const std::string &key, const std::string &shellKey)
bool ImportString (const std::string &key, const std::string &shellKey)
bool PutInt (const std::string &key, int value)
bool PutPtr (const std::string &key, void *value)
bool PutString (const std::string &key, const std::string &value)
void RecreateLock ()
void ReInitializeLock ()
void UnLock ()
void WriteLock ()

Detailed Description

A simple key value store intended to hold global configuration. It is able to import the settings from the shell environment, the variables imported this way supersede these provided from the C++ code.

Definition at line 37 of file XrdClEnv.hh.

Constructor & Destructor Documentation

◆ ~Env()

virtual XrdCl::Env::~Env ( )
inlinevirtual

Destructor.

Definition at line 43 of file XrdClEnv.hh.

43{}

Member Function Documentation

◆ DelInt()

bool XrdCl::Env::DelInt ( const std::string & key)

Remove the int associated with the given key

Returns
false if there is a shell-imported setting for this key, true otherwise

Definition at line 174 of file XrdClEnv.cc.

175 {
176 std::string key = UnifyKey( k );
177 XrdSysRWLockHelper scopedLock( pLock, false ); // obtain write lock
178
179 IntMap::iterator it;
180 it = pIntMap.find( key );
181 if( it == pIntMap.end() )
182 return true;
183
184 Log *log = DefaultEnv::GetLog();
185 if( it->second.second )
186 {
187 log->Debug( UtilityMsg,
188 "Env: trying to delete a shell-imported integer entry: %s",
189 key.c_str() );
190 return false;
191 }
192 log->Debug( UtilityMsg, "Env: deleting integer entry: %s", key.c_str() );
193 pIntMap.erase( it );
194 return true;
195 }
static Log * GetLog()
Get default log.
const uint64_t UtilityMsg
XrdSysError Log
Definition XrdConfig.cc:113

References XrdCl::Log::Debug(), XrdCl::DefaultEnv::GetLog(), and XrdCl::UtilityMsg.

Here is the call graph for this function:

◆ DelString()

bool XrdCl::Env::DelString ( const std::string & key)

Remove the string associated with the given key

Returns
false if there is a shell-imported setting for this key, true otherwise

Definition at line 89 of file XrdClEnv.cc.

90 {
91 std::string key = UnifyKey( k );
92 XrdSysRWLockHelper scopedLock( pLock, false ); // obtain write lock
93
94 StringMap::iterator it;
95 it = pStringMap.find( key );
96 if( it == pStringMap.end() )
97 return true;
98
99 Log *log = DefaultEnv::GetLog();
100 if( it->second.second )
101 {
102 log->Debug( UtilityMsg,
103 "Env: trying to delete a shell-imported string entry: %s",
104 key.c_str() );
105 return false;
106 }
107 log->Debug( UtilityMsg, "Env: deleting string entry: %s", key.c_str() );
108 pStringMap.erase( it );
109 return true;
110 }

References XrdCl::Log::Debug(), XrdCl::DefaultEnv::GetLog(), and XrdCl::UtilityMsg.

Here is the call graph for this function:

◆ GetDefaultIntValue()

bool XrdCl::Env::GetDefaultIntValue ( const std::string & key,
int & value )

Get default integer value for the given key

Parameters
key: the key
value: output parameter, default value corresponding to the key
Returns
: true if a default integer value for the given key exists, false otherwise

Definition at line 284 of file XrdClEnv.cc.

285 {
286 std::string key = UnifyKey( k );
287 auto itr = theDefaultInts.find( key );
288 if( itr == theDefaultInts.end() ) return false;
289 value = itr->second;
290 return true;
291 }
static std::unordered_map< std::string, int > theDefaultInts

References XrdCl::theDefaultInts.

◆ GetDefaultStringValue()

bool XrdCl::Env::GetDefaultStringValue ( const std::string & key,
std::string & value )

Get default string value for the given key

Parameters
key: the key
value: output parameter, default value corresponding to the key
Returns
: true if a default string value for the given key exists, false otherwise

Definition at line 296 of file XrdClEnv.cc.

297 {
298 std::string key = UnifyKey( k );
299 auto itr = theDefaultStrs.find( key );
300 if( itr == theDefaultStrs.end() ) return false;
301 value = itr->second;
302 return true;
303 }
static std::unordered_map< std::string, std::string > theDefaultStrs

References XrdCl::theDefaultStrs.

◆ GetInt()

bool XrdCl::Env::GetInt ( const std::string & key,
int & value )

Get an int associated to the given key

Returns
true if the value was found, false otherwise

Definition at line 115 of file XrdClEnv.cc.

116 {
117 std::string key = UnifyKey( k );
118 XrdSysRWLockHelper scopedLock( pLock );
119 IntMap::iterator it;
120 it = pIntMap.find( key );
121 if( it == pIntMap.end() )
122 {
123 Log *log = DefaultEnv::GetLog();
124 log->Debug( UtilityMsg,
125 "Env: trying to get a non-existent integer entry: %s",
126 key.c_str() );
127 return false;
128 }
129 value = it->second.first;
130 return true;
131 }

References XrdCl::Log::Debug(), XrdCl::DefaultEnv::GetLog(), and XrdCl::UtilityMsg.

Referenced by XrdCl::AsyncSocketHandler::AsyncSocketHandler(), XrdCl::Channel::Channel(), XrdCl::PostMasterImpl::PostMasterImpl(), XrdCl::ZipListHandler::ZipListHandler(), XrdCl::CopyProcess::AddJob(), BuildPath(), child(), XrdCl::AsyncSocketHandler::Connect(), XrdClHttp::Factory::GetHeaderTimeoutWithDefault(), XrdClHttp::File::GetHeaderTimeoutWithDefault(), XrdCl::Utils::GetHostAddresses(), XrdCl::Utils::GetIntParameter(), XrdCl::Utils::InferChecksumType(), XrdCl::Socket::Initialize(), XrdCl::XRootDTransport::InitializeChannel(), XrdCl::InitTLS(), XrdCl::URL::IsMetalink(), XrdCl::XRootDTransport::IsStreamBroken(), XrdCl::XRootDTransport::IsStreamTTLElapsed(), main(), XrdCl::XRootDTransport::NeedEncryption(), parent(), XrdCl::FileStateHandler::PgWrite(), prepare(), XrdCl::XRootDMsgHandler::Process(), XrdCl::MessageUtils::ProcessSendParams(), XrdCl::MessageUtils::RewriteCGIAndPath(), XrdCl::FileTimer::Run(), XrdCl::TickGeneratorTask::Run(), XrdClHttp::CurlWorker::Run(), and XrdCl::XRootDTransport::SubStreamNumber().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetPtr()

bool XrdCl::Env::GetPtr ( const std::string & key,
void *& value )

Get a pointer associated to the given key

Returns
true if the value was found, false otherwise

Definition at line 200 of file XrdClEnv.cc.

201 {
202 std::string key = UnifyKey( k );
203 XrdSysRWLockHelper scopedLock( pLock );
204 PtrMap::iterator it;
205 it = pPtrMap.find( key );
206 if( it == pPtrMap.end() )
207 {
208 Log *log = DefaultEnv::GetLog();
209 log->Debug( UtilityMsg,
210 "Env: trying to get a non-existent pointer entry: %s",
211 key.c_str() );
212 return false;
213 }
214 value = it->second;
215 return true;
216 }

References XrdCl::Log::Debug(), XrdCl::DefaultEnv::GetLog(), and XrdCl::UtilityMsg.

Here is the call graph for this function:

◆ GetString()

bool XrdCl::Env::GetString ( const std::string & key,
std::string & value )

Get a string associated to the given key

Returns
true if the value was found, false otherwise

Definition at line 31 of file XrdClEnv.cc.

32 {
33 std::string key = UnifyKey( k );
34 XrdSysRWLockHelper scopedLock( pLock );
35 StringMap::iterator it;
36 it = pStringMap.find( key );
37 if( it == pStringMap.end() )
38 {
39 Log *log = DefaultEnv::GetLog();
40 log->Debug( UtilityMsg,
41 "Env: trying to get a non-existent string entry: %s",
42 key.c_str() );
43 return false;
44 }
45 value = it->second.first;
46 return true;
47 }

References XrdCl::Log::Debug(), XrdCl::DefaultEnv::GetLog(), and XrdCl::UtilityMsg.

Referenced by BuildPath(), BuildPrompt(), DoCat(), DoLS(), DoTail(), XrdCl::DefaultEnv::GetMonitor(), XrdCl::Utils::GetStringParameter(), XrdCl::PostMaster::Initialize(), and XrdCl::PlugInManager::ProcessEnvironmentSettings().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ImportInt()

bool XrdCl::Env::ImportInt ( const std::string & key,
const std::string & shellKey )

Import an int from the shell environment. Any imported setting takes precedence over the one set by other means.

Returns
true if the setting exists in the shell, false otherwise

Definition at line 237 of file XrdClEnv.cc.

238 {
239 std::string key = UnifyKey( k );
240 XrdSysRWLockHelper scopedLock( pLock, false );
241 std::string strValue = GetEnv( shellKey );
242 if( strValue == "" )
243 return false;
244
245 Log *log = DefaultEnv::GetLog();
246 char *endPtr;
247 int value = (int)strtol( strValue.c_str(), &endPtr, 0 );
248 if( *endPtr )
249 {
250 log->Error( UtilityMsg,
251 "Env: Unable to import %s as %s: %s is not a proper integer",
252 shellKey.c_str(), key.c_str(), strValue.c_str() );
253 return false;
254 }
255
256 log->Info( UtilityMsg, "Env: Importing from shell %s=%d as %s",
257 shellKey.c_str(), value, key.c_str() );
258
259 pIntMap[key] = std::make_pair( value, true );
260 return true;
261 }

References XrdCl::Log::Error(), XrdCl::DefaultEnv::GetLog(), XrdCl::Log::Info(), and XrdCl::UtilityMsg.

Here is the call graph for this function:

◆ ImportString()

bool XrdCl::Env::ImportString ( const std::string & key,
const std::string & shellKey )

Import a string from the shell environment. Any imported setting takes precedence over the one set by ther means.

Returns
true if the setting exists in the shell, false otherwise

Definition at line 266 of file XrdClEnv.cc.

267 {
268 std::string key = UnifyKey( k );
269 XrdSysRWLockHelper scopedLock( pLock, false );
270 std::string value = GetEnv( shellKey );
271 if( value == "" )
272 return false;
273
274 Log *log = DefaultEnv::GetLog();
275 log->Info( UtilityMsg, "Env: Importing from shell %s=%s as %s",
276 shellKey.c_str(), value.c_str(), key.c_str() );
277 pStringMap[key] = std::make_pair( value, true );
278 return true;
279 }

References XrdCl::DefaultEnv::GetLog(), XrdCl::Log::Info(), and XrdCl::UtilityMsg.

Here is the call graph for this function:

◆ PutInt()

bool XrdCl::Env::PutInt ( const std::string & key,
int value )

Associate an int with the given key

Returns
false if there is already a shell-imported setting for this key, true otherwise

Definition at line 136 of file XrdClEnv.cc.

137 {
138 std::string key = UnifyKey( k );
139 XrdSysRWLockHelper scopedLock( pLock, false );
140
141 //--------------------------------------------------------------------------
142 // Insert the string if it's not there yet
143 //--------------------------------------------------------------------------
144 IntMap::iterator it;
145 it = pIntMap.find( key );
146 if( it == pIntMap.end() )
147 {
148 pIntMap[key] = std::make_pair( value, false );
149 return true;
150 }
151
152 //--------------------------------------------------------------------------
153 // The entry exists and it has been imported from the shell
154 //--------------------------------------------------------------------------
155 Log *log = DefaultEnv::GetLog();
156 if( it->second.second )
157 {
158 log->Debug( UtilityMsg,
159 "Env: trying to override a shell-imported integer entry: %s",
160 key.c_str() );
161 return false;
162 }
163 log->Debug( UtilityMsg,
164 "Env: overriding entry: %s=%d with %d",
165 key.c_str(), it->second.first, value );
166
167 pIntMap[key] = std::make_pair( value, false );
168 return true;
169 }

References XrdCl::Log::Debug(), XrdCl::DefaultEnv::GetLog(), and XrdCl::UtilityMsg.

Referenced by DoCD(), DoLocate(), ExecuteCommand(), ExecuteInteractive(), XrdCl::InitTLS(), main(), ProcessCommandLineEnv(), and XrdPosixConfig::SetEnv().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PutPtr()

bool XrdCl::Env::PutPtr ( const std::string & key,
void * value )

Associate an int with the given key

Returns
true if the key was previously unset, false otherwise.

Definition at line 221 of file XrdClEnv.cc.

222 {
223 std::string key = UnifyKey( k );
224 XrdSysRWLockHelper scopedLock( pLock, false );
225
226 // Pointers cannot be imported from shell environment, we always set it.
227 bool ret = pPtrMap.find(key) == pPtrMap.end();
228
229 pPtrMap[key] = value;
230
231 return ret;
232 }

Referenced by XrdPosixConfig::SetEnv().

Here is the caller graph for this function:

◆ PutString()

bool XrdCl::Env::PutString ( const std::string & key,
const std::string & value )

Associate a string with the given key

Returns
false if there is already a shell-imported setting for this key, true otherwise

Definition at line 52 of file XrdClEnv.cc.

53 {
54 std::string key = UnifyKey( k );
55 XrdSysRWLockHelper scopedLock( pLock, false );
56
57 //--------------------------------------------------------------------------
58 // Insert the string if it's not there yet
59 //--------------------------------------------------------------------------
60 StringMap::iterator it;
61 it = pStringMap.find( key );
62 if( it == pStringMap.end() )
63 {
64 pStringMap[key] = std::make_pair( value, false );
65 return true;
66 }
67
68 //--------------------------------------------------------------------------
69 // The entry exists and it has been imported from the shell
70 //--------------------------------------------------------------------------
71 Log *log = DefaultEnv::GetLog();
72 if( it->second.second )
73 {
74 log->Debug( UtilityMsg,
75 "Env: trying to override a shell-imported string entry: %s",
76 key.c_str() );
77 return false;
78 }
79 log->Debug( UtilityMsg,
80 "Env: overriding entry: %s=\"%s\" with \"%s\"",
81 key.c_str(), it->second.first.c_str(), value.c_str() );
82 pStringMap[key] = std::make_pair( value, false );
83 return true;
84 }

References XrdCl::Log::Debug(), XrdCl::DefaultEnv::GetLog(), and XrdCl::UtilityMsg.

Referenced by CreateExecutor(), DoCD(), main(), and ProcessCommandLineEnv().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RecreateLock()

void XrdCl::Env::RecreateLock ( )
inline

Definition at line 171 of file XrdClEnv.hh.

172 {
173 new( &pLock )XrdSysRWLock();
174 }

Referenced by child().

Here is the caller graph for this function:

◆ ReInitializeLock()

void XrdCl::Env::ReInitializeLock ( )
inline

Definition at line 160 of file XrdClEnv.hh.

161 {
162 // this is really shaky, but seems to work on linux and fork safety
163 // is probably not required anywhere else
164 pLock.UnLock();
165 pLock.ReInitialize();
166 }

◆ UnLock()

void XrdCl::Env::UnLock ( )
inline

Definition at line 152 of file XrdClEnv.hh.

153 {
154 pLock.UnLock();
155 }

◆ WriteLock()

void XrdCl::Env::WriteLock ( )
inline

Definition at line 144 of file XrdClEnv.hh.

145 {
146 pLock.WriteLock();
147 }

The documentation for this class was generated from the following files: