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 | 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 | }
|
---|
24 | public:
|
---|
25 | ErrorHandler() {DimServer::addErrorHandler(this);}
|
---|
26 | };
|
---|
27 |
|
---|
28 | class ExitHandler : public DimExitHandler
|
---|
29 | {
|
---|
30 | void exitHandler(int code)
|
---|
31 | {
|
---|
32 | cout << "exit code " << code << endl;
|
---|
33 | }
|
---|
34 | public:
|
---|
35 | ExitHandler() {DimServer::addExitHandler(this);}
|
---|
36 | };
|
---|
37 |
|
---|
38 | class 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 | }
|
---|
55 | public :
|
---|
56 | CmndServ() : DimCommand("TEST/CMND","C"),
|
---|
57 | servstr("TEST/STRVAL","empty") {};
|
---|
58 | };
|
---|
59 |
|
---|
60 | /*
|
---|
61 | class CmndServMany : public DimCommand
|
---|
62 | {
|
---|
63 | void commandHandler()
|
---|
64 | {
|
---|
65 | cout << "Command " << getString() << " received" << endl;
|
---|
66 | }
|
---|
67 | public :
|
---|
68 | CmndServMany(char *name) : DimCommand(name,"C") {};
|
---|
69 | };
|
---|
70 | */
|
---|
71 |
|
---|
72 | void add_serv(const int & ival)
|
---|
73 | {
|
---|
74 | DimService *abc;
|
---|
75 |
|
---|
76 | abc = new DimService("TEST/INTVAL_CONST",(int &)ival);
|
---|
77 | }
|
---|
78 |
|
---|
79 | void add_serv_str(const string & s1)
|
---|
80 | {
|
---|
81 | DimService *abc;
|
---|
82 |
|
---|
83 | abc = new DimService("TEST/STRINGVAL_CONST",(char *)s1.c_str());
|
---|
84 | }
|
---|
85 |
|
---|
86 | void 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 |
|
---|
94 | class ServWithHandler : public DimService
|
---|
95 | {
|
---|
96 | int value;
|
---|
97 |
|
---|
98 | void serviceHandler()
|
---|
99 | {
|
---|
100 | value++;
|
---|
101 | // setData(value);
|
---|
102 | }
|
---|
103 | public :
|
---|
104 | ServWithHandler(char *name) : DimService(name, value) { value = 0;};
|
---|
105 | };
|
---|
106 |
|
---|
107 | int 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 |
|
---|
117 | /*
|
---|
118 | int i, arr[15000];
|
---|
119 | DimService *servp;
|
---|
120 | DimCommand *cmndp;
|
---|
121 | char str[132];
|
---|
122 | */
|
---|
123 | float farr[4];
|
---|
124 | DimService *farrp;
|
---|
125 |
|
---|
126 | s1 = "hello";
|
---|
127 | add_serv(ival);
|
---|
128 | DimService servint("TEST/INTVAL",ival);
|
---|
129 | add_serv_str(s1);
|
---|
130 | boolval = 0;
|
---|
131 | add_serv_bool(boolval);
|
---|
132 | CmndServ cmdsvr;
|
---|
133 |
|
---|
134 | testServ = new ServWithHandler("MY_NEW_TEST_SERVICE_WITH_HANDLER");
|
---|
135 |
|
---|
136 | farr[0] = 1.2;
|
---|
137 | farr[1] = 2.3;
|
---|
138 | farrp = new DimService("/PCITCO147/sensors/fan/input","F", farr, sizeof(farr));
|
---|
139 | DimServer::start("TEST");
|
---|
140 |
|
---|
141 | /*
|
---|
142 | // DimServer::autoStartOff();
|
---|
143 | DimServer::start("TEST");
|
---|
144 |
|
---|
145 | for(i = 0; i < 15000; i++)
|
---|
146 | {
|
---|
147 | arr[i] = i;
|
---|
148 | sprintf(str,"ServiceManyTest/%05d",i);
|
---|
149 | servp = new DimService(str,arr[i]);
|
---|
150 | servp->setQuality(1);
|
---|
151 | servp->updateService(arr[i]);
|
---|
152 | // DimServer::start("TEST");
|
---|
153 | sprintf(str,"CommandManyTest/%05d",i);
|
---|
154 | cmndp = new CmndServMany(str);
|
---|
155 | // DimServer::start("TEST");
|
---|
156 | }
|
---|
157 | */
|
---|
158 |
|
---|
159 | while(1)
|
---|
160 | {
|
---|
161 | sleep(5);
|
---|
162 | s1 = "hello1";
|
---|
163 | if(!boolval)
|
---|
164 | boolval = 1;
|
---|
165 | else
|
---|
166 | boolval = 0;
|
---|
167 | ival++;
|
---|
168 | servint.updateService();
|
---|
169 | }
|
---|
170 | return 0;
|
---|
171 | }
|
---|
172 |
|
---|