]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2011 New Dream Network | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
15 | #ifndef CEPH_COMMON_ENTITY_NAME_H | |
16 | #define CEPH_COMMON_ENTITY_NAME_H | |
17 | ||
31f18b77 | 18 | #include <ifaddrs.h> |
7c673cae | 19 | |
7c673cae FG |
20 | #include "msg/msg_types.h" |
21 | ||
22 | /* Represents a Ceph entity name. | |
23 | * | |
24 | * For example, mds.0 is the name of the first metadata server. | |
25 | * client | |
26 | */ | |
27 | struct EntityName | |
28 | { | |
7c673cae | 29 | void encode(bufferlist& bl) const { |
11fdf7f2 TL |
30 | using ceph::encode; |
31 | encode(type, bl); | |
32 | encode(id, bl); | |
7c673cae | 33 | } |
11fdf7f2 TL |
34 | void decode(bufferlist::const_iterator& bl) { |
35 | using ceph::decode; | |
7c673cae FG |
36 | uint32_t type_; |
37 | std::string id_; | |
11fdf7f2 TL |
38 | decode(type_, bl); |
39 | decode(id_, bl); | |
7c673cae FG |
40 | set(type_, id_); |
41 | } | |
42 | ||
43 | const std::string& to_str() const; | |
44 | const char *to_cstr() const; | |
45 | bool from_str(const std::string& s); | |
46 | void set(uint32_t type_, const std::string &id_); | |
47 | int set(const std::string &type_, const std::string &id_); | |
48 | void set_type(uint32_t type_); | |
49 | int set_type(const char *type); | |
50 | void set_id(const std::string &id_); | |
51 | void set_name(entity_name_t n); | |
52 | ||
53 | const char* get_type_str() const; | |
54 | ||
55 | uint32_t get_type() const { return type; } | |
56 | bool is_osd() const { return get_type() == CEPH_ENTITY_TYPE_OSD; } | |
57 | bool is_mgr() const { return get_type() == CEPH_ENTITY_TYPE_MGR; } | |
58 | bool is_mds() const { return get_type() == CEPH_ENTITY_TYPE_MDS; } | |
59 | bool is_client() const { return get_type() == CEPH_ENTITY_TYPE_CLIENT; } | |
60 | bool is_mon() const { return get_type() == CEPH_ENTITY_TYPE_MON; } | |
61 | ||
62 | const char * get_type_name() const; | |
63 | const std::string &get_id() const; | |
64 | bool has_default_id() const; | |
65 | ||
66 | static std::string get_valid_types_as_str(); | |
11fdf7f2 | 67 | static uint32_t str_to_ceph_entity_type(std::string_view); |
7c673cae FG |
68 | |
69 | friend bool operator<(const EntityName& a, const EntityName& b); | |
70 | friend std::ostream& operator<<(std::ostream& out, const EntityName& n); | |
71 | friend bool operator==(const EntityName& a, const EntityName& b); | |
72 | friend bool operator!=(const EntityName& a, const EntityName& b); | |
73 | ||
74 | private: | |
11fdf7f2 TL |
75 | struct str_to_entity_type_t { |
76 | uint32_t type; | |
77 | const char *str; | |
78 | }; | |
79 | static const std::array<str_to_entity_type_t, 6> STR_TO_ENTITY_TYPE; | |
80 | ||
81 | uint32_t type = 0; | |
7c673cae FG |
82 | std::string id; |
83 | std::string type_id; | |
84 | }; | |
85 | ||
7c673cae FG |
86 | WRITE_CLASS_ENCODER(EntityName) |
87 | ||
88 | WRITE_EQ_OPERATORS_2(EntityName, type, id) | |
89 | ||
90 | #endif |