22 doc->
D(
"example of user defined RPC method that returns up to 3 results");
23 doc->
P(
"arg", MJSON_STRING,
"example string argment");
24 doc->
P(
"optional_arg?", MJSON_INT,
"optional example integer argument");
25 doc->
R(
"string", MJSON_STRING,
"returns the value of \"arg\" parameter");
26 doc->
R(
"integer", MJSON_INT,
"returns the value of \"optional_arg\" parameter");
30 MJsonNode* error = NULL;
32 std::string arg =
mjsonrpc_get_param(params,
"arg", &error)->GetString();
if (error)
return error;
36 printf(
"user_example1(%s,%d)\n", arg.c_str(), optional_arg);
38 return mjsonrpc_make_result(
"string", MJsonNode::MakeString(arg.c_str()),
"integer", MJsonNode::MakeInt(optional_arg));
49 doc->
D(
"example of user defined RPC method that returns more than 3 results");
50 doc->
P(
"arg", MJSON_STRING,
"example string argment");
51 doc->
P(
"optional_arg?", MJSON_INT,
"optional example integer argument");
52 doc->
R(
"string1", MJSON_STRING,
"returns the value of \"arg\" parameter");
53 doc->
R(
"string2", MJSON_STRING,
"returns \"hello\"");
54 doc->
R(
"string3", MJSON_STRING,
"returns \"world!\"");
55 doc->
R(
"value1", MJSON_INT,
"returns the value of \"optional_arg\" parameter");
56 doc->
R(
"value2", MJSON_NUMBER,
"returns 3.14");
60 MJsonNode* error = NULL;
62 std::string arg =
mjsonrpc_get_param(params,
"arg", &error)->GetString();
if (error)
return error;
66 printf(
"user_example2(%s,%d)\n", arg.c_str(), optional_arg);
68 MJsonNode* result = MJsonNode::MakeObject();
70 result->AddToObject(
"string1", MJsonNode::MakeString(arg.c_str()));
71 result->AddToObject(
"string2", MJsonNode::MakeString(
"hello"));
72 result->AddToObject(
"string3", MJsonNode::MakeString(
"world!"));
73 result->AddToObject(
"value1", MJsonNode::MakeInt(optional_arg));
74 result->AddToObject(
"value2", MJsonNode::MakeNumber(3.14));
87 doc->
D(
"example of user defined RPC method that returns an error");
88 doc->
P(
"arg", MJSON_INT,
"integer value, if zero, throws a JSON-RPC error");
89 doc->
R(
"status", MJSON_INT,
"returns the value of \"arg\" parameter");
93 MJsonNode* error = NULL;
95 int arg =
mjsonrpc_get_param(params,
"arg", &error)->GetInt();
if (error)
return error;
98 printf(
"user_example3(%d)\n", arg);
119 printf(
"mjsonrpc_user_init!\n");
void D(const char *description)
void P(const char *name, int mjson_type, const char *description)
MJsonNode * mjsonrpc_make_result(MJsonNode *node)
void mjsonrpc_user_init()
MJsonNode * mjsonrpc_make_error(int code, const char *message, const char *data)
const MJsonNode * mjsonrpc_get_param(const MJsonNode *params, const char *name, MJsonNode **error)
void mjsonrpc_add_handler(const char *method, mjsonrpc_handler_t *handler, bool needs_locking)
void R(const char *name, int mjson_type, const char *description)
static MJsonNode * user_example3(const MJsonNode *params)
static MJsonNode * user_example1(const MJsonNode *params)
static MJsonNode * user_example2(const MJsonNode *params)