Logo ROOT   6.14/05
Reference Guide
XrdClientEnv.hh
Go to the documentation of this file.
1 #ifndef XRD_CENV_H
2 #define XRD_CENV_H
3 /******************************************************************************/
4 /* */
5 /* X r d C l i e n t E n v . h h */
6 /* */
7 /* Author: Fabrizio Furano (INFN Padova, 2004) */
8 /* Adapted from TXNetFile (root.cern.ch) originally done by */
9 /* Alvise Dorigo, Fabrizio Furano */
10 /* INFN Padova, 2003 */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 //////////////////////////////////////////////////////////////////////////
34 // //
35 // Singleton used to handle the default parameter values //
36 // //
37 //////////////////////////////////////////////////////////////////////////
38 
39 #include "XrdOuc/XrdOucEnv.hh"
40 #include "XrdSys/XrdSysPthread.hh"
41 
42 #include <string.h>
43 
44 #define EnvGetLong(x) XrdClientEnv::Instance()->ShellGetInt(x)
45 #define EnvGetString(x) XrdClientEnv::Instance()->ShellGet(x)
46 #define EnvPutString(name, val) XrdClientEnv::Instance()->Put(name, val)
47 #define EnvPutInt(name, val) XrdClientEnv::Instance()->PutInt(name, val)
48 
49 class XrdClientEnv {
50  private:
51 
52  XrdOucEnv *fOucEnv;
55  XrdOucEnv *fShellEnv;
56 
57  protected:
58  XrdClientEnv();
59  ~XrdClientEnv();
60 
61  //---------------------------------------------------------------------------
62  //! Import the variables from the shell environment, the variable names
63  //! are capitalized and prefixed with "XRD_"
64  //---------------------------------------------------------------------------
65  bool ImportStr( const char *varname );
66  bool ImportInt( const char *varname );
67 
68  public:
69 
70  const char * Get(const char *varname) {
71  const char *res;
72  XrdSysMutexHelper m(fMutex);
73 
74  res = fOucEnv->Get(varname);
75  return res;
76  }
77 
78  long GetInt(const char *varname) {
79  long res;
80  XrdSysMutexHelper m(fMutex);
81 
82  res = fOucEnv->GetInt(varname);
83  return res;
84  }
85 
86  //---------------------------------------------------------------------------
87  //! Get a string variable from the environment, the same as Get, but
88  //! checks the shell environment first
89  //---------------------------------------------------------------------------
90  const char *ShellGet( const char *varname );
91 
92  //---------------------------------------------------------------------------
93  //! Get an integet variable from the environment, the same as GetInt, but
94  //! checks the shell environment first
95  //---------------------------------------------------------------------------
96  long ShellGetInt( const char *varname );
97 
98 
99  void Put(const char *varname, const char *value) {
100  XrdSysMutexHelper m(fMutex);
101 
102  fOucEnv->Put(varname, value);
103  }
104 
105  void PutInt(const char *varname, long value) {
106  XrdSysMutexHelper m(fMutex);
107 
108  fOucEnv->PutInt(varname, value);
109  }
110  void Lock()
111  {
112  fMutex.Lock();
113  }
114 
115  void UnLock()
116  {
117  fMutex.UnLock();
118  }
119 
121  {
122  return fMutex.ReInitRecMutex();
123  }
124 
125  static XrdClientEnv *Instance();
126 };
127 #endif
XrdOucEnv * fShellEnv
Definition: XrdClientEnv.hh:55
auto * m
Definition: textangle.C:8
static XrdClientEnv * fgInstance
Definition: XrdClientEnv.hh:54
XrdSysRecMutex fMutex
Definition: XrdClientEnv.hh:53
#define XrdSysRecMutex
Definition: XrdSysToOuc.h:18
void Put(const char *varname, const char *value)
Definition: XrdClientEnv.hh:99
long GetInt(const char *varname)
Definition: XrdClientEnv.hh:78
const char * Get(const char *varname)
Definition: XrdClientEnv.hh:70
XrdOucEnv * fOucEnv
Definition: XrdClientEnv.hh:52
const char * ShellGet(const char *varname)
Get a string variable from the environment, the same as Get, but checks the shell environment first...
#define XrdSysMutexHelper
Definition: XrdSysToOuc.h:17
static XrdClientEnv * Instance()
long ShellGetInt(const char *varname)
Get an integet variable from the environment, the same as GetInt, but checks the shell environment fi...
bool ImportInt(const char *varname)
void PutInt(const char *varname, long value)
bool ImportStr(const char *varname)
Import the variables from the shell environment, the variable names are capitalized and prefixed with...