summaryrefslogtreecommitdiff
path: root/TAO/tao/GIOP_Message_Generator_Parser.cpp
blob: fc431c2436b94499713a53bb4e318c182f992e87 (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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#include "tao/GIOP_Message_Generator_Parser.h"
#include "tao/Pluggable_Messaging_Utils.h"
#include "tao/GIOP_Utils.h"
#include "tao/CDR.h"
#include "tao/Object_KeyC.h"
#include "tao/IOPC.h"
#include "tao/Tagged_Profile.h"
#include "tao/debug.h"

#if !defined (__ACE_INLINE__)
# include "tao/GIOP_Message_Generator_Parser.inl"
#endif /* __ACE_INLINE__ */

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


int
TAO_GIOP_Message_Generator_Parser::parse_reply (
    TAO_InputCDR &stream,
    TAO_Pluggable_Reply_Params &params)
{

  // Read the request id
  if (!stream.read_ulong (params.request_id_))
    {
      if (TAO_debug_level > 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("TAO (%P|%t) : TAO_GIOP_Message_Generator_Parser::parse_reply, \n ")
                           ACE_TEXT ("extracting request id")),
                          -1);
    }

  // and the reply status type.  status can be NO_EXCEPTION,
  // SYSTEM_EXCEPTION, USER_EXCEPTION, LOCATION_FORWARD

  // Cannot handle LOCATION_FORWARD_PERM here
  CORBA::ULong rep_stat = 0;
  if (!stream.read_ulong (rep_stat))
    {
      if (TAO_debug_level > 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("TAO (%P|%t) : TAO_GIOP_Message_Generator_Parser::parse_reply, \n ")
                           ACE_TEXT ("extracting reply status")),
                          -1);
      return -1;
    }


  // Pass the right Pluggable interface code to the transport layer
  switch (rep_stat)
    {
      // Request completed successfully
    case TAO_GIOP_NO_EXCEPTION:
      params.reply_status_ =
        TAO_PLUGGABLE_MESSAGE_NO_EXCEPTION;
      break;

      // Request terminated with user exception
    case TAO_GIOP_USER_EXCEPTION:
      params.reply_status_ =
        TAO_PLUGGABLE_MESSAGE_USER_EXCEPTION;
      break;
      // Request terminated with system exception
    case TAO_GIOP_SYSTEM_EXCEPTION:
      params.reply_status_ =
        TAO_PLUGGABLE_MESSAGE_SYSTEM_EXCEPTION;
      break;
      // Reply is a location forward type
    case TAO_GIOP_LOCATION_FORWARD:
      params.reply_status_ =
        TAO_PLUGGABLE_MESSAGE_LOCATION_FORWARD;
      break;
      // Reply is a location forward perm type
      // @@For the time being the behaviour of the
      // LOCATION_FORWARD_PERM would be similar to the
      // LOCATION_FORWARD as there is a controversy surrounding the
      // usage of this in the OMG.
    case TAO_GIOP_LOCATION_FORWARD_PERM:
      params.reply_status_ =
        TAO_PLUGGABLE_MESSAGE_LOCATION_FORWARD;
      break;
      // Reply is a location forward type
    case TAO_GIOP_NEEDS_ADDRESSING_MODE:
      params.reply_status_ =
        TAO_PLUGGABLE_MESSAGE_NEEDS_ADDRESSING_MODE;
      break;
    default:
      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("(%N|%l) Unknown reply status \n")));
    }

  return 0;
}


int
TAO_GIOP_Message_Generator_Parser::parse_locate_reply (
    TAO_InputCDR &cdr,
    TAO_Pluggable_Reply_Params &params)
{
  // Read the request id
  if (!cdr.read_ulong (params.request_id_))
    {
      if (TAO_debug_level > 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("TAO (%P|%t|%N|%l):parse_locate_reply, ")
                           ACE_TEXT ("extracting request id \n")),
                          -1);
    }

  // and the reply status type.  status can be NO_EXCEPTION,
  // SYSTEM_EXCEPTION, USER_EXCEPTION, LOCATION_FORWARD

  // Cannot handle LOCATION_FORWARD_PERM here

  // Please note here that we are NOT converting to the Pluggable
  // messaging layer exception as this is GIOP specific. Not many
  // messaging protocols have the locate_* messages.
  if (!cdr.read_ulong (params.reply_status_))
    {
      if (TAO_debug_level > 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("TAO N|(%P|%t|l) parse_locate_reply, ")
                           ACE_TEXT ("extracting reply  status\n")),
                          -1);
    }

  return 0;

}


