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

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