00001 #ifndef __XRDOFSEVR_H__
00002 #define __XRDOFSEVR_H__
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 <strings.h>
00034 #include "XrdOuc/XrdOucHash.hh"
00035 #include "XrdOuc/XrdOucErrInfo.hh"
00036 #include "XrdSys/XrdSysPthread.hh"
00037 #include "XrdOuc/XrdOucStream.hh"
00038
00039 class XrdSysError;
00040 class XrdCmsClient;
00041
00042 class XrdOfsEvr
00043 {
00044 public:
00045 class theClient;
00046
00047 void flushEvents();
00048
00049 int Init(XrdSysError *eObj);
00050
00051 int Init(XrdCmsClient *trg=0);
00052
00053 void recvEvents();
00054
00055 void Wait4Event(const char *path, XrdOucErrInfo *einfo);
00056
00057 void Work4Event(theClient *Client);
00058
00059 XrdOfsEvr() : mySem(0), eDest(0), Balancer(0) {runQ = 0; deferQ = 0;}
00060 ~XrdOfsEvr();
00061
00062 class theClient : XrdOucEICB
00063 {
00064 public:
00065
00066 void Done(int &Result, XrdOucErrInfo *eInfo, const char *path=0)
00067 { (void)Result; (void)eInfo; (void)path; EvrP->Work4Event(this);}
00068
00069 int Same(unsigned long long arg1, unsigned long long arg2)
00070 { (void)arg1; (void)arg2; return 0;}
00071
00072 theClient *Next;
00073 const char *User;
00074 char *Path;
00075 XrdOfsEvr *EvrP;
00076 XrdOucEICB *evtCB;
00077 unsigned long long evtCBarg;
00078
00079 theClient(XrdOfsEvr *evr, XrdOucErrInfo *einfo, const char *path=0)
00080 {evtCB = einfo->getErrCB(evtCBarg);
00081 User = einfo->getErrUser();
00082 Path = (path ? strdup(path) : 0);
00083 EvrP = evr;
00084 Next = 0;
00085 }
00086 ~theClient() {if (Path) free(Path);}
00087 };
00088
00089 struct theEvent {theClient *aClient;
00090 char *finalMsg;
00091 int finalRC;
00092 char Happened;
00093
00094 theEvent(int rc, const char *emsg, theClient *cp=0)
00095 {aClient = cp; finalRC = rc; Happened = 0;
00096 finalMsg = (emsg ? strdup(emsg) : 0);
00097 }
00098 ~theEvent()
00099 {if (finalMsg) free(finalMsg);
00100 if (aClient) delete aClient;
00101 }
00102 };
00103
00104 private:
00105
00106 void eventStage();
00107 void sendEvent(theEvent *ep);
00108
00109 static const int maxLife = (8*60*60);
00110 XrdSysMutex myMutex;
00111 XrdSysSemaphore mySem;
00112 XrdOucStream eventFIFO;
00113 XrdSysError *eDest;
00114 XrdCmsClient *Balancer;
00115 theClient *deferQ;
00116 int runQ;
00117 int msgFD;
00118
00119 XrdOucHash<theEvent> Events;
00120 };
00121 #endif