summaryrefslogtreecommitdiff
path: root/TAO/tao/GIOP_Message_Connectors.cpp
blob: c4d6a4d9f1f54d830f27aed12744d4964ed0ab54 (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
//$Id$
#include "tao/GIOP_Message_Connectors.h"
#include "tao/Any.h"
#include "tao/debug.h"
#include "tao/Principal.h"
#include "tao/TAOC.h"

#if !defined (__ACE_INLINE__)
# include "tao/GIOP_Message_Connectors.i"
#endif /* __ACE_INLINE__ */

CORBA::Boolean
TAO_GIOP_Message_Connectors::
  write_request_header (const IOP::ServiceContextList& /*svc_ctx*/,
                        CORBA::ULong request_id,
                        CORBA::Octet response_flags,
                        TAO_Target_Specification & /*spec*/,
                        const char * /*opname*/,
                        TAO_OutputCDR &msg)
{
  // Adding only stuff that are common to all versions of GIOP.
  // @@ Note: If at any stage we feel that this amount of granularity
  // for factorisation is not important we can dispense with it
  // anyway.

  // First the request id
  msg << request_id;

  // Second the response flags
  // Sync scope - ignored by server if request is not oneway.
  if (response_flags == CORBA::Octet (TAO::SYNC_WITH_TRANSPORT) ||
      response_flags == CORBA::Octet (TAO::SYNC_NONE) ||
      response_flags == CORBA::Octet (TAO::SYNC_EAGER_BUFFERING) ||
      response_flags == CORBA::Octet (TAO::SYNC_DELAYED_BUFFERING))
    // No response required.
    msg << CORBA::Any::from_octet (0);
  
  else if (response_flags == CORBA::Octet (TAO::SYNC_WITH_SERVER))
    // Return before dispatching servant.  We're also setting the high
    // bit here. This is a temporary fix until the rest of GIOP 1.2 is
    // implemented in TAO.
    msg << CORBA::Any::from_octet (129);
  
  else if (response_flags == CORBA::Octet (TAO::SYNC_WITH_TARGET))
    // Return after dispatching servant.
    msg << CORBA::Any::from_octet (3);

  else
    // Until more flags are defined by the OMG.
    return 0;

  return 1;
}

int
TAO_GIOP_Message_Connectors::
  parse_reply (TAO_Message_State_Factory &mesg_state,
               TAO_Pluggable_Connector_Params &params,
               CORBA::ULong &reply_status)
{
  
    // Cast to the GIOP Message state
  TAO_GIOP_Message_State *state = ACE_dynamic_cast (TAO_GIOP_Message_State *,
                                                    &mesg_state);

  // Read the request id
  if (!state->cdr.read_ulong (params.request_id))
    {
      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG,
                    "TAO (%P|%t|%N|%l) : TAO_GIOP_Message_1_1::parse_reply, "
                    "extracting request id"));
      return -1;
    }

  // and the reply status type.  status can be NO_EXCEPTION,
  // SYSTEM_EXCEPTION, USER_EXCEPTION, LOCATION_FORWARD
  // CAnnot handle LOCATION_FORWARD_PERM here
  if (!state->cdr.read_ulong (reply_status))
    {
      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG,
                    "TAO (%P|%t|%N|%l) : TAO_GIOP_Message_1_1::parse_reply, "
                    "extracting reply status\n"));
      return -1;
    }

  return 0;
}


int
TAO_GIOP_Message_Connectors::validate_version (TAO_GIOP_Message_State *state)
  
{
  // Grab the read pointer
  char *buf = state->cdr.rd_ptr ();

  if ((buf[this->major_version_offset ()] != this->major_version ()) ||
       (buf[this->minor_version_offset ()] != this->minor_version ()))
    return -1;
  
  state->giop_version.major = buf[this->major_version_offset ()];
  state->giop_version.minor = buf[this->minor_version_offset ()];
  
  return 0;
}

int
TAO_GIOP_Message_Connectors::
process_connector_messages (TAO_Transport * /*transport*/, 
                            TAO_ORB_Core * /*orb_core*/,
                            TAO_InputCDR & /*input*/,
                            CORBA::Octet /*message_type*/)
{
   ACE_NOTSUP_RETURN (-1);
}


