summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Notify/Notify_Event_Map.h
blob: 44281098d805d2138a89021dc5065819d6235437 (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
/* -*- C++ -*- */
//=============================================================================
/**
 *  @file   Notify_Event_Map.h
 *
 *  $Id$
 *
 * Stores information about subscription mappings
 *
 *
 *  @author Pradeep Gore <pradeep@cs.wustl.edu>
 */
//=============================================================================


#ifndef TAO_NOTIFY_Event_Map_HEADER_H
#define TAO_NOTIFY_Event_Map_HEADER_H
#include "ace/pre.h"

#include "orbsvcs/CosNotificationC.h"

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

#include "Notify_Collection.h"
#include "notify_export.h"
#include "orbsvcs/ESF/ESF_Worker.h"

#include "ace/Hash_Map_Manager.h"

class TAO_Notify_EventListener;
class TAO_Notify_UpdateListener;
class TAO_Notify_EventType;
class TAO_Notify_Collection_Factory;
class TAO_Notify_EMO_Factory;

/**
 * @class TAO_Notify_Event_Map
 *
 * @brief TAO_Notify_Event_Map
 *
 * This is a compound container consisting of:
 * - A "recipient" map : mapping between an event and its subscriibers
 * - Lists of current events being subscribed, published.
 * - Lists of subscriptions, publications update listeners.
 */
class TAO_Notify_Export TAO_Notify_Event_Map
{
public:
  /// Constructor.
  TAO_Notify_Event_Map (TAO_Notify_EMO_Factory* emo_factory);

  /// Destructor.
  virtual ~TAO_Notify_Event_Map ();

  /// Init
  void init (ACE_ENV_SINGLE_ARG_DECL);

  /// Shutdown releases all listeners.
  void shutdown (ACE_ENV_SINGLE_ARG_DECL);

  // = Subscribe and Unsubscribe methods.
  void subscribe_for_events (TAO_Notify_EventListener* event_listener, TAO_Notify_EventType_List& update, const CosNotification::EventTypeSeq & added ACE_ENV_ARG_DECL);

  void unsubscribe_from_events (TAO_Notify_EventListener* event_listener, TAO_Notify_EventType_List &update, const CosNotification::EventTypeSeq & removed ACE_ENV_ARG_DECL);

  // = Publish and Unpublish methods
  // Later:
  // Suppliers can send anonymous requests to the Event Manager to indicate
  // what kind of events they expect to produce.
  void update_publication_list (const CosNotification::EventTypeSeq & added, const CosNotification::EventTypeSeq & removed, TAO_Notify_EventType_List &added_list, TAO_Notify_EventType_List &removed_list ACE_ENV_ARG_DECL);

  // = Subscription Updates
  /// Registers the subscription update listener with the Event Manager.
  void register_for_subscription_updates (TAO_Notify_UpdateListener* update_listener ACE_ENV_ARG_DECL);

  /// Unregister from subscription updates.
  void unregister_from_subscription_updates (TAO_Notify_UpdateListener* update_listener ACE_ENV_ARG_DECL);

  // = Publication Updates
  /// Registers the publication update listener with the Event Manager.
  void register_for_publication_updates (TAO_Notify_UpdateListener* update_listener ACE_ENV_ARG_DECL);

  /// Unregister from publication updates.
  void unregister_from_publication_updates (TAO_Notify_UpdateListener* update_listener ACE_ENV_ARG_DECL);

  // = Subscription list lookup
  int find (TAO_Notify_EventType const & event_type, TAO_Notify_EventListener_List*& event_listener_list);

  // = Accessors
  /// Obtain the publication list.
  CosNotification::EventTypeSeq* obtain_offered_types(void);

  /// Obtain the subscription list.
  CosNotification::EventTypeSeq* obtain_subscription_types (void);

  TAO_Notify_UpdateListener_List* subscription_change_listeners (void);
  TAO_Notify_UpdateListener_List* publication_change_listeners (void);
  TAO_Notify_EventListener_List* default_subscription_list (void);

protected:
  // = Typedefs
  typedef ACE_Hash_Map_Manager <TAO_Notify_EventType,
    TAO_Notify_EventListener_List*, TAO_SYNCH_MUTEX> EVENT_RECIPIENT_MAP;

  // = Data Members
  /**
   * A Map of event types and the groups of event listeners interested in them.
   * The keys of the map are a list of events that consumers have currently
   * subscribed for.
   */
  EVENT_RECIPIENT_MAP event_recipient_map_;

  /// Save a reference to the default list, we don't want to spend time
  /// looking for it in the <event_recipient_map>.
  TAO_Notify_EventListener_List* default_subscription_list_;

  /// The list of event types that are being currently published by suppliers.
  TAO_Notify_EventType_List publication_list_;

  /**
   * The list of event types that are being currently subscribed to by
   * consumers. This list is the same as the list of keys in the
   * <event_recepient_map>. We keep a copy of that list here to reduce
   * contention for the map which will be accessed for every event that
   * enters the system.
   */
  TAO_Notify_EventType_List subscription_list_;

  /// This is a list of listeners that want to be notified if the subsciptions
  /// from consumers changes the <event_recipient_map_> keys.
  TAO_Notify_UpdateListener_List* subscription_change_listeners_;

  /// This is a list of listeners that want to be notified if the publications
  /// from suppliers changes the <publication_list_>.
  TAO_Notify_UpdateListener_List* publication_change_listeners_;

  /// Evenet Manager Objects factory.
  TAO_Notify_EMO_Factory* emo_factory_;

  /// Collection objects factory.
  TAO_Notify_Collection_Factory* collection_factory_;
};

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

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

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