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

Last change on this file since 14621 was 12757, checked in by tbretz, 13 years ago
Switched to v19r27
File size: 4.2 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","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}
91
92void add_serv_str(const string & s1)
93{
94 DimService *abc;
95
96 abc = new DimService("TEST/STRINGVAL_CONST",(char *)s1.c_str());
97}
98
99DimService *bool_serv[10];
100void add_serv_bool(const bool & boolval)
101{
102
103// serv = new DimService("TEST/BOOLVAL_CONST",(short &)boolval);
104 bool_serv[0] = new DimService("TEST/BOOLVAL_CONST","C:1", (void *)&boolval, 1);
105 bool_serv[1] = new DimService("TEST/BOOLVAL_CONST1","C:1", (void *)&boolval, 1);
106}
107
108class ServWithHandler : public DimService
109{
110 int value;
111
112 void serviceHandler()
113 {
114 value++;
115// setData(value);
116 }
117public :
118 ServWithHandler(char *name) : DimService(name, value) { value = 0;};
119};
120
121int main()
122{
123 int ival = 0;
124// ErrorHandler errHandler;
125// ExitHandler exHandler;
126// DimServer::setDnsNode("axdes2.cern.ch");
127 string s1;
128 bool boolval;
129 ServWithHandler *testServ;
130 DimServerDns *newDns;
131 char *extraDns = 0;
132 DimService *new_servint;
133
134// DimService *dim = new DimService("test","C");
135// delete dim;
136
137 DimServer::start("TEST");
138 extraDns = DimUtil::getEnvVar("EXTRA_DNS_NODE");
139 if(extraDns)
140 newDns = new DimServerDns(extraDns, 0, "new_TEST");
141
142/*
143 int i, arr[15000];
144 DimService *servp;
145 DimCommand *cmndp;
146 char str[132];
147*/
148// float farr[4];
149// DimService *farrp;
150
151 s1 = "hello";
152 add_serv(ival);
153 DimService servint("TEST/INTVAL",ival);
154
155 if(extraDns)
156 {
157 new_servint = new DimService(newDns, "new_TEST/INTVAL",ival);
158 }
159
160 add_serv_str(s1);
161 boolval = 0;
162 add_serv_bool(boolval);
163 CmndServ cmdsvr;
164
165 testServ = new ServWithHandler("MY_NEW_TEST_SERVICE_WITH_HANDLER");
166
167// farr[0] = 1.2;
168// farr[1] = 2.3;
169// farrp = new DimService("/PCITCO147/sensors/fan/input","F", farr, sizeof(farr));
170
171
172/*
173// DimServer::autoStartOff();
174 DimServer::start("TEST");
175
176 for(i = 0; i < 15000; i++)
177 {
178 arr[i] = i;
179 sprintf(str,"ServiceManyTest/%05d",i);
180 servp = new DimService(str,arr[i]);
181 servp->setQuality(1);
182 servp->updateService(arr[i]);
183// DimServer::start("TEST");
184 sprintf(str,"CommandManyTest/%05d",i);
185 cmndp = new CmndServMany(str);
186// DimServer::start("TEST");
187 }
188*/
189 while(1)
190 {
191 sleep(5);
192/*
193 while(cmdsvr.hasNext())
194 {
195 cmdsvr.getNext();
196 cmdsvr.handleIt();
197 }
198*/
199 s1 = "hello1";
200 if(!boolval)
201 boolval = 1;
202 else
203 boolval = 0;
204 ival++;
205 bool_serv[1]->updateService();
206
207 int inCallback = DimServer::inCallback();
208 cout << "main: In callback "<< inCallback << endl;
209 servint.updateService();
210 if(extraDns)
211 new_servint->updateService();
212 }
213 return 0;
214}
215
Note: See TracBrowser for help on using the repository browser.