///////////////////////////////////////////////////////////////////
// Methods for TAO_GIOP_Message_Connector_11
//////////////////////////////////////////////////////////////////

CORBA::Boolean
TAO_GIOP_Message_Connector_11::
  write_request_header (const IOP::ServiceContextList& svc_ctx, 
                        CORBA::ULong request_id,
                        CORBA::Octet response_flags,
                        TAO_Target_Specification &spec,
                        const char *opname,
                        TAO_OutputCDR &msg)
{
  // This is sepecific to GIOP 1.1. So put them here
  msg << svc_ctx;

  // Let us  call our parent class to check what he can do for
  // us.
  TAO_GIOP_Message_Connectors::write_request_header (svc_ctx,
                                                     request_id,
                                                     response_flags,
                                                     spec,
                                                     opname,
                                                     msg);

  // In this case we cannot recognise anything other than the Object
  // key as the address disposition variable. But we do a sanity check
  // anyway.
  const TAO_ObjectKey *key = spec.object_key ();
  if (key)
    {
      // Put in the object key
      msg << *key;
    }
  else
    {
      if (TAO_debug_level)
        ACE_DEBUG ((LM_DEBUG,
                    ASYS_TEXT ("(%N |%l) Unable to handle this request \n")));
      return 0;
    }

  msg << opname;

  // The principal is not used. So send a null pointer
  static CORBA::Principal_ptr principal = 0;
  msg << principal;


  return 1;

}




CORBA::Boolean
TAO_GIOP_Message_Connector_11::
  write_locate_request_header (CORBA::ULong request_id,
                               TAO_Target_Specification &spec,
                               TAO_OutputCDR &msg)
{
  msg << request_id;

  // In this case we cannot recognise anything other than the Object
  // key as the address disposition variable. But we do a sanity check
  // anyway.
  const TAO_ObjectKey *key = spec.object_key ();
  if (key)
    {
      // Everything is fine
      msg << *key;
    }
  else
    {
      if (TAO_debug_level)
        ACE_DEBUG ((LM_DEBUG,
                    ASYS_TEXT ("(%N | %l) Unable to handle this request \n")));
      return 0;
    }
 
  return 1;
}


int
TAO_GIOP_Message_Connector_11::
  parse_reply (TAO_Message_State_Factory &mesg_state,
               TAO_Pluggable_Connector_Params &params,
               CORBA::ULong &reply_status)
{
  // Cast to the GIOP Message state
  TAO_GIOP_Message_State *state = ACE_dynamic_cast (TAO_GIOP_Message_State *,
                                                    &mesg_state);

  switch (state->message_type)
    {
    case TAO_GIOP_REQUEST:
      // In GIOP 1.0 and GIOP 1.1 this is an error,
      ACE_ERROR_RETURN ((LM_ERROR,
                         "TAO (%P|%t) %N:%l TAO_GIOP_Message_1_1::parse_reply: "
                         "request.\n"),
                        -1);

    case TAO_GIOP_CANCELREQUEST:
    case TAO_GIOP_LOCATEREQUEST:
      // Errors
    case TAO_GIOP_CLOSECONNECTION:
      default:
        ACE_ERROR_RETURN ((LM_ERROR,
                           ASYS_TEXT ("TAO (%P|%t) %N:%l parse_reply: ") 
                           ASYS_TEXT ("wrong message.\n")),
                          -1);
        break;
    case TAO_GIOP_LOCATEREPLY:
      // Handle after the switch
      break;
    case TAO_GIOP_REPLY:
      if ((state->cdr >> params.svc_ctx) == 0)
        {
          if (TAO_debug_level > 0)
            ACE_DEBUG ((LM_DEBUG,
                        ASYS_TEXT ("TAO (%P|%t) parse_reply, ")
                        ASYS_TEXT ("extracting context\n")));
          return -1;
        }
      // Rest of the stuff after the switch
      break;
    case TAO_GIOP_FRAGMENT:
      // Never happens: why??
      break;
    }
  
  if (TAO_GIOP_Message_Connectors::parse_reply (*state,
                                                params,
                                                reply_status) == -1)
    return -1;

  return 0;
}