xrootd
XrdOfsEvr.hh
Go to the documentation of this file.
00001 #ifndef __XRDOFSEVR_H__
00002 #define __XRDOFSEVR_H__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                          X r d O f s E v r . h h                           */
00006 /*                                                                            */
00007 /* (c) 2006 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 <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          {EvrP->Work4Event(this);}
00068 
00069 int  Same(unsigned long long arg1, unsigned long long arg2) {return 0;}
00070 
00071 theClient         *Next;
00072 const char        *User;
00073 char              *Path;
00074 XrdOfsEvr         *EvrP;
00075 XrdOucEICB        *evtCB;
00076 unsigned long long evtCBarg;
00077 
00078          theClient(XrdOfsEvr *evr, XrdOucErrInfo *einfo, const char *path=0)
00079                            {evtCB = einfo->getErrCB(evtCBarg);
00080                             User  = einfo->getErrUser();
00081                             Path  = (path ? strdup(path) : 0);
00082                             EvrP  = evr;
00083                             Next  = 0;
00084                            }
00085         ~theClient() {if (Path) free(Path);}
00086         };
00087 
00088 struct theEvent  {theClient  *aClient;
00089                   char       *finalMsg;
00090                   int         finalRC;
00091                   char        Happened;
00092 
00093                   theEvent(int rc, const char *emsg, theClient *cp=0)
00094                           {aClient = cp; finalRC = rc; Happened = 0;
00095                            finalMsg = (emsg ? strdup(emsg) : 0);
00096                           }
00097                  ~theEvent() 
00098                           {if (finalMsg) free(finalMsg);
00099                            if (aClient) delete aClient;
00100                           }
00101                   };
00102 
00103 private:
00104 
00105 void eventStage();
00106 void sendEvent(theEvent *ep);
00107 
00108 static const int     maxLife = (8*60*60); // Eight hours
00109 XrdSysMutex          myMutex;
00110 XrdSysSemaphore      mySem;
00111 XrdOucStream         eventFIFO;
00112 XrdSysError         *eDest;
00113 XrdCmsClient        *Balancer;
00114 theClient           *deferQ;
00115 int                  runQ;
00116 int                  msgFD;
00117 
00118 XrdOucHash<theEvent> Events;
00119 };
00120 #endif