1 #include <Core/Core.h>
2 #include <Core/Rpc/Rpc.h>
3 
4 using namespace Upp;
5 
RPC_METHOD(Multiply)6 RPC_METHOD(Multiply)
7 {
8 	int m, n;
9 	rpc >> m >> n;
10 	rpc << m * n;
11 }
12 
RPC_METHOD(Multiply2)13 RPC_METHOD(Multiply2)
14 {
15 	int m = rpc++;
16 	int n = rpc++;
17 	rpc = m * n;
18 }
19 
RPC_METHOD(Divide)20 RPC_METHOD(Divide)
21 {
22 	int m = rpc++;
23 	int n = rpc++;
24 	if(n == 0)
25 		ThrowRpcError("divide by zero");
26 	rpc = m / n;
27 }
28 
RPC_METHOD(MultiplyNamed)29 RPC_METHOD(MultiplyNamed)
30 {
31 	int n = rpc["first"];
32 	int m = rpc["second"];
33 	rpc = m * n;
34 }
35 
RPC_METHOD(JsonMultiply)36 RPC_METHOD(JsonMultiply)
37 {
38 	Value v = rpc++;
39 	rpc = Json("result", (int)v["first"] * (int)v["second"]);
40 }
41 
42 CONSOLE_APP_MAIN
43 {
44 	StdLogSetup(LOG_COUT|LOG_FILE);
45 //	LogXmlRpcRequests();
46 //	SetXmlRpcServerTrace(UppLog());
47 
48 //  Working in "shortened" mode - without URL specified, RpcRequests are performed by methods in
49 //  the same process.
50 
51 	DUMP(JsonRpcRequest()("Multiply", 2, 3).Execute());
52 	DUMP(JsonRpcRequest()("Multiply2", 4, 5).Execute());
53 	DUMP(XmlRpcRequest()("Multiply2", 6, 7).Execute());
54 	DUMP(JsonRpcRequestNamed()("MultiplyNamed")("first", 8)("second", 9).Execute());
55 	DUMP(JsonRpcRequest()("Divide", 2, 0).Execute());
56 	DUMP(JsonRpcRequest()("Divide", 20, 4).Execute());
57 	DUMP(JsonRpcRequest()("JsonMultiply", Json("first", 4)("second", 10)).Execute());
58 }
59