summaryrefslogtreecommitdiff
path: root/TAO/tao/DynamicInterface/DII_Invocation.cpp
blob: abb404acba03737b2f50588dab95d2c4e4e48974 (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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// $Id$

#include "tao/AnyTypeCode/DynamicC.h"
#include "tao/AnyTypeCode/TypeCode.h"

#include "DII_Invocation.h"
#include "Unknown_User_Exception.h"
#include "DII_Arguments.h"
#include "ExceptionList.h"
#include "Request.h"
#include "DII_Reply_Dispatcher.h"

#include "tao/operation_details.h"
#include "tao/Invocation_Utils.h"
#include "tao/debug.h"
#include "tao/AnyTypeCode/Any_Unknown_IDL_Type.h"
#include "tao/Profile_Transport_Resolver.h"
#include "tao/ORB_Constants.h"

#include "ace/OS_NS_string.h"

#if TAO_HAS_INTERCEPTORS == 1
# include "tao/PI/RequestInfo_Util.h"
#endif

ACE_RCSID (DynamicInterface,
           DII_Invocation,
           "$Id$")

namespace TAO
{
  DII_Invocation::DII_Invocation (CORBA::Object_ptr otarget,
                                  Profile_Transport_Resolver &resolver,
                                  TAO_Operation_Details &detail,
                                  CORBA::ExceptionList *excp,
                                  CORBA::Request_ptr req,
                                  bool response_expected)
    : Synch_Twoway_Invocation (otarget,
                               resolver,
                               detail,
                               response_expected)
      , excp_list_ (excp)
      , host_ (req)
  {
  }

#if TAO_HAS_INTERCEPTORS == 1
  Dynamic::ParameterList *
  DII_Invocation::arguments (ACE_ENV_SINGLE_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException))
  {
    // Generate the argument list on demand.
    Dynamic::ParameterList *parameter_list =
      TAO_RequestInfo_Util::make_parameter_list (ACE_ENV_SINGLE_ARG_PARAMETER);
    ACE_CHECK_RETURN (0);

    Dynamic::ParameterList_var safe_parameter_list = parameter_list;

    TAO::Argument **args =
      this->details_.args ();

    if (this->details_.args_num () > 1)
      {
        // Take the second argument since the first is a return value.
        TAO::NVList_Argument *tmp_arg =
          dynamic_cast <TAO::NVList_Argument*> (args[1]);

        tmp_arg->interceptor_paramlist (parameter_list);
      }

    return safe_parameter_list._retn ();
  }
#endif /* TAO_HAS_INTERCEPTORS == 1 */

  Invocation_Status
  DII_Invocation::remote_invocation (ACE_Time_Value *max_wait_time
                                     ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::Exception))
  {
    return Synch_Twoway_Invocation::remote_twoway (max_wait_time
                                                   ACE_ENV_ARG_PARAMETER);
  }

  Invocation_Status
  DII_Invocation::handle_user_exception (TAO_InputCDR &cdr
                                         ACE_ENV_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::Exception))
  {
    Reply_Guard mon (this,
                     TAO_INVOKE_FAILURE);

    if (TAO_debug_level > 3)
      {
        ACE_DEBUG ((LM_DEBUG,
                    "TAO (%P|%t) - DII_Invocation::"
                    "handle_user_exception \n"));
      }

    // Match the exception interface repository id with the
    // exception in the exception list.
    // This is important to decode the exception.
    CORBA::String_var buf;

    TAO_InputCDR tmp_stream (cdr,
                             cdr.start ()->length (),
                             0);

    // Pull the exception ID out of the marshaling buffer.
    if (tmp_stream.read_string (buf.inout ()) == 0)
      {
        ACE_THROW_RETURN (CORBA::MARSHAL (TAO::VMCID,
                                          CORBA::COMPLETED_YES),
                          TAO_INVOKE_FAILURE);
      }

    for (CORBA::ULong i = 0;
         this->excp_list_ != 0 && i < this->excp_list_->count ();
         i++)
      {
          CORBA::TypeCode_var tc =
            this->excp_list_->item (i
                                    ACE_ENV_ARG_PARAMETER);
          ACE_CHECK_RETURN (TAO_INVOKE_FAILURE);

          const char *xid = tc->id (ACE_ENV_SINGLE_ARG_PARAMETER);
          ACE_CHECK_RETURN (TAO_INVOKE_FAILURE);

          if (ACE_OS::strcmp (buf.in (), xid) != 0)
            {
              continue;
            }

          CORBA::Any any;
          TAO::Unknown_IDL_Type *unk = 0;
          ACE_NEW_RETURN (unk,
                          TAO::Unknown_IDL_Type (
                              tc.in (),
                              cdr
                            ),
                          TAO_INVOKE_FAILURE);

          any.replace (unk);

          mon.set_status (TAO_INVOKE_USER_EXCEPTION);

          ACE_THROW_RETURN (CORBA::UnknownUserException (any),
                            TAO_INVOKE_USER_EXCEPTION);
        }

    // If we couldn't find the right exception, report it as
    // CORBA::UNKNOWN.

    // But first, save the user exception in case we
    // are being used in a TAO gateway.
    this->host_->raw_user_exception (cdr);


    mon.set_status (TAO_INVOKE_USER_EXCEPTION);

    // @@ It would seem that if the remote exception is a
    //    UserException we can assume that the request was
    //    completed.
    ACE_THROW_RETURN (CORBA::UNKNOWN (TAO::VMCID,
                                      CORBA::COMPLETED_YES),
                      TAO_INVOKE_USER_EXCEPTION);

  }


//***************************************************************************
  DII_Deferred_Invocation::DII_Deferred_Invocation (
      CORBA::Object_ptr otarget,
      Profile_Transport_Resolver &resolver,
      TAO_Operation_Details &detail,
      TAO_DII_Deferred_Reply_Dispatcher *rd,
      CORBA::Request_ptr req,
      bool response_expected)
    : Asynch_Remote_Invocation (otarget,
                                resolver,
                                detail,
                                rd,
                                response_expected)
      , host_ (req)
  {

  }

#if TAO_HAS_INTERCEPTORS == 1
  //@NOTE: Need to figure a way to share this code
  Dynamic::ParameterList *
  DII_Deferred_Invocation::arguments (ACE_ENV_SINGLE_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException))
  {
    // Generate the argument list on demand.
    Dynamic::ParameterList *parameter_list =
      TAO_RequestInfo_Util::make_parameter_list (ACE_ENV_SINGLE_ARG_PARAMETER);
    ACE_CHECK_RETURN (0);

    Dynamic::ParameterList_var safe_parameter_list = parameter_list;

    TAO::Argument **args =
      this->details_.args ();

    if (this->details_.args_num () > 1)
      {
        // Take the second argument since the first is a return value.
        TAO::NVList_Argument *tmp_arg =
          dynamic_cast <TAO::NVList_Argument*> (args[1]);

        tmp_arg->interceptor_paramlist (parameter_list);
      }

    return safe_parameter_list._retn ();
  }
#endif /* TAO_HAS_INTERCEPTORS == 1*/

  Invocation_Status
  DII_Deferred_Invocation::remote_invocation (
      ACE_Time_Value *max_wait_time
      ACE_ENV_ARG_DECL
    )
    ACE_THROW_SPEC ((CORBA::Exception))
  {
    this->safe_rd_->transport (this->resolver_.transport ());

    return Asynch_Remote_Invocation::remote_invocation (
        max_wait_time
        ACE_ENV_ARG_PARAMETER);
  }
}