source: trunk/FACT++/dim/src/examples/cpp_server.cxx@ 17010

Last change on this file since 17010 was 11071, checked in by tbretz, 13 years ago
Replaced v19r21 by a version extracted with 'unzip -a' to get proper unix text format.
File size: 3.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 }
56public :
57 CmndServ() : DimCommand("TEST/CMND","C"),
58 servstr("TEST/STRVAL","empty") {};
59};
60
61/*
62class CmndServMany : public DimCommand
63{
64 void commandHandler()
65 {
66 cout << "Command " << getString() << " received" << endl;
67 }
68public :
69 CmndServMany(char *name) : DimCommand(name,"C") {};
70};
71*/
72
73void add_serv(const int & ival)
74{
75 DimService *abc;
76
77 abc = new DimService("TEST/INTVAL_CONST",(int &)ival);
78}
79
80void add_serv_str(const string & s1)
81{
82 DimService *abc;
83
84 abc = new DimService("TEST/STRINGVAL_CONST",(char *)s1.c_str());
85}
86
87void add_serv_bool(const bool & boolval)
88{
89 DimService *serv;
90
91// serv = new DimService("TEST/BOOLVAL_CONST",(short &)boolval);
92 serv = new DimService("TEST/BOOLVAL_CONST","C:1", (void *)&boolval, 1);
93}
94
95class ServWithHandler : public DimService
96{
97 int value;
98
99 void serviceHandler()
100 {
101 value++;
102// setData(value);
103 }
104public :
105 ServWithHandler(char *name) : DimService(name, value) { value = 0;};
106};
107
108int main()
109{
110 int ival = 0;
111// ErrorHandler errHandler;
112// ExitHandler exHandler;
113// DimServer::setDnsNode("axdes2.cern.ch");
114 string s1;
115 bool boolval;
116 ServWithHandler *testServ;
117 DimServerDns *newDns;
118 char *extraDns;
119
120 DimServer::start("TEST");
121 extraDns = DimUtil::getEnvVar("EXTRA_DNS_NODE");
122// newDns = new DimServerDns(extraDns, 0, "new_TEST");
123 newDns = new DimServerDns(extraDns);
124
125/*
126 int i, arr[15000];
127 DimService *servp;
128 DimCommand *cmndp;
129 char str[132];
130*/
131// float farr[4];
132// DimService *farrp;
133
134 s1 = "hello";
135 add_serv(ival);
136 DimService servint("TEST/INTVAL",ival);
137 DimService new_servint(newDns, "new_TEST/INTVAL",ival);
138 DimServer::start(newDns, "new_TEST");
139
140 add_serv_str(s1);
141 boolval = 0;
142 add_serv_bool(boolval);
143 CmndServ cmdsvr;
144
145 testServ = new ServWithHandler("MY_NEW_TEST_SERVICE_WITH_HANDLER");
146
147// farr[0] = 1.2;
148// farr[1] = 2.3;
149// farrp = new DimService("/PCITCO147/sensors/fan/input","F", farr, sizeof(farr));
150
151
152/*
153// DimServer::autoStartOff();
154 DimServer::start("TEST");
155
156 for(i = 0; i < 15000; i++)
157 {
158 arr[i] = i;
159 sprintf(str,"ServiceManyTest/%05d",i);
160 servp = new DimService(str,arr[i]);
161 servp->setQuality(1);
162 servp->updateService(arr[i]);
163// DimServer::start("TEST");
164 sprintf(str,"CommandManyTest/%05d",i);
165 cmndp = new CmndServMany(str);
166// DimServer::start("TEST");
167 }
168*/
169
170 while(1)
171 {
172 sleep(5);
173 s1 = "hello1";
174 if(!boolval)
175 boolval = 1;
176 else
177 boolval = 0;
178 ival++;
179 servint.updateService();
180 new_servint.updateService();
181 }
182 return 0;
183}
184
Note: See TracBrowser for help on using the repository browser.