0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Status.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
26 
27 #ifndef Common_Status_h
28 #define Common_Status_h
29 
30 #include <Common/Serializable.h>
31 
32 #include <mutex>
33 #include <string>
34 #include <utility>
35 
36 namespace Hypertable {
37 
40 
42  class Status : public Serializable {
43 
44  public:
45 
47  enum class Code: int32_t {
49  OK = 0,
51  WARNING = 1,
53  CRITICAL = 2,
55  UNKNOWN = 3
56  };
57 
59  class Text {
60  public:
61  static constexpr const char *SERVER_IS_COMING_UP = "Server is coming up";
62  static constexpr const char *SERVER_IS_SHUTTING_DOWN = "Server is shutting down";
63  static constexpr const char *STANDBY = "Standby";
64  };
65 
66  static const char *code_to_string(Code code);
67  static Code string_to_code(std::string str);
68 
70  Status() { }
71 
75  Status(Code code, const std::string &text) : m_code(code), m_text(text) {}
76 
79  Status(const Status &other) {
80  Code code;
81  std::string text;
82  other.get(&code, text);
83  std::lock_guard<std::mutex> lock(m_mutex);
84  m_code = code;
85  m_text.clear();
86  m_text.append(text);
87  }
88 
91  Status &operator=(const Status &rhs) {
92  Status temp(rhs);
93  std::swap(m_code, temp.m_code);
94  std::swap(m_text, temp.m_text);
95  return *this;
96  }
97 
101  void set(Code code, const std::string &text) {
102  std::lock_guard<std::mutex> lock(m_mutex);
103  m_code = code;
104  m_text.clear();
105  m_text.append(text);
106  }
107 
111  void get(Code *code, std::string &text) const {
112  std::lock_guard<std::mutex> lock(m_mutex);
113  *code = m_code;
114  text = m_text;
115  }
116 
119  Code get() {
120  std::lock_guard<std::mutex> lock(m_mutex);
121  return m_code;
122  }
123 
131  std::string format_output_line(const std::string &service);
132 
133  private:
134 
137  uint8_t encoding_version() const override;
138 
142  size_t encoded_length_internal() const override;
143 
146  void encode_internal(uint8_t **bufp) const override;
147 
154  void decode_internal(uint8_t version, const uint8_t **bufp,
155  size_t *remainp) override;
156 
159 
162 
164  std::string m_text;
165 
166  };
167 
169 }
170 
171 
172 #endif // Common_Status_h
Status & operator=(const Status &rhs)
Copy assignment operator.
Definition: Status.h:91
static std::mutex mutex
Definition: Logger.cc:43
Holds Nagios-style program status information.
Definition: Status.h:42
static constexpr const char * SERVER_IS_SHUTTING_DOWN
Definition: Status.h:62
Po::typed_value< String > * str(String *v=0)
Definition: Properties.h:166
Status()
Constructor.
Definition: Status.h:70
void set(Code code, const std::string &text)
Sets status code and text.
Definition: Status.h:101
Code
Enumeration for status codes.
Definition: Status.h:47
static const char * code_to_string(Code code)
Definition: Status.cc:39
static constexpr const char * STANDBY
Definition: Status.h:63
Status text string constants.
Definition: Status.h:59
Status(const Status &other)
Copy constructor.
Definition: Status.h:79
void encode_internal(uint8_t **bufp) const override
Writes serialized representation of object to a buffer.
Definition: Status.cc:80
uint8_t encoding_version() const override
Returns encoding version.
Definition: Status.cc:66
Declarations for Serializable.
__nat swap(__any, __any)
Hypertable definitions
size_t encoded_length_internal() const override
Returns internal serialized length.
Definition: Status.cc:70
Mixin class that provides a standard serialization interface.
Definition: Serializable.h:65
std::string m_text
Status text.
Definition: Status.h:164
static Code string_to_code(std::string str)
Definition: Status.cc:53
void get(Code *code, std::string &text) const
Gets status code and text.
Definition: Status.h:111
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
Definition: Status.cc:85
std::mutex m_mutex
Mutex for serializaing access to members
Definition: Status.h:158
Code m_code
Status code.
Definition: Status.h:161
std::string format_output_line(const std::string &service)
Formats a Nagios-style output line.
Definition: Status.cc:92
Status(Code code, const std::string &text)
Constructor with initial values.
Definition: Status.h:75
static constexpr const char * SERVER_IS_COMING_UP
Definition: Status.h:61