summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/HTIOP/HTIOP_Completion_Handler.cpp
blob: ca5eb903363325492221c7e218756ccc98544af5 (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
// $Id$

#include "HTIOP_Completion_Handler.h"

#include "HTIOP_Transport.h"
#include "HTIOP_Endpoint.h"

#include "ace/HTBP/HTBP_Stream.h"
#include "ace/HTBP/HTBP_Session.h"

#include "tao/Timeprobe.h"
#include "tao/debug.h"
#include "tao/ORB_Core.h"
#include "tao/Server_Strategy_Factory.h"
#include "tao/Transport_Cache_Manager.h"
#include "tao/Thread_Lane_Resources.h"
#include "tao/Acceptor_Impl.h"

ACE_RCSID (HTIOP,
           TAO_HTIOP_Completion_Handler,
           "$Id$")


TAO::HTIOP::Completion_Handler::Completion_Handler (ACE_Thread_Manager *t)
  : COMPLETION_BASE(t,0,0),
    orb_core_ (0),
    channel_(0),
    concurrency_strategy_ (0)
{
  // This constructor should *never* get called, it is just here to
  // make the compiler happy: the default implementation of the
  // Creation_Strategy requires a constructor with that signature, we
  // don't use that implementation, but some (most?) compilers
  // instantiate it anyway.
  ACE_ASSERT (this->orb_core_ != 0);
}

TAO::HTIOP::Completion_Handler::Completion_Handler (TAO_ORB_Core *orb_core,
                                                    CORBA::Boolean )
  :  COMPLETION_BASE(orb_core->thr_mgr(),0,0),
     orb_core_ (orb_core),
     channel_(0),
     concurrency_strategy_ (0)
{
}


TAO::HTIOP::Completion_Handler::~Completion_Handler (void)
{
}

int
TAO::HTIOP::Completion_Handler::open (void*)
{
  this->orb_core_->reactor()->register_handler(this,
                                               ACE_Event_Handler::READ_MASK);

  ACE_NEW_RETURN (concurrency_strategy_,
                  TAO::HTIOP::CONCURRENCY_STRATEGY2 (this->orb_core_),
                  -1);
  return 0;
}

int
TAO::HTIOP::Completion_Handler::resume_handler (void)
{
  return ACE_Event_Handler::ACE_APPLICATION_RESUMES_HANDLER;
}

int
TAO::HTIOP::Completion_Handler::handle_input (ACE_HANDLE h)
{
      // Create a service handler, using the appropriate creation
      // strategy.
  if (this->channel_ == 0)
    ACE_NEW_RETURN (this->channel_,
                    ACE::HTBP::Channel (h),
                    -1);

  if (this->channel_->pre_recv() != 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "TAO::HTIOP::Completion_Handler: pre_recv not done, "
                       "channel state = %d\n",
                       this->channel_->state()),
                      0);

  this->reactor()->remove_handler (this,
                                   ACE_Event_Handler::READ_MASK |
                                   ACE_Event_Handler::DONT_CALL);

  this->channel_->register_notifier(this->reactor());

  // look up session related to the channel.
  // Do we already have a handler for it?
  // If so, get the connection handler, otherwise create it new.

  ACE::HTBP::Session *session = this->channel_->session();
  ACE_Event_Handler *handler = session->handler();

  if (handler == 0)
    {
      TAO::HTIOP::Connection_Handler *svc_handler = 0;
      if (this->make_svc_handler (svc_handler) == -1)
        {
          if (TAO_debug_level > 0)
            ACE_DEBUG ((LM_DEBUG,
                        ACE_LIB_TEXT ("TAO::HTIOP::Completion_Handler %p\n"),
                        ACE_LIB_TEXT ("make_svc_handler")));
          return -1;
        }

      svc_handler->peer().session(session);
      session->handler (svc_handler);

      svc_handler->transport()->register_handler();
      svc_handler->open(0);
#if 0
      // *** I am not yet sure how to reconsile the notification strategy
      // with TPC concurrency.

  // Activate the <svc_handler> using the designated concurrency
  // strategy (note that this method becomes responsible for
  // handling errors and freeing up the memory if things go
  // awry...).
      if (this->concurrency_strategy_->
          activate_svc_handler (svc_handler,this->arg_) == -1)
        {
      // Note that <activate_svc_handler> closes the <svc_handler>
      // on failure.

          if (TAO_debug_level > 0)
            ACE_DEBUG ((LM_DEBUG,
                        ACE_LIB_TEXT ("%p\n"),
                        ACE_LIB_TEXT ("activate_svc_handler")));
          return -1;
        }
#endif /* 0 */
    }

  if (this->channel_->state() == ACE::HTBP::Channel::Data_Queued)
    {
      this->reactor()->notify (session->handler(),
                               ACE_Event_Handler::READ_MASK);
    }
  return 0;
}

int
TAO::HTIOP::Completion_Handler::make_svc_handler (TAO::HTIOP::Connection_Handler *&sh)
{
  if (sh == 0)
    {
      // Purge connections (if necessary)
      this->orb_core_->lane_resources ().transport_cache ().purge ();
      ACE_NEW_RETURN (sh,
                      TAO::HTIOP::Connection_Handler (this->orb_core_,
                                                      0),
                      -1);
    }

  return 0;
}

int
TAO::HTIOP::Completion_Handler::add_transport_to_cache (void)
{
  return 0;
}

int
TAO::HTIOP::Completion_Handler::handle_close (ACE_HANDLE,
                                            ACE_Reactor_Mask)
{
  //commit suicide
  delete this;
  return 0;
}