xrootd
XrdCmsRole.hh
Go to the documentation of this file.
00001 #ifndef __XRDCMSROLE_HH__
00002 #define __XRDCMSROLE_HH__
00003 /******************************************************************************/
00004 /*                                                                            */
00005 /*                         X r d C m s R o l e . h h                          */
00006 /*                                                                            */
00007 /* (c) 2011 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 #include <string.h>
00014   
00015 // This class centralizes the naming of various roles servers can have.
00016 
00017 class XrdCmsRole
00018 {
00019 public:
00020 
00021 enum RoleID {MetaManager = 0,
00022              Manager,      Supervisor, Server,
00023              ProxyManager, ProxySuper, ProxyServer,
00024              PeerManager,  Peer,       noRole
00025             };
00026 
00027 static RoleID      Convert(const char *Tok1, const char *Tok2)
00028                    {if (!Tok2)
00029                        {if (!strcmp(   Tok1, "server"))     return Server;
00030                         if (!strcmp(   Tok1, "supervisor")) return Supervisor;
00031                         if (!strcmp(   Tok1, "peer"))       return Peer;
00032                         return (strcmp(Tok1, "manager") ?   noRole:Manager);
00033                        }
00034                     if (!strcmp(       Tok1, "proxy"))
00035                        {if (!strcmp(   Tok2, "server"))     return ProxyServer;
00036                         if (!strcmp(   Tok2, "supervisor")) return ProxySuper;
00037                         return (strcmp(Tok2, "manager") ?   noRole:ProxyManager);
00038                        }
00039                     if (!strcmp(       Tok1, "meta"))
00040                         return (strcmp(Tok2, "manager") ?   noRole:MetaManager);
00041                     if (!strcmp(       Tok1, "peer"))
00042                         return (strcmp(Tok2, "manager") ?   noRole:Peer);
00043                     return noRole;
00044                    }
00045 
00046 static const char *Name(RoleID rid)
00047                    {static const char *rName[] = {"metamanager",   // MetaMan
00048                                                   "manager",       // Manager
00049                                                   "supervisor",    // Super
00050                                                   "server",        // Server
00051                                                   "proxy-manager", // ProxyMan
00052                                                   "proxy-super",   // ProxySuper
00053                                                   "proxy-server",  // ProxyServ
00054                                                   "peer-manager",  // PeerMan
00055                                                   "peer"           // Peer
00056                                                  };
00057                     if (rid >= MetaManager && rid < noRole) return rName[rid];
00058                     return "??";
00059                    }
00060 
00061 static const char *Type(RoleID rid) // Maximum of 3 characters plus null byte!
00062                    {static const char *tName[] = {"MM",            // MetaMan
00063                                                   "M",             // Manager
00064                                                   "R",             // Super
00065                                                   "S",             // Server
00066                                                   "PM",            // ProxyMan
00067                                                   "PR",            // ProxySuper
00068                                                   "PS",            // ProxyServ
00069                                                   "EM",            // PeerMan
00070                                                   "E"              // Peer
00071                                                  };
00072                     if (rid >= MetaManager && rid < noRole) return tName[rid];
00073                     return "??";
00074                    }
00075 
00076                    XrdCmsRole() {}
00077                   ~XrdCmsRole() {}
00078 };
00079 #endif