XRootD
XrdCl::Env Class Reference

#include <XrdClEnv.hh>

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

Public Member Functions

virtual ~Env ()
 Destructor. More...
 
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 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 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 195 of file XrdClEnv.cc.

196  {
197  std::string key = UnifyKey( k );
198  auto itr = theDefaultInts.find( key );
199  if( itr == theDefaultInts.end() ) return false;
200  value = itr->second;
201  return true;
202  }
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 207 of file XrdClEnv.cc.

208  {
209  std::string key = UnifyKey( k );
210  auto itr = theDefaultStrs.find( key );
211  if( itr == theDefaultStrs.end() ) return false;
212  value = itr->second;
213  return true;
214  }
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:112

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(), 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::TickGeneratorTask::Run(), XrdCl::FileTimer::Run(), and XrdCl::XRootDTransport::SubStreamNumber().

+ Here is the call graph for this function:
+ Here is the caller 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 148 of file XrdClEnv.cc.

149  {
150  std::string key = UnifyKey( k );
151  XrdSysRWLockHelper scopedLock( pLock, false );
152  std::string strValue = GetEnv( shellKey );
153  if( strValue == "" )
154  return false;
155 
156  Log *log = DefaultEnv::GetLog();
157  char *endPtr;
158  int value = (int)strtol( strValue.c_str(), &endPtr, 0 );
159  if( *endPtr )
160  {
161  log->Error( UtilityMsg,
162  "Env: Unable to import %s as %s: %s is not a proper integer",
163  shellKey.c_str(), key.c_str(), strValue.c_str() );
164  return false;
165  }
166 
167  log->Info( UtilityMsg, "Env: Importing from shell %s=%d as %s",
168  shellKey.c_str(), value, key.c_str() );
169 
170  pIntMap[key] = std::make_pair( value, true );
171  return true;
172  }

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

178  {
179  std::string key = UnifyKey( k );
180  XrdSysRWLockHelper scopedLock( pLock, false );
181  std::string value = GetEnv( shellKey );
182  if( value == "" )
183  return false;
184 
185  Log *log = DefaultEnv::GetLog();
186  log->Info( UtilityMsg, "Env: Importing from shell %s=%s as %s",
187  shellKey.c_str(), value.c_str(), key.c_str() );
188  pStringMap[key] = std::make_pair( value, true );
189  return true;
190  }

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(), XrdSsiClientProvider::GetService(), XrdCl::InitTLS(), main(), ProcessCommandLineEnv(), XrdPosixConfig::SetEnv(), and XrdSsiClientProvider::SetTimeout().

+ Here is the call graph for this function:
+ 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 XrdCl::FSExecutor::FSExecutor(), 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 141 of file XrdClEnv.hh.

142  {
143  new( &pLock )XrdSysRWLock();
144  }

Referenced by child().

+ Here is the caller graph for this function:

◆ ReInitializeLock()

void XrdCl::Env::ReInitializeLock ( )
inline

Definition at line 130 of file XrdClEnv.hh.

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  }
void ReInitialize(PrefType)

References XrdSysRWLock::ReInitialize(), and XrdSysRWLock::UnLock().

+ Here is the call graph for this function:

◆ UnLock()

void XrdCl::Env::UnLock ( )
inline

Definition at line 122 of file XrdClEnv.hh.

123  {
124  pLock.UnLock();
125  }

References XrdSysRWLock::UnLock().

+ Here is the call graph for this function:

◆ WriteLock()

void XrdCl::Env::WriteLock ( )
inline

Definition at line 114 of file XrdClEnv.hh.

115  {
116  pLock.WriteLock();
117  }

References XrdSysRWLock::WriteLock().

+ Here is the call graph for this function:

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