XrdCmsPList.cc

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*                                                                            */
00003 /*                        X r d C m s P L i s t . c c                         */
00004 /*                                                                            */
00005 /* (c) 2007 by the Board of Trustees of the Leland Stanford, Jr., University  */
00006 /*                            All Rights Reserved                             */
00007 /*   Produced by Andrew Hanushevsky for Stanford University under contract    */
00008 /*              DE-AC02-76-SFO0515 with the Department of Energy              */
00009 /******************************************************************************/
00010 
00011 //         $Id: XrdCmsPList.cc 35287 2010-09-14 21:19:35Z ganis $
00012 
00013 // Original Version: 1.8 2007/07/18 01:34:53 abh
00014 
00015 const char *XrdCmsPListCVSID = "$Id: XrdCmsPList.cc 35287 2010-09-14 21:19:35Z ganis $";
00016   
00017 #include "XrdCms/XrdCmsPList.hh"
00018 
00019 /******************************************************************************/
00020 /*                                   A d d                                    */
00021 /******************************************************************************/
00022   
00023 /******************************************************************************/
00024 /*                                I n s e r t                                 */
00025 /******************************************************************************/
00026   
00027 int XrdCmsPList_Anchor::Add(const char *pname, XrdCmsPInfo *pinfo)
00028 {
00029    int plen = strlen(pname);
00030    XrdCmsPList *p, *pp;
00031 
00032 // Set up the search
00033 //
00034    Lock();
00035    p = next;
00036    pp = 0;
00037 
00038 // Find the proper insertion point. Paths are sorted in decreasin length order.
00039 //
00040    while(p && p->pathlen >= plen)
00041         {if (p->pathlen == plen && !strcmp(p->pathname,pname))
00042             {UnLock(); return 0;}
00043          pp = p; 
00044           p = p->next;
00045         }
00046 
00047 // Insert a new element
00048 //
00049    p = new XrdCmsPList(pname, pinfo);
00050    if (pp) { p->next = pp->next; pp->next = p;}
00051       else { p->next =     next;     next = p;}
00052 
00053 // All done
00054 //
00055    UnLock();
00056    return 1;
00057 }
00058 
00059 /******************************************************************************/
00060 /*                                  F i n d                                   */
00061 /******************************************************************************/
00062   
00063 int XrdCmsPList_Anchor::Find(const char *pname, XrdCmsPInfo &pinfo)
00064 {
00065    int plen = strlen(pname);
00066 
00067 // Lock the anchor and setup for search
00068 //
00069    Lock();
00070    XrdCmsPList *p = next;
00071 
00072 // Find matching entry
00073 //
00074    while(p) if (p->pathlen <= plen && !strncmp(p->pathname, pname, p->pathlen)) 
00075                {pinfo = p->pathmask; break;}
00076                else p = p->next;
00077 
00078 // All done
00079 //
00080    UnLock();
00081    return p != 0;
00082 }
00083 
00084 /******************************************************************************/
00085 /*                                I n s e r t                                 */
00086 /******************************************************************************/
00087   
00088 SMask_t XrdCmsPList_Anchor::Insert(const char *pname, XrdCmsPInfo *pinfo)
00089 {
00090    int rc, plen = strlen(pname);
00091    XrdCmsPList *p, *pp;
00092    SMask_t newmask;
00093 
00094 // Set up the search
00095 //
00096    Lock();
00097    p = next;
00098    pp = 0;
00099 
00100 // Find the proper insertion point. Paths are sorted in decreasin length
00101 // order. We must merge in the incomming mask with all subset paths.
00102 //
00103    rc = 1;
00104    while(p && p->pathlen >= plen)
00105         {if (p->pathlen == plen && !(rc = strcmp(p->pathname,pname))) break;
00106             else if (!strncmp(p->pathname,pname,plen)
00107                  &&  !(p->pathmask.rovec & pinfo->rovec))
00108                     {p->pathmask.And(~(pinfo->rovec)); p->pathmask.Or(pinfo);}
00109          pp = p; 
00110           p = p->next;
00111         }
00112 
00113 // Either merge the path masks or insert a new path. For a new path, add to
00114 // it masks of all superset paths that may follow it in the chain of paths.
00115 //
00116    if (!rc) {p->pathmask.And(~(pinfo->rovec)); p->pathmask.Or(pinfo);}
00117       else { p = new XrdCmsPList(pname, pinfo);
00118              if (pp)
00119                 { p->next = pp->next;
00120                  pp->next = p;
00121                 } else {
00122                   p->next = next;
00123                      next = p;
00124                 }
00125              pp = p->next;
00126              while(pp) {if (pp->pathlen < plen
00127                         &&  !strncmp(pp->pathname,pname,pp->pathlen))
00128                            p->pathmask.Or(&(pp->pathmask));
00129                         pp = pp->next;
00130                        }
00131            }
00132 
00133 // All done
00134 //
00135    newmask = p->pathmask.rovec | p->pathmask.rwvec;
00136    UnLock();
00137    return newmask;
00138 }
00139  
00140 /******************************************************************************/
00141 /*                                R e m o v e                                 */
00142 /******************************************************************************/
00143   
00144 void XrdCmsPList_Anchor::Remove(SMask_t mask)
00145 {
00146     SMask_t zmask(~mask);
00147     XrdCmsPList *pp = next, *prevp = 0;
00148 
00149 // Lock the list
00150 //
00151    Lock();
00152 
00153 // Remove bit from mask. If mask is zero, remove the entry
00154 //
00155    while(pp)
00156         {if (!pp->pathmask.And(zmask))
00157             {if (prevp) {prevp->next = pp->next; delete pp; pp = prevp->next;}
00158                 else    {       next = pp->next; delete pp; pp = next;}
00159             }
00160             else {prevp = pp; pp = pp->next;}
00161         }
00162 
00163 // All done
00164 //
00165    UnLock();
00166 }
00167 
00168 /******************************************************************************/
00169 /*                                  F i n d                                   */
00170 /******************************************************************************/
00171   
00172 const char *XrdCmsPList_Anchor::Type(const char *pname)
00173 {
00174    int isrw = 0, plen = strlen(pname);
00175 
00176 // Lock the anchor and setup for search
00177 //
00178    Lock();
00179    XrdCmsPList *p = next;
00180 
00181 // Find matching entry
00182 //
00183    while(p) if (p->pathlen <= plen && !strncmp(p->pathname, pname, p->pathlen)) 
00184                {isrw = (p->pathmask.rwvec != 0); break;}
00185                else p = p->next;
00186 
00187 // All done
00188 //
00189    UnLock();
00190    if (p) return (isrw ? "w" : "r");
00191    return "?";
00192 }
00193  
00194 /******************************************************************************/
00195 /*                                 P T y p e                                  */
00196 /******************************************************************************/
00197   
00198 const char *XrdCmsPList::PType()
00199 {
00200     if (pathmask.ssvec) return (pathmask.rwvec ? "ws" : "rs");
00201     return (pathmask.rwvec ? "w" : "r");
00202 }

Generated on Tue Jul 5 14:46:31 2011 for ROOT_528-00b_version by  doxygen 1.5.1