source: branches/fscctrl_safety_limits/dim/src/examples/rpc_server.cxx@ 19365

Last change on this file since 19365 was 18058, checked in by tbretz, 10 years ago
Updated to v20r11
File size: 1.6 KB
Line 
1#include <dis.hxx>
2#include <dic.hxx>
3#include <iostream>
4using namespace std;
5#include <stdio.h>
6
7class RpcInt : public DimRpc
8{
9 int val;
10
11 void rpcHandler()
12 {
13 val = getInt();
14 dim_print_date_time();
15 printf("Got RPC %d\n", val);
16 val++;
17// usleep(700000);
18 dim_print_date_time();
19 printf("Answering RPC %d\n", val);
20 setData(val);
21 }
22public:
23 RpcInt(const char *name): DimRpc(name,"I","I") {val = 0;};
24};
25
26typedef struct tst{
27 char str1[16];
28 int ints[5];
29 char str2[18];
30 float floats[4];
31 int int1;
32 float floats1[16];
33} MyStruct;
34
35typedef struct jeffIn{
36 char c1;
37 char c2;
38 char c3;
39 char str[3000];
40}JeffIn;
41
42typedef struct jeffOut{
43 int i1;
44 char c1;
45 char str[3000];
46}JeffOut;
47
48class RpcStruct : public DimRpc
49{
50 MyStruct *val;
51
52 void rpcHandler()
53 {
54 val = (MyStruct *)getData();
55 val->int1++;
56 setData(val, sizeof(MyStruct));
57 }
58public:
59 RpcStruct(const char *name): DimRpc(name,"C:16;I:5;C:18;F:4;I:1;F:16",
60 "C:16;I:5;C:18;F:4;I:1;F:16") {val = 0;};
61};
62
63class JeffRpcStruct : public DimRpc
64{
65 JeffIn *pin;
66 JeffOut pout;
67 int counter;
68
69 void rpcHandler()
70 {
71 pin = (JeffIn *)getData();
72 pout.i1 = counter++;
73 pout.c1 = pin->c1;
74 strcpy(pout.str,pin->str);
75 setData(&pout, (int)strlen(pout.str)+1+5);
76 }
77public:
78 JeffRpcStruct(const char *name): DimRpc(name,"C:1;C:1;C:1;C",
79 "I:1;C:1;C") {counter = 0;};
80};
81
82int main()
83{
84 RpcInt myRpcInt("TESTRPC/INT");
85 RpcInt *myRpcP;
86 RpcStruct myRpcStruct("TESTRPC/STRUCT");
87 JeffRpcStruct jeffRpcStruct("TESTJEFF");
88 int i;
89 char name[64];
90
91 for(i = 0; i < 10; i++)
92 {
93 sprintf(name,"TESTRPC%d/INT",i);
94 myRpcP = new RpcInt(name);
95 }
96 DimServer::start("TESTRPC");
97 while(1)
98 pause();
99 return 0;
100}
Note: See TracBrowser for help on using the repository browser.