source: trunk/FACT++/dim/src/examples/test_server.cxx@ 19594

Last change on this file since 19594 was 18920, checked in by tbretz, 7 years ago
Updated to v20r20 - This also includes some minor fixes, I requested.
File size: 4.7 KB
Line 
1#include <iostream>
2#include <dis.hxx>
3#ifndef WIN32
4#include <unistd.h>
5#endif
6using namespace std;
7#include <string>
8
9class ErrorHandler : public DimErrorHandler
10{
11 void errorHandler(int severity, int code, char *msg)
12 {
13 int index = 0;
14 char **services;
15 if(code){}
16 cout << severity << " " << msg << endl;
17 services = DimServer::getClientServices();
18 cout<< "from "<< DimServer::getClientName() << " services:" << endl;
19 while(services[index])
20 {
21 cout << services[index] << endl;
22 index++;
23 }
24 }
25public:
26 ErrorHandler() {DimServer::addErrorHandler(this);}
27};
28
29class ExitHandler : public DimExitHandler
30{
31 void exitHandler(int code)
32 {
33 cout << "exit code " << code << endl;
34 }
35public:
36 ExitHandler() {DimServer::addExitHandler(this);}
37};
38
39class CmndServ : public DimCommand, public DimTimer
40{
41 DimService servstr;
42 void commandHandler()
43 {
44 int index = 0;
45 char **services;
46 cout << "Command " << getString() << " received" << endl;
47 servstr.updateService(getString());
48 services = DimServer::getClientServices();
49 cout<< "from "<< DimServer::getClientName() << " services:" << endl;
50 while(services[index])
51 {
52 cout << services[index] << endl;
53 index++;
54 }
55 }
56
57public :
58 CmndServ() : DimCommand("TEST/CMND","C"),
59 servstr("TEST/STRVAL",(char *)"empty") {};
60/*
61 void handleIt()
62 {
63 int index = 0;
64 char **services;
65 dim_print_date_time();
66 cout << "Command " << getString() << " received" << endl;
67 cout << "time: "<<getTimestamp()<<" millies: "<<getTimestampMillisecs()<<endl;
68 servstr.updateService(getString());
69 }
70*/
71};
72
73/*
74class CmndServMany : public DimCommand
75{
76 void commandHandler()
77 {
78 cout << "Command " << getString() << " received" << endl;
79 }
80public :
81 CmndServMany(char *name) : DimCommand(name,"C") {};
82};
83*/
84
85void add_serv(const int & ival)
86{
87 DimService *abc;
88
89 abc = new DimService("TEST/INTVAL_CONST",(int &)ival);
90 if(abc){}
91}
92
93void add_serv_str(const string & s1)
94{
95 DimService *abc;
96
97 abc = new DimService("TEST/STRINGVAL_CONST",(char *)s1.c_str());
98 if(abc){}
99}
100
101DimService *bool_serv[10];
102void add_serv_bool(const bool & boolval)
103{
104
105// serv = new DimService("TEST/BOOLVAL_CONST",(short &)boolval);
106 bool_serv[0] = new DimService("TEST/BOOLVAL_CONST","C:1", (void *)&boolval, 1);
107 bool_serv[1] = new DimService("TEST/BOOLVAL_CONST1","C:1", (void *)&boolval, 1);
108}
109
110class ServWithHandler : public DimService
111{
112 int value;
113
114 void serviceHandler()
115 {
116 value++;
117// setData(value);
118 }
119public :
120 ServWithHandler(char *name) : DimService(name, value) { value = 0;};
121};
122
123int main()
124{
125 int ival = 0;
126// ErrorHandler errHandler;
127// ExitHandler exHandler;
128// DimServer::setDnsNode("axdes2.cern.ch");
129 string s1;
130 bool boolval;
131 ServWithHandler *testServ;
132 DimServerDns *newDns;
133 char *extraDns = 0;
134 DimService *new_servint;
135
136// DimService *dim = new DimService("test","C");
137// delete dim;
138
139 dis_set_debug_on();
140 DimServer::start("TEST");
141 extraDns = DimUtil::getEnvVar((char *)"EXTRA_DNS_NODE");
142 if(extraDns)
143 newDns = new DimServerDns(extraDns, 0, (char *)"TEST");
144// newDns = new DimServerDns(extraDns, 0, (char *)"new_TEST");
145
146// int i, arr[15000];
147// DimService *servp;
148// DimCommand *cmndp;
149// char str[132];
150
151// float farr[4];
152// DimService *farrp;
153
154 s1 = "hello";
155 add_serv(ival);
156 DimService servint("TEST/INTVAL",ival);
157
158 if(extraDns)
159 {
160// new_servint = new DimService(newDns, "new_TEST/INTVAL",ival);
161 new_servint = new DimService(newDns, "TEST/new_INTVAL",ival);
162 }
163
164 add_serv_str(s1);
165 boolval = 0;
166 add_serv_bool(boolval);
167 CmndServ cmdsvr;
168
169 testServ = new ServWithHandler((char *)"MY_NEW_TEST_SERVICE_WITH_HANDLER");
170 if(testServ){}
171
172 // farr[0] = 1.2;
173// farr[1] = 2.3;
174// farrp = new DimService("/PCITCO147/sensors/fan/input","F", farr, sizeof(farr));
175
176
177// DimServer::autoStartOff();
178// DimServer::start("TEST");
179
180// for(i = 0; i < 15000; i++)
181// {
182// arr[i] = i;
183// sprintf(str,"ServiceManyTest/%05d",i);
184// servp = new DimService(str,arr[i]);
185// servp->setQuality(1);
186// servp->updateService(arr[i]);
187//// DimServer::start("TEST");
188// sprintf(str,"CommandManyTest/%05d",i);
189// cmndp = new CmndServMany(str);
190//// DimServer::start("TEST");
191// }
192
193 while(1)
194 {
195 sleep(5);
196
197// while(cmdsvr.hasNext())
198// {
199// cmdsvr.getNext();
200// cmdsvr.handleIt();
201// }
202
203 s1 = "hello1";
204 if(!boolval)
205 boolval = 1;
206 else
207 boolval = 0;
208 ival++;
209 bool_serv[1]->updateService();
210
211// int inCallback = DimServer::inCallback();
212// cout << "main: In callback "<< inCallback << endl;
213 servint.updateService();
214 if(extraDns)
215 new_servint->updateService();
216 }
217 return 0;
218}
219
220/*
221int main()
222{
223DimService *servint, *newServint;
224int ival = 0;
225
226DimServer::start("TEST");
227servint = new DimService("TEST/INTVAL",ival);
228sleep(20);
229DimServer::stop();
230sleep(1);
231DimServer::start("TESTOTHER");
232newServint = new DimService("TESTOTHER/INTVAL",ival);
233sleep(20);
234DimServer::stop();
235}
236*/
Note: See TracBrowser for help on using the repository browser.