]>
Commit | Line | Data |
---|---|---|
224ce89b WB |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #pragma once | |
5 | ||
6 | #include <ostream> | |
7 | #include <string> | |
8 | ||
9 | #include "include/encoding.h" | |
10 | ||
11 | // health_status_t | |
12 | enum health_status_t { | |
13 | HEALTH_ERR = 0, | |
14 | HEALTH_WARN = 1, | |
15 | HEALTH_OK = 2, | |
16 | }; | |
17 | ||
9f95a23c | 18 | inline void encode(health_status_t hs, ceph::buffer::list& bl) { |
11fdf7f2 | 19 | using ceph::encode; |
224ce89b | 20 | uint8_t v = hs; |
11fdf7f2 | 21 | encode(v, bl); |
224ce89b | 22 | } |
9f95a23c | 23 | inline void decode(health_status_t& hs, ceph::buffer::list::const_iterator& p) { |
11fdf7f2 | 24 | using ceph::decode; |
224ce89b | 25 | uint8_t v; |
11fdf7f2 | 26 | decode(v, p); |
224ce89b WB |
27 | hs = health_status_t(v); |
28 | } | |
29 | template<> | |
30 | struct denc_traits<health_status_t> { | |
31 | static constexpr bool supported = true; | |
32 | static constexpr bool featured = false; | |
33 | static constexpr bool bounded = true; | |
34 | static constexpr bool need_contiguous = false; | |
9f95a23c | 35 | static void bound_encode(const ceph::buffer::ptr& v, size_t& p, uint64_t f=0) { |
224ce89b WB |
36 | p++; |
37 | } | |
38 | static void encode(const health_status_t& v, | |
9f95a23c | 39 | ceph::buffer::list::contiguous_appender& p, |
224ce89b WB |
40 | uint64_t f=0) { |
41 | ::denc((uint8_t)v, p); | |
42 | } | |
9f95a23c | 43 | static void decode(health_status_t& v, ceph::buffer::ptr::const_iterator& p, |
224ce89b WB |
44 | uint64_t f=0) { |
45 | uint8_t tmp; | |
46 | ::denc(tmp, p); | |
47 | v = health_status_t(tmp); | |
48 | } | |
9f95a23c | 49 | static void decode(health_status_t& v, ceph::buffer::list::const_iterator& p, |
224ce89b WB |
50 | uint64_t f=0) { |
51 | uint8_t tmp; | |
52 | ::denc(tmp, p); | |
53 | v = health_status_t(tmp); | |
54 | } | |
55 | }; | |
56 | ||
57 | inline std::ostream& operator<<(std::ostream &oss, const health_status_t status) { | |
58 | switch (status) { | |
59 | case HEALTH_ERR: | |
60 | oss << "HEALTH_ERR"; | |
61 | break; | |
62 | case HEALTH_WARN: | |
63 | oss << "HEALTH_WARN"; | |
64 | break; | |
65 | case HEALTH_OK: | |
66 | oss << "HEALTH_OK"; | |
67 | break; | |
68 | } | |
69 | return oss; | |
70 | } | |
9f95a23c TL |
71 | |
72 | inline const char *short_health_string(const health_status_t status) { | |
73 | switch (status) { | |
74 | case HEALTH_ERR: | |
75 | return "ERR"; | |
76 | case HEALTH_WARN: | |
77 | return "WRN"; | |
78 | case HEALTH_OK: | |
79 | return "OK"; | |
80 | default: | |
81 | return "???"; | |
82 | } | |
83 | } |