summaryrefslogtreecommitdiff
path: root/TAO/tao/Remote_Object_Proxy_Impl.cpp
blob: 9953a9b6210fc24796e3a6bf640b501b90b3ccf3 (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 "tao/Remote_Object_Proxy_Impl.h"
#include "tao/Exception.h"
#include "tao/Any.h"
#include "tao/Stub.h"
#include "tao/Invocation.h"
#include "tao/IFR_Client_Adapter.h"

#include "ace/Dynamic_Service.h"

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

TAO_Remote_Object_Proxy_Impl::TAO_Remote_Object_Proxy_Impl (void)
{
  // No-Op
}


TAO_Remote_Object_Proxy_Impl::~TAO_Remote_Object_Proxy_Impl (void)
{
  // No-Op
}

CORBA::Boolean
TAO_Remote_Object_Proxy_Impl::_is_a (const CORBA::Object_ptr target,
                                     const CORBA::Char *logical_type_id,
                                     CORBA_Environment &ACE_TRY_ENV)
{
  // Here we go remote to answer the question.
  CORBA::Boolean _tao_retval = 0;

  TAO_Stub *istub = target->_stubobj ();
  if (istub == 0)
    ACE_THROW_RETURN (CORBA::INTERNAL (
                        CORBA_SystemException::_tao_minor_code (
                          TAO_DEFAULT_MINOR_CODE,
                          EINVAL),
                        CORBA::COMPLETED_NO),
                      _tao_retval);

  TAO_GIOP_Twoway_Invocation _tao_call (istub,
                                        "_is_a",
                                        5,
                                        1,
                                        istub->orb_core ());

  // Loop until we succeed or we raise an exception.
  // @@ Nanbor: Do we still need to clear the environment variable?
  //  ACE_TRY_ENV.clear ();
  for (;;)
    {
      _tao_call.start (ACE_TRY_ENV);
      ACE_CHECK_RETURN (_tao_retval);

      CORBA::Short flag = TAO_TWOWAY_RESPONSE_FLAG;

      _tao_call.prepare_header (ACE_static_cast (CORBA::Octet, flag),
                                ACE_TRY_ENV);
      ACE_CHECK_RETURN (_tao_retval);

      TAO_OutputCDR &_tao_out = _tao_call.out_stream ();
      if (!(
            (_tao_out << logical_type_id)
            ))
        ACE_THROW_RETURN (CORBA::MARSHAL (), _tao_retval);

      int _invoke_status =
        _tao_call.invoke (0, 0, ACE_TRY_ENV);
      ACE_CHECK_RETURN (_tao_retval);

      if (_invoke_status == TAO_INVOKE_RESTART)
        continue;
      // if (_invoke_status == TAO_INVOKE_EXCEPTION)
      // cannot happen
      if (_invoke_status != TAO_INVOKE_OK)
        {
          ACE_THROW_RETURN (CORBA::UNKNOWN (TAO_DEFAULT_MINOR_CODE,
                                            CORBA::COMPLETED_YES),
                            _tao_retval);

        }
      break;
    }
  TAO_InputCDR &_tao_in = _tao_call.inp_stream ();
  if (!(_tao_in >> CORBA::Any::to_boolean (_tao_retval)))
    ACE_THROW_RETURN (CORBA::MARSHAL (TAO_DEFAULT_MINOR_CODE,
                                      CORBA::COMPLETED_YES),
                      _tao_retval);
  return _tao_retval;

}

#if (TAO_HAS_MINIMUM_CORBA == 0)

CORBA::Boolean 
TAO_Remote_Object_Proxy_Impl::_non_existent (const CORBA::Object_ptr target,
                                             CORBA_Environment &ACE_TRY_ENV)
{
  CORBA::Boolean _tao_retval = 0;

  ACE_TRY
    {
      // Must catch exceptions, if the server raises a
      // CORBA::OBJECT_NOT_EXIST then we must return 1, instead of
      // propagating the exception.
      TAO_Stub *istub = target->_stubobj ();
      if (istub == 0)
        ACE_THROW_RETURN (CORBA::INTERNAL (
                            CORBA_SystemException::_tao_minor_code (
                              TAO_DEFAULT_MINOR_CODE,
                              EINVAL),
                            CORBA::COMPLETED_NO),
                          _tao_retval);

      TAO_GIOP_Twoway_Invocation _tao_call (istub,
                                            "_non_existent",
                                            13,
                                            1,
                                            istub->orb_core ());

      // ACE_TRY_ENV.clear ();
      for (;;)
        {
          _tao_call.start (ACE_TRY_ENV);
          ACE_TRY_CHECK;

          CORBA::Short flag = TAO_TWOWAY_RESPONSE_FLAG;

          _tao_call.prepare_header (ACE_static_cast (CORBA::Octet, flag),
                                    ACE_TRY_ENV);
          ACE_TRY_CHECK;

          int _invoke_status =
            _tao_call.invoke (0, 0, ACE_TRY_ENV);
          ACE_TRY_CHECK;

          if (_invoke_status == TAO_INVOKE_RESTART)
            continue;
          ACE_ASSERT (_invoke_status != TAO_INVOKE_EXCEPTION);
          if (_invoke_status != TAO_INVOKE_OK)
            {
              ACE_THROW_RETURN (CORBA::UNKNOWN (TAO_DEFAULT_MINOR_CODE,
                                                CORBA::COMPLETED_YES),
                                _tao_retval);
            }
          break;
        }
      TAO_InputCDR &_tao_in = _tao_call.inp_stream ();
      if (!(
            (_tao_in >> CORBA::Any::to_boolean (_tao_retval))
            ))
        ACE_THROW_RETURN (CORBA::MARSHAL (), _tao_retval);
    }
  ACE_CATCH (CORBA::OBJECT_NOT_EXIST, ex)
    {
      _tao_retval = 1;
    }
  ACE_CATCHANY
    {
      ACE_RE_THROW;
    }
  ACE_ENDTRY;
  return _tao_retval;
}

CORBA_InterfaceDef_ptr
TAO_Remote_Object_Proxy_Impl::_get_interface (const CORBA::Object_ptr target,
                                              CORBA_Environment &ACE_TRY_ENV)
{
  TAO_IFR_Client_Adapter *adapter =
    ACE_Dynamic_Service<TAO_IFR_Client_Adapter>::instance (
        TAO_ORB_Core::ifr_client_adapter_name ()
      );

  if (adapter == 0)
    {
      ACE_THROW_RETURN (CORBA::INTF_REPOS (),
                        0);
    }

  return adapter->get_interface_remote (target,
                                        ACE_TRY_ENV);
}

#endif /* TAO_HAS_MINIMUM_CORBA == 0 */