summaryrefslogtreecommitdiff
path: root/TAO/examples/OBV/Typed_Events/Event_Types_impl.h
blob: 2114e479bbdce6580c1c3c24d7f3b2fec70eecdf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
// -*- C++ -*-
// $Id$

#if !defined (EVENT_TYPES_IMPL_H)
#define EVENT_TYPES_IMPL_H
#include "Event_TypesC.h"

// Event hierarchy implementation classes ======================

// The implementation of a valuetype in C++ needs to derive from
// the IDL generated OBV_Event, which provides the data members
// and their accessor/modifier.
// In TAO it is possible to have inline instead the standard virtual
// accessor/modifier functions. But then they can't be overridden for
// marshalling. (doesn't yet work anyway but will come soon %!).
//
// The 'client' of a valuetype (client means here the parts
// of an application which locally access the valuetype through its interface)
// uses pointer to the 'Event' class, or better the Event_var type
// which is similar an object reference _var.
//
// Specs say that the instances of Event_impl should be created by means
// of Event_init::create (), which are equivalents to the init () operations
// in the IDL of the valuetype --- its not yet impl. and will come later on %!
// Today you have to declare your own create () member.
//
// One more step to make (far way from Event to Event_impl, isn't it?):
// We must mix in a class to have a reference counter implementation
// (: Sit down and type twenty times CORBA::DefaultValueRefCountBase :)
// A plus is its on your hand to choose possibly a reference counter
// with (like the standard supplied one) or without lock. But I hate
// the fact that reference counting is based on virtual _add_ref ()/
// _remove_ref () functions, which may cause substantial overhead.
// I'm thinking of a TAO option to let tao_idl mix in the reference counter
// previous and generate _var classes which access inline functions.
// ... And I wonder how the OMG want to manage cyclic graphs with
// reference counting.

#if defined(_MSC_VER)
#pragma warning(disable:4250)
#endif /* _MSC_VER */

class Event_impl : public virtual OBV_Event,
                   public virtual CORBA::DefaultValueRefCountBase
{
 public:
  Event_impl ();
  virtual ~Event_impl ();

  virtual void do_print (void);
  // Implementation of the do_print () operation the valuetype should have.
  // All operations in valuetypes are virtual.

  // The state member for the event time is yet implemented in OBV_Event
  // (or in the Event class, if -Wb,obv_opt_accessor is given to tao_idl).
};

// An instance of the Event_factory class has to be registered
// in the ORB with ORB::register_value_factory ().

// Then the unmarshal engine can obtain a fresh instance of Event_impl
// from the (user implemented) Event_factory::create_for_unmarshal ()
// function. These should return a pointer to Event, but as long as
// covariant return types are not commonly supported one has to
// return a pointer to CORBA::ValueBase. This option handles the macro
// in front of the create_for_unmarshal () declaration. Now the code
// is compiler portable, but not ORB vendor portable ...

// ... but stop a moment. We don't want an instance of Event.
// It is only the base class for Temperature, Position and Log_Msg.
// We didn't declared Event as abstract valuetype, cause we want to
// store the timestamp in it. So we express that no instance can
// exists while we don't make a factory for it (and don't register one).

#ifdef is_certainly_not_defined
class Event_factory : public Event_init
{
 public:

  // create (...) would go here
private:
  virtual ~Event_factory ();
  TAO_OBV_CREATE_RETURN_TYPE (Event)  create_for_unmarshal ();
};
#endif /* is not defined */


// The procedure to register your instance is currently not much like
// OBV specs says. This implementation has currently one
// process-wide map for the registered factories. The specs want one
// per ORB. To run first OBV tests, and that is what we do yet, it is
// more practicable to have simply just one map. (%!)
// Further on it is non-standard how the repository id of the valuetype
// is obtained. Look at the macro TAO_OBV_REGISTER_FACTORY(your_factory_type)
// in tao/ValueFactory.h (explained there) how it is done or just use it
// for first experiments.
// Exceptions are not yet implemented in this area.


// Temperature implementation classes ===================================

// The Temperature_impl should inherit its own OBV_Temperature and
// the implementation of Event. (so-called ladder style implementation
// inheritance, I guess.) Its yet there, but purists
// can additionally inherit public virtual from the CORBA::DefaultVal...


