FACT++  1.0
rpc_client.cxx
Go to the documentation of this file.
1 #include <dic.hxx>
2 #include <iostream>
3 using namespace std;
4 #include <stdio.h>
5 
6 class Rpc : public DimRpcInfo
7 {
8 public:
9  void rpcInfoHandler() {
11  cout << "Callback RPC Received : " << getInt() << endl;
12  }
13  Rpc(const char *name) : DimRpcInfo(name, 1, -1) {};
14 };
15 
16 typedef 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 
25 class RpcStruct : public DimRpcInfo
26 {
27 public:
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 
37 void 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();
55 dim_lock();
57 cout << "Instance "<<(dim_long)tag<<" sent "<<out<< " got "<<in <<endl;
58 dim_unlock();
59  out++;
60  }
61 }
62 
63 void 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  {
78  cout << "RPC Sent : " << out << endl;
79  myRpc->setData(out);
80  out++;
81  sleep(5);
82  }
83 }
84 
85 int 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 }
char str2[18]
Definition: rpc_client.cxx:19
int i
Definition: db_dim_client.c:21
STL namespace.
dim_long dim_start_thread(void *(*thread_ast)(void *), dim_long tag)
Definition: dim_thr.c:231
void rpcInfoHandler()
Definition: rpc_client.cxx:9
void do_workCB()
Definition: rpc_client.cxx:63
void do_work(void *tag)
Definition: rpc_client.cxx:37
struct tst MyStruct
void dim_init()
Definition: dim_thr.c:111
int main()
Definition: rpc_client.cxx:85
void dim_unlock()
Definition: dim_thr.c:472
long dim_long
Definition: dim_common.h:57
int getInt()
Definition: dic.hxx:405
char str1[16]
Definition: rpc_client.cxx:17
RpcStruct(const char *name)
Definition: rpc_client.cxx:34
void dim_lock()
Definition: dim_thr.c:455
Rpc(const char *name)
Definition: rpc_client.cxx:13
int int1
Definition: rpc_client.cxx:21
void setData(void *data, int size)
Definition: dic.hxx:413
void dim_print_date_time()
Definition: utilities.c:134
sprintf(name1,"NewService%d", i)
void rpcInfoHandler()
Definition: rpc_client.cxx:28