2015-03-31 21:45:08 +00:00
|
|
|
#pragma once
|
|
|
|
|
#include <fc/io/stdio.hpp>
|
|
|
|
|
#include <fc/io/json.hpp>
|
|
|
|
|
#include <fc/io/buffered_iostream.hpp>
|
|
|
|
|
#include <fc/io/sstream.hpp>
|
2015-04-21 19:01:25 +00:00
|
|
|
#include <fc/rpc/api_connection.hpp>
|
2015-03-31 21:45:08 +00:00
|
|
|
#include <fc/thread/thread.hpp>
|
|
|
|
|
|
2015-04-29 19:41:55 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
2015-03-31 21:45:08 +00:00
|
|
|
namespace fc { namespace rpc {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Provides a simple wrapper for RPC calls to a given interface.
|
|
|
|
|
*/
|
|
|
|
|
class cli : public api_connection
|
|
|
|
|
{
|
|
|
|
|
public:
|
2018-03-19 16:35:57 +00:00
|
|
|
cli( uint32_t max_depth ) : api_connection(max_depth) {}
|
2015-06-30 19:28:12 +00:00
|
|
|
~cli();
|
2015-03-31 21:45:08 +00:00
|
|
|
|
2015-06-30 19:28:12 +00:00
|
|
|
virtual variant send_call( api_id_type api_id, string method_name, variants args = variants() );
|
|
|
|
|
virtual variant send_callback( uint64_t callback_id, variants args = variants() );
|
|
|
|
|
virtual void send_notice( uint64_t callback_id, variants args = variants() );
|
|
|
|
|
|
|
|
|
|
void start();
|
|
|
|
|
void stop();
|
|
|
|
|
void wait();
|
|
|
|
|
void format_result( const string& method, std::function<string(variant,const variants&)> formatter);
|
2015-04-29 19:41:55 +00:00
|
|
|
|
2020-10-15 12:54:05 +00:00
|
|
|
virtual void getline( const fc::string& prompt, fc::string& line );
|
2015-04-29 19:41:55 +00:00
|
|
|
|
2015-06-30 19:28:12 +00:00
|
|
|
void set_prompt( const string& prompt );
|
2015-05-18 17:40:01 +00:00
|
|
|
|
2015-03-31 21:45:08 +00:00
|
|
|
private:
|
2015-06-30 19:28:12 +00:00
|
|
|
void run();
|
2015-03-31 22:46:05 +00:00
|
|
|
|
2015-06-30 19:28:12 +00:00
|
|
|
std::string _prompt = ">>>";
|
2015-03-31 21:45:08 +00:00
|
|
|
std::map<string,std::function<string(variant,const variants&)> > _result_formatters;
|
|
|
|
|
fc::future<void> _run_complete;
|
|
|
|
|
};
|
2020-10-15 12:54:05 +00:00
|
|
|
} }
|