XrdClientEnv.hh

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //                                                                      //
00003 // XrdClientEnv                                                         // 
00004 //                                                                      //
00005 // Author: Fabrizio Furano (INFN Padova, 2004)                          //
00006 // Adapted from TXNetFile (root.cern.ch) originally done by             //
00007 //  Alvise Dorigo, Fabrizio Furano                                      //
00008 //          INFN Padova, 2003                                           //
00009 //                                                                      //
00010 // Singleton used to handle the default parameter values                //
00011 //                                                                      //
00012 //////////////////////////////////////////////////////////////////////////
00013 
00014 //       $Id: XrdClientEnv.hh 38011 2011-02-08 18:35:57Z ganis $
00015 
00016 #ifndef XRD_CENV_H
00017 #define XRD_CENV_H
00018 
00019 #include "XrdOuc/XrdOucEnv.hh"
00020 #include "XrdSys/XrdSysPthread.hh"
00021 
00022 #include <string.h>
00023 
00024 using namespace std;
00025 
00026 
00027 #define EnvGetLong(x) XrdClientEnv::Instance()->ShellGetInt(x)
00028 #define EnvGetString(x) XrdClientEnv::Instance()->ShellGet(x)
00029 #define EnvPutString(name, val) XrdClientEnv::Instance()->Put(name, val)
00030 #define EnvPutInt(name, val) XrdClientEnv::Instance()->PutInt(name, val)
00031 
00032 class XrdClientEnv {
00033  private:
00034 
00035    XrdOucEnv           *fOucEnv;
00036    XrdSysRecMutex       fMutex;
00037    static XrdClientEnv *fgInstance;
00038    XrdOucEnv           *fShellEnv;
00039 
00040  protected:
00041    XrdClientEnv();
00042    ~XrdClientEnv();
00043 
00044    //---------------------------------------------------------------------------
00045    //! Import the variables from the shell environment, the variable names
00046    //! are capitalized and prefixed with "XRD_"
00047    //---------------------------------------------------------------------------
00048    bool ImportStr( const char *varname );
00049    bool ImportInt( const char *varname );
00050 
00051  public:
00052 
00053    const char *          Get(const char *varname) {
00054       const char *res;
00055       XrdSysMutexHelper m(fMutex);
00056 
00057       res = fOucEnv->Get(varname);
00058       return res;
00059    }
00060 
00061    long                   GetInt(const char *varname) {
00062       long res;
00063       XrdSysMutexHelper m(fMutex);
00064 
00065       res = fOucEnv->GetInt(varname);
00066       return res;
00067    }
00068 
00069    //---------------------------------------------------------------------------
00070    //! Get a string variable from the environment, the same as Get, but
00071    //! checks the shell environment first
00072    //---------------------------------------------------------------------------
00073    const char *ShellGet( const char *varname );
00074 
00075    //---------------------------------------------------------------------------
00076    //! Get an integet variable from the environment, the same as GetInt, but
00077    //! checks the shell environment first
00078    //---------------------------------------------------------------------------
00079    long        ShellGetInt( const char *varname );
00080 
00081 
00082    void                   Put(const char *varname, const char *value) {
00083       XrdSysMutexHelper m(fMutex);
00084 
00085       fOucEnv->Put(varname, value);
00086    }
00087 
00088    void  PutInt(const char *varname, long value) {
00089       XrdSysMutexHelper m(fMutex);
00090 
00091       fOucEnv->PutInt(varname, value);
00092    }
00093 
00094    static XrdClientEnv    *Instance();
00095 
00096 };
00097 
00098 #endif

Generated on Tue Jul 5 14:46:18 2011 for ROOT_528-00b_version by  doxygen 1.5.1