CppCMS
|
JSON-RPC service application. More...
#include <cppcms/rpc_json.h>
Classes | |
struct | method_data |
Public Types | |
enum | role_type { any_role, method_role, notification_role } |
typedef booster::function < void(json::array const &)> | method_type |
Public Member Functions | |
void | bind (std::string const &name, method_type const &, role_type type=any_role) |
void | smd (json::value const &) |
void | smd_raw (std::string const &) |
void | smd_from_file (std::string const &) |
virtual void | main (std::string) |
booster::shared_ptr< json_call > | release_call () |
json_rpc_server (cppcms::service &srv) | |
std::string | method () |
bool | notification () |
json::array const & | params () |
void | return_result (json::value const &) |
void | return_error (json::value const &) |
JSON-RPC service application.
User is expected to derive his own objects from this class in order to implement Json-RPC calls similarly to how cppcms::application is used.
typedef booster::function<void(json::array const &)> cppcms::rpc::json_rpc_server::method_type |
Generic type of JSON-RPC method
void cppcms::rpc::json_rpc_server::bind | ( | std::string const & | name, |
method_type const & | , | ||
role_type | type = any_role |
||
) |
Bind method JSON-RPC method with name name
virtual void cppcms::rpc::json_rpc_server::main | ( | std::string | ) | [virtual] |
Main function that dispatches JSON-RPC service calls
Reimplemented from cppcms::application.
std::string cppcms::rpc::json_rpc_server::method | ( | ) |
Get the name of method that was called
Check if method call is notification only. You should not return a value.
Note: if you do not add restriction when binding json-rpc method on the role of the call you should always check this value. Otherwise trying to call return_result or return_error would throw.
json::array const& cppcms::rpc::json_rpc_server::params | ( | ) |
Get call parameters as json::array (vector of json::value)
Release json_call for asynchronous responses. Calls release_context() and assignes it to json_call object.
void cppcms::rpc::json_rpc_server::return_error | ( | json::value const & | ) |
Complete method response with a error. Throws call_error if the method was called as notification
void cppcms::rpc::json_rpc_server::return_result | ( | json::value const & | ) |
Complete method response with a result. Throws call_error if the method was called as notification
void cppcms::rpc::json_rpc_server::smd | ( | json::value const & | ) |
Specify service SMD
void cppcms::rpc::json_rpc_server::smd_from_file | ( | std::string const & | ) |
Take service SMD as raw text from file
void cppcms::rpc::json_rpc_server::smd_raw | ( | std::string const & | ) |
Specify service SMD as raw text rather then JSON value