2019-02-08 19:43:25 +00:00
|
|
|
#ifndef LLARP_UTIL_STATUS_HPP
|
|
|
|
#define LLARP_UTIL_STATUS_HPP
|
2019-02-19 09:43:17 +00:00
|
|
|
|
2019-02-15 23:04:04 +00:00
|
|
|
#include <util/json.hpp>
|
2019-02-11 17:14:43 +00:00
|
|
|
#include <util/string_view.hpp>
|
2019-02-19 09:43:17 +00:00
|
|
|
|
2019-02-08 19:43:25 +00:00
|
|
|
#include <vector>
|
2019-02-08 22:44:21 +00:00
|
|
|
#include <string>
|
2019-02-11 17:14:43 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <absl/types/variant.h>
|
2019-02-08 19:43:25 +00:00
|
|
|
|
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
namespace util
|
|
|
|
{
|
2019-02-15 23:04:04 +00:00
|
|
|
using StatusObject_Impl = json::Document;
|
|
|
|
using Value_t = json::Value;
|
2019-02-08 19:43:25 +00:00
|
|
|
|
|
|
|
struct StatusObject
|
|
|
|
{
|
2019-02-15 23:04:04 +00:00
|
|
|
using String_t = string_view;
|
2019-02-11 17:14:43 +00:00
|
|
|
using Variant = absl::variant< uint64_t, std::string, bool, StatusObject,
|
|
|
|
std::vector< std::string >,
|
|
|
|
std::vector< StatusObject > >;
|
|
|
|
using value_type = std::tuple< String_t, Variant >;
|
|
|
|
|
|
|
|
StatusObject(const StatusObject&);
|
2019-02-08 19:43:25 +00:00
|
|
|
~StatusObject();
|
|
|
|
|
2019-02-11 17:14:43 +00:00
|
|
|
StatusObject(std::initializer_list< value_type > vals)
|
|
|
|
{
|
|
|
|
Impl.SetObject();
|
|
|
|
std::for_each(vals.begin(), vals.end(),
|
|
|
|
[&](const value_type& item) { Put(item); });
|
|
|
|
}
|
2019-02-08 19:43:25 +00:00
|
|
|
|
|
|
|
void
|
2019-02-11 17:14:43 +00:00
|
|
|
Put(String_t name, const Variant& value);
|
2019-02-08 19:43:25 +00:00
|
|
|
|
|
|
|
void
|
2019-02-11 17:14:43 +00:00
|
|
|
Put(const value_type& value);
|
2019-02-08 19:43:25 +00:00
|
|
|
|
2019-02-11 17:14:43 +00:00
|
|
|
StatusObject_Impl Impl;
|
2019-02-08 19:43:25 +00:00
|
|
|
|
2019-02-11 17:14:43 +00:00
|
|
|
private:
|
2019-02-08 19:43:25 +00:00
|
|
|
void
|
2019-02-11 17:14:43 +00:00
|
|
|
PutBool(String_t name, bool val);
|
2019-02-08 19:43:25 +00:00
|
|
|
void
|
2019-02-11 17:14:43 +00:00
|
|
|
PutInt(String_t name, uint64_t val);
|
|
|
|
void
|
|
|
|
PutObject(String_t name, const StatusObject& val);
|
|
|
|
void
|
|
|
|
PutObjectArray(String_t name, const std::vector< StatusObject >& arr);
|
|
|
|
void
|
|
|
|
PutStringArray(String_t name, const std::vector< std::string >& arr);
|
|
|
|
void
|
|
|
|
PutString(String_t name, const std::string& val);
|
2019-02-08 19:43:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// an entity that has a status that can be extracted
|
|
|
|
struct IStateful
|
|
|
|
{
|
2019-02-18 23:58:12 +00:00
|
|
|
virtual ~IStateful(){};
|
2019-02-08 19:43:25 +00:00
|
|
|
|
2019-02-11 17:14:43 +00:00
|
|
|
virtual StatusObject
|
|
|
|
ExtractStatus() const = 0;
|
2019-02-08 19:43:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace util
|
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
#endif
|