Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
fc::rpc::cli Class Reference

#include <cli.hpp>

Inheritance diagram for fc::rpc::cli:
Collaboration diagram for fc::rpc::cli:

Public Member Functions

 ~cli ()
 
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)
 
virtual void getline (const fc::string &prompt, fc::string &line)
 
void set_prompt (const string &prompt)
 
- Public Member Functions inherited from fc::api_connection
 api_connection ()
 
virtual ~api_connection ()
 
template<typename T >
api< Tget_remote_api (api_id_type api_id=0)
 
variant receive_call (api_id_type api_id, const string &method_name, const variants &args=variants()) const
 
variant receive_callback (uint64_t callback_id, const variants &args=variants()) const
 
void receive_notice (uint64_t callback_id, const variants &args=variants()) const
 
template<typename Interface >
api_id_type register_api (const Interface &a)
 
template<typename Signature >
uint64_t register_callback (const std::function< Signature > &cb)
 
std::vector< std::string > get_method_names (api_id_type local_api_id=0) const
 

Additional Inherited Members

- Public Attributes inherited from fc::api_connection
fc::signal< void()> closed
 

Detailed Description

Provides a simple wrapper for RPC calls to a given interface.

Definition at line 16 of file cli.hpp.

Constructor & Destructor Documentation

◆ ~cli()

fc::rpc::cli::~cli ( )

Definition at line 39 of file cli.cpp.

40{
41 if( _run_complete.valid() )
42 {
43 stop();
44 }
45}
void stop()
Definition cli.cpp:68
Here is the call graph for this function:

Member Function Documentation

◆ format_result()

void fc::rpc::cli::format_result ( const string & method,
std::function< string(variant, const variants &)> formatter )

Definition at line 79 of file cli.cpp.

80{
81 _result_formatters[method] = formatter;
82}

◆ getline()

void fc::rpc::cli::getline ( const fc::string & prompt,
fc::string & line )
virtual

Definition at line 191 of file cli.cpp.

192{
193 // getting file descriptor for C++ streams is near impossible
194 // so we just assume it's the same as the C stream...
195#ifdef HAVE_READLINE
196#ifndef WIN32
197 if( isatty( fileno( stdin ) ) )
198#else
199 // it's implied by
200 // https://msdn.microsoft.com/en-us/library/f4s0ddew.aspx
201 // that this is the proper way to do this on Windows, but I have
202 // no access to a Windows compiler and thus,
203 // no idea if this actually works
204 if( _isatty( _fileno( stdin ) ) )
205#endif
206 {
207 rl_attempted_completion_function = cli_completion;
208
209 static fc::thread getline_thread("getline");
210 getline_thread.async( [&](){
211 char* line_read = nullptr;
212 std::cout.flush(); //readline doesn't use cin, so we must manually flush _out
213 line_read = readline(prompt.c_str());
214 if( line_read == nullptr )
215 FC_THROW_EXCEPTION( fc::eof_exception, "" );
216 rl_bind_key( '\t', rl_complete );
217 if( *line_read )
218 add_history(line_read);
219 line = line_read;
220 free(line_read);
221 }).wait();
222 }
223 else
224#endif
225 {
226 std::cout << prompt;
227 // sync_call( cin_thread, [&](){ std::getline( *input_stream, line ); }, "getline");
228 fc::getline( fc::cin, line );
229 return;
230 }
231}
void wait()
Definition cli.cpp:74
#define FC_THROW_EXCEPTION(EXCEPTION, FORMAT,...)
Here is the call graph for this function:

◆ send_call()

variant fc::rpc::cli::send_call ( api_id_type api_id,
string method_name,
variants args = variants() )
virtual

makes calls to the remote server

Implements fc::api_connection.

Definition at line 47 of file cli.cpp.

48{
49 FC_ASSERT(false);
50}
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.

◆ send_callback()

variant fc::rpc::cli::send_callback ( uint64_t callback_id,
variants args = variants() )
virtual

Implements fc::api_connection.

Definition at line 52 of file cli.cpp.

53{
54 FC_ASSERT(false);
55}

◆ send_notice()

void fc::rpc::cli::send_notice ( uint64_t callback_id,
variants args = variants() )
virtual

Implements fc::api_connection.

Definition at line 57 of file cli.cpp.

58{
59 FC_ASSERT(false);
60}

◆ set_prompt()

void fc::rpc::cli::set_prompt ( const string & prompt)

Definition at line 84 of file cli.cpp.

85{
86 _prompt = prompt;
87}

◆ start()

void fc::rpc::cli::start ( )

Definition at line 62 of file cli.cpp.

63{
64 cli_commands() = get_method_names(0);
65 _run_complete = fc::async( [&](){ run(); } );
66}
std::vector< std::string > get_method_names(api_id_type local_api_id=0) const
Here is the call graph for this function:

◆ stop()

void fc::rpc::cli::stop ( )

Definition at line 68 of file cli.cpp.

69{
70 _run_complete.cancel();
71 _run_complete.wait();
72}
Here is the caller graph for this function:

◆ wait()

void fc::rpc::cli::wait ( )

Definition at line 74 of file cli.cpp.

75{
76 _run_complete.wait();
77}
Here is the caller graph for this function:

The documentation for this class was generated from the following files: