00001 #ifndef __OLB_PLIST__H 00002 #define __OLB_PLIST__H 00003 /******************************************************************************/ 00004 /* */ 00005 /* X r d O l b P L i s t . h h */ 00006 /* */ 00007 /* (c) 2003 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-AC03-76-SFO0515 with the Department of Energy */ 00011 /******************************************************************************/ 00012 00013 // $Id: XrdOlbPList.hh,v 1.3 2007/07/26 15:18:24 ganis Exp $ 00014 00015 #include <string.h> 00016 #include <strings.h> 00017 #include <stdlib.h> 00018 00019 #include "XrdOlb/XrdOlbTypes.hh" 00020 #include "XrdSys/XrdSysPthread.hh" 00021 00022 /******************************************************************************/ 00023 /* S t r u c t o o l b _ P I n f o */ 00024 /******************************************************************************/ 00025 00026 class XrdOlbPInfo 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 XrdOlbPInfo *pi) 00037 {rovec |= pi->rovec; rwvec |= pi->rwvec; ssvec |= pi->ssvec;} 00038 00039 inline void Set(const XrdOlbPInfo *pi) 00040 {rovec = pi->rovec; rwvec = pi->rwvec; ssvec = pi->ssvec;} 00041 00042 XrdOlbPInfo() {rovec = rwvec = ssvec = 0;} 00043 ~XrdOlbPInfo() {} 00044 XrdOlbPInfo &operator =(const XrdOlbPInfo &rhs) 00045 {Set(&rhs); return *this;} 00046 }; 00047 00048 /******************************************************************************/ 00049 /* C l a s s o o l b _ P L i s t */ 00050 /******************************************************************************/ 00051 00052 class XrdOlbPList 00053 { 00054 public: 00055 friend class XrdOlbPList_Anchor; 00056 00057 inline XrdOlbPList *Next() {return next;} 00058 inline char *Path() {return pathname;} 00059 const char *PType(); 00060 00061 XrdOlbPList(const char *pname="", XrdOlbPInfo *pi=0) 00062 {next = 0; 00063 pathlen = strlen(pname); 00064 pathname = strdup(pname); 00065 if (pi) pathmask.Set(pi); 00066 } 00067 00068 ~XrdOlbPList() {if (pathname) free(pathname);} 00069 00070 private: 00071 00072 XrdOlbPList *next; 00073 int pathlen; 00074 char *pathname; 00075 XrdOlbPInfo pathmask; 00076 }; 00077 00078 class XrdOlbPList_Anchor 00079 { 00080 public: 00081 00082 inline void Lock() {mutex.Lock();} 00083 inline void UnLock() {mutex.UnLock();} 00084 00085 inline void Empty(XrdOlbPList *newlist=0) 00086 {Lock(); 00087 XrdOlbPList *p = next; 00088 while(p) {next = p->next; delete p; p = next;} 00089 next = newlist; 00090 UnLock(); 00091 } 00092 00093 int Find(const char *pname, XrdOlbPInfo &masks); 00094 00095 inline XrdOlbPList *First() {return next;} 00096 00097 SMask_t Insert(const char *pname, XrdOlbPInfo *pinfo); 00098 00099 inline int NotEmpty() {return next != 0;} 00100 00101 void Remove(SMask_t mask); 00102 00103 const char *Type(const char *pname); 00104 00105 inline XrdOlbPList *Zorch(XrdOlbPList *newlist=0) 00106 {Lock(); 00107 XrdOlbPList *p = next; 00108 next = newlist; 00109 UnLock(); 00110 return p; 00111 } 00112 00113 XrdOlbPList_Anchor() {next = 0;} 00114 00115 ~XrdOlbPList_Anchor() {Empty();} 00116 00117 private: 00118 00119 XrdSysMutex mutex; 00120 XrdOlbPList *next; 00121 }; 00122 #endif
1.7.1