00001 #ifndef __BWM_HANDLE__
00002 #define __BWM_HANDLE__
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <stdlib.h>
00016
00017 #include "XrdBwm/XrdBwmPolicy.hh"
00018 #include "XrdOuc/XrdOucErrInfo.hh"
00019 #include "XrdSys/XrdSysPthread.hh"
00020
00021 class XrdBwmLogger;
00022
00023 class XrdBwmHandle
00024 {
00025 public:
00026
00027 enum HandleState {Idle = 0, Scheduled, Dispatched};
00028
00029 HandleState Status;
00030
00031 int Activate(XrdOucErrInfo &einfo);
00032
00033 static XrdBwmHandle *Alloc(const char *theUsr, const char *thePath,
00034 const char *lclNode, const char *rmtNode,
00035 int Incomming);
00036
00037 static void *Dispatch();
00038
00039 inline const char *Name() {return Parms.Lfn;}
00040
00041 void Retire();
00042
00043 static int setPolicy(XrdBwmPolicy *pP, XrdBwmLogger *lP);
00044
00045 XrdBwmHandle() : Status(Idle), Next(0), qTime(0), rTime(0),
00046 xSize(0), xTime(0)
00047 {}
00048
00049 ~XrdBwmHandle() {}
00050
00051 private:
00052 static XrdBwmHandle *Alloc(XrdBwmHandle *oldHandle=0);
00053 static XrdBwmHandle *refHandle(int refID, XrdBwmHandle *hP=0);
00054
00055 static XrdBwmPolicy *Policy;
00056 static XrdBwmLogger *Logger;
00057 static XrdBwmHandle *Free;
00058 static unsigned int numQueued;
00059
00060 XrdSysMutex hMutex;
00061 XrdBwmPolicy::SchedParms Parms;
00062 XrdBwmHandle *Next;
00063 XrdOucEICB *ErrCB;
00064 unsigned long long ErrCBarg;
00065 time_t qTime;
00066 time_t rTime;
00067 long long xSize;
00068 long xTime;
00069 int rHandle;
00070
00071 class theEICB : public XrdOucEICB
00072 {
00073 public:
00074
00075 void Done(int &Result, XrdOucErrInfo *eInfo) {mySem.Post();}
00076
00077 int Same(unsigned long long arg1, unsigned long long arg2)
00078 {return arg1 == arg2;}
00079
00080 void Wait() {mySem.Wait();}
00081
00082 theEICB() : mySem(0) {}
00083
00084 virtual ~theEICB() {}
00085
00086 private:
00087 XrdSysSemaphore mySem;
00088 } myEICB;
00089 };
00090 #endif