00001 #ifndef __BWM_HANDLE__
00002 #define __BWM_HANDLE__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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;
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