xrootd
XrdClientEnv.hh
Go to the documentation of this file.
1 
2 // //
3 // XrdClientEnv //
4 // //
5 // Author: Fabrizio Furano (INFN Padova, 2004) //
6 // Adapted from TXNetFile (root.cern.ch) originally done by //
7 // Alvise Dorigo, Fabrizio Furano //
8 // INFN Padova, 2003 //
9 // //
10 // Singleton used to handle the default parameter values //
11 // //
13 
14 // $Id$
15 
16 #ifndef XRD_CENV_H
17 #define XRD_CENV_H
18 
19 #include "XrdOuc/XrdOucEnv.hh"
20 #include "XrdSys/XrdSysPthread.hh"
21 
22 #include <string.h>
23 
24 using namespace std;
25 
26 
27 #define EnvGetLong(x) XrdClientEnv::Instance()->ShellGetInt(x)
28 #define EnvGetString(x) XrdClientEnv::Instance()->ShellGet(x)
29 #define EnvPutString(name, val) XrdClientEnv::Instance()->Put(name, val)
30 #define EnvPutInt(name, val) XrdClientEnv::Instance()->PutInt(name, val)
31 
32 class XrdClientEnv {
33  private:
34 
39 
40  protected:
41  XrdClientEnv();
42  ~XrdClientEnv();
43 
44  //---------------------------------------------------------------------------
47  //---------------------------------------------------------------------------
48  bool ImportStr( const char *varname );
49  bool ImportInt( const char *varname );
50 
51  public:
52 
53  const char * Get(const char *varname) {
54  const char *res;
55  XrdSysMutexHelper m(fMutex);
56 
57  res = fOucEnv->Get(varname);
58  return res;
59  }
60 
61  long GetInt(const char *varname) {
62  long res;
63  XrdSysMutexHelper m(fMutex);
64 
65  res = fOucEnv->GetInt(varname);
66  return res;
67  }
68 
69  //---------------------------------------------------------------------------
72  //---------------------------------------------------------------------------
73  const char *ShellGet( const char *varname );
74 
75  //---------------------------------------------------------------------------
78  //---------------------------------------------------------------------------
79  long ShellGetInt( const char *varname );
80 
81 
82  void Put(const char *varname, const char *value) {
83  XrdSysMutexHelper m(fMutex);
84 
85  fOucEnv->Put(varname, value);
86  }
87 
88  void PutInt(const char *varname, long value) {
89  XrdSysMutexHelper m(fMutex);
90 
91  fOucEnv->PutInt(varname, value);
92  }
93  void Lock()
94  {
95  fMutex.Lock();
96  }
97 
98  void UnLock()
99  {
100  fMutex.UnLock();
101  }
102 
103  int ReInitLock()
104  {
105  return fMutex.ReInitRecMutex();
106  }
107 
108  static XrdClientEnv *Instance();
109 };
110 
111 #endif