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 00013 // $Id: XrdCmsPList.hh,v 1.2 2010/01/01 02:24:47 abh Exp $ 00014 00015 #include <string.h> 00016 #include <strings.h> 00017 #include <stdlib.h> 00018 00019 #include "XrdCms/XrdCmsTypes.hh" 00020 #include "XrdSys/XrdSysPthread.hh" 00021 00022 /******************************************************************************/ 00023 /* C l a s s X r d C m s P I n f o */ 00024 /******************************************************************************/ 00025 00026 class XrdCmsPInfo 00027 { 00028 public: 00029 SMask_t rovec; 00030 SMask_t rwvec; 00031 SMask_t ssvec; 00032 00033 inline int And(const SMask_t mask) 00034 {return ((rovec &= mask)|(rwvec &= mask)|(ssvec &= mask)) != 0;} 00035 00036 inline void Or(const XrdCmsPInfo *pi) 00037 {rovec |= pi->rovec; rwvec |= pi->rwvec; ssvec |= pi->ssvec;} 00038 00039 inline void Set(const XrdCmsPInfo *pi) 00040 {rovec = pi->rovec; rwvec = pi->rwvec; ssvec = pi->ssvec;} 00041 00042 XrdCmsPInfo() {rovec = rwvec = ssvec = 0;} 00043 ~XrdCmsPInfo() {} 00044 XrdCmsPInfo &operator =(const XrdCmsPInfo &rhs) 00045 {Set(&rhs); return *this;} 00046 }; 00047 00048 /******************************************************************************/ 00049 /* C l a s s X r d C m s P L i s t */ 00050 /******************************************************************************/ 00051 00052 class XrdCmsPList 00053 { 00054 public: 00055 friend class XrdCmsPList_Anchor; 00056 00057 inline XrdCmsPList *Next() {return next;} 00058 inline char *Path() {return pathname;} 00059 const char *PType(); 00060 00061 XrdCmsPList(const char *pname="", XrdCmsPInfo *pi=0) 00062 : next(0), pathname(strdup(pname)), pathlen(strlen(pname)), 00063 pathtype(0) {if (pi) pathmask.Set(pi);} 00064 00065 ~XrdCmsPList() {if (pathname) free(pathname);} 00066 00067 private: 00068 00069 XrdCmsPInfo pathmask; 00070 XrdCmsPList *next; 00071 char *pathname; 00072 int pathlen; 00073 char pathtype; 00074 char reserved[3]; 00075 }; 00076 00077 class XrdCmsPList_Anchor 00078 { 00079 public: 00080 00081 inline void Lock() {mutex.Lock();} 00082 inline void UnLock() {mutex.UnLock();} 00083 00084 inline void Empty(XrdCmsPList *newlist=0) 00085 {Lock(); 00086 XrdCmsPList *p = next; 00087 while(p) {next = p->next; delete p; p = next;} 00088 next = newlist; 00089 UnLock(); 00090 } 00091 00092 int Find(const char *pname, XrdCmsPInfo &masks); 00093 00094 inline XrdCmsPList *First() {return next;} 00095 00096 SMask_t Insert(const char *pname, XrdCmsPInfo *pinfo); 00097 00098 inline int NotEmpty() {return next != 0;} 00099 00100 void Remove(SMask_t mask); 00101 00102 const char *Type(const char *pname); 00103 00104 inline XrdCmsPList *Zorch(XrdCmsPList *newlist=0) 00105 {Lock(); 00106 XrdCmsPList *p = next; 00107 next = newlist; 00108 UnLock(); 00109 return p; 00110 } 00111 00112 XrdCmsPList_Anchor() {next = 0;} 00113 00114 ~XrdCmsPList_Anchor() {Empty();} 00115 00116 private: 00117 00118 XrdSysMutex mutex; 00119 XrdCmsPList *next; 00120 }; 00121 #endif
1.7.1