xrootd
XrdBwmHandle.hh
Go to the documentation of this file.
00001 #ifndef __BWM_HANDLE__
00002 #define __BWM_HANDLE__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                       X r d B w m H a n d l e . h h                        */
00006 /*                                                                            */
00007 /* (c) 2008 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 <stdlib.h>
00034 
00035 #include "XrdBwm/XrdBwmPolicy.hh"
00036 #include "XrdOuc/XrdOucErrInfo.hh"
00037 #include "XrdSys/XrdSysPthread.hh"
00038 
00039 class XrdBwmLogger;
00040   
00041 class XrdBwmHandle
00042 {
00043 public:
00044 
00045 enum HandleState {Idle = 0, Scheduled, Dispatched};
00046 
00047        HandleState   Status;
00048 
00049        int           Activate(XrdOucErrInfo &einfo);
00050 
00051 static XrdBwmHandle *Alloc(const char *theUsr,  const char *thePath,
00052                            const char *lclNode, const char *rmtNode,
00053                            int Incomming);
00054 
00055 static void         *Dispatch();
00056 
00057 inline const char   *Name() {return Parms.Lfn;}
00058 
00059        void          Retire();
00060 
00061 static int           setPolicy(XrdBwmPolicy *pP, XrdBwmLogger *lP);
00062 
00063                      XrdBwmHandle() : Status(Idle), Next(0), qTime(0), rTime(0),
00064                                       xSize(0), xTime(0)
00065                                     {}
00066 
00067                     ~XrdBwmHandle() {}
00068 
00069 private:
00070 static XrdBwmHandle *Alloc(XrdBwmHandle *oldHandle=0);
00071 static XrdBwmHandle *refHandle(int refID, XrdBwmHandle *hP=0);
00072 
00073 static XrdBwmPolicy      *Policy;
00074 static XrdBwmLogger      *Logger;
00075 static XrdBwmHandle      *Free;       // List of free handles
00076 static unsigned int       numQueued;
00077 
00078        XrdSysMutex        hMutex;
00079 XrdBwmPolicy::SchedParms  Parms;
00080        XrdBwmHandle      *Next;
00081        XrdOucEICB        *ErrCB;
00082        unsigned long long ErrCBarg;
00083        time_t             qTime;
00084        time_t             rTime;
00085                 long long xSize;
00086                      long xTime;
00087        int                rHandle;
00088 
00089 class  theEICB : public XrdOucEICB
00090 {
00091 public:
00092 
00093          void Done(int &Result, XrdOucErrInfo *eInfo, const char *Path=0)
00094                   {mySem.Post();}
00095 
00096          int  Same(unsigned long long arg1, unsigned long long arg2) 
00097                   {return arg1 == arg2;}
00098 
00099          void Wait() {mySem.Wait();}
00100 
00101               theEICB() : mySem(0) {}
00102 
00103 virtual      ~theEICB() {}
00104 
00105 private:
00106 XrdSysSemaphore mySem;
00107 }                         myEICB;
00108 };
00109 #endif