Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_control_api_plugin.cpp
Go to the documentation of this file.
3
4#include <fc/io/json.hpp>
5
6namespace sysio {
7
8static appbase::abstract_plugin& _test_control_api_plugin = app().register_plugin<test_control_api_plugin>();
9
10using namespace sysio;
11
19
20
21test_control_api_plugin::test_control_api_plugin(){}
23
24void test_control_api_plugin::set_program_options(options_description&, options_description&) {}
25void test_control_api_plugin::plugin_initialize(const variables_map&) {}
26
27struct async_result_visitor : public fc::visitor<std::string> {
28 template<typename T>
29 std::string operator()(const T& v) const {
30 return fc::json::to_string(v);
31 }
32};
33
34#define CALL_WITH_API_400(api_name, api_handle, api_namespace, call_name, http_response_code, params_type) \
35{std::string("/v1/" #api_name "/" #call_name), \
36 [api_handle](string, string body, url_response_callback cb) mutable { \
37 try { \
38 auto params = parse_params<api_namespace::call_name ## _params, params_type>(body);\
39 fc::variant result( api_handle.call_name( std::move(params) ) ); \
40 cb(http_response_code, std::move(result)); \
41 } catch (...) { \
42 http_plugin::handle_exception(#api_name, #call_name, body, cb); \
43 } \
44 }}
45
46#define TEST_CONTROL_RW_CALL(call_name, http_response_code, params_type) CALL_WITH_API_400(test_control, rw_api, test_control_apis::read_write, call_name, http_response_code, params_type)
47
49 my.reset(new test_control_api_plugin_impl(app().get_plugin<chain_plugin>().chain()));
50 auto rw_api = app().get_plugin<test_control_plugin>().get_read_write_api();
51
52 app().get_plugin<http_plugin>().add_api({
54 });
55}
56
58
59}
abstract_plugin & get_plugin(const string &name) const
static string to_string(const variant &v, const yield_function_t &yield, const output_formatting format=output_formatting::stringify_large_ints_and_doubles)
Definition json.cpp:674
virtual void set_program_options(options_description &, options_description &) override
void plugin_initialize(const variables_map &)
application & app()
#define T(meth, val, expected)
std::string operator()(const T &v) const
#define TEST_CONTROL_RW_CALL(call_name, http_response_code, params_type)