source: Evidence/DIM/dis.hxx@ 138

Last change on this file since 138 was 127, checked in by ogrimm, 15 years ago
First commit of Evidence control system core components
File size: 8.4 KB
Line 
1#ifndef __DISHHDEFS
2#define __DISHHDEFS
3#include <assert.h>
4#include <stdlib.h>
5#include <string.h>
6#ifndef WIN32
7#include <unistd.h>
8#endif
9#ifdef __VMS
10#include <starlet.h>
11#endif
12#include "dim_core.hxx"
13#include "dim.hxx"
14/*
15#define DimSHORT "S"
16#define DimINT "I"
17#define DimLONG "L"
18#define DimFLOAT "F"
19#define DimDOUBLE "D"
20#define DimSTRING "C"
21#define DimXLONG "X"
22*/
23enum DisTYPE {
24 DisPOINTER, DisSHORT, DisINT, DisFLOAT, DisDOUBLE, DisSTRING, DisXLONG, DisCOMMAND
25};
26
27class DimService;
28class DimCommand;
29
30class DllExp DimServiceHandler{
31public:
32 DimService *itsService;
33 DimService *getService() { return itsService; } ;
34 virtual void serviceHandler() = 0;
35 virtual ~DimServiceHandler() {};
36};
37
38class DllExp DimCommandHandler{
39public:
40 DimCommand *itsCommand;
41 DimCommand *getCommand() { return itsCommand; } ;
42 virtual void commandHandler() = 0;
43 virtual ~DimCommandHandler() {};
44};
45
46class DllExp DimClientExitHandler{
47public:
48 virtual void clientExitHandler() = 0;
49 virtual ~DimClientExitHandler() {};
50};
51
52class DllExp DimExitHandler{
53public:
54 virtual void exitHandler(int code) = 0;
55 virtual ~DimExitHandler() {};
56};
57
58class DllExp DimServerDns
59{
60public:
61 DimServerDns(const char *node);
62 DimServerDns(const char *node, int port);
63 DimServerDns(const char *node, int port, char *name);
64 ~DimServerDns();
65 void init(const char *node, int port);
66 long getDnsId();
67 void setName(const char *name);
68 char *getName();
69 void autoStartOn();
70 void autoStartOff();
71 int isAutoStart();
72 void addServiceId(int id);
73 int *getServiceIdList();
74private:
75 char *itsNode;
76 int itsPort;
77 long itsDnsId;
78 char *itsName;
79 int autoStart;
80 int *itsServiceIdList;
81 int itsServiceIdListSize;
82 int itsNServiceIds;
83// int itsNServices;
84};
85
86class DllExp DimServer : public DimServiceHandler, public DimCommandHandler,
87 public DimClientExitHandler, public DimExitHandler, public DimErrorHandler
88{
89public:
90 static char *clientName;
91 static char *itsName;
92 static char *dimDnsNode;
93 static int autoStart;
94 static DimClientExitHandler *itsClientExit;
95 static DimExitHandler *itsExit;
96 static DimErrorHandler *itsSrvError;
97// static int itsNServices;
98 DimServer();
99 virtual ~DimServer();
100 static void start(const char *name);
101 static void start(DimServerDns *dns, const char *name);
102 static void start();
103 static void start(DimServerDns *dns);
104 static void stop();
105 static void stop(DimServerDns *dns);
106 static void autoStartOn();
107 static void autoStartOff();
108 // Get Current Client Identifier
109 static int getClientId();
110 // Get Current Client Name
111 static char *getClientName();
112 static void setClientExitHandler(int clientId);
113 static void clearClientExitHandler(int clientId);
114 static void addClientExitHandler(DimClientExitHandler *handler);
115 void addClientExitHandler();
116 static void addExitHandler(DimExitHandler *handler);
117 static void addErrorHandler(DimErrorHandler *handler);
118 static int setDnsNode(const char *node);
119 static int setDnsNode(const char *node, int port);
120 static long addDns(const char *node, int port);
121 static void stopDns(long dnsid);
122 static char *getDnsNode();
123 static int getDnsPort();
124 static void setWriteTimeout(int secs);
125 static int getWriteTimeout();
126 void addExitHandler();
127 void addErrorHandler();
128 virtual void clientExitHandler() {};
129 virtual void exitHandler(int /* code */) {};
130 virtual void errorHandler(int /* severity */, int /* code */, char* /* msg */) {};
131// static char *getClientServices();
132// static char *getClientServices(int clientId);
133 static char **getClientServices();
134
135 virtual void serviceHandler() {};
136 virtual void commandHandler() {};
137};
138
139class DllExp DimService : public DimServiceHandler {
140
141public :
142 DimServiceHandler *itsServiceHandler;
143
144 // The object contains the value to be published. Service to be updated with an argument of same type;
145 DimService();
146
147 DimService(const char *name, int &value);
148 DimService(const char *name, float &value);
149 DimService(const char *name, double &value);
150 DimService(const char *name, longlong &value);
151 DimService(const char *name, short &value);
152 DimService(const char *name, char *string);
153
154 DimService(const char *name, char *format, void *structure, int size);
155
156 DimService(const char *name, char *format, DimServiceHandler *handler);
157
158 DimService(DimServerDns *dns, const char *name, int &value);
159 DimService(DimServerDns *dns, const char *name, float &value);
160 DimService(DimServerDns *dns, const char *name, double &value);
161 DimService(DimServerDns *dns, const char *name, longlong &value);
162 DimService(DimServerDns *dns, const char *name, short &value);
163 DimService(DimServerDns *dns, const char *name, char *string);
164
165 DimService(DimServerDns *dns, const char *name, char *format, void *structure, int size);
166
167 DimService(DimServerDns *dns, const char *name, char *format, DimServiceHandler *handler);
168
169 virtual ~DimService();
170
171 // Update methods
172 int updateService();
173 // Update the value as well...
174 int updateService( int &value );
175 int updateService( float &value );
176 int updateService( double &value ) ;
177 int updateService( longlong &value );
178 int updateService( short &value );
179 int updateService( char *string );
180
181 int updateService( void *structure, int size );
182
183 // Selective Update methods
184 int selectiveUpdateService(int *cids);
185 // Update the value as well...
186 int selectiveUpdateService( int &value, int *cids);
187 int selectiveUpdateService( float &value, int *cids );
188 int selectiveUpdateService( double &value, int *cids );
189 int selectiveUpdateService( longlong &value, int *cids );
190 int selectiveUpdateService( short &value, int *cids );
191 int selectiveUpdateService( char *string, int *cids );
192
193 int selectiveUpdateService( void *structure, int size, int *cids );
194
195 void setQuality(int quality);
196 void setTimestamp(int secs, int millisecs);
197
198 void *itsData;
199 int itsDataSize;
200 int itsSize;
201 DisTYPE itsType;
202 void setData(void *data, int size);
203 void setData(int &data);
204 void setData(float &data);
205 void setData(double &data);
206 void setData(longlong &data);
207 void setData(short &data);
208 void setData(char *data);
209
210 virtual void serviceHandler() {};
211 // Accessors
212 char *getName();
213 int getTimeout(int clientId);
214 int getNClients();
215private :
216 char *itsName;
217 int itsId;
218 int itsTagId;
219 void declareIt(char *name, char *format, DimServiceHandler *handler, DimServerDns *dns);
220 void storeIt(void *data, int size);
221 DimServerDns *itsDns;
222};
223
224class DllExp CmndInfo : public SLLItem {
225 friend class DimCommand;
226 void *itsData;
227 int itsDataSize;
228public:
229 CmndInfo(void *data, int datasize);
230 ~CmndInfo();
231};
232
233class DllExp DimCommand : public DimCommandHandler {
234
235public :
236 DimCommandHandler *itsCommandHandler;
237
238 DimCommand(const char *name, char *format);
239
240 DimCommand(const char *name, char *format, DimCommandHandler *handler);
241
242 DimCommand(DimServerDns *dns, const char *name, char *format);
243
244 DimCommand(DimServerDns *dns, const char *name, char *format, DimCommandHandler *handler);
245
246 int getNext();
247 void *itsData;
248 int itsSize;
249 void *getData();
250 int getInt();
251 float getFloat();
252 double getDouble();
253 longlong getLonglong();
254 short getShort();
255 char *getString();
256 int getSize();
257 char *getFormat();
258
259 virtual void commandHandler();
260
261 // Accessors
262 char *getName();
263 virtual ~DimCommand();
264
265private :
266 char *itsName;
267 int itsId;
268 int itsTagId;
269 char *itsFormat;
270 void declareIt(char *name, char *format, DimCommandHandler *handler, DimServerDns *dns);
271 CmndInfo *currCmnd;
272 SLList itsCmndList;
273 DimServerDns *itsDns;
274};
275
276class DllExp DimRpc
277{
278public :
279
280 // The object contains the value to be published. Service to be updated with an argument of same type;
281 DimRpc();
282
283 DimRpc(const char *name, const char *formatin, const char *formatout);
284
285 DimRpc(DimServerDns *dns, const char *name, const char *formatin, const char *formatout);
286
287 // Desctructor
288 virtual ~DimRpc();
289
290 void *itsDataIn;
291 int itsSizeIn;
292 void *getData();
293 int getInt();
294 float getFloat();
295 double getDouble();
296 longlong getLonglong();
297 short getShort();
298 char *getString();
299 int getSize();
300
301 void *itsDataOut;
302 int itsDataOutSize;
303 int itsSizeOut;
304
305 void setData(void *data, int size);
306 void setData(int &data);
307 void setData(float &data);
308 void setData(double &data);
309 void setData(longlong &data);
310 void setData(short &data);
311 void setData(char *data);
312
313 virtual void rpcHandler() = 0;
314 // Accessors
315 char *getName();
316 int itsIdIn;
317 int itsIdOut;
318private :
319 int itsTagId;
320 char *itsName;
321 char *itsNameIn;
322 char *itsNameOut;
323 void declareIt(char *name, char *formatin, char *formatout, DimServerDns *dns);
324 void storeIt(void *data, int size);
325 void timerHandler();
326 DimServerDns *itsDns;
327public:
328 int itsKilled;
329 int itsTimeout;
330};
331
332
333#endif
334
Note: See TracBrowser for help on using the repository browser.