XrdClientEnv.hh

Go to the documentation of this file.
00001 #ifndef XRD_CENV_H
00002 #define XRD_CENV_H
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                     X r d C l i e n t E n v . h h                          */
00006 /*                                                                            */
00007 /* Author: Fabrizio Furano (INFN Padova, 2004)                                */
00008 /* Adapted from TXNetFile (root.cern.ch) originally done by                   */
00009 /*  Alvise Dorigo, Fabrizio Furano                                            */
00010 /*          INFN Padova, 2003                                                 */
00011 /*                                                                            */
00012 /* This file is part of the XRootD software suite.                            */
00013 /*                                                                            */
00014 /* XRootD is free software: you can redistribute it and/or modify it under    */
00015 /* the terms of the GNU Lesser General Public License as published by the     */
00016 /* Free Software Foundation, either version 3 of the License, or (at your     */
00017 /* option) any later version.                                                 */
00018 /*                                                                            */
00019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT      */
00020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or      */
00021 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public       */
00022 /* License for more details.                                                  */
00023 /*                                                                            */
00024 /* You should have received a copy of the GNU Lesser General Public License   */
00025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file  */
00026 /* COPYING (GPL license).  If not, see <http://www.gnu.org/licenses/>.        */
00027 /*                                                                            */
00028 /* The copyright holder's institutional names and contributor's names may not */
00029 /* be used to endorse or promote products derived from this software without  */
00030 /* specific prior written permission of the institution or contributor.       */
00031 /******************************************************************************/
00032 
00034 //                                                                      //
00035 // Singleton used to handle the default parameter values                //
00036 //                                                                      //
00038 
00039 #include "XrdOuc/XrdOucEnv.hh"
00040 #include "XrdSys/XrdSysPthread.hh"
00041 
00042 #include <string.h>
00043 
00044 #define EnvGetLong(x) XrdClientEnv::Instance()->ShellGetInt(x)
00045 #define EnvGetString(x) XrdClientEnv::Instance()->ShellGet(x)
00046 #define EnvPutString(name, val) XrdClientEnv::Instance()->Put(name, val)
00047 #define EnvPutInt(name, val) XrdClientEnv::Instance()->PutInt(name, val)
00048 
00049 class XrdClientEnv {
00050  private:
00051 
00052    XrdOucEnv           *fOucEnv;
00053    XrdSysRecMutex       fMutex;
00054    static XrdClientEnv *fgInstance;
00055    XrdOucEnv           *fShellEnv;
00056 
00057  protected:
00058    XrdClientEnv();
00059    ~XrdClientEnv();
00060 
00061    //---------------------------------------------------------------------------
00064    //---------------------------------------------------------------------------
00065    bool ImportStr( const char *varname );
00066    bool ImportInt( const char *varname );
00067 
00068  public:
00069 
00070    const char *          Get(const char *varname) {
00071       const char *res;
00072       XrdSysMutexHelper m(fMutex);
00073 
00074       res = fOucEnv->Get(varname);
00075       return res;
00076    }
00077 
00078    long                   GetInt(const char *varname) {
00079       long res;
00080       XrdSysMutexHelper m(fMutex);
00081 
00082       res = fOucEnv->GetInt(varname);
00083       return res;
00084    }
00085 
00086    //---------------------------------------------------------------------------
00089    //---------------------------------------------------------------------------
00090    const char *ShellGet( const char *varname );
00091 
00092    //---------------------------------------------------------------------------
00095    //---------------------------------------------------------------------------
00096    long        ShellGetInt( const char *varname );
00097 
00098 
00099    void                   Put(const char *varname, const char *value) {
00100       XrdSysMutexHelper m(fMutex);
00101 
00102       fOucEnv->Put(varname, value);
00103    }
00104 
00105    void  PutInt(const char *varname, long value) {
00106       XrdSysMutexHelper m(fMutex);
00107 
00108       fOucEnv->PutInt(varname, value);
00109    }
00110    void Lock()
00111    {
00112      fMutex.Lock();
00113    }
00114 
00115    void UnLock()
00116    {
00117      fMutex.UnLock();
00118    }
00119 
00120    int ReInitLock()
00121    {
00122      return fMutex.ReInitRecMutex();
00123    }
00124 
00125   static XrdClientEnv *Instance();
00126 };
00127 #endif

Generated on 5 Oct 2016 for xrootd by  doxygen 1.4.7