summaryrefslogtreecommitdiff
path: root/trunk/TAO/tests/Portable_Interceptors/Processing_Mode_Policy/Collocated/Echo_Collocated_ORBInitializer.cpp
blob: b9773fde351988145910c6aee1c712874cd464ca (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
// -*- C++ -*-
//
// $Id$

#include "Echo_Collocated_ORBInitializer.h"
#include "interceptors.h"
#include "tao/PI/ORBInitInfo.h"
#include "tao/ORB_Core.h"
#include "ace/OS_NS_string.h"

Echo_Collocated_ORBInitializer::Echo_Collocated_ORBInitializer (
    PortableInterceptor::ProcessingMode server_proc_mode,
    PortableInterceptor::ProcessingMode client_proc_mode)
  : server_processing_mode_(server_proc_mode),
    client_processing_mode_(client_proc_mode)
{
}

void
Echo_Collocated_ORBInitializer::pre_init (
    PortableInterceptor::ORBInitInfo_ptr
    ACE_ENV_ARG_DECL_NOT_USED)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
}

void
Echo_Collocated_ORBInitializer::post_init (
    PortableInterceptor::ORBInitInfo_ptr info
    ACE_ENV_ARG_DECL)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  CORBA::String_var orb_id =
    info->orb_id (ACE_ENV_SINGLE_ARG_PARAMETER);
  ACE_CHECK;

  // TAO-Specific way to get to the ORB Core (and thus, the ORB).
  TAO_ORBInitInfo_var tao_info =
    TAO_ORBInitInfo::_narrow (info
                              ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  CORBA::ORB_var orb = CORBA::ORB::_duplicate(tao_info->orb_core()->orb());

  if (CORBA::is_nil(orb.in()))
    {
      ACE_THROW (CORBA::INTERNAL ());
      ACE_CHECK;
    }

  PortableInterceptor::ORBInitInfo_3_1_var info_3_1 =
    PortableInterceptor::ORBInitInfo_3_1::_narrow(info
                                                  ACE_ENV_ARG_PARAMETER);
  ACE_CHECK;

  if (CORBA::is_nil(info_3_1.in()))
    {
      ACE_THROW (CORBA::INTERNAL ());
      ACE_CHECK;
    }

  if (!ACE_OS::strcmp (orb_id.in (), "client_orb"))
    {
      PortableInterceptor::ClientRequestInterceptor_ptr interceptor =
        PortableInterceptor::ClientRequestInterceptor::_nil ();

      // Install the Echo client request interceptor
      ACE_NEW_THROW_EX (interceptor,
                        Echo_Client_Request_Interceptor,
                        CORBA::NO_MEMORY ());
      ACE_CHECK;

      PortableInterceptor::ClientRequestInterceptor_var
        client_interceptor = interceptor;

      CORBA::Any client_proc_mode_as_any;
      client_proc_mode_as_any <<= this->client_processing_mode_;

      CORBA::PolicyList policy_list (1);

      policy_list.length (1);
      policy_list[0] =
        orb->create_policy (PortableInterceptor::PROCESSING_MODE_POLICY_TYPE,
                            client_proc_mode_as_any
                            ACE_ENV_ARG_PARAMETER);
      ACE_CHECK;

      info_3_1->add_client_request_interceptor_with_policy (
                                        client_interceptor.in (),
                                        policy_list
                                        ACE_ENV_ARG_PARAMETER);
      ACE_CHECK;

      policy_list[0]->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_CHECK;
      policy_list[0] = CORBA::Policy::_nil ();
    }
  else if (!ACE_OS::strcmp (orb_id.in (), "server_orb"))
    {
      PortableInterceptor::ServerRequestInterceptor_ptr interceptor =
        PortableInterceptor::ServerRequestInterceptor::_nil ();

      // Install the Echo server request interceptor
      ACE_NEW_THROW_EX (interceptor,
                        Echo_Server_Request_Interceptor,
                        CORBA::NO_MEMORY ());
      ACE_CHECK;

      PortableInterceptor::ServerRequestInterceptor_var
        server_interceptor = interceptor;

      CORBA::Any server_proc_mode_as_any;
      server_proc_mode_as_any <<= this->server_processing_mode_;

      CORBA::PolicyList policy_list (1);

      policy_list.length (1);
      policy_list[0] =
        orb->create_policy (PortableInterceptor::PROCESSING_MODE_POLICY_TYPE,
                            server_proc_mode_as_any
                            ACE_ENV_ARG_PARAMETER);
      ACE_CHECK;

      info_3_1->add_server_request_interceptor_with_policy (
                                            server_interceptor.in (),
                                            policy_list
                                            ACE_ENV_ARG_PARAMETER);
      ACE_CHECK;

      policy_list[0]->destroy (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_CHECK;
      policy_list[0] = CORBA::Policy::_nil ();
    }
  else
  {
  }
}