xrootd
XrdCmsPList.hh
Go to the documentation of this file.
00001 #ifndef XRDCMSPLIST__H
00002 #define XRDCMSPLIST__H
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                        X r d C m s P L i s t . h h                         */
00006 /*                                                                            */
00007 /* (c) 2007 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 <string.h>
00034 #include <strings.h>
00035 #include <stdlib.h>
00036 
00037 #include "XrdCms/XrdCmsTypes.hh"
00038 #include "XrdSys/XrdSysPthread.hh"
00039   
00040 /******************************************************************************/
00041 /*                     C l a s s   X r d C m s P I n f o                      */
00042 /******************************************************************************/
00043   
00044 class XrdCmsPInfo
00045 {
00046 public:
00047    SMask_t rovec;
00048    SMask_t rwvec;
00049    SMask_t ssvec;
00050 
00051 inline int  And(const SMask_t mask)
00052                {return ((rovec &= mask)|(rwvec &= mask)|(ssvec &= mask)) != 0;}
00053 
00054 inline void Or(const XrdCmsPInfo *pi)
00055                {rovec |=  pi->rovec; rwvec |=  pi->rwvec; ssvec |=  pi->ssvec;}
00056 
00057 inline void Set(const XrdCmsPInfo *pi)
00058                {rovec  =  pi->rovec; rwvec  =  pi->rwvec; ssvec  =  pi->ssvec;}
00059 
00060            XrdCmsPInfo() {rovec = rwvec = ssvec = 0;}
00061           ~XrdCmsPInfo() {}
00062            XrdCmsPInfo   &operator =(const XrdCmsPInfo &rhs)
00063                         {Set(&rhs); return *this;}
00064 };
00065  
00066 /******************************************************************************/
00067 /*                     C l a s s   X r d C m s P L i s t                      */
00068 /******************************************************************************/
00069   
00070 class XrdCmsPList
00071 {
00072 public:
00073 friend class XrdCmsPList_Anchor;
00074 
00075 inline XrdCmsPList   *Next() {return next;}
00076 inline char          *Path() {return pathname;}
00077 const  char          *PType();
00078 
00079        XrdCmsPList(const char *pname="", XrdCmsPInfo *pi=0)
00080                   : next(0), pathname(strdup(pname)), pathlen(strlen(pname)),
00081                     pathtype(0) {if (pi) pathmask.Set(pi);}
00082 
00083       ~XrdCmsPList() {if (pathname) free(pathname);}
00084 
00085 private:
00086 
00087 XrdCmsPInfo     pathmask;
00088 XrdCmsPList    *next;
00089 char           *pathname;
00090 int             pathlen;
00091 char            pathtype;
00092 char            reserved[3];
00093 };
00094 
00095 class XrdCmsPList_Anchor
00096 {
00097 public:
00098 
00099 inline void         Lock() {mutex.Lock();}
00100 inline void       UnLock() {mutex.UnLock();}
00101 
00102        int          Add(const char *pname, XrdCmsPInfo *pinfo);
00103 
00104 inline void         Empty(XrdCmsPList *newlist=0)
00105                     {Lock();
00106                      XrdCmsPList *p = next;
00107                      while(p) {next = p->next; delete p; p = next;}
00108                      next = newlist;
00109                      UnLock();
00110                     }
00111 
00112        int          Find(const char *pname, XrdCmsPInfo &masks);
00113 
00114 inline XrdCmsPList *First() {return next;}
00115 
00116        SMask_t      Insert(const char *pname, XrdCmsPInfo *pinfo);
00117 
00118 inline int          NotEmpty() {return next != 0;}
00119 
00120        void         Remove(SMask_t mask);
00121 
00122 const  char        *Type(const char *pname);
00123 
00124 inline XrdCmsPList *Zorch(XrdCmsPList *newlist=0)
00125                    {Lock();
00126                     XrdCmsPList *p = next;
00127                     next = newlist;
00128                     UnLock();
00129                     return p;
00130                    }
00131 
00132        XrdCmsPList_Anchor() {next = 0;}
00133 
00134       ~XrdCmsPList_Anchor() {Empty();}
00135 
00136 private:
00137 
00138 XrdSysMutex   mutex;
00139 XrdCmsPList  *next;
00140 };
00141 #endif