xrootd
XrdOfsEvs.hh
Go to the documentation of this file.
00001 #ifndef __XRDOFSEVS_H__
00002 #define __XRDOFSEVS_H__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                          X r d O f s E v s . h h                           */
00006 /*                                                                            */
00007 /* (c) 2005 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 /*             Based on code developed by Derek Feichtinger, CERN.            */
00032 /******************************************************************************/
00033 
00034 #include <strings.h>
00035 #include "XrdSys/XrdSysPthread.hh"
00036 
00037 class XrdOfsEvsMsg;
00038 class XrdOucEnv;
00039 class XrdOucProg;
00040 class XrdSysError;
00041 
00042 /******************************************************************************/
00043 /*                         X r d O f s E v s I n f o                          */
00044 /******************************************************************************/
00045   
00046 class XrdOfsEvsInfo
00047 {
00048 public:
00049 
00050 enum evArg {evTID=0, evLFN1, evCGI1, evLFN2, evCGI2, evFMODE, evFSIZE, evARGS};
00051 
00052 inline long long   FSize() {return theFSize;}
00053 
00054 inline mode_t      FMode() {return theFMode;}
00055 
00056 inline void        Set(evArg aNum, const char *aVal) {Arg[aNum] = aVal;}
00057 
00058 inline const char *Val(evArg aNum) {return Arg[aNum];}
00059 
00060  XrdOfsEvsInfo(const char *tid,
00061                const char *lfn1,         const char *cgi1="", XrdOucEnv *env1=0,
00062                mode_t      mode=0,       long long   fsize=0,
00063                const char *lfn2="$LFN2", const char *cgi2="", XrdOucEnv *env2=0)
00064               {Arg[evTID]  = tid;
00065                Arg[evLFN1] = lfn1;
00066                Arg[evCGI1] = (cgi1 ? cgi1  : ""); Env1 = env1;
00067                Arg[evLFN2] = (lfn2 ? lfn2 : "$LFN2");
00068                Arg[evCGI2] = (cgi2  ? cgi2  : ""); Env2 = env2;
00069                theFMode = mode; theFSize = fsize;
00070               }
00071 
00072 ~XrdOfsEvsInfo() {}
00073 
00074 private:
00075 
00076 const char *Arg[evARGS];
00077 XrdOucEnv  *Env1;
00078 XrdOucEnv  *Env2;
00079 long long   theFSize;
00080 mode_t      theFMode;
00081 };
00082 
00083 /******************************************************************************/
00084 /*                       X r d O f s E v s F o r m a t                        */
00085 /******************************************************************************/
00086 
00087 class XrdOfsEvsFormat
00088 {
00089 public:
00090 
00091 enum evFlags {Null = 0, freeFmt = 1, cvtMode = 2, cvtFSize = 4};
00092 
00093 const char                *Format;
00094       evFlags              Flags;
00095       XrdOfsEvsInfo::evArg Args[XrdOfsEvsInfo::evARGS];
00096 
00097       int     SNP(XrdOfsEvsInfo &Info, char *buff, int blen)
00098                      {return snprintf(buff,blen,Format, Info.Val(Args[0]),
00099                                      Info.Val(Args[1]), Info.Val(Args[2]),
00100                                      Info.Val(Args[3]), Info.Val(Args[4]),
00101                                      Info.Val(Args[5]), Info.Val(Args[6]));
00102                      }
00103 
00104       void    Def(evFlags theFlags, const char *Fmt, ...);
00105 
00106       void    Set(evFlags theFlags, const char *Fmt, int *fullArgs)
00107                  {if (Format && Flags & freeFmt) free((char *)Format);
00108                   Format = Fmt; Flags = theFlags;
00109                   memcpy(Args, fullArgs, sizeof(Args));
00110                  }
00111 
00112       XrdOfsEvsFormat() : Format(0), Flags(Null) {}
00113      ~XrdOfsEvsFormat() {}
00114 };
00115 
00116 /******************************************************************************/
00117 /*                             X r d O f s E v s                              */
00118 /******************************************************************************/
00119   
00120 class XrdOfsEvs
00121 {
00122 public:
00123 
00124 enum Event {All    = 0x7fffff00, None   = 0x00000000,
00125             Chmod  = 0x00000100, Closer = 0x00000201,
00126             Closew = 0x00000402, Close  = 0x00000600,
00127             Create = 0x00000803, Fwrite = 0x00001004,
00128             Mkdir  = 0x00002005, Mv     = 0x00004006,
00129             Openr  = 0x00008007, Openw  = 0x00010008,
00130             Open   = 0x00018000, Rm     = 0x00020009,
00131             Rmdir  = 0x0004000a, Trunc  = 0x0008000b,
00132             nCount = 12,
00133             Mask   = 0X000000ff, enMask = 0x7fffff00
00134            };
00135 
00136 static const int   minMsgSize = 1360; // (16+320+1024)
00137 static const int   maxMsgSize = 2384; // (16+320+1024+1024);
00138 
00139 int         Enabled(Event theEvents) {return theEvents & enEvents;}
00140 
00141 int         maxSmsg() {return maxMin;}
00142 int         maxLmsg() {return maxMax;}
00143 
00144 void        Notify(Event eNum, XrdOfsEvsInfo &Info);
00145 
00146 static int  Parse(XrdSysError &Eroute, Event eNum, char *mText);
00147 
00148 const char *Prog() {return theTarget;}
00149 
00150 void        sendEvents(void);
00151 
00152 int         Start(XrdSysError *eobj);
00153 
00154       XrdOfsEvs(Event theEvents, const char *Target, int minq=90, int maxq=10);
00155      ~XrdOfsEvs();
00156 
00157 private:
00158 const char     *eName(int eNum);
00159 int             Feed(const char *data, int dlen);
00160 XrdOfsEvsMsg   *getMsg(int bigmsg);
00161 void            retMsg(XrdOfsEvsMsg *tp);
00162 
00163 static XrdOfsEvsFormat MsgFmt[XrdOfsEvs::nCount];
00164 
00165 pthread_t       tid;
00166 char           *theTarget;
00167 Event           enEvents;
00168 XrdSysError    *eDest;
00169 XrdOucProg     *theProg;
00170 XrdSysMutex     qMut;
00171 XrdSysSemaphore qSem;
00172 XrdOfsEvsMsg   *msgFirst;
00173 XrdOfsEvsMsg   *msgLast;
00174 XrdSysMutex     fMut;
00175 XrdOfsEvsMsg   *msgFreeMax;
00176 XrdOfsEvsMsg   *msgFreeMin;
00177 int             endIT;
00178 int             msgFD;
00179 int             numMax;
00180 int             maxMax;
00181 int             numMin;
00182 int             maxMin;
00183 };
00184 #endif