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
>
3
#include <
sysio/db_size_api_plugin/db_size_api_plugin.hpp
>
4
#include <
sysio/http_plugin/http_plugin.hpp
>
5
6
namespace
sysio
{
7
8
static
appbase::abstract_plugin
& _db_size_api_plugin =
app
().
register_plugin
<db_size_api_plugin>();
9
10
using 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
28
void
db_size_api_plugin::plugin_startup
() {
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
34
db_size_stats
db_size_api_plugin::get
() {
35
const
chainbase::database
& db =
app
().
get_plugin
<
chain_plugin
>().chain().db();
36
db_size_stats
ret
;
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
42
chainbase::database::database_index_row_count_multiset
indices = db.
row_count_per_index
();
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
}
CALL_WITH_400
#define CALL_WITH_400(api_name, api_handle, api_namespace, call_name, http_response_code, params_type)
Definition
chain_api_plugin.cpp:51
appbase::abstract_plugin
Definition
plugin.hpp:28
appbase::application::get_plugin
abstract_plugin & get_plugin(const string &name) const
Definition
application.cpp:520
appbase::application::register_plugin
auto & register_plugin()
Definition
application.hpp:136
chainbase::database
Definition
chainbase.hpp:253
chainbase::database::get_segment_manager
pinnable_mapped_file::segment_manager * get_segment_manager()
Definition
chainbase.hpp:411
chainbase::database::database_index_row_count_multiset
std::multiset< std::pair< unsigned, std::string > > database_index_row_count_multiset
Definition
chainbase.hpp:260
chainbase::database::row_count_per_index
database_index_row_count_multiset row_count_per_index() const
Definition
chainbase.hpp:526
sysio::chain_plugin
Definition
chain_plugin.hpp:763
sysio::db_size_api_plugin::get
db_size_stats get()
Definition
db_size_api_plugin.cpp:34
sysio::db_size_api_plugin::plugin_startup
void plugin_startup()
Definition
db_size_api_plugin.cpp:28
sysio::http_plugin
Definition
http_plugin.hpp:65
INVOKE_R_V
#define INVOKE_R_V(api_handle, call_name)
Definition
db_size_api_plugin.cpp:24
db_size_api_plugin.hpp
variant.hpp
http_plugin.hpp
json.hpp
appbase::app
application & app()
Definition
application.cpp:210
sysio
Definition
abi_serializer.cpp:8
sysio::db_size_index_count
Definition
db_size_api_plugin.hpp:12
sysio::db_size_stats
Definition
db_size_api_plugin.hpp:17
sysio::db_size_stats::free_bytes
uint64_t free_bytes
Definition
db_size_api_plugin.hpp:18
ret
CK_RV ret
Definition
yubihsm_pkcs11.c:973
plugins
db_size_api_plugin
db_size_api_plugin.cpp
Generated by
1.12.0