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

Last change on this file since 18855 was 18349, checked in by tbretz, 9 years ago
Updated to v20r15
File size: 4.6 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 DimServer::start("TEST");
140 extraDns = DimUtil::getEnvVar((char *)"EXTRA_DNS_NODE");
141 if(extraDns)
142 newDns = new DimServerDns(extraDns, 0, (char *)"new_TEST");
143
144// int i, arr[15000];
145// DimService *servp;
146// DimCommand *cmndp;
147// char str[132];
148
149// float farr[4];
150// DimService *farrp;
151
152 s1 = "hello";
153 add_serv(ival);
154 DimService servint("TEST/INTVAL",ival);
155
156 if(extraDns)
157 {
158 new_servint = new DimService(newDns, "new_TEST/INTVAL",ival);
159 }
160
161 add_serv_str(s1);
162 boolval = 0;
163 add_serv_bool(boolval);
164 CmndServ cmdsvr;
165
166 testServ = new ServWithHandler((char *)"MY_NEW_TEST_SERVICE_WITH_HANDLER");
167 if(testServ){}
168
169 // farr[0] = 1.2;
170// farr[1] = 2.3;
171// farrp = new DimService("/PCITCO147/sensors/fan/input","F", farr, sizeof(farr));
172
173
174// DimServer::autoStartOff();
175// DimServer::start("TEST");
176
177// for(i = 0; i < 15000; i++)
178// {
179// arr[i] = i;
180// sprintf(str,"ServiceManyTest/%05d",i);
181// servp = new DimService(str,arr[i]);
182// servp->setQuality(1);
183// servp->updateService(arr[i]);
184//// DimServer::start("TEST");
185// sprintf(str,"CommandManyTest/%05d",i);
186// cmndp = new CmndServMany(str);
187//// DimServer::start("TEST");
188// }
189
190 while(1)
191 {
192 sleep(5);
193
194// while(cmdsvr.hasNext())
195// {
196// cmdsvr.getNext();
197// cmdsvr.handleIt();
198// }
199
200 s1 = "hello1";
201 if(!boolval)
202 boolval = 1;
203 else
204 boolval = 0;
205 ival++;
206 bool_serv[1]->updateService();
207
208// int inCallback = DimServer::inCallback();
209// cout << "main: In callback "<< inCallback << endl;
210 servint.updateService();
211 if(extraDns)
212 new_servint->updateService();
213 }
214 return 0;
215}
216
217/*
218int main()
219{
220DimService *servint, *newServint;
221int ival = 0;
222
223DimServer::start("TEST");
224servint = new DimService("TEST/INTVAL",ival);
225sleep(20);
226DimServer::stop();
227sleep(1);
228DimServer::start("TESTOTHER");
229newServint = new DimService("TESTOTHER/INTVAL",ival);
230sleep(20);
231DimServer::stop();
232}
233*/
Note: See TracBrowser for help on using the repository browser.