summaryrefslogtreecommitdiff
path: root/TAO/tao/EndpointPolicy/EndpointPolicy_Factory.cpp
blob: 11c4a887519361cea2a3e3f78328b261e15e44b9 (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
// @(#) $Id$
#include "tao/EndpointPolicy/EndpointPolicy_Factory.h"

ACE_RCSID (EndpointPolicy,
           EndpointPolicy_Factory,
           "$Id$")

#include "tao/EndpointPolicy/EndpointPolicy_i.h"
#include "tao/EndpointPolicy/EndpointPolicyA.h"
#include "tao/EndpointPolicy/Endpoint_Value_Impl.h"

#include "tao/PolicyC.h"
#include "tao/ORB_Constants.h"
#include "tao/ORB_Core.h"
#include "tao/Acceptor_Registry.h"
#include "tao/AnyTypeCode/TAOA.h"
#include "tao/AnyTypeCode/Any.h"
#include "tao/Thread_Lane_Resources.h"
#include "tao/Transport_Acceptor.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL


TAO_EndpointPolicy_Factory::TAO_EndpointPolicy_Factory (TAO_ORB_Core * orb_core)
: orb_core_ (orb_core)
{
}


CORBA::Policy_ptr
TAO_EndpointPolicy_Factory::create_policy (
    CORBA::PolicyType type,
    const CORBA::Any &value
    ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException,
                   CORBA::PolicyError))
{
  if (type == EndpointPolicy::ENDPOINT_POLICY_TYPE)
  {
    const EndpointPolicy::EndpointList* endpoint_list;
    if ((value >>= endpoint_list) == 0)
      ACE_THROW_RETURN (CORBA::PolicyError (CORBA::BAD_POLICY_VALUE),
      CORBA::Policy::_nil ());

    TAO_Acceptor_Registry & registry
      = this->orb_core_->lane_resources ().acceptor_registry ();

    TAO_Acceptor ** acceptors_begin = registry.begin ();
    TAO_Acceptor ** acceptors_end = registry.end ();
    CORBA::ULong num_eps = endpoint_list->length ();

    // The endpoint list in the value is validated to ensure that
    // at least one endpoint in the list matches an endpoint the
    // ORB is listening on.

    bool found_one = true;
    for (CORBA::ULong idx = 0; !found_one && idx < num_eps; ++idx)
    {
      CORBA::ULong prot_tag = (*endpoint_list)[idx]->protocol_tag();

      const TAO_Endpoint_Value_Impl *evi =
        dynamic_cast <const TAO_Endpoint_Value_Impl*> ((*endpoint_list)[idx]);

      for (TAO_Acceptor** acceptor = acceptors_begin;
           !found_one && acceptor != acceptors_end;
           ++acceptor)
        {
          if ((*acceptor)->tag() == prot_tag)
            found_one = evi->validate_acceptor(*acceptor);
        }
    }
    // There is no endpoint policy value matches an endpoint the ORB
    // is listening on. A CORBA::PolicyError exception with a
    // PolicyErrorCode of UNSUPPORTED_POLICY_VALUE is raised.
    if (!found_one)
      ACE_THROW_RETURN (CORBA::PolicyError (CORBA::UNSUPPORTED_POLICY_VALUE),
                        CORBA::Policy::_nil ());

    TAO_EndpointPolicy_i *tmp;
    ACE_NEW_THROW_EX (tmp,
      TAO_EndpointPolicy_i (*endpoint_list),
      CORBA::NO_MEMORY (TAO::VMCID,
      CORBA::COMPLETED_NO));
    ACE_CHECK_RETURN (CORBA::Policy::_nil ());

    return tmp;
  }
  else
    ACE_THROW_RETURN (CORBA::PolicyError (CORBA::BAD_POLICY_TYPE),
                      CORBA::Policy::_nil ());
}


TAO_END_VERSIONED_NAMESPACE_DECL