xrootd
XrdFrcCID.hh
Go to the documentation of this file.
00001 #ifndef __FRCCID_H__
00002 #define __FRCCID_H__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                          X r d F r c C I D . h h                           */
00006 /*                                                                            */
00007 /* (c) 2010 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 <stdlib.h>
00034 #include <string.h>
00035 
00036 #include "XrdSys/XrdSysPthread.hh"
00037 
00038 class XrdOucEnv;
00039 class XrdOucStream;
00040 
00041 class XrdFrcCID
00042 {
00043 public:
00044        int    Add(const char *iName, const char *cName, time_t addT, pid_t Pid);
00045 
00046        int    Get(const char *iName, char *buff, int blen);
00047 
00048        int    Get(const char *iName, const char *vName, XrdOucEnv *evP);
00049 
00050        int    Init(const char *qPath);
00051 
00052        void   Ref(const char *iName);
00053 
00054               XrdFrcCID() : Dflt(0), First(0), cidFN(0), cidFN2(0) {}
00055              ~XrdFrcCID() {}
00056 
00057 private:
00058 
00059 struct cidEnt
00060       {cidEnt *Next;
00061        char   *iName;
00062        char   *cName;
00063        time_t  addT;
00064        pid_t   Pid;
00065        int     useCnt;
00066        short   iNLen;
00067        short   cNLen;
00068 
00069                cidEnt(cidEnt *epnt,const char *iname,const char *cname,
00070                       time_t addt, pid_t idp)
00071                      : Next(epnt), iName(strdup(*iname ? iname : "anon")),
00072                        cName(strdup(cname)), addT(addt), Pid(idp), useCnt(0),
00073                        iNLen(strlen(iName)), cNLen(strlen(cName)) {}
00074               ~cidEnt() {if (iName) free(iName); if (cName) free(cName);}
00075 
00076       };
00077 
00078 class  cidMon {public:
00079                cidMon() {cidMutex.Lock();}
00080               ~cidMon() {cidMutex.UnLock();}
00081                private:
00082                static XrdSysMutex cidMutex;
00083               };
00084 
00085 cidEnt *Find(const char *iName);
00086 int     Init(XrdOucStream &cidFile);
00087 int     Update();
00088 
00089 cidEnt *Dflt;
00090 cidEnt *First;
00091 char   *cidFN;
00092 char   *cidFN2;
00093 };
00094 
00095 namespace XrdFrc
00096 {
00097 extern XrdFrcCID CID;
00098 }
00099 #endif