source: trunk/FACT++/dim/src/examples/Copy of test_server.cxx@ 16336

Last change on this file since 16336 was 11071, checked in by tbretz, 14 years ago
Replaced v19r21 by a version extracted with 'unzip -a' to get proper unix text format.
File size: 3.4 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 cout << severity << " " << msg << endl;
16 services = DimServer::getClientServices();
17 cout<< "from "<< DimServer::getClientName() << " services:" << endl;
18 while(services[index])
19 {
20 cout << services[index] << endl;
21 index++;
22 }
23 }
24public:
25 ErrorHandler() {DimServer::addErrorHandler(this);}
26};
27
28class ExitHandler : public DimExitHandler
29{
30 void exitHandler(int code)
31 {
32 cout << "exit code " << code << endl;
33 }
34public:
35 ExitHandler() {DimServer::addExitHandler(this);}
36};
37
38class CmndServ : public DimCommand, public DimTimer
39{
40 DimService servstr;
41 void commandHandler()
42 {
43 int index = 0;
44 char **services;
45 cout << "Command " << getString() << " received" << endl;
46 servstr.updateService(getString());
47 services = DimServer::getClientServices();
48 cout<< "from "<< DimServer::getClientName() << " services:" << endl;
49 while(services[index])
50 {
51 cout << services[index] << endl;
52 index++;
53 }
54 }
55public :
56 CmndServ() : DimCommand("TEST/CMND","C"),
57 servstr("TEST/STRVAL","empty") {};
58};
59
60/*
61class CmndServMany : public DimCommand
62{
63 void commandHandler()
64 {
65 cout << "Command " << getString() << " received" << endl;
66 }
67public :
68 CmndServMany(char *name) : DimCommand(name,"C") {};
69};
70*/
71
72void add_serv(const int & ival)
73{
74 DimService *abc;
75
76 abc = new DimService("TEST/INTVAL_CONST",(int &)ival);
77}
78
79void add_serv_str(const string & s1)
80{
81 DimService *abc;
82
83 abc = new DimService("TEST/STRINGVAL_CONST",(char *)s1.c_str());
84}
85
86void add_serv_bool(const bool & boolval)
87{
88 DimService *serv;
89
90// serv = new DimService("TEST/BOOLVAL_CONST",(short &)boolval);
91 serv = new DimService("TEST/BOOLVAL_CONST","C:1", (void *)&boolval, 1);
92}
93
94class ServWithHandler : public DimService
95{
96 int value;
97
98 void serviceHandler()
99 {
100 value++;
101// setData(value);
102 }
103public :
104 ServWithHandler(char *name) : DimService(name, value) { value = 0;};
105};
106
107int main()
108{
109 int ival = 0;
110// ErrorHandler errHandler;
111// ExitHandler exHandler;
112// DimServer::setDnsNode("axdes2.cern.ch");
113 string s1;
114 bool boolval;
115 ServWithHandler *testServ;
116 DimServerDns *newDns;
117
118 newDns = new DimServerDns("lxplus237.cern.ch", 0, "new_TEST");
119
120/*
121 int i, arr[15000];
122 DimService *servp;
123 DimCommand *cmndp;
124 char str[132];
125*/
126// float farr[4];
127// DimService *farrp;
128
129 s1 = "hello";
130 add_serv(ival);
131 DimService servint("TEST/INTVAL",ival);
132 DimService new_servint(newDns, "new_TEST/INTVAL",ival);
133 add_serv_str(s1);
134 boolval = 0;
135 add_serv_bool(boolval);
136 CmndServ cmdsvr;
137
138 testServ = new ServWithHandler("MY_NEW_TEST_SERVICE_WITH_HANDLER");
139
140// farr[0] = 1.2;
141// farr[1] = 2.3;
142// farrp = new DimService("/PCITCO147/sensors/fan/input","F", farr, sizeof(farr));
143
144 DimServer::start("TEST");
145
146/*
147// DimServer::autoStartOff();
148 DimServer::start("TEST");
149
150 for(i = 0; i < 15000; i++)
151 {
152 arr[i] = i;
153 sprintf(str,"ServiceManyTest/%05d",i);
154 servp = new DimService(str,arr[i]);
155 servp->setQuality(1);
156 servp->updateService(arr[i]);
157// DimServer::start("TEST");
158 sprintf(str,"CommandManyTest/%05d",i);
159 cmndp = new CmndServMany(str);
160// DimServer::start("TEST");
161 }
162*/
163
164 while(1)
165 {
166 sleep(5);
167 s1 = "hello1";
168 if(!boolval)
169 boolval = 1;
170 else
171 boolval = 0;
172 ival++;
173 servint.updateService();
174 }
175 return 0;
176}
177
Note: See TracBrowser for help on using the repository browser.