summaryrefslogtreecommitdiff
path: root/TAO/tao/RTCORBA/RT_Endpoint_Selector_Factory.cpp
blob: a87cff52a16a498c1bd635a228eb63d258355ec5 (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
// $Id$

#include "RT_Endpoint_Selector_Factory.h"
#include "RT_Invocation_Endpoint_Selectors.h"
#include "tao/Invocation.h"
#include "RT_Endpoint_Utils.h"
#include "RT_Stub.h"

ACE_RCSID(tao, RT_Endpoint_Selector_Factory, "$Id$")

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

RT_Endpoint_Selector_Factory::RT_Endpoint_Selector_Factory (void)
{
  ACE_NEW (this->priority_endpoint_selector_,
           TAO_Priority_Endpoint_Selector);

  ACE_NEW (this->bands_endpoint_selector_,
           TAO_Bands_Endpoint_Selector);

  ACE_NEW (this->protocol_endpoint_selector_,
           TAO_Protocol_Endpoint_Selector);

  ACE_NEW (this->priority_protocol_selector_,
           TAO_Priority_Protocol_Selector);

  ACE_NEW (this->bands_protocol_selector_,
           TAO_Bands_Protocol_Selector);

  ACE_NEW (this->default_endpoint_selector_,
           TAO_Default_Endpoint_Selector);
}

RT_Endpoint_Selector_Factory::~RT_Endpoint_Selector_Factory (void)
{
  delete this->priority_endpoint_selector_;
  delete this->bands_endpoint_selector_;
  delete this->protocol_endpoint_selector_;
  delete this->priority_protocol_selector_;
  delete this->bands_protocol_selector_;
  delete this->default_endpoint_selector_;
}

TAO_Invocation_Endpoint_Selector *
RT_Endpoint_Selector_Factory::get_selector (TAO_GIOP_Invocation *invocation,
                                             CORBA::Environment &ACE_TRY_ENV)
{
  // Initialize selection state with all RTCORBA policies affecting
  // endpoint selection.

  TAO_RT_Stub *rt_stub =
    ACE_dynamic_cast (TAO_RT_Stub *, invocation->stub ());

  if (rt_stub == 0)
    {
      ACE_DEBUG ((LM_DEBUG, "Unexpected error narrowing stub to TAO_RT_Stub"));

      ACE_THROW_RETURN (CORBA::INTERNAL (
                           CORBA_SystemException::_tao_minor_code (
                                                                   TAO_DEFAULT_MINOR_CODE,
                                                                   EINVAL),
                           CORBA::COMPLETED_NO),
                        0);
    }

  CORBA::Policy_var priority_model_policy =
    rt_stub->exposed_priority_model (ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

  //  state.private_connection_ =
  //   rt_stub->private_connection ();

  CORBA::Policy_var client_protocol_policy =
    TAO_RT_Endpoint_Utils::client_protocol_policy (invocation, ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

  CORBA::Policy_var bands_policy = TAO_RT_Endpoint_Utils::priority_bands_policy (invocation, ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

  //
  // Look at RTCORBA policies to decide on appropriate selector.
  //

  // CASE 2: No PriorityModelPolicy set.
  if (priority_model_policy.ptr () == 0)
    {
     // Bands without priority model do not make sense.
      if (bands_policy.ptr () != 0)
        {
          if (invocation->inconsistent_policies ().ptr ())
            {
              invocation->inconsistent_policies ()->length (1);
              invocation->inconsistent_policies ()[0u] =
                CORBA::Policy::_duplicate (bands_policy.in ());
            }
          ACE_THROW_RETURN (CORBA::INV_POLICY (), 0);
        }

      if (client_protocol_policy.ptr () == 0)
        return this->default_endpoint_selector_;
      else
        return this->protocol_endpoint_selector_;
    }

  // @@ This is to be used in case 3:
  CORBA::Short server_priority = 0;
  CORBA::Boolean is_client_propagated = 0;

  TAO_Protocols_Hooks *tph = invocation->orb_core ()->get_protocols_hooks (ACE_TRY_ENV);
  ACE_CHECK_RETURN (0);

  tph->get_selector_hook (priority_model_policy.in (),
                          is_client_propagated,
                          server_priority);

  // CASE 3: PriorityBandedConnection Policy is set.
  if (bands_policy.ptr () != 0)
    {
      // Matching band found.  Instantiate appropriate selector.
      if (client_protocol_policy.ptr () == 0)
        return this->bands_endpoint_selector_;
      else
        return this->bands_protocol_selector_;
    }

  // CASE 4: CLIENT_PROPAGATED priority model, no bands.
  if (is_client_propagated)
    {
      if (client_protocol_policy.ptr () == 0)
        return this->priority_endpoint_selector_;
      else
        return this->priority_protocol_selector_;
    }
  else
    {
      // CASE 5: SERVER_DECLARED priority model, no bands.
      if (client_protocol_policy.ptr () == 0)
        return this->default_endpoint_selector_;
      else
        return this->protocol_endpoint_selector_;
    }
}


void
RT_Endpoint_Selector_Factory::
init_client_protocol (TAO_GIOP_Invocation *,
                      CORBA::Environment &)
{
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("RT_Endpoint_Selector_Factory:init_client_protocol - Is deprecated!")));
  /*
  TAO_RT_Stub *rt_stub =
    ACE_dynamic_cast (TAO_RT_Stub *, invocation->stub_);

  ACE_TRY
    {
      invocation->endpoint_selection_state_.client_protocol_policy_ =
        rt_stub->effective_client_protocol (ACE_TRY_ENV);
      ACE_TRY_CHECK;
    }
  ACE_CATCH (CORBA::INV_POLICY, ex)
    {
      if (invocation->inconsistent_policies_.ptr ())
        {
          invocation->inconsistent_policies_->length (1);
          invocation->inconsistent_policies_[0u] =
            rt_stub->client_protocol ();
        }
      ACE_RE_THROW;
    }
  ACE_ENDTRY;
  ACE_CHECK;

  */
}

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

ACE_STATIC_SVC_DEFINE (RT_Endpoint_Selector_Factory,
                       ACE_TEXT ("RT_Endpoint_Selector_Factory"),
                       ACE_SVC_OBJ_T,
                       &ACE_SVC_NAME (RT_Endpoint_Selector_Factory),
                       ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
                       0)
ACE_FACTORY_DEFINE (TAO_RTCORBA, RT_Endpoint_Selector_Factory)