xrootd
XrdClForkHandler.hh
Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Copyright (c) 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_FORK_HANDLER_HH__
00020 #define __XRD_CL_FORK_HANDLER_HH__
00021 
00022 #include <XrdSys/XrdSysPthread.hh>
00023 #include <set>
00024 
00025 namespace XrdCl
00026 {
00027   class FileStateHandler;
00028   class FileSystem;
00029   class PostMaster;
00030   class FileTimer;
00031 
00032   //----------------------------------------------------------------------------
00033   // Helper class for handling forking
00034   //----------------------------------------------------------------------------
00035   class ForkHandler
00036   {
00037     public:
00038       ForkHandler();
00039 
00040       //------------------------------------------------------------------------
00042       //------------------------------------------------------------------------
00043       void RegisterFileObject( FileStateHandler *file )
00044       {
00045         XrdSysMutexHelper scopedLock( pMutex );
00046         pFileObjects.insert( file );
00047       }
00048 
00049       //------------------------------------------------------------------------
00050       // Un-register a file object
00051       //------------------------------------------------------------------------
00052       void UnRegisterFileObject( FileStateHandler *file )
00053       {
00054         XrdSysMutexHelper scopedLock( pMutex );
00055         pFileObjects.erase( file );
00056       }
00057 
00058       //------------------------------------------------------------------------
00059       // Register a file system object
00060       //------------------------------------------------------------------------
00061       void RegisterFileSystemObject( FileSystem *fs )
00062       {
00063         XrdSysMutexHelper scopedLock( pMutex );
00064         pFileSystemObjects.insert( fs );
00065       }
00066 
00067       //------------------------------------------------------------------------
00069       //------------------------------------------------------------------------
00070       void UnRegisterFileSystemObject( FileSystem *fs )
00071       {
00072         XrdSysMutexHelper scopedLock( pMutex );
00073         pFileSystemObjects.erase( fs );
00074       }
00075 
00076       //------------------------------------------------------------------------
00078       //------------------------------------------------------------------------
00079       void RegisterPostMaster( PostMaster *postMaster )
00080       {
00081         XrdSysMutexHelper scopedLock( pMutex );
00082         pPostMaster = postMaster;
00083       }
00084 
00085       void RegisterFileTimer( FileTimer *fileTimer )
00086       {
00087         XrdSysMutexHelper scopedLock( pMutex );
00088         pFileTimer = fileTimer;
00089       }
00090 
00091       //------------------------------------------------------------------------
00093       //------------------------------------------------------------------------
00094       void Prepare();
00095 
00096       //------------------------------------------------------------------------
00098       //------------------------------------------------------------------------
00099       void Parent();
00100 
00101       //------------------------------------------------------------------------
00103       //------------------------------------------------------------------------
00104       void Child();
00105 
00106     private:
00107       std::set<FileStateHandler*>  pFileObjects;
00108       std::set<FileSystem*>        pFileSystemObjects;
00109       PostMaster                  *pPostMaster;
00110       FileTimer                   *pFileTimer;
00111       XrdSysMutex                  pMutex;
00112   };
00113 }
00114 
00115 #endif // __XRD_CL_FORK_HANDLER_HH__