summaryrefslogtreecommitdiff
path: root/TAO/tao/Reply_Dispatcher.cpp
blob: b9d4f42e1acf1def7573040f46612611a83d4cd6 (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
// $Id$

#include "tao/Reply_Dispatcher.h"
#include "tao/debug.h"

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

// Constructor.
TAO_Reply_Dispatcher::TAO_Reply_Dispatcher (void)
{
}

// Destructor.
TAO_Reply_Dispatcher::~TAO_Reply_Dispatcher (void)
{
}

TAO_GIOP_Message_State *
TAO_Reply_Dispatcher::message_state (void) const
{
  return 0;
}

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

// Constructor.
TAO_Synch_Reply_Dispatcher::TAO_Synch_Reply_Dispatcher (TAO_GIOP_Message_State* message_state)
  : message_state_ (message_state)
{
}

// Destructor.
TAO_Synch_Reply_Dispatcher::~TAO_Synch_Reply_Dispatcher (void)
{
}

// Dispatch the reply.
int
TAO_Synch_Reply_Dispatcher::dispatch_reply (CORBA::ULong reply_status,
                                            const TAO_GIOP_Version &version,
                                            TAO_GIOP_ServiceContextList &reply_ctx,
                                            TAO_GIOP_Message_State *message_state)
{
  ACE_ASSERT (message_state == this->message_state_);
  // @@ Notice that the message is ignored because we assume that
  //    the message_state is the same we are giving down to the ORB to
  //    use.... I.E. this class cannot be used with Muxed stream, but
  //    chances are that the way to implement that will change several
  //    times in the next few weeks.
  this->reply_status_ = reply_status;
  this->version_ = version;

  // Steal the buffer, that way we don't do any unnecesary copies of
  // this data.
  CORBA::ULong max = reply_ctx.maximum ();
  CORBA::ULong len = reply_ctx.length ();
  TAO_GIOP_ServiceContext* context_list = reply_ctx.get_buffer (1);
  this->reply_ctx_.replace (max, len, context_list, 1);

  return 0;
}

TAO_GIOP_Message_State *
TAO_Synch_Reply_Dispatcher::message_state (void) const
{
  return this->message_state_;
}

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

// Constructor.
TAO_Asynch_Reply_Dispatcher::TAO_Asynch_Reply_Dispatcher (TAO_GIOP_Message_State *message_state,
                                                          const TAO_Reply_Handler_Skeleton &reply_handler_skel,
                                                          Messaging::ReplyHandler_ptr reply_handler_ptr)
  : message_state_ (message_state),
    reply_handler_skel_ (reply_handler_skel),
    reply_handler_ (reply_handler_ptr)
{
}

// Destructor.
TAO_Asynch_Reply_Dispatcher::~TAO_Asynch_Reply_Dispatcher (void)
{
  delete message_state_;
  message_state_ = 0;
}

// Dispatch the reply.
int
TAO_Asynch_Reply_Dispatcher::dispatch_reply (CORBA::ULong reply_status,
                                             const TAO_GIOP_Version &version,
                                             TAO_GIOP_ServiceContextList &reply_ctx,
                                             TAO_GIOP_Message_State *message_state)
{
  ACE_ASSERT (message_state == this->message_state_);
  // @@ Notice that the message is ignored because we assume that
  //    the message_state is the same we are giving down to the ORB to
  //    use.... I.E. this class cannot be used with Muxed stream, but
  //    chances are that the way to implement that will change several
  //    times in the next few weeks.
  this->reply_status_ = reply_status;
  this->version_ = version;

  // Steal the buffer, that way we don't do any unnecesary copies of
  // this data.
  CORBA::ULong max = reply_ctx.maximum ();
  CORBA::ULong len = reply_ctx.length ();
  TAO_GIOP_ServiceContext* context_list = reply_ctx.get_buffer (1);
  this->reply_ctx_.replace (max, len, context_list, 1);

  if (TAO_debug_level > 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "%N:%l:TAO_Asynch_Reply_Dispatcher::dispatch_reply:\n"));
    }
  
  ACE_DECLARE_NEW_CORBA_ENV;
  
  // Call the Reply Handler's skeleton.
  reply_handler_skel_ (message_state_->cdr,
                       reply_handler_,
                       ACE_TRY_ENV);
                                  
  return 0;
}

TAO_GIOP_Message_State *
TAO_Asynch_Reply_Dispatcher::message_state (void) const
{
  return this->message_state_;
}