XrdClEnv.hh

Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
00003 // Author: Lukasz Janyst <ljanyst@cern.ch>
00004 //------------------------------------------------------------------------------
00005 // XRootD is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU Lesser General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // XRootD is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with XRootD.  If not, see <http://www.gnu.org/licenses/>.
00017 //------------------------------------------------------------------------------
00018 
00019 #ifndef __XRD_CL_ENV_HH__
00020 #define __XRD_CL_ENV_HH__
00021 
00022 #include <map>
00023 #include <string>
00024 #include <utility>
00025 
00026 #include "XrdSys/XrdSysPthread.hh"
00027 
00028 namespace XrdCl
00029 {
00030   //----------------------------------------------------------------------------
00035   //----------------------------------------------------------------------------
00036   class Env
00037   {
00038     public:
00039       //------------------------------------------------------------------------
00041       //------------------------------------------------------------------------
00042       virtual ~Env() {}
00043 
00044       //------------------------------------------------------------------------
00048       //------------------------------------------------------------------------
00049       bool GetString( const std::string &key, std::string &value );
00050 
00051       //------------------------------------------------------------------------
00056       //------------------------------------------------------------------------
00057       bool PutString( const std::string &key, const std::string &value );
00058 
00059       //------------------------------------------------------------------------
00063       //------------------------------------------------------------------------
00064       bool GetInt( const std::string &key, int &value );
00065 
00066       //------------------------------------------------------------------------
00071       //------------------------------------------------------------------------
00072       bool PutInt( const std::string &key, int value );
00073 
00074       //------------------------------------------------------------------------
00078       //------------------------------------------------------------------------
00079       bool ImportInt( const std::string &key, const std::string &shellKey );
00080 
00081       //------------------------------------------------------------------------
00085       //------------------------------------------------------------------------
00086       bool ImportString( const std::string &key, const std::string &shellKey );
00087 
00088       //------------------------------------------------------------------------
00089       // Lock the environment for writing
00090       //------------------------------------------------------------------------
00091       void WriteLock()
00092       {
00093         pLock.WriteLock();
00094       }
00095 
00096       //------------------------------------------------------------------------
00097       // Unlock the environment
00098       //------------------------------------------------------------------------
00099       void UnLock()
00100       {
00101         pLock.UnLock();
00102       }
00103 
00104       //------------------------------------------------------------------------
00105       // Re-initialize the lock
00106       //------------------------------------------------------------------------
00107       void ReInitializeLock()
00108       {
00109         // this is really shaky, but seems to work on linux and fork safety
00110         // is probably not required anywhere else
00111         pLock.UnLock();
00112         pLock.ReInitialize();
00113       }
00114 
00115     private:
00116       std::string GetEnv( const std::string &key );
00117       typedef std::map<std::string, std::pair<std::string, bool> > StringMap;
00118       typedef std::map<std::string, std::pair<int, bool> >         IntMap;
00119 
00120       XrdSysRWLock pLock;
00121       StringMap    pStringMap;
00122       IntMap       pIntMap;
00123   };
00124 }
00125 
00126 #endif // __XRD_CL_ENV_HH__

Generated on 16 Jan 2014 for xrootd by  doxygen 1.4.7