MIDAS
Loading...
Searching...
No Matches
mjsonrpc_user.cxx File Reference
#include <stdio.h>
#include "mjsonrpc.h"
Include dependency graph for mjsonrpc_user.cxx:

Go to the source code of this file.

Functions

static MJsonNode * user_example1 (const MJsonNode *params)
 
static MJsonNode * user_example2 (const MJsonNode *params)
 
static MJsonNode * user_example3 (const MJsonNode *params)
 
void mjsonrpc_user_init ()
 

Function Documentation

◆ user_example1()

static MJsonNode * user_example1 ( const MJsonNode *  params)
static

Definition at line 18 of file mjsonrpc_user.cxx.

19{
20 if (!params) {
21 MJSO* doc = MJSO::I();
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");
27 return doc;
28 }
29
30 MJsonNode* error = NULL;
31
32 std::string arg = mjsonrpc_get_param(params, "arg", &error)->GetString(); if (error) return error;
33 int optional_arg = mjsonrpc_get_param(params, "optional_arg", NULL)->GetInt();
34
36 printf("user_example1(%s,%d)\n", arg.c_str(), optional_arg);
37
38 return mjsonrpc_make_result("string", MJsonNode::MakeString(arg.c_str()), "integer", MJsonNode::MakeInt(optional_arg));
39}
MJsonNode * mjsonrpc_make_result(MJsonNode *node)
Definition mjsonrpc.cxx:135
static MJSO * I()
Definition mjsonrpc.cxx:298
int mjsonrpc_debug
Definition mjsonrpc.cxx:112
const MJsonNode * mjsonrpc_get_param(const MJsonNode *params, const char *name, MJsonNode **error)
Definition mjsonrpc.cxx:178
TH1X EXPRT * h1_book(const char *name, const char *title, int bins, double min, double max)
Definition rmidas.h:24
Here is the call graph for this function:
Here is the caller graph for this function:

◆ user_example2()

static MJsonNode * user_example2 ( const MJsonNode *  params)
static

Definition at line 45 of file mjsonrpc_user.cxx.

46{
47 if (!params) {
48 MJSO* doc = MJSO::I();
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");
57 return doc;
58 }
59
60 MJsonNode* error = NULL;
61
62 std::string arg = mjsonrpc_get_param(params, "arg", &error)->GetString(); if (error) return error;
63 int optional_arg = mjsonrpc_get_param(params, "optional_arg", NULL)->GetInt();
64
66 printf("user_example2(%s,%d)\n", arg.c_str(), optional_arg);
67
68 MJsonNode* result = MJsonNode::MakeObject();
69
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));
75
76 return mjsonrpc_make_result(result);
77}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ user_example3()

static MJsonNode * user_example3 ( const MJsonNode *  params)
static

Definition at line 83 of file mjsonrpc_user.cxx.

84{
85 if (!params) {
86 MJSO* doc = MJSO::I();
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");
90 return doc;
91 }
92
93 MJsonNode* error = NULL;
94
95 int arg = mjsonrpc_get_param(params, "arg", &error)->GetInt(); if (error) return error;
96
98 printf("user_example3(%d)\n", arg);
99
100 if (arg)
101 return mjsonrpc_make_result("status", MJsonNode::MakeInt(arg));
102 else
103 return mjsonrpc_make_error(15, "example error message", "example error data");
104}
MJsonNode * mjsonrpc_make_error(int code, const char *message, const char *data)
Definition mjsonrpc.cxx:123
Here is the call graph for this function:
Here is the caller graph for this function: