summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Event/Event_Manip.h
blob: b087dc2ce4a9c4d1f0f369c15156b146f8762bdf (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
/* -*- C++ -*- */
//=============================================================================
/**
 *  @file Event_Manip.h
 *
 *  $Id$
 *
 *  @author Carlos O'Ryan (coryan@cs.wust.edu)
 *
 * The Event Channel uses some of this classes to simplify its event
 * manipulation.
 * For instance it keeps a reference counted RtecEventComm::EventSet
 * and classes to automatically manage this reference count.
 *
 *
 */
//=============================================================================


#ifndef TAO_EC_EVENT_MANIP_H
#define TAO_EC_EVENT_MANIP_H
#include /**/ "ace/pre.h"

#include "orbsvcs/orbsvcs/RtecEventCommC.h"
#include "old_event_export.h"

/**
 * @class TAO_EC_Event_Set
 *
 * @brief A reference counted RtecEventComm::EventSet
 *
 * The Event_Channel receives an event set from its suppliers, but
 * it has to pass it to (potentially) multiple consumers, running
 * at different priorities.
 * Thus is is difficult to know in advance the life time of this
 * EventSet.
 */
class TAO_RTOLDEvent_Export TAO_EC_Event_Set
{
public:
  /// Constructor...
  TAO_EC_Event_Set (CORBA::ULong length,
                    RtecEventComm::Event* buffer);

  /// destructor
  ~TAO_EC_Event_Set (void);

  /// The length.
  CORBA::ULong length (void) const;

  /// Access a particular element.
  RtecEventComm::Event& operator[] (CORBA::ULong i) const;

  /// Create from an event set.
  static TAO_EC_Event_Set* _create (const RtecEventComm::Event&);
  static TAO_EC_Event_Set* _create (RtecEventComm::EventSet&);

  /// Reference counting.
  static TAO_EC_Event_Set* _duplicate (TAO_EC_Event_Set*);
  static void _release (TAO_EC_Event_Set*);

private:
  /// Manipulate the reference count.
  CORBA::ULong _incr_refcnt (void);
  CORBA::ULong _decr_refcnt (void);

private:
  ACE_UNIMPLEMENTED_FUNC (TAO_EC_Event_Set (const TAO_EC_Event_Set&))
  ACE_UNIMPLEMENTED_FUNC (TAO_EC_Event_Set& operator= (const TAO_EC_Event_Set&))

private:
  /// The length of the buffer.
  CORBA::ULong length_;

  /// The buffer.
  RtecEventComm::Event* buffer_;

  /// Synchronize access to the class internals.
  TAO_SYNCH_MUTEX lock_;

  /// The reference count.
  CORBA::ULong refcnt_;
};

/**
 * @class TAO_EC_Event
 *
 * @brief A smart event class.
 *
 * Inside the Event Channl a set of events is broken into the
 * events that compose it and processed independently.
 * To minimize data copying and memory allocations the Event is
 * represented as a smart reference to one element of the
 * reference counted Event Set (see TAO_EC_Event_Set above).
 * Events can be chained together using a cont() field, much like
 * ACE_Message_Block.
 */
class TAO_RTOLDEvent_Export TAO_EC_Event
{
public:
  /// Default constructor.
  TAO_EC_Event (void);

  /// Constructor, we assume ownership (i.e. duplicate and release the
  /// set)
  TAO_EC_Event (TAO_EC_Event_Set *event_set,
                CORBA::ULong index);

  /// Destructor
  ~TAO_EC_Event (void);

  /// "Deep" copy, i.e. increases the reference count.
  TAO_EC_Event (const TAO_EC_Event& event);
  TAO_EC_Event& operator= (const TAO_EC_Event& event);

  /// Return true if there is no event inside this object.
  int empty (void) const;

  /// Release the event...
  void clear (void);

  /// The event..
  RtecEventComm::Event& event (void);
  const RtecEventComm::Event& event (void) const;

  // = Shortcuts
  RtecEventComm::EventHeader& header (void);
  RtecEventComm::EventData& data (void);
  const RtecEventComm::EventHeader& header (void) const;
  const RtecEventComm::EventData& data (void) const;

  RtecEventComm::EventSourceID source (void) const;
  RtecEventComm::EventType type (void) const;

private:
  /// The event set.
  TAO_EC_Event_Set *event_set_;

  /// The position of the event in the set
  CORBA::ULong index_;
};

#if defined (__ACE_INLINE__)
#include "Event_Manip.i"
#endif /* __ACE_INLINE__ */

#include /**/ "ace/post.h"
#endif /* TAO_EC_EVENT_MANIP_H */