int
TAO_GIOP_Message_Generator_Parser::is_ready_for_bidirectional (void)
{
  return 0;
}

void
TAO_GIOP_Message_Generator_Parser::marshal_reply_status (
    TAO_OutputCDR &output,
    TAO_Pluggable_Reply_Params &reply
  )
{
  switch (reply.reply_status_)
    {
    case TAO_PLUGGABLE_MESSAGE_NO_EXCEPTION:
      output.write_ulong (TAO_GIOP_NO_EXCEPTION);
      break;
    case TAO_PLUGGABLE_MESSAGE_LOCATION_FORWARD:
      output.write_ulong (TAO_GIOP_LOCATION_FORWARD);
      break;
    case TAO_PLUGGABLE_MESSAGE_SYSTEM_EXCEPTION:
      output.write_ulong (TAO_GIOP_SYSTEM_EXCEPTION);
      break;
    case TAO_PLUGGABLE_MESSAGE_USER_EXCEPTION:
      output.write_ulong (TAO_GIOP_USER_EXCEPTION);
      break;
    default:
      // Some other specific exception
      output.write_ulong (reply.reply_status_);
      break;
    }
}

CORBA::Boolean
TAO_GIOP_Message_Generator_Parser::unmarshall_object_key (
    TAO_ObjectKey &object_key,
    TAO_InputCDR &input)
{
  CORBA::Boolean hdr_status =
    (CORBA::Boolean) input.good_bit ();

  CORBA::Long key_length = 0;
  hdr_status = hdr_status && input.read_long (key_length);

  if (hdr_status)
    {
      object_key.replace (key_length,
                          key_length,
                          (CORBA::Octet*)input.rd_ptr (),
                          0);
      input.skip_bytes (key_length);
    }

  return hdr_status;
}


CORBA::Boolean
TAO_GIOP_Message_Generator_Parser::unmarshall_iop_profile (
    TAO_Tagged_Profile &profile_addr,
    TAO_InputCDR &input)
{
  CORBA::Boolean hdr_status =
    (CORBA::Boolean) input.good_bit ();

  // Get the IOP::Tagged profile.
  IOP::TaggedProfile &tagged_profile =
    profile_addr.tagged_profile ();

  hdr_status &= input >> tagged_profile;

  // Extract the object key from the TaggedProfile.
  hdr_status &=profile_addr.extract_object_key (tagged_profile);

  return hdr_status;
}

CORBA::Boolean
TAO_GIOP_Message_Generator_Parser::unmarshall_ref_addr (
    TAO_Tagged_Profile &profile_addr,
    TAO_InputCDR &input
  )
{
  CORBA::Boolean hdr_status =
    (CORBA::Boolean) input.good_bit ();

  /*
   * The GIOP::IORAddressingInfo is defined as follows
   *   struct IORAddressingInfo
   *     {
   *       unsigned long selected_profile_index;
   *       IOP::IOR ior;
   *     };
   *
   * and the IOP::IOR is defined to be
   *   struct IOR
   *      {
   *        string type_id;
   *        sequence<TaggedProfile>   profiles;
   *      };
   */

  // First read the profile index
  CORBA::ULong prof_index =  0;

  hdr_status =
    hdr_status && input.read_ulong (prof_index);

  // Set the value in TAO_Tagged_Profile
  if (hdr_status)
    profile_addr.profile_index (prof_index);

  // Get the length of the type_id
  CORBA::Long id_length = 0;
  hdr_status = hdr_status && input.read_long (id_length);

  if (hdr_status)
    {
      // Get the type_id
      ACE_CString &type_id =
        profile_addr.type_id ();

      type_id.set (input.rd_ptr (),
                   0);

      input.skip_bytes (id_length);
    }

  // Unmarshall the sequnce of TaggedProfiles
  IOP::IOR::_tao_seq_TaggedProfile ior_profiles;

  hdr_status &= input >> ior_profiles;

  // Get the IOP::Tagged profile.
  IOP::TaggedProfile &tagged_profile =
    profile_addr.tagged_profile ();

  // Get the right TaggedProfile from the <ior_profiles>
  if (hdr_status)
    {
      tagged_profile =
        ior_profiles [prof_index];
    }

  // Extract the object key from the TaggedProfile.
  hdr_status &=
    profile_addr.extract_object_key (tagged_profile);

  return hdr_status;
}