summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Notify/Method_Request_Lookup.cpp
blob: 14c22d871cc57ecebe61121ed99d4dffe902bf8e (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
244
245
246
247
// $Id$

#include "Method_Request_Lookup.h"

#if ! defined (__ACE_INLINE__)
#include "Method_Request_Lookup.inl"
#endif /* __ACE_INLINE__ */

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

#include "tao/debug.h"
#include "Consumer_Map.h"
#include "ProxySupplier.h"
#include "ProxyConsumer.h"
#include "Proxy.h"
#include "Admin.h"
#include "SupplierAdmin.h"
#include "Event_Manager.h"
#include "Method_Request_Dispatch.h"
#include "Delivery_Request.h"
#include "EventChannelFactory.h"

TAO_Notify_Method_Request_Lookup::TAO_Notify_Method_Request_Lookup (
      const TAO_Notify_Event * event,
      TAO_Notify_ProxyConsumer * proxy)
  : TAO_Notify_Method_Request_Event (event)
  , proxy_consumer_ (proxy)
{
}

TAO_Notify_Method_Request_Lookup::~TAO_Notify_Method_Request_Lookup ()
{
}

void
TAO_Notify_Method_Request_Lookup::work (
  TAO_Notify_ProxySupplier* proxy_supplier
  ACE_ENV_ARG_DECL)
{
  if (delivery_request_.get () == 0)
  {
    TAO_Notify_Method_Request_Dispatch_No_Copy request (*this, proxy_supplier, true);
    proxy_supplier->deliver (request ACE_ENV_ARG_PARAMETER);
  }
  else
  {
    delivery_request_->dispatch (proxy_supplier, true ACE_ENV_ARG_PARAMETER);
    ACE_CHECK;
  }
}

TAO_Notify_Method_Request_Lookup::execute_i (ACE_ENV_SINGLE_ARG_DECL)
{
  if (this->proxy_consumer_->has_shutdown ())
    return 0; // If we were shutdown while waiting in the queue, return with no action.

  TAO_Notify_SupplierAdmin* parent = this->proxy_consumer_->supplier_admin ();

  CORBA::Boolean val =  this->proxy_consumer_->check_filters (this->event_,
                                                             parent->filter_admin (),
                                                             parent->filter_operator ()
                                                             ACE_ENV_ARG_PARAMETER);

  if (TAO_debug_level > 1)
    ACE_DEBUG ((LM_DEBUG, "Proxyconsumer %x filter eval result = %d",&this->proxy_consumer_ , val));

  // Filter failed - do nothing.
  if (val == 0)
    return 0;

  // The map of subscriptions.
  TAO_Notify_Consumer_Map* map = this->proxy_consumer_->event_manager ()->consumer_map ();

  TAO_Notify_Consumer_Map::ENTRY* entry = map->find (this->event_->type () ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (0);

  TAO_Notify_ProxySupplier_Collection* consumers = 0;

  if (entry != 0)
  {
    consumers = entry->collection ();

    if (consumers != 0)
      consumers->for_each (this ACE_ENV_ARG_PARAMETER);

    map->release (entry);
  }

  // Get the default consumers
  consumers = map->broadcast_collection ();

  if (consumers != 0)
    consumers->for_each (this ACE_ENV_ARG_PARAMETER);
  this->complete ();
  return 0;
}

/// Static method used to reconstruct a Method Request Dispatch
TAO_Notify_Method_Request_Lookup_Queueable *
TAO_Notify_Method_Request_Lookup::unmarshal (
  TAO_Notify::Delivery_Request_Ptr & delivery_request,
  TAO_Notify_EventChannelFactory &ecf,
  TAO_InputCDR & cdr
  ACE_ENV_ARG_DECL)
{
  bool ok = true;
  TAO_Notify_Method_Request_Lookup_Queueable * result = 0;
  CORBA::ULong count;
  if (cdr.read_ulong (count))
  {
    TAO_Notify::IdVec id_path (count);
    for (size_t nid = 0; ok && nid < count; ++nid)
    {
      TAO_Notify_Object::ID id = 0;
      if ( cdr.read_long (id))
      {
        id_path.push_back (id);
      }
      else
      {
        ok = false;
      }
    }

    if (ok)
    {
      TAO_Notify_ProxyConsumer * proxy_consumer = ecf.find_proxy_consumer (
        id_path,
        0 ACE_ENV_ARG_PARAMETER);
      ACE_CHECK_RETURN(0);
      if (proxy_consumer != 0)
      {
        ACE_NEW_NORETURN (result,
          TAO_Notify_Method_Request_Lookup_Queueable (delivery_request, proxy_consumer));
      }
      else
      {
        ACE_ERROR ((LM_ERROR,
          ACE_TEXT ("(%P|%t) TAO_Notify_Method_Request_Lookup_No_Copy::unmarshal: unknown proxy id\n")
          ));
      }
    }
    else
    {
      ACE_ERROR ((LM_ERROR,
        ACE_TEXT ("(%P|%t) TAO_Notify_Method_Request_Lookup_No_Copy::unmarshal: Cant read proxy id path\n")
        ));
    }
  }
  return result;

}


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

TAO_Notify_Method_Request_Lookup_Queueable::TAO_Notify_Method_Request_Lookup_Queueable (
      const TAO_Notify_Event_var& event,
      TAO_Notify_ProxyConsumer* proxy_consumer)
  : TAO_Notify_Method_Request_Queueable (event.get ())
  , TAO_Notify_Method_Request_Lookup (event.get (), proxy_consumer)
  , event_var_ (event)
  , proxy_guard_ (proxy_consumer)
{
}

TAO_Notify_Method_Request_Lookup_Queueable::TAO_Notify_Method_Request_Lookup_Queueable (
      TAO_Notify::Delivery_Request_Ptr & request,
      TAO_Notify_ProxyConsumer * proxy_consumer)
  : TAO_Notify_Method_Request_Queueable (request->event ().get ())
  , TAO_Notify_Method_Request_Lookup (request->event ().get (), proxy_consumer)
  , event_var_ (request->event ())
  , proxy_guard_ (proxy_consumer)
{
}


TAO_Notify_Method_Request_Lookup_Queueable::~TAO_Notify_Method_Request_Lookup_Queueable ()
{
}

int
TAO_Notify_Method_Request_Lookup_Queueable::execute (ACE_ENV_SINGLE_ARG_DECL)
{
  return this->execute_i (ACE_ENV_SINGLE_ARG_PARAMETER);
}

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

TAO_Notify_Method_Request_Lookup_No_Copy::TAO_Notify_Method_Request_Lookup_No_Copy (
        const TAO_Notify_Event* event,
        TAO_Notify_ProxyConsumer* proxy_consumer)
  : TAO_Notify_Method_Request_Lookup (event, proxy_consumer)
{
}

TAO_Notify_Method_Request_Lookup_No_Copy::~TAO_Notify_Method_Request_Lookup_No_Copy ()
{
}

int
TAO_Notify_Method_Request_Lookup_No_Copy::execute (ACE_ENV_SINGLE_ARG_DECL)
{
  return this->execute_i (ACE_ENV_SINGLE_ARG_PARAMETER);
}

TAO_Notify_Method_Request_Queueable*
TAO_Notify_Method_Request_Lookup_No_Copy::copy (ACE_ENV_SINGLE_ARG_DECL)
{
  TAO_Notify_Method_Request_Queueable* request;

  TAO_Notify_Event_var event_var;
  this->event_->queueable_copy (event_var ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (0);

  ACE_NEW_THROW_EX (request,
                    TAO_Notify_Method_Request_Lookup_Queueable (event_var, this->proxy_consumer_),
                    CORBA::INTERNAL ());

  return request;
}

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)

template class TAO_Notify_Method_Request_Lookup_T<const TAO_Notify_Event_var
, TAO_Notify_ProxyConsumer_Guard
, const TAO_Notify_Event_var&
, TAO_Notify_ProxyConsumer*>;

template class TAO_Notify_Method_Request_Lookup_T<const TAO_Notify_Event*
, TAO_Notify_ProxyConsumer*
, const TAO_Notify_Event*
, TAO_Notify_ProxyConsumer*>;

#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)

#pragma instantiate TAO_Notify_Method_Request_Lookup_T<const TAO_Notify_Event_var
, TAO_Notify_ProxyConsumer_Guard
, const TAO_Notify_Event_var&
, TAO_Notify_ProxyConsumer*>

#pragma instantiate TAO_Notify_Method_Request_Lookup_T<const TAO_Notify_Event*
, TAO_Notify_ProxyConsumer*
, const TAO_Notify_Event*
, TAO_Notify_ProxyConsumer*>

#endif /*ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */