xrootd
XrdCmsRole.hh
Go to the documentation of this file.
1 #ifndef __XRDCMSROLE_HH__
2 #define __XRDCMSROLE_HH__
3 /******************************************************************************/
4 /* */
5 /* X r d C m s R o l e . h h */
6 /* */
7 /* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include <string.h>
34 
35 // This class centralizes the naming of various roles servers can have.
36 
38 {
39 public:
40 
41 enum RoleID {MetaManager = 0,
45  };
46 
47 static RoleID Convert(const char *Tok1, const char *Tok2)
48  {if (!Tok2)
49  {if (!strcmp( Tok1, "server")) return Server;
50  if (!strcmp( Tok1, "supervisor")) return Supervisor;
51  if (!strcmp( Tok1, "peer")) return Peer;
52  return (strcmp(Tok1, "manager") ? noRole:Manager);
53  }
54  if (!strcmp( Tok1, "proxy"))
55  {if (!strcmp( Tok2, "server")) return ProxyServer;
56  if (!strcmp( Tok2, "supervisor")) return ProxySuper;
57  return (strcmp(Tok2, "manager") ? noRole:ProxyManager);
58  }
59  if (!strcmp( Tok1, "meta"))
60  return (strcmp(Tok2, "manager") ? noRole:MetaManager);
61  if (!strcmp( Tok1, "peer"))
62  return (strcmp(Tok2, "manager") ? noRole:Peer);
63  return noRole;
64  }
65 
66 static const char *Name(RoleID rid)
67  {static const char *rName[] = {"metamanager", // MetaMan
68  "manager", // Manager
69  "supervisor", // Super
70  "server", // Server
71  "proxy-manager", // ProxyMan
72  "proxy-super", // ProxySuper
73  "proxy-server", // ProxyServ
74  "peer-manager", // PeerMan
75  "peer" // Peer
76  };
77  if (rid >= MetaManager && rid < noRole) return rName[rid];
78  return "??";
79  }
80 
81 static const char *Type(RoleID rid) // Maximum of 3 characters plus null byte!
82  {static const char *tName[] = {"MM", // MetaMan
83  "M", // Manager
84  "R", // Super
85  "S", // Server
86  "PM", // ProxyMan
87  "PR", // ProxySuper
88  "PS", // ProxyServ
89  "EM", // PeerMan
90  "E" // Peer
91  };
92  if (rid >= MetaManager && rid < noRole) return tName[rid];
93  return "??";
94  }
95 
98 };
99 #endif