1 | #include <iostream>
|
---|
2 | #include <dis.hxx>
|
---|
3 | #ifndef WIN32
|
---|
4 | #include <unistd.h>
|
---|
5 | #endif
|
---|
6 | using namespace std;
|
---|
7 | #include <string>
|
---|
8 |
|
---|
9 | class 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 | }
|
---|
25 | public:
|
---|
26 | ErrorHandler() {DimServer::addErrorHandler(this);}
|
---|
27 | };
|
---|
28 |
|
---|
29 | class ExitHandler : public DimExitHandler
|
---|
30 | {
|
---|
31 | void exitHandler(int code)
|
---|
32 | {
|
---|
33 | cout << "exit code " << code << endl;
|
---|
34 | }
|
---|
35 | public:
|
---|
36 | ExitHandler() {DimServer::addExitHandler(this);}
|
---|
37 | };
|
---|
38 |
|
---|
39 | class 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 |
|
---|
57 | public :
|
---|
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 | /*
|
---|
74 | class CmndServMany : public DimCommand
|
---|
75 | {
|
---|
76 | void commandHandler()
|
---|
77 | {
|
---|
78 | cout << "Command " << getString() << " received" << endl;
|
---|
79 | }
|
---|
80 | public :
|
---|
81 | CmndServMany(char *name) : DimCommand(name,"C") {};
|
---|
82 | };
|
---|
83 | */
|
---|
84 |
|
---|
85 | void add_serv(const int & ival)
|
---|
86 | {
|
---|
87 | DimService *abc;
|
---|
88 |
|
---|
89 | abc = new DimService("TEST/INTVAL_CONST",(int &)ival);
|
---|
90 | if(abc){}
|
---|
91 | }
|
---|
92 |
|
---|
93 | void 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 |
|
---|
101 | DimService *bool_serv[10];
|
---|
102 | void 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 |
|
---|
110 | class ServWithHandler : public DimService
|
---|
111 | {
|
---|
112 | int value;
|
---|
113 |
|
---|
114 | void serviceHandler()
|
---|
115 | {
|
---|
116 | value++;
|
---|
117 | // setData(value);
|
---|
118 | }
|
---|
119 | public :
|
---|
120 | ServWithHandler(char *name) : DimService(name, value) { value = 0;};
|
---|
121 | };
|
---|
122 |
|
---|
123 | int 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 | /*
|
---|
145 | int i, arr[15000];
|
---|
146 | DimService *servp;
|
---|
147 | DimCommand *cmndp;
|
---|
148 | char str[132];
|
---|
149 | */
|
---|
150 | // float farr[4];
|
---|
151 | // DimService *farrp;
|
---|
152 |
|
---|
153 | s1 = "hello";
|
---|
154 | add_serv(ival);
|
---|
155 | DimService servint("TEST/INTVAL",ival);
|
---|
156 |
|
---|
157 | if(extraDns)
|
---|
158 | {
|
---|
159 | new_servint = new DimService(newDns, "new_TEST/INTVAL",ival);
|
---|
160 | }
|
---|
161 |
|
---|
162 | add_serv_str(s1);
|
---|
163 | boolval = 0;
|
---|
164 | add_serv_bool(boolval);
|
---|
165 | CmndServ cmdsvr;
|
---|
166 |
|
---|
167 | testServ = new ServWithHandler((char *)"MY_NEW_TEST_SERVICE_WITH_HANDLER");
|
---|
168 | if(testServ){}
|
---|
169 |
|
---|
170 | // farr[0] = 1.2;
|
---|
171 | // farr[1] = 2.3;
|
---|
172 | // farrp = new DimService("/PCITCO147/sensors/fan/input","F", farr, sizeof(farr));
|
---|
173 |
|
---|
174 |
|
---|
175 | /*
|
---|
176 | // DimServer::autoStartOff();
|
---|
177 | DimServer::start("TEST");
|
---|
178 |
|
---|
179 | for(i = 0; i < 15000; i++)
|
---|
180 | {
|
---|
181 | arr[i] = i;
|
---|
182 | sprintf(str,"ServiceManyTest/%05d",i);
|
---|
183 | servp = new DimService(str,arr[i]);
|
---|
184 | servp->setQuality(1);
|
---|
185 | servp->updateService(arr[i]);
|
---|
186 | // DimServer::start("TEST");
|
---|
187 | sprintf(str,"CommandManyTest/%05d",i);
|
---|
188 | cmndp = new CmndServMany(str);
|
---|
189 | // DimServer::start("TEST");
|
---|
190 | }
|
---|
191 | */
|
---|
192 | while(1)
|
---|
193 | {
|
---|
194 | sleep(5);
|
---|
195 | /*
|
---|
196 | while(cmdsvr.hasNext())
|
---|
197 | {
|
---|
198 | cmdsvr.getNext();
|
---|
199 | cmdsvr.handleIt();
|
---|
200 | }
|
---|
201 | */
|
---|
202 | s1 = "hello1";
|
---|
203 | if(!boolval)
|
---|
204 | boolval = 1;
|
---|
205 | else
|
---|
206 | boolval = 0;
|
---|
207 | ival++;
|
---|
208 | bool_serv[1]->updateService();
|
---|
209 |
|
---|
210 | // int inCallback = DimServer::inCallback();
|
---|
211 | // cout << "main: In callback "<< inCallback << endl;
|
---|
212 | servint.updateService();
|
---|
213 | if(extraDns)
|
---|
214 | new_servint->updateService();
|
---|
215 | }
|
---|
216 | return 0;
|
---|
217 | }
|
---|
218 |
|
---|