1 | #include <dic.hxx>
|
---|
2 | #include <iostream>
|
---|
3 | using namespace std;
|
---|
4 |
|
---|
5 | class Rpc : public DimRpcInfo
|
---|
6 | {
|
---|
7 | public:
|
---|
8 | void rpcInfoHandler() {
|
---|
9 | dim_print_date_time();
|
---|
10 | cout << "Callback RPC Received : " << getInt() << endl;
|
---|
11 | }
|
---|
12 | Rpc(char *name) : DimRpcInfo(name, 1, -1) {};
|
---|
13 | };
|
---|
14 |
|
---|
15 | typedef struct tst{
|
---|
16 | char str1[16];
|
---|
17 | int ints[5];
|
---|
18 | char str2[18];
|
---|
19 | float floats[4];
|
---|
20 | int int1;
|
---|
21 | float floats1[16];
|
---|
22 | } MyStruct;
|
---|
23 |
|
---|
24 | class RpcStruct : public DimRpcInfo
|
---|
25 | {
|
---|
26 | public:
|
---|
27 | void rpcInfoHandler() {
|
---|
28 | MyStruct *val;
|
---|
29 | val = (MyStruct *)getData();
|
---|
30 | cout << "Callback RPC Received : " << endl;
|
---|
31 | cout << val->str1 << " " << val->str2 << " " << val->int1 << endl;
|
---|
32 | }
|
---|
33 | RpcStruct(char *name) : DimRpcInfo(name, "dead") {};
|
---|
34 | };
|
---|
35 |
|
---|
36 | void do_work(void *tag)
|
---|
37 | {
|
---|
38 | DimRpcInfo *myRpc;
|
---|
39 | // Rpc *myRpc;
|
---|
40 | char name[64];
|
---|
41 | int out, in;
|
---|
42 |
|
---|
43 | sprintf(name,"TESTRPC%d/INT",(long)tag);
|
---|
44 | myRpc = new DimRpcInfo(name, 10, -1);
|
---|
45 | // myRpc = new Rpc(name);
|
---|
46 |
|
---|
47 | out = 1;
|
---|
48 | while(1)
|
---|
49 | {
|
---|
50 | sleep(5);
|
---|
51 | // cout << "RPC Sent : " << out << endl;
|
---|
52 | myRpc->setData(out);
|
---|
53 | in = myRpc->getInt();
|
---|
54 | dim_lock();
|
---|
55 | dim_print_date_time();
|
---|
56 | cout << "Instance "<<(long)tag<<" sent "<<out<< " got "<<in <<endl;
|
---|
57 | dim_unlock();
|
---|
58 | out++;
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | void do_workCB()
|
---|
63 | {
|
---|
64 | // DimRpcInfo *myRpc;
|
---|
65 | Rpc *myRpc;
|
---|
66 | char name[64];
|
---|
67 | int out, in;
|
---|
68 |
|
---|
69 | sprintf(name,"TESTRPC/INT");
|
---|
70 | myRpc = new Rpc(name);
|
---|
71 | // myRpc = new Rpc(name);
|
---|
72 |
|
---|
73 | out = 1;
|
---|
74 | while(1)
|
---|
75 | {
|
---|
76 | dim_print_date_time();
|
---|
77 | cout << "RPC Sent : " << out << endl;
|
---|
78 | myRpc->setData(out);
|
---|
79 | out++;
|
---|
80 | sleep(5);
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | int main()
|
---|
85 | {
|
---|
86 | int i;
|
---|
87 |
|
---|
88 | dim_init();
|
---|
89 | // DimClient::setNoDataCopy();
|
---|
90 |
|
---|
91 | for(i = 0; i < 1; i++)
|
---|
92 | {
|
---|
93 | dim_start_thread(do_work,(void *)i);
|
---|
94 | }
|
---|
95 | // do_workCB();
|
---|
96 | while(1)
|
---|
97 | pause();
|
---|
98 | /*
|
---|
99 | int rpcValue = 0;
|
---|
100 | // DimRpcInfo rpc("TESTRPC/INT",-1);
|
---|
101 | Rpc rpcCB("TESTRPC/INT");
|
---|
102 | RpcStruct rpcStruct("TESTRPC/STRUCT");
|
---|
103 | MyStruct myStruct;
|
---|
104 |
|
---|
105 | strcpy(myStruct.str1,"hello");
|
---|
106 | strcpy(myStruct.str2,"world");
|
---|
107 | myStruct.int1 = 1;
|
---|
108 | while(1)
|
---|
109 | {
|
---|
110 | dim_print_date_time();
|
---|
111 | cout << "Sending " << rpcValue << endl;
|
---|
112 | rpcCB.setData(rpcValue);
|
---|
113 | rpcValue++;
|
---|
114 | // sleep(5);
|
---|
115 | rpcStruct.setData(&myStruct, sizeof(myStruct));
|
---|
116 | myStruct.int1++;
|
---|
117 | // rpc.setData(rpcValue);
|
---|
118 | // rpcValue = rpc.getInt();
|
---|
119 | // cout << "RPC Received : " << rpcValue << endl;
|
---|
120 | sleep(10);
|
---|
121 | }
|
---|
122 | return 0;
|
---|
123 | */
|
---|
124 | }
|
---|