source: branches/FACT++_part_filenames/dim/src/examples/rpc_client.cxx@ 18752

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