summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Notify/Notify_Event_Manager.cpp
blob: e0d1a48bcbe3b984ebdba3b413694609750090ed (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
// $Id$

#include "orbsvcs/ESF/ESF_Proxy_Collection.h"
#include "Notify_Event_Manager.h"
#include "Notify_Factory.h"
#include "Notify_Worker_Task.h"
#include "Notify_Event_Manager_Objects_Factory.h"
#include "Notify_Update_Dispatch_Command.h"
#include "Notify_AdminProperties.h"

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

ACE_RCSID(Notify, Notify_Event_Manager, "$Id$")

TAO_Notify_Event_Manager::TAO_Notify_Event_Manager (TAO_Notify_EventChannel_i* event_channel, TAO_Notify_EMO_Factory* emo_factory)
  :event_channel_ (event_channel),
   event_map_ (0),
   event_processor_ (0),
   updates_dispatching_task_ (0),
   emo_factory_ (emo_factory),
   admin_properties_ (0)
{
}

TAO_Notify_Event_Manager::~TAO_Notify_Event_Manager ()
{
  delete this->event_map_;
  delete this->event_processor_;
  delete this->lock_;
  delete this->admin_properties_;

  emo_factory_->destroy_updates_task (this->updates_dispatching_task_);
}

void
TAO_Notify_Event_Manager::init (TAO_ENV_SINGLE_ARG_DECL)
{
  ACE_NEW_THROW_EX (this->lock_,
                    ACE_Lock_Adapter<TAO_SYNCH_MUTEX> (),
                    CORBA::NO_MEMORY ());

  // Create members.

  this->admin_properties_ = new TAO_Notify_AdminProperties ();

  this->event_map_ =
    this->emo_factory_->create_event_map (TAO_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  this->event_processor_ =
    this->emo_factory_->create_event_processor (this TAO_ENV_ARG_PARAMETER);
  ACE_CHECK;

  this->updates_dispatching_task_ =
    this->emo_factory_->create_updates_task (TAO_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  // Init the objects
  this->event_map_->init (TAO_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  this->event_processor_->init (TAO_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  // @@ check return value
  this->updates_dispatching_task_->init_task (this->admin_properties_);
  // The updates task doesn't really use admin properties but this makes it future proof.
}

void
TAO_Notify_Event_Manager::shutdown (TAO_ENV_SINGLE_ARG_DECL)
{
  ACE_GUARD_THROW_EX (ACE_Lock, ace_mon, *this->lock_,
                      CORBA::INTERNAL ());
  ACE_CHECK;

  this->event_processor_->shutdown (TAO_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  this->event_map_->shutdown (TAO_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  this->updates_dispatching_task_->shutdown (TAO_ENV_SINGLE_ARG_PARAMETER);
}

void
TAO_Notify_Event_Manager::subscribe_for_events (TAO_Notify_EventListener* event_listener, const CosNotification::EventTypeSeq & added, const CosNotification::EventTypeSeq & removed TAO_ENV_ARG_DECL)
{
  TAO_Notify_EventType_List added_update, removed_update;

  this->event_map_->subscribe_for_events (event_listener, added_update,
                                         added TAO_ENV_ARG_PARAMETER);
  ACE_CHECK;

  this->event_map_->unsubscribe_from_events (event_listener, removed_update,
                                              removed TAO_ENV_ARG_PARAMETER);
  ACE_CHECK;

  // if either of the lists are *not* empty, send updates
  if (added_update.is_empty () == 0 || removed_update.is_empty () == 0)
    this->dispatch_updates_i (this->event_map_->subscription_change_listeners (),
                              added_update, removed_update TAO_ENV_ARG_PARAMETER);
}

void
TAO_Notify_Event_Manager::update_publication_list (const CosNotification::EventTypeSeq & added, const CosNotification::EventTypeSeq & removed TAO_ENV_ARG_DECL)
{
  TAO_Notify_EventType_List added_list;
  TAO_Notify_EventType_List removed_list;

  this->event_map_->update_publication_list (added, removed,
                                            added_list, removed_list TAO_ENV_ARG_PARAMETER);
  ACE_CHECK;

  // if either of the lists are *not* empty, send updates
  if (added_list.is_empty () == 0 || removed_list.is_empty () == 0)
    this->dispatch_updates_i (this->event_map_->publication_change_listeners (),
                              added_list, removed_list TAO_ENV_ARG_PARAMETER);
}

void
TAO_Notify_Event_Manager::dispatch_updates_i (TAO_Notify_UpdateListener_List* update_listener_list, TAO_Notify_EventType_List& added, TAO_Notify_EventType_List& removed TAO_ENV_ARG_DECL)
{
  ACE_GUARD_THROW_EX (ACE_Lock, ace_mon, *this->lock_,
                      CORBA::INTERNAL ());

  TAO_Notify_Update_Worker update_worker (this->updates_dispatching_task_,
                                          added, removed);

  update_listener_list->for_each (&update_worker TAO_ENV_ARG_PARAMETER);
}

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

TAO_Notify_Update_Worker::TAO_Notify_Update_Worker (TAO_Notify_Worker_Task * updates_dispatching_task, TAO_Notify_EventType_List& added, TAO_Notify_EventType_List& removed)
  : added_ (added),
    removed_ (removed),
    updates_dispatching_task_ (updates_dispatching_task)
{
}

void
TAO_Notify_Update_Worker::work (TAO_Notify_UpdateListener* listener TAO_ENV_ARG_DECL)
{
  TAO_Notify_Update_Dispatch_Command* mb =
    new TAO_Notify_Update_Dispatch_Command (listener, this->added_,
                                            this->removed_);

  this->updates_dispatching_task_->process_event (mb TAO_ENV_ARG_PARAMETER);
}

/********************************************************************/
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)

template class ACE_Hash_Map_Entry<TAO_Notify_EventType, TAO_Notify_EventListener_List *>;
template class ACE_Hash_Map_Manager<TAO_Notify_EventType, TAO_Notify_EventListener_List *,TAO_SYNCH_MUTEX>;
template class ACE_Hash_Map_Manager_Ex<TAO_Notify_EventType, TAO_Notify_EventListener_List *,ACE_Hash<TAO_Notify_EventType>, ACE_Equal_To<TAO_Notify_EventType>,TAO_SYNCH_MUTEX>;
template class ACE_Hash_Map_Iterator<TAO_Notify_EventType, TAO_Notify_EventListener_List *,TAO_SYNCH_MUTEX>;
template class ACE_Hash_Map_Iterator_Ex<TAO_Notify_EventType, TAO_Notify_EventListener_List *,ACE_Hash<TAO_Notify_EventType>, ACE_Equal_To<TAO_Notify_EventType>,TAO_SYNCH_MUTEX>;
template class ACE_Hash_Map_Iterator_Base_Ex<TAO_Notify_EventType, TAO_Notify_EventListener_List *,ACE_Hash<TAO_Notify_EventType>, ACE_Equal_To<TAO_Notify_EventType>,TAO_SYNCH_MUTEX>;
template class ACE_Hash_Map_Reverse_Iterator<TAO_Notify_EventType, TAO_Notify_EventListener_List *,TAO_SYNCH_MUTEX>;
template class ACE_Hash_Map_Reverse_Iterator_Ex<TAO_Notify_EventType, TAO_Notify_EventListener_List *,ACE_Hash<TAO_Notify_EventType>, ACE_Equal_To<TAO_Notify_EventType>,TAO_SYNCH_MUTEX>;
template class ACE_Hash<TAO_Notify_EventType>;
template class ACE_Equal_To<TAO_Notify_EventType>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)

#pragma instantiate ACE_Hash_Map_Entry<TAO_Notify_EventType, TAO_Notify_EventListener_List *>
#pragma instantiate ACE_Hash_Map_Manager<TAO_Notify_EventType, TAO_Notify_EventListener_List *,TAO_SYNCH_MUTEX>
#pragma instantiate ACE_Hash_Map_Manager_Ex<TAO_Notify_EventType, TAO_Notify_EventListener_List *,ACE_Hash<TAO_Notify_EventType>, ACE_Equal_To<TAO_Notify_EventType>,TAO_SYNCH_MUTEX>
#pragma instantiate ACE_Hash_Map_Iterator<TAO_Notify_EventType, TAO_Notify_EventListener_List *,TAO_SYNCH_MUTEX>
#pragma instantiate ACE_Hash_Map_Iterator_Ex<TAO_Notify_EventType, TAO_Notify_EventListener_List *,ACE_Hash<TAO_Notify_EventType>, ACE_Equal_To<TAO_Notify_EventType>,TAO_SYNCH_MUTEX>
#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<TAO_Notify_EventType, TAO_Notify_EventListener_List *,ACE_Hash<TAO_Notify_EventType>, ACE_Equal_To<TAO_Notify_EventType>,TAO_SYNCH_MUTEX>
#pragma instantiate ACE_Hash_Map_Reverse_Iterator<TAO_Notify_EventType, TAO_Notify_EventListener_List *,TAO_SYNCH_MUTEX>
#pragma instantiate ACE_Hash_Map_Reverse_Iterator_Ex<TAO_Notify_EventType, TAO_Notify_EventListener_List *,ACE_Hash<TAO_Notify_EventType>, ACE_Equal_To<TAO_Notify_EventType>,TAO_SYNCH_MUTEX>
#pragma instantiate template ACE_Hash<TAO_Notify_EventType>
#pragma instantiate template ACE_Equal_To<TAO_Notify_EventType>
#endif /*ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */