Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
db_size_api_plugin.cpp
Go to the documentation of this file.
1#include <fc/variant.hpp>
2#include <fc/io/json.hpp>
5
6namespace sysio {
7
8static appbase::abstract_plugin& _db_size_api_plugin = app().register_plugin<db_size_api_plugin>();
9
10using namespace sysio;
11
12#define CALL_WITH_400(api_name, api_handle, call_name, INVOKE, http_response_code) \
13{std::string("/v1/" #api_name "/" #call_name), \
14 [api_handle](string, string body, url_response_callback cb) mutable { \
15 try { \
16 body = parse_params<std::string, http_params_types::no_params>(body); \
17 INVOKE \
18 cb(http_response_code, fc::variant(result)); \
19 } catch (...) { \
20 http_plugin::handle_exception(#api_name, #call_name, body, cb); \
21 } \
22 }}
23
24#define INVOKE_R_V(api_handle, call_name) \
25 auto result = api_handle->call_name();
26
27
29 app().get_plugin<http_plugin>().add_api({
30 CALL_WITH_400(db_size, this, get, INVOKE_R_V(this, get), 200),
31 });
32}
33
35 const chainbase::database& db = app().get_plugin<chain_plugin>().chain().db();
37
38 ret.free_bytes = db.get_segment_manager()->get_free_memory();
39 ret.size = db.get_segment_manager()->get_size();
40 ret.used_bytes = ret.size - ret.free_bytes;
41
43 for(const auto& i : indices)
44 ret.indices.emplace_back(db_size_index_count{i.second, i.first});
45
46 return ret;
47}
48
49#undef INVOKE_R_V
50#undef CALL
51
52}
#define CALL_WITH_400(api_name, api_handle, api_namespace, call_name, http_response_code, params_type)
abstract_plugin & get_plugin(const string &name) const
pinnable_mapped_file::segment_manager * get_segment_manager()
std::multiset< std::pair< unsigned, std::string > > database_index_row_count_multiset
database_index_row_count_multiset row_count_per_index() const
#define INVOKE_R_V(api_handle, call_name)
application & app()
CK_RV ret