summaryrefslogtreecommitdiff
path: root/TAO/tao/RT_ORBInitializer.cpp
blob: e27cedbbe9b103f539e5f3cfc65818cc6cd571a7 (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
// -*- C++ -*-
//
// $Id$

#include "tao/RT_ORBInitializer.h"

ACE_RCSID (TAO,
           RT_ORBInitializer,
           "$Id$")

#if TAO_HAS_RT_CORBA == 1


#include "tao/RTCORBAC.h"
#include "tao/RT_Policy_i.h"
#include "tao/RT_Protocols_Hooks.h"
#include "tao/Priority_Mapping_Manager.h"
#include "tao/Exception.h"
#include "tao/ORB_Core.h"
#include "tao/RT_ORB_Loader.h"

#include "ace/Service_Repository.h"
#include "ace/Svc_Conf.h"

static void
add_static_service (const ACE_Static_Svc_Descriptor &desc)
{
  const ACE_Service_Type *service_type;
  if (ACE_Service_Repository::instance ()->find (desc.name_,
                                                 &service_type,
                                                 0) >= 0)
    {
      // The service is already there, just return
      return;
    }
                                    
  ACE_Service_Object_Exterminator gobbler;
  void *sym = (*desc.alloc_)(&gobbler);

  ACE_Service_Type_Impl *service_type_impl =
    ace_create_service_type (desc.name_,
                             desc.type_,
                             sym,
                             desc.flags_,
                             gobbler);

  // @@ Raise exception
  ACE_NEW (service_type,
           ACE_Service_Type (desc.name_,
                             service_type_impl,
                             0,
                             desc.active_));
  // @@ Error checking
  (void) ACE_Service_Repository::instance ()->insert (service_type);
}

void
TAO_RT_ORBInitializer::pre_init (
    PortableInterceptor::ORBInitInfo_ptr info
    TAO_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  TAO_ENV_ARG_DEFN;

  add_static_service (ace_svc_desc_TAO_RT_Protocols_Hooks);
  add_static_service (ace_svc_desc_TAO_RT_ORB_Loader);

  // Sets the name of the Protocol_Hooks to be the RT_Protocols_Hooks.
  TAO_ORB_Core::set_protocols_hooks ("RT_Protocols_Hooks");

  // Set the Priority_Mapping_Manager
  TAO_Priority_Mapping_Manager *manager = 0;

  ACE_NEW_THROW_EX (manager,
                    TAO_Priority_Mapping_Manager,
                    CORBA::NO_MEMORY (
                      CORBA::SystemException::_tao_minor_code (
                        TAO_DEFAULT_MINOR_CODE,
                        ENOMEM),
                      CORBA::COMPLETED_NO));
  ACE_CHECK;

  TAO_Priority_Mapping_Manager_var safe_manager = manager;

  info->register_initial_reference ("PriorityMappingManager",
                                    manager,
                                    ACE_TRY_ENV);
  ACE_CHECK;

  // Sets the client_protocol policy.
  TAO_RT_Protocols_Hooks::set_client_protocols_hook
    (TAO_ClientProtocolPolicy::hook);

  // Sets the server_protocol policy.
  TAO_RT_Protocols_Hooks::set_server_protocols_hook
    (TAO_ServerProtocolPolicy::hook);
}

void
TAO_RT_ORBInitializer::post_init (
    PortableInterceptor::ORBInitInfo_ptr info
    TAO_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  TAO_ENV_ARG_DEFN;

  this->register_policy_factories (info,
                                   ACE_TRY_ENV);
  ACE_CHECK;
}

void
TAO_RT_ORBInitializer::register_policy_factories (
  PortableInterceptor::ORBInitInfo_ptr info,
  CORBA::Environment &ACE_TRY_ENV)
{
  // Register the RTCORBA policy factories.

  // The RTCORBA policy factory is stateless and reentrant, so share a
  // single instance between all ORBs.
  PortableInterceptor::PolicyFactory_ptr policy_factory =
    &(this->policy_factory_);

  // Bind the same policy factory to all RTCORBA related policy
  // types since a single policy factory is used to create each of
  // the different types of RTCORBA policies.

  CORBA::PolicyType type = RTCORBA::PRIORITY_MODEL_POLICY_TYPE;
  info->register_policy_factory (type,
                                 policy_factory,
                                 ACE_TRY_ENV);
  ACE_CHECK;

  type = RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE;
  info->register_policy_factory (type,
                                 policy_factory,
                                 ACE_TRY_ENV);
  ACE_CHECK;

  type = RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE;
  info->register_policy_factory (type,
                                 policy_factory,
                                 ACE_TRY_ENV);
  ACE_CHECK;
}

#endif  /* TAO_HAS_RT_CORBA == 1 */