summaryrefslogtreecommitdiff
path: root/TAO/tao/Pluggable.cpp
blob: 287f1d678b8de613ecdfea6d796090db6691f9d8 (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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
// This may look like C, but it's really -*- C++ -*-
// $Id$

#include "tao/Pluggable.h"
#include "tao/Stub.h"
#include "tao/Environment.h"
#include "tao/GIOP.h"
#include "tao/ORB_Core.h"
#include "tao/Client_Strategy_Factory.h"
#include "tao/Wait_Strategy.h"
#include "tao/Request_Mux_Strategy.h"
#include "tao/Reply_Dispatcher.h"

// Constructor.
TAO_Transport::TAO_Transport (TAO_ORB_Core *orb_core)
  : message_size_ (0),
    message_offset_ (0),
    message_received_ (0),
    rms_ (0),
    ws_ (0),
    orb_core_ (0)
{
  orb_core_ = orb_core;

  // Create WS now.
  this->ws_ = orb_core->client_factory ()->create_wait_strategy (this);

  // Create RMS now.
  this->rms_ = orb_core->client_factory ()->create_request_mux_strategy ();
}

TAO_Transport::~TAO_Transport (void)
{
  delete ws_;
  ws_ = 0;
  delete rms_;
  rms_ =0;
}

// @@ Alex: this stream stuff belongs to the RMS, right?
//    Maybe the right interface is:
//    TAO_Transport::bind_reply_dispatcher (request_id,
//                                          reply_dispatcher,
//                                          input_cdr);

// Set the CDR stream for reading the input message.
void
TAO_Transport::input_cdr_stream (TAO_InputCDR *cdr)
{
  this->rms_->set_cdr_stream (cdr);
}

// @@ Do you need an accessor? Or is the CDR stream simply passed by
//    the RMS to the right target.  We should go to the RMS and obtain
//    the CDR stream from it, that way we can implement an optimized
//    version of the RMS that uses a single CDR stream allocated from
//    the stack.

// Get the CDR stream for reading the input message.
TAO_InputCDR *
TAO_Transport::input_cdr_stream (void) const
{
  return this->rms_->get_cdr_stream ();
}

void
TAO_Transport::destroy_cdr_stream (TAO_InputCDR *cdr) const
{
  this->rms_->destroy_cdr_stream (cdr);
}

// Set the total size of the incoming message. (This does not
// include the header size).
void
TAO_Transport::message_size (CORBA::ULong message_size)
{
  this->message_size_ = message_size;

  // Reset the offset.
  this->message_offset_ = 0;
}

// Get the total size of the incoming message.
CORBA::ULong
TAO_Transport::message_size (void) const
{
  return this->message_size_;
}

// Get the current offset of the incoming message.
CORBA::ULong
TAO_Transport::message_offset (void) const
{
  return this->message_offset_;
}

// Update the offset of the incoming message.
int
TAO_Transport::incr_message_offset (CORBA::Long bytes_transferred)
{
  if ((this->message_offset_ + bytes_transferred) > this->message_size_)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "TAO: %N:%l: (%P | %t): TAO_Transport::incr_message_offset: "
                       "Failed to update the offset of incoming message\n"),
                      -1);

  this->message_offset_ +=  bytes_transferred;

  return 0;
}

// Set the flag to indicate whether the input message was read fully
// or no.
void
TAO_Transport::message_received (int received)
{
  this->message_received_ = received;
}

// Get the flag.
int
TAO_Transport::message_received (void) const
{
  return this->message_received_;
}

// Get it.
TAO_ORB_Core *
TAO_Transport::orb_core (void) const
{
  return this->orb_core_;
}

TAO_Request_Mux_Strategy *
TAO_Transport::rms (void) const
{
  return rms_;
}

// Return the Wait strategy used by the Transport.
TAO_Wait_Strategy *
TAO_Transport::wait_strategy (void) const
{
  return this->ws_;
}

// Get request id for the current invocation from the RMS object.
CORBA::ULong
TAO_Transport::request_id (void)
{
  return this->rms ()->request_id ();
}

// Bind the reply dispatcher with the RMS object.
int
TAO_Transport::bind_reply_dispatcher (CORBA::ULong request_id,
                                      TAO_Reply_Dispatcher *rd)
{
  return this->rms_->bind_dispatcher (request_id,
                                      rd);
}

// Read and handle the reply. Returns 0 when there is Short Read on
// the connection. Returns 1 when the full reply is read and
// handled. Returns -1 on errors.
// If <block> is 1, then reply is read in a blocking manner.

// @@ Should this be an pure virtual method? (Alex)
int
TAO_Transport::handle_client_input (int /* block */)
{
  ACE_NOTSUP_RETURN (-1);
}

// @@ Should this be an pure virtual method? (Alex)
int
TAO_Transport::register_handler (void)
{
  ACE_NOTSUP_RETURN (-1);
}

int
TAO_Transport::suspend_handler (void)
{
  ACE_NOTSUP_RETURN (-1);
}

int
TAO_Transport::resume_handler (void)
{
  ACE_NOTSUP_RETURN (-1);
}

int
TAO_Transport::handle_close (void)
{
  ACE_NOTSUP_RETURN (-1);
}

int
TAO_Transport::wait_for_reply (void)
{
  return this->ws_->wait ();
}

// *********************************************************************

TAO_Connector_Registry::TAO_Connector_Registry (void)
  : iiop_connector_ (0)
{
}

TAO_Connector_Registry::~TAO_Connector_Registry (void)
{
}

TAO_Connector *
TAO_Connector_Registry::get_connector (CORBA::ULong tag)
{
  // For now, only IIOP connectors.
  if (tag != TAO_IOP_TAG_INTERNET_IOP)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Invalid connector tag %d\n",
                       tag),
                      0);
  else
    return iiop_connector_;
}

CORBA::Boolean
TAO_Connector_Registry::add_connector (TAO_Connector *connector)
{
  if (connector->tag() == TAO_IOP_TAG_INTERNET_IOP)
    {
      // do not copy, but save the reference (i.e. pointer)
      this->iiop_connector_ = connector;
      return 1;
    }
  else
    ACE_ERROR_RETURN ((LM_ERROR,
                       "Invalid connector tag %d\n",
                       connector->tag ()),
                      0);
}

int
TAO_Connector_Registry::open(TAO_Resource_Factory *trf, ACE_Reactor *reactor)
{
  // @@ Once again since we only accept 1 iiop connector, this is easy
  if (iiop_connector_)
    return this->iiop_connector_->open (trf, reactor);
  else
    return 0;
}

int
TAO_Connector_Registry::close_all()
{
  // @@ Loop through all registered connectors ... not too hard
  //    since there is only one!
  if (iiop_connector_)
    return this->iiop_connector_->close ();
  else
    return 0;
}

int
TAO_Connector_Registry::preconnect (const char *the_preconnections)
{
  // It would be good to use auto_ptr<> to guard against premature
  // termination and, thus, leaks.
  int result=0;
  char *preconnections = ACE_OS::strdup (the_preconnections);

  // @@ OK, what we should do is parse the string so that we can
  // gather @@ together addresses of the same protocol together and
  // pass to the @@ appropriate connector.  But, for now we ASSUME
  // they are all @@ INET IP:Port!! HACK. fredk

  if (this->iiop_connector_)
    result = this->iiop_connector_->preconnect (preconnections);

  ACE_OS::free (preconnections);

  return result;
}

int
TAO_Connector_Registry::connect (TAO_Stub *&obj,
                                 TAO_Transport *&transport)
{
  CORBA::ULong req_tag = TAO_IOP_TAG_INTERNET_IOP;
  TAO_Profile *profile = obj->profile_in_use ();

  // @@ And the profile selection policy is .... ONLY IIOP, and the
  // @@ first one found!
  if (profile->tag () != req_tag)
    return -1;

  // here is where we get the appropriate connector object but we are
  // the Connector Registry so call get_connector(tag)

  TAO_Connector *connector =
    this->get_connector (req_tag);

  return connector->connect (profile, transport);
}

TAO_IOP_Version::~TAO_IOP_Version (void)
{
}

TAO_IOP_Version::TAO_IOP_Version (const TAO_IOP_Version &src)
  : major (src.major),
    minor (src.minor)
{
}

TAO_IOP_Version::TAO_IOP_Version (CORBA::Octet maj, CORBA::Octet min)
  : major (maj),
    minor (min)
{
}

void
TAO_IOP_Version::set_version (CORBA::Octet maj, CORBA::Octet min)
{
  this->major = maj;
  this->minor = min;
}

int
TAO_IOP_Version::operator== (const TAO_IOP_Version *&src)
{
  return this->major == src->major && this->minor == src->minor;
}

int
TAO_IOP_Version::operator== (const TAO_IOP_Version &src)
{
  return this->major == src.major && this->minor == src.minor;
}

TAO_IOP_Version &
TAO_IOP_Version::operator= (const TAO_IOP_Version &src)
{
  this->major = src.major;
  this->minor = src.minor;
  return *this;
}

TAO_Profile::~TAO_Profile (void)
{
}

TAO_Connector::~TAO_Connector (void)
{
}

TAO_Acceptor::~TAO_Acceptor (void)
{
}