xrootd
XrdFrcReqFile.hh
Go to the documentation of this file.
00001 #ifndef __FRCREQFILE_H__
00002 #define __FRCREQFILE_H__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                      X r d F r c R e q F i l e . h h                       */
00006 /*                                                                            */
00007 /* (c) 2010 by the Board of Trustees of the Leland Stanford, Jr., University  */
00008 /*                            All Rights Reserved                             */
00009 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00010 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
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 
00033 #include "XrdFrc/XrdFrcRequest.hh"
00034 #include "XrdSys/XrdSysPthread.hh"
00035 
00036 class XrdFrcReqFile
00037 {
00038 public:
00039 
00040        void   Add(XrdFrcRequest *rP);
00041 
00042        void   Can(XrdFrcRequest *rP);
00043 
00044        void   Del(XrdFrcRequest *rP);
00045 
00046        int    Get(XrdFrcRequest *rP);
00047 
00048        int    Init();
00049 
00050        char  *List(char *Buff, int bsz, int &Offs,
00051                     XrdFrcRequest::Item *ITList=0, int ITNum=0);
00052 
00053        void   ListL(XrdFrcRequest &tmpReq, char *Buff, int bsz,
00054                     XrdFrcRequest::Item *ITList, int ITNum);
00055 
00056               XrdFrcReqFile(const char *fn, int aVal);
00057              ~XrdFrcReqFile() {}
00058 
00059 private:
00060 enum LockType {lkNone, lkShare, lkExcl, lkInit};
00061 
00062 static const int ReqSize  = sizeof(XrdFrcRequest);
00063 
00064 void   FailAdd(char *lfn, int unlk=1);
00065 void   FailCan(char *rid, int unlk=1);
00066 void   FailDel(char *lfn, int unlk=1);
00067 int    FailIni(const char *lfn);
00068 int    FileLock(LockType ltype=lkExcl);
00069 int    reqRead(void *Buff, int Offs);
00070 int    reqWrite(void *Buff, int Offs, int updthdr=1);
00071 
00072 XrdSysMutex flMutex;
00073 
00074 struct FileHdr
00075 {
00076 int    First;
00077 int    Last;
00078 int    Free;
00079 }      HdrData;
00080 
00081 char  *lokFN;
00082 int    lokFD;
00083 int    reqFD;
00084 char  *reqFN;
00085 
00086 int    isAgent;
00087 
00088 struct recEnt {recEnt       *Next;
00089                XrdFrcRequest reqData;
00090                recEnt(XrdFrcRequest &reqref) {Next = 0; reqData = reqref;}
00091               };
00092 int    ReWrite(recEnt *rP);
00093 
00094 class rqMonitor
00095 {
00096 public:
00097       rqMonitor(int isAgent) : doUL(isAgent)
00098                   {if (isAgent) rqMutex.Lock();}
00099      ~rqMonitor() {if (doUL)    rqMutex.UnLock();}
00100 private:
00101 static XrdSysMutex rqMutex;
00102 int                doUL;
00103 };
00104 };
00105 #endif