class Temperature_impl : public virtual OBV_Temperature,
                         public virtual Event_impl
{
public:
  Temperature_impl ();
  // Constructor for the factory

  Temperature_impl (CORBA::Float temp);
  // Constructor, should regularly be a factory create () method.
  // But it is more simple to do so here.

  virtual ~Temperature_impl ();

  virtual void do_print (void);
  // Overrides Event_impl::do_print (). Note that a new declaration
  // in IDL in a derived class is not allowed.
};

class Temperature_factory : public Temperature_init
{
  friend class Temperature;
 public:
  // create (...) would go here
private:
  virtual ~Temperature_factory ();
  TAO_OBV_CREATE_RETURN_TYPE (Temperature)  create_for_unmarshal ();
};


// Position implementation classes =====================================

class Position_impl : public virtual OBV_Position,
                      public virtual Event_impl
{
public:
  Position_impl ();
  Position_impl (Point &p);
  virtual ~Position_impl ();

  virtual CORBA::Float x ();
  virtual void x (CORBA::Float);
  virtual CORBA::Float y ();
  virtual void y (CORBA::Float);
  virtual CORBA::Float z ();
  virtual void z (CORBA::Float);
  //These are the attributes

  virtual void do_print (void);
};

class Position_factory : public Position_init
{
  friend class Position;
 public:

  // create (...) would go here
private:
  virtual ~Position_factory ();
  TAO_OBV_CREATE_RETURN_TYPE (Position)  create_for_unmarshal ();
};


// Log_Msg implementation classes =====================================

class Log_Msg_impl : public virtual OBV_Log_Msg,
                     public virtual Event_impl
{
public:
  Log_Msg_impl ();
  Log_Msg_impl (CORBA::Short urgency_p, const char *message_p);
  virtual ~Log_Msg_impl ();

  virtual void do_print (void);
};

class Log_Msg_factory : public Log_Msg_init
{
  friend class Log_Msg;
 public:

  // create (...) would go here
private:
  virtual ~Log_Msg_factory ();
  TAO_OBV_CREATE_RETURN_TYPE (Log_Msg)  create_for_unmarshal ();
};


// Event_List_Link implementation classes =====================================

class Event_List_Link_factory;
class Event_List_Iterator;

class Event_List_Link_impl : public virtual OBV_Event_List_Link,
                         public virtual CORBA::DefaultValueRefCountBase
{
  friend class Event_List_Link_factory;
  friend class Event_List;
  friend class Event_List_Iterator;

 public:
  Event_List_Link_impl ();
  Event_List_Link_impl (Event *e);
  virtual ~Event_List_Link_impl ();

  Event *get_event (void);

 private:
  Event_List_Link *get_next_link (void);

  void attach_next_link (Event_List_Link * chain);
  // Attach a chain at the end.
};


class Event_List_Link_factory : public Event_List_Link_init
{
  friend class Event_List_Link;
 private:
  virtual ~Event_List_Link_factory ();
  TAO_OBV_CREATE_RETURN_TYPE (Event_List_Link)  create_for_unmarshal ();
};


// The event list itself.   ----------------------------------

class Event_List_impl : public virtual OBV_Event_List,
                        public virtual CORBA::DefaultValueRefCountBase
{
  friend class Event_List_Iterator;
 public:
  Event_List_impl ();
  virtual ~Event_List_impl ();

  void store_event (Event* e);

  Event_List_Link *get_first_link();
  // The iterator needs it.

 private:
  Event_List_Link *last_link_cache_;
  // For fast attachment. Need not to be a _var cause we hold at least one
  // reference through my_first_event_list_link which is a state member and
  // is mapped to a _var.

  // And it isn't a state member of valuetype.
  // Currently we can't yet do this, because sharing of valuetypes is not
  // yet impl ...%!.
  // Without the availability to share we would get two different instances
  // of the last list link at the receiving end of an invocation.
};


class Event_List_factory : public Event_List_init
{
  friend class Event_List;
 private:
  virtual ~Event_List_factory ();
  TAO_OBV_CREATE_RETURN_TYPE (Event_List)  create_for_unmarshal ();
};


class Event_List_Iterator
{
 public:
  Event_List_Iterator (void);
  Event_List_Iterator (Event_List *list);
  // Construct it to point to the first list link.

  virtual ~Event_List_Iterator ();

  void init (Event_List *list);

  Event *next ();
  // Get pointer to the current event.

  CORBA::Boolean next (Event_var &event);
  // Sets the Event_var argument to the current event.
  // This forces proper memory management in the user code, as the Event_var
  // could be stored beyond the life time of the iterator.

  void advance ();
  // Walks one event ahead.

 private:
  Event_List_Link_var current_;
};


// Checkpoint server side --------------------------------------------


// Criterion classes -------------------------------------------------


// Criterion itself has no implementation since it is abstract.

// It is necessary to inherit from OBV_Event (or an Event implementation)
// for implementing the state members of Event.


class Temperature_Criterion_impl :
                           public virtual OBV_Temperature_Criterion,
                           public virtual OBV_Event,
                           public virtual CORBA::DefaultValueRefCountBase
{
public:
  Temperature_Criterion_impl ();
  Temperature_Criterion_impl (CORBA::ULong origin_id, CORBA::Float temp);

  virtual ~Temperature_Criterion_impl ();

  CORBA::Boolean is_critical (Event* e);
  virtual void do_print (void);
};

class Temperature_Criterion_factory : public Temperature_Criterion_init
{
  friend class Temperature;
private:
  virtual ~Temperature_Criterion_factory ();
  TAO_OBV_CREATE_RETURN_TYPE (Temperature_Criterion) create_for_unmarshal ();
};



class Position_Criterion_impl :
                            public virtual OBV_Position_Criterion,
                            public virtual OBV_Event,
                            public virtual CORBA::DefaultValueRefCountBase
{
public:
  Position_Criterion_impl ();
  Position_Criterion_impl (CORBA::ULong origin_id,
                           Position *lb,
                           Position *tr);
  virtual ~Position_Criterion_impl ();

  CORBA::Boolean is_critical (Event* e);
  virtual void do_print (void);
};

class Position_Criterion_factory : public Position_Criterion_init
{
  friend class Position;
private:
  virtual ~Position_Criterion_factory ();
  TAO_OBV_CREATE_RETURN_TYPE (Position_Criterion)  create_for_unmarshal ();
};



class Log_Msg_Criterion_impl : public virtual OBV_Log_Msg_Criterion,
                               public virtual OBV_Event,
                               public virtual CORBA::DefaultValueRefCountBase
{
public:
  Log_Msg_Criterion_impl ();
  virtual ~Log_Msg_Criterion_impl ();

  CORBA::Boolean is_critical (Event* e);
  virtual void do_print (void);
};

class Log_Msg_Criterion_factory : public Log_Msg_Criterion_init
{
  friend class Log_Msg;
private:
  virtual ~Log_Msg_Criterion_factory ();
  TAO_OBV_CREATE_RETURN_TYPE (Log_Msg_Criterion)  create_for_unmarshal ();
};


class Criterion_List_impl : public virtual OBV_Criterion_List,
                        public virtual CORBA::DefaultValueRefCountBase
{
 public:
  Criterion_List_impl ();
  virtual ~Criterion_List_impl ();

  void store_criterion (Criterion *c);
  CORBA::Boolean is_critical (Event *e);
};


// This is just a wrapper and it uses the Event_List_Iterator on
// the underlaying Event_List. Better would be a template for all the
// iterators.

class Criterion_List_Iterator
{
 public:
  Criterion_List_Iterator (Criterion_List *list);
  // Construct it to point to the first list link.

  virtual ~Criterion_List_Iterator ();

  void init (Criterion_List *list);

  Criterion *next ();
  // Get pointer to the current Criterion.

  void advance ();
  // Walks one Criterion ahead.

 private:
  Event_List_Iterator iterator_;
};


// Some origin_id's

#define KITCHEN 1001
#define BATHROOM 1002
#define JONAS 1

#if defined(_MSC_VER)
#pragma warning(default:4250)
#endif /* _MSC_VER */
#endif /* EVENT_TYPES_IMPL_H */