summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Event/EC_ObserverStrategy.h
blob: 78de76032235f9ca425412ef00010d0398fa7af0 (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
/* -*- C++ -*- */
// $Id$
//
// ============================================================================
//
// = LIBRARY
//   ORBSVCS Real-time Event Channel
//
// = FILENAME
//   EC_ObserverStrategy
//
// = AUTHOR
//   Carlos O'Ryan (coryan@cs.wustl.edu)
//
// = CREDITS
//   Based on previous work by Tim Harrison (harrison@cs.wustl.edu)
//   and other members of the DOC group.
//   More details can be found in:
//   http://www.cs.wustl.edu/~schmidt/oopsla.ps.gz
//   http://www.cs.wustl.edu/~schmidt/JSAC-98.ps.gz
//
//
// ============================================================================

#ifndef TAO_EC_OBSERVERSTRATEGY_H
#define TAO_EC_OBSERVERSTRATEGY_H

#include "ace/Map_Manager.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/RB_Tree.h"
#include "orbsvcs/RtecEventChannelAdminC.h"

class ACE_Lock;
class TAO_EC_Event_Channel;
class TAO_EC_ProxyPushConsumer;
class TAO_EC_ProxyPushSupplier;

class TAO_ORBSVCS_Export TAO_EC_ObserverStrategy
{
  // = TITLE
  //   The strategy to handle observers for the Event Channel
  //   subscriptions and publication.
  //
  // = DESCRIPTION
  //   The Event Channel supports Observers for the set of
  //   subscriptions and publications.
  //   This is used to implement federations of event channels,
  //   either through UDP (multicast and unicast) and/or regular CORBA
  //   calls.
  //
  //   This behavior of the EC is strategized to avoid overhead when
  //   no gateways are needed.
  //
public:
  virtual ~TAO_EC_ObserverStrategy (void);
  // Destructor

  virtual RtecEventChannelAdmin::Observer_Handle
      append_observer (RtecEventChannelAdmin::Observer_ptr,
		       CORBA::Environment &env)
    TAO_THROW_SPEC ((CORBA::SystemException,
                     RtecEventChannel::EventChannel::SYNCHRONIZATION_ERROR,
                     RtecEventChannel::EventChannel::CANT_APPEND_OBSERVER))
    = 0;
  virtual void remove_observer (
                        RtecEventChannelAdmin::Observer_Handle,
                        CORBA::Environment &env)
    TAO_THROW_SPEC ((CORBA::SystemException,
                     RtecEventChannel::EventChannel::SYNCHRONIZATION_ERROR,
                     RtecEventChannel::EventChannel::CANT_REMOVE_OBSERVER))
     = 0;
  // The basic methods to support the EC strategies.

  virtual void connected (TAO_EC_ProxyPushConsumer*,
                          CORBA::Environment&) = 0;
  virtual void disconnected (TAO_EC_ProxyPushConsumer*,
                             CORBA::Environment&) = 0;
  // Used by the EC to inform the ObserverStrategy that a Consumer has
  // connected or disconnected from it.

  virtual void connected (TAO_EC_ProxyPushSupplier*,
                          CORBA::Environment&) = 0;
  virtual void disconnected (TAO_EC_ProxyPushSupplier*,
                             CORBA::Environment&) = 0;
  // Used by the EC to inform the ObserverStrategy that a Consumer has
  // connected or disconnected from it.
};

// ****************************************************************

class TAO_EC_Null_ObserverStrategy : public TAO_EC_ObserverStrategy
{
  // = TITLE
  //   A null observer strategy.
  //
  // = DESCRIPTION
  //   This class keeps no information and simply ignores the messages
  //   from the EC.
  //
public:
  TAO_EC_Null_ObserverStrategy (void);
  // Constructor

  // = The TAO_EC_ObserverStrategy methods.
  virtual RtecEventChannelAdmin::Observer_Handle
      append_observer (RtecEventChannelAdmin::Observer_ptr,
		       CORBA::Environment &env)
    TAO_THROW_SPEC ((CORBA::SystemException,
                     RtecEventChannel::EventChannel::SYNCHRONIZATION_ERROR,
                     RtecEventChannel::EventChannel::CANT_APPEND_OBSERVER));
  virtual void remove_observer (
                        RtecEventChannelAdmin::Observer_Handle,
                        CORBA::Environment &env)
    TAO_THROW_SPEC ((CORBA::SystemException,
                     RtecEventChannel::EventChannel::SYNCHRONIZATION_ERROR,
                     RtecEventChannel::EventChannel::CANT_REMOVE_OBSERVER));
  virtual void connected (TAO_EC_ProxyPushConsumer*,
                          CORBA::Environment&);
  virtual void disconnected (TAO_EC_ProxyPushConsumer*,
                             CORBA::Environment&);
  virtual void connected (TAO_EC_ProxyPushSupplier*,
                          CORBA::Environment&);
  virtual void disconnected (TAO_EC_ProxyPushSupplier*,
                             CORBA::Environment&);
};

// ****************************************************************

class TAO_EC_Basic_ObserverStrategy : public TAO_EC_ObserverStrategy
{
  // = TITLE
  //   A simple observer strategy.
  //
  // = DESCRIPTION
  //   This class simply keeps the information about the current list
  //   of observers, whenever the list of consumers and/or suppliers
  //   changes in queries the EC, computes the global subscription
  //   and/or publication list and sends the update message to all the
  //   observers.
  //
  // = MEMORY MANAGMENT
  //   It assumes ownership of the <lock>, but not of the
  //   Event_Channel.
  //
public:
  TAO_EC_Basic_ObserverStrategy (TAO_EC_Event_Channel* ec,
                                 ACE_Lock* lock);
  // Constructor

  virtual ~TAO_EC_Basic_ObserverStrategy (void);
  // Destructor

  // = The TAO_EC_ObserverStrategy methods.
  virtual RtecEventChannelAdmin::Observer_Handle
      append_observer (RtecEventChannelAdmin::Observer_ptr,
		       CORBA::Environment &env)
    TAO_THROW_SPEC ((CORBA::SystemException,
                     RtecEventChannel::EventChannel::SYNCHRONIZATION_ERROR,
                     RtecEventChannel::EventChannel::CANT_APPEND_OBSERVER));
  virtual void remove_observer (
                        RtecEventChannelAdmin::Observer_Handle,
                        CORBA::Environment &env)
    TAO_THROW_SPEC ((CORBA::SystemException,
                     RtecEventChannel::EventChannel::SYNCHRONIZATION_ERROR,
                     RtecEventChannel::EventChannel::CANT_REMOVE_OBSERVER));
  virtual void connected (TAO_EC_ProxyPushConsumer*,
                          CORBA::Environment&);
  virtual void disconnected (TAO_EC_ProxyPushConsumer*,
                             CORBA::Environment&);
  virtual void connected (TAO_EC_ProxyPushSupplier*,
                          CORBA::Environment&);
  virtual void disconnected (TAO_EC_ProxyPushSupplier*,
                             CORBA::Environment&);


  struct Observer_Entry
  {
    // = TITLE
    //   The data kept for each observer.
    //
    // = DESCRIPTION
    //   The observer and its handle are kept in a simple structure.
    //   In the future this structure could contain QoS information,
    //   such as:
    //   + how often do we update the observer?
    //   + When was the last update.
    //   + Does it want to receive all changes?
    //

    ACE_INLINE Observer_Entry (void);
    ACE_INLINE Observer_Entry (RtecEventChannelAdmin::Observer_Handle h,
                               RtecEventChannelAdmin::Observer_ptr o);

    RtecEventChannelAdmin::Observer_Handle handle;
    // The handle

    RtecEventChannelAdmin::Observer_var observer;
    // The observer
  };

  struct Header_Compare
  {
    int operator () (const RtecEventComm::EventHeader& lhs,
                     const RtecEventComm::EventHeader& rhs) const;
  };

private:
  void fill_qos (RtecEventChannelAdmin::ConsumerQOS &qos,
                 CORBA::Environment &env);
  void fill_qos (RtecEventChannelAdmin::SupplierQOS &qos,
                 CORBA::Environment &env);
  // Helper functions to compute the consumer and supplier QOS.

private:
  TAO_EC_Event_Channel* event_channel_;
  // The event channel.

  ACE_Lock* lock_;
  // The lock

  typedef ACE_Map_Manager<RtecEventChannelAdmin::Observer_Handle,Observer_Entry,ACE_Null_Mutex> Observer_Map;
  typedef ACE_Map_Iterator<RtecEventChannelAdmin::Observer_Handle,Observer_Entry,ACE_Null_Mutex> Observer_Map_Iterator;

  RtecEventChannelAdmin::Observer_Handle handle_generator_;
  // The handles are generated in sequential order, but are opaque to
  // the client.

  Observer_Map observers_;
  // Keep the set of Observers

  typedef ACE_RB_Tree<RtecEventComm::EventHeader,int,Header_Compare,ACE_Null_Mutex> Headers;
  typedef ACE_RB_Tree_Iterator<RtecEventComm::EventHeader,int,Header_Compare,ACE_Null_Mutex> HeadersIterator;
};

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

#endif /* TAO_EC_OBSERVERSTRATEGY_H */