C++ Server-Side SDK
LaunchDarkly SDK
data_source_status_base.hpp
1 #include <chrono>
2 #include <optional>
3 
4 #include <launchdarkly/data_sources/data_source_status_error_info.hpp>
5 #include <launchdarkly/data_sources/data_source_status_error_kind.hpp>
6 
7 // Common is included in the namespace to disambiguate from client/server
8 // for backward compatibility.
9 namespace launchdarkly::common::data_sources {
10 
11 template <typename TDataSourceState>
13  public:
14  using ErrorKind = DataSourceStatusErrorKind;
16  using DateTime = std::chrono::time_point<std::chrono::system_clock>;
17  using DataSourceState = TDataSourceState;
18 
23  [[nodiscard]] DataSourceState State() const { return state_; }
24 
42  [[nodiscard]] DateTime StateSince() const { return state_since_; }
43 
57  [[nodiscard]] std::optional<ErrorInfo> LastError() const {
58  return last_error_;
59  }
60 
61  DataSourceStatusBase(DataSourceState state,
62  DateTime state_since,
63  std::optional<ErrorInfo> last_error)
64  : state_(state),
65  state_since_(state_since),
66  last_error_(std::move(last_error)) {}
67 
68  ~DataSourceStatusBase() = default;
69  DataSourceStatusBase(DataSourceStatusBase const& item) = default;
70  DataSourceStatusBase(DataSourceStatusBase&& item) noexcept = default;
71  DataSourceStatusBase& operator=(DataSourceStatusBase const&) = delete;
72  DataSourceStatusBase& operator=(DataSourceStatusBase&&) = delete;
73 
74  private:
75  DataSourceState state_;
76  DateTime state_since_;
77  std::optional<ErrorInfo> last_error_;
78 };
79 
80 } // namespace launchdarkly::common::data_sources
Definition: data_source_status_base.hpp:12
DateTime StateSince() const
Definition: data_source_status_base.hpp:42
DataSourceState State() const
Definition: data_source_status_base.hpp:23
std::optional< ErrorInfo > LastError() const
Definition: data_source_status_base.hpp:57
Definition: data_source_status_error_info.hpp:14