summaryrefslogtreecommitdiff
path: root/TAO/tao/Profile_Transport_Resolver.cpp
blob: caf61e038bc4c69e1fc84d8ebe5be5f75d939630 (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
//$Id$
#include "Profile_Transport_Resolver.h"
#include "Profile.h"
#include "Transport.h"
#include "Stub.h"
#include "Invocation_Endpoint_Selectors.h"
#include "ORB_Core.h"
#include "Endpoint_Selector_Factory.h"
#include "Codeset_Manager.h"
#include "Connector_Registry.h"
#include "Transport_Connector.h"

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

namespace TAO
{
  Profile_Transport_Resolver::Profile_Transport_Resolver (TAO_Stub *stub)
    : stub_ (stub)
      , transport_ (0)
      , profile_ (0)
  {
  }

  Profile_Transport_Resolver::~Profile_Transport_Resolver (void)
  {
    if (this->profile_)
      this->profile_->_decr_refcnt ();

    this->transport_->make_idle ();
    TAO_Transport::release (this->transport_);
  }

  TAO_Stub *
  Profile_Transport_Resolver::stub (void) const
  {
    return this->stub_;
  }

  void
  Profile_Transport_Resolver::profile (TAO_Profile *p)
  {
    // @@ NOTE:This is just a workaround for a more serious problem with
    // profile management. This would cover some potential issues that
    // Ossama is working on.
    // Ossama, please remove them when you are done.
    TAO_Profile *tmp = this->profile_;

    // Dont do anything if the incoming profile is null
    if (p)
      {
        (void) p->_incr_refcnt ();
        this->profile_ = p;

        if (tmp)
          (void) tmp->_decr_refcnt ();
    }
  }

  TAO_Profile *
  Profile_Transport_Resolver::profile (void) const
  {
    return this->profile_;
  }

  TAO_Transport *
  Profile_Transport_Resolver::transport (void) const
  {
    return this->transport_;
  }


  void
  Profile_Transport_Resolver::resolve (ACE_ENV_SINGLE_ARG_DECL)
    ACE_THROW_SPEC ((CORBA::SystemException))
  {
    TAO_Invocation_Endpoint_Selector *es =
      this->stub_->orb_core ()->endpoint_selector_factory ()->get_selector (
        ACE_ENV_SINGLE_ARG_PARAMETER);
    ACE_CHECK;

    es->select_endpoint (this
                         ACE_ENV_ARG_PARAMETER);
    ACE_CHECK;

    if (this->transport_ == 0)
      ACE_THROW (CORBA::INTERNAL ());

    const TAO_GIOP_Message_Version& version =
      this->profile_->version ();

    // Initialize the messaging object
    if (this->transport_->messaging_init (version.major,
                                          version.minor) == -1)
      ACE_THROW (CORBA::INTERNAL (
                        CORBA::SystemException::_tao_minor_code (
                          TAO_DEFAULT_MINOR_CODE,
                          EINVAL),
                        CORBA::COMPLETED_NO));

    if (!this->transport_->is_tcs_set())
      this->stub_->orb_core ()->codeset_manager()->
        set_tcs (*this->profile_,*this->transport_);
  }

  bool
  Profile_Transport_Resolver::try_connect (TAO_Endpoint *ep
                                           ACE_ENV_ARG_DECL)
  {
    TAO_Connector_Registry *conn_reg =
      this->stub_->orb_core ()->connector_registry (ACE_ENV_SINGLE_ARG_PARAMETER);
    ACE_CHECK_RETURN (false);

    if (conn_reg == 0)
      {
        ACE_THROW_RETURN (CORBA::INTERNAL (
                        CORBA::SystemException::_tao_minor_code (
                          TAO_DEFAULT_MINOR_CODE,
                          EINVAL),
                        CORBA::COMPLETED_NO),
                        0);
      }

    // Get the max_wait_time
    ACE_Time_Value *max_wait_time = 0;
//    ACE_Time_Value connection_timeout;
    int is_conn_timeout = 0;
#if 0
  // Check for the connection timout policy in the ORB
  this->orb_core ()->connection_timeout (this->stub (),
                                         is_conn_timeout,
                                         connection_timeout);

  // If a connection timeout policy is set, use that as the timeout
  // value.
   if (!is_conn_timeout)
     max_wait_time =
       this->max_wait_time ();
   else
     max_wait_time = &connection_timeout;
#endif /*fi 0*/
   // Obtain a connection.
   this->transport_ =
     conn_reg->get_connector (ep)->connect (this,
                                            ep,
                                            max_wait_time
                                            ACE_ENV_ARG_PARAMETER);
   ACE_CHECK_RETURN (false);

   // A timeout error occurred
   if (this->transport_ == 0 && errno == ETIME)
     {
       // If the user has set a roundtrip timeout policy, then throw a
       // timeout exception, else just fall through and return 0 to
       // look at the next endpoint
       if (!is_conn_timeout)
         {
          ACE_THROW_RETURN (CORBA::TIMEOUT (
              CORBA::SystemException::_tao_minor_code (
                TAO_TIMEOUT_CONNECT_MINOR_CODE,
                errno),
              CORBA::COMPLETED_NO),
              false);
         }
     }
   else if (this->transport_ == 0)
     return false;

   return true;
  }


}