summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Notify/Notify_Event_Map.h
blob: ef139ca335305d1cd37c781bf8060d7dbc24ac48 (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
/* -*- C++ -*- */
// $Id$
//
// ============================================================================
//
// = LIBRARY
//   ORBSVCS Notification
//
// = FILENAME
//   Notify_Event_Map.h
//
// = DESCRIPTION
//   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_Export TAO_Notify_Event_Map
{
  // = TITLE
  //   TAO_Notify_Event_Map
  //
  // = DESCRIPTION
  //   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.
  //
public:
  TAO_Notify_Event_Map (TAO_Notify_EMO_Factory* emo_factory);
  // Constructor.

  virtual ~TAO_Notify_Event_Map ();
  // Destructor.

  void init (TAO_ENV_SINGLE_ARG_DECL);
  // Init

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

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

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

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

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

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

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

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

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

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

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

  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
  EVENT_RECIPIENT_MAP event_recipient_map_;
  // 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.

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

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

  TAO_Notify_EventType_List subscription_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_UpdateListener_List* subscription_change_listeners_;
  // 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* publication_change_listeners_;
  // This is a list of listeners that want to be notified if the publications
  // from suppliers changes the <publication_list_>.

  TAO_Notify_EMO_Factory* emo_factory_;
  // Evenet Manager Objects factory.

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

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

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

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