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 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

◆ 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 232 of file XrdClEnv.cc.

233 {
234 std::string key = UnifyKey( k );
235 auto itr = theDefaultInts.find( key );
236 if( itr == theDefaultInts.end() ) return false;
237 value = itr->second;
238 return true;
239 }
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 244 of file XrdClEnv.cc.

245 {
246 std::string key = UnifyKey( k );
247 auto itr = theDefaultStrs.find( key );
248 if( itr == theDefaultStrs.end() ) return false;
249 value = itr->second;
250 return true;
251 }
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 89 of file XrdClEnv.cc.

90 {
91 std::string key = UnifyKey( k );
92 XrdSysRWLockHelper scopedLock( pLock );
93 IntMap::iterator it;
94 it = pIntMap.find( key );
95 if( it == pIntMap.end() )
96 {
97 Log *log = DefaultEnv::GetLog();
98 log->Debug( UtilityMsg,
99 "Env: trying to get a non-existent integer entry: %s",
100 key.c_str() );
101 return false;
102 }
103 value = it->second.first;
104 return true;
105 }
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.

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 148 of file XrdClEnv.cc.

149 {
150 std::string key = UnifyKey( k );
151 XrdSysRWLockHelper scopedLock( pLock );
152 PtrMap::iterator it;
153 it = pPtrMap.find( key );
154 if( it == pPtrMap.end() )
155 {
156 Log *log = DefaultEnv::GetLog();
157 log->Debug( UtilityMsg,
158 "Env: trying to get a non-existent pointer entry: %s",
159 key.c_str() );
160 return false;
161 }
162 value = it->second;
163 return true;
164 }

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 185 of file XrdClEnv.cc.

186 {
187 std::string key = UnifyKey( k );
188 XrdSysRWLockHelper scopedLock( pLock, false );
189 std::string strValue = GetEnv( shellKey );
190 if( strValue == "" )
191 return false;
192
193 Log *log = DefaultEnv::GetLog();
194 char *endPtr;
195 int value = (int)strtol( strValue.c_str(), &endPtr, 0 );
196 if( *endPtr )
197 {
198 log->Error( UtilityMsg,
199 "Env: Unable to import %s as %s: %s is not a proper integer",
200 shellKey.c_str(), key.c_str(), strValue.c_str() );
201 return false;
202 }
203
204 log->Info( UtilityMsg, "Env: Importing from shell %s=%d as %s",
205 shellKey.c_str(), value, key.c_str() );
206
207 pIntMap[key] = std::make_pair( value, true );
208 return true;
209 }

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 214 of file XrdClEnv.cc.

215 {
216 std::string key = UnifyKey( k );
217 XrdSysRWLockHelper scopedLock( pLock, false );
218 std::string value = GetEnv( shellKey );
219 if( value == "" )
220 return false;
221
222 Log *log = DefaultEnv::GetLog();
223 log->Info( UtilityMsg, "Env: Importing from shell %s=%s as %s",
224 shellKey.c_str(), value.c_str(), key.c_str() );
225 pStringMap[key] = std::make_pair( value, true );
226 return true;
227 }

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 110 of file XrdClEnv.cc.

111 {
112 std::string key = UnifyKey( k );
113 XrdSysRWLockHelper scopedLock( pLock, false );
114
115 //--------------------------------------------------------------------------
116 // Insert the string if it's not there yet
117 //--------------------------------------------------------------------------
118 IntMap::iterator it;
119 it = pIntMap.find( key );
120 if( it == pIntMap.end() )
121 {
122 pIntMap[key] = std::make_pair( value, false );
123 return true;
124 }
125
126 //--------------------------------------------------------------------------
127 // The entry exists and it has been imported from the shell
128 //--------------------------------------------------------------------------
129 Log *log = DefaultEnv::GetLog();
130 if( it->second.second )
131 {
132 log->Debug( UtilityMsg,
133 "Env: trying to override a shell-imported integer entry: %s",
134 key.c_str() );
135 return false;
136 }
137 log->Debug( UtilityMsg,
138 "Env: overriding entry: %s=%d with %d",
139 key.c_str(), it->second.first, value );
140
141 pIntMap[key] = std::make_pair( value, false );
142 return true;
143 }

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 169 of file XrdClEnv.cc.

170 {
171 std::string key = UnifyKey( k );
172 XrdSysRWLockHelper scopedLock( pLock, false );
173
174 // Pointers cannot be imported from shell environment, we always set it.
175 bool ret = pPtrMap.find(key) == pPtrMap.end();
176
177 pPtrMap[key] = value;
178
179 return ret;
180 }

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 155 of file XrdClEnv.hh.

156 {
157 new( &pLock )XrdSysRWLock();
158 }

Referenced by child().

Here is the caller graph for this function:

◆ ReInitializeLock()

void XrdCl::Env::ReInitializeLock ( )
inline

Definition at line 144 of file XrdClEnv.hh.

145 {
146 // this is really shaky, but seems to work on linux and fork safety
147 // is probably not required anywhere else
148 pLock.UnLock();
149 pLock.ReInitialize();
150 }

◆ UnLock()

void XrdCl::Env::UnLock ( )
inline

Definition at line 136 of file XrdClEnv.hh.

137 {
138 pLock.UnLock();
139 }

◆ WriteLock()

void XrdCl::Env::WriteLock ( )
inline

Definition at line 128 of file XrdClEnv.hh.

129 {
130 pLock.WriteLock();
131 }

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