summaryrefslogtreecommitdiff
path: root/TAO/tao/Strategies/COIOP_Connector.cpp
blob: ce03957681a7affe9ad20d644c942f0987ff1e58 (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
// This may look like C, but it's really -*- C++ -*-
#include "tao/Strategies/COIOP_Connector.h"

#if defined (TAO_HAS_COIOP) && (TAO_HAS_COIOP != 0)

#include "ace/Connector.h"
#include "tao/debug.h"
#include "tao/ORB_Core.h"
#include "tao/SystemException.h"
#include "ace/OS_NS_strings.h"
#include "ace/OS_NS_string.h"
#include "tao/Strategies/COIOP_Profile.h"
#include <cstring>

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

TAO_COIOP_Connector::TAO_COIOP_Connector (void)
  : TAO_Connector (TAO_TAG_COIOP_PROFILE)
{
}

TAO_COIOP_Connector::~TAO_COIOP_Connector (void)
{
}

int
TAO_COIOP_Connector::open (TAO_ORB_Core *orb_core)
{
  this->orb_core (orb_core);

  // Create our connect strategy
  if (this->create_connect_strategy () == -1)
    return -1;

  return 0;
}

int
TAO_COIOP_Connector::close (void)
{
  return 0;
}

int
TAO_COIOP_Connector::set_validate_endpoint (TAO_Endpoint *endpoint)
{
  TAO_COIOP_Endpoint *COIOP_endpoint =
    this->remote_endpoint (endpoint);

  if (COIOP_endpoint == 0)
    return -1;

  return 0;
}

TAO_Transport *
TAO_COIOP_Connector::make_connection (TAO::Profile_Transport_Resolver *,
                                      TAO_Transport_Descriptor_Interface &,
                                      ACE_Time_Value * /*max_wait_time*/)
{
  // No remote connection possible with COIOP
  return 0;
}

TAO_Profile *
TAO_COIOP_Connector::create_profile (TAO_InputCDR& cdr)
{
  TAO_Profile *pfile = 0;
  ACE_NEW_RETURN (pfile,
                  TAO_COIOP_Profile (this->orb_core ()),
                  0);

  int const r = pfile->decode (cdr);
  if (r == -1)
    {
      pfile->_decr_refcnt ();
      pfile = 0;
    }

  return pfile;
}

TAO_Profile *
TAO_COIOP_Connector::make_profile (void)
{
  // The endpoint should be of the form:
  //    N.n@uuid/object_key
  // or:
  //    uuid/object_key

  TAO_Profile *profile = 0;
  ACE_NEW_THROW_EX (profile,
                    TAO_COIOP_Profile (this->orb_core ()),
                    CORBA::NO_MEMORY (
                      CORBA::SystemException::_tao_minor_code (
                        TAO::VMCID,
                        ENOMEM),
                      CORBA::COMPLETED_NO));

  return profile;
}

int
TAO_COIOP_Connector::check_prefix (const char *endpoint)
{
  // Check for a valid string
  if (!endpoint || !*endpoint)
    return -1;  // Failure

  const char *protocol[] = { "COIOP", "COIOPloc" };

  size_t const slot = std::strchr (endpoint, ':') - endpoint;

  size_t const len0 = std::strlen (protocol[0]);
  size_t const len1 = std::strlen (protocol[1]);

  // Check for the proper prefix in the IOR.  If the proper prefix
  // isn't in the IOR then it is not an IOR we can use.
  if (slot == len0
      && ACE_OS::strncasecmp (endpoint, protocol[0], len0) == 0)
    return 0;
  else if (slot == len1
           && ACE_OS::strncasecmp (endpoint, protocol[1], len1) == 0)
    return 0;

  return -1;
  // Failure: not an COIOP IOR
  // DO NOT throw an exception here.
}

char
TAO_COIOP_Connector::object_key_delimiter (void) const
{
  return TAO_COIOP_Profile::object_key_delimiter_;
}

TAO_COIOP_Endpoint *
TAO_COIOP_Connector::remote_endpoint (TAO_Endpoint *endpoint)
{
  if (endpoint->tag () != TAO_TAG_COIOP_PROFILE)
    return 0;

  TAO_COIOP_Endpoint *COIOP_endpoint =
    dynamic_cast<TAO_COIOP_Endpoint *> (endpoint );

  return COIOP_endpoint;
}

int
TAO_COIOP_Connector::cancel_svc_handler (
  TAO_Connection_Handler * /* svc_handler */)
{
  return 0;
}

TAO_END_VERSIONED_NAMESPACE_DECL

#endif /* TAO_HAS_COIOP && TAO_HAS_COIOP != 0 */