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

#include "orbsvcs/HTIOP/HTIOP_Factory.h"
#include "orbsvcs/HTIOP/HTIOP_Acceptor.h"
#include "orbsvcs/HTIOP/HTIOP_Connector.h"
#include "orbsvcs/HTIOP/HTIOP_Profile.h"

#include "ace/HTBP/HTBP_Environment.h"
#include "tao/IOPC.h"

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

static const char the_prefix[] = "htiop";

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

TAO::HTIOP::Protocol_Factory::Protocol_Factory (void)
  :  TAO_Protocol_Factory (OCI_TAG_HTIOP_PROFILE),
     major_ (TAO_DEF_GIOP_MAJOR),
     minor_ (TAO_DEF_GIOP_MINOR),
     ht_env_ (0),
     inside_ (-1)
{
}

TAO::HTIOP::Protocol_Factory::~Protocol_Factory (void)
{
  delete this->ht_env_;
}

int
TAO::HTIOP::Protocol_Factory::match_prefix (const ACE_CString &prefix)
{
  // Check for the proper prefix for this protocol.
  return (ACE_OS::strcasecmp (prefix.c_str (), ::the_prefix) == 0);
}

const char *
TAO::HTIOP::Protocol_Factory::prefix (void) const
{
  return ::the_prefix;
}

char
TAO::HTIOP::Protocol_Factory::options_delimiter (void) const
{
  return '/';
}

int
TAO::HTIOP::Protocol_Factory::init (int argc,
                                  ACE_TCHAR* argv[])
{
  const ACE_TCHAR * config_file = 0;
  const ACE_TCHAR * persist_file = 0;

  ACE_stat statbuf;
  int use_registry = 0;

  for (int i = 0; i < argc; i++)
    {
      if (ACE_OS::strcasecmp(argv[i], ACE_TEXT("-config")) == 0)
        {
          if (++i < argc)
            if (ACE_OS::stat (argv[i],&statbuf) != -1)
              config_file = argv[i];
        }
      else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT("-env_persist")) == 0)
        {
          if (++i < argc)
            if (ACE_OS::stat (argv[i],&statbuf) != -1)
              persist_file = argv[i];
        }
      else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT("-win32_reg")) == 0)
        {
          use_registry = 1;
        }
      else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT("-inside")) == 0)
        {
          if (++i < argc)
            this->inside_ = ::atoi (ACE_TEXT_TO_CHAR_IN(argv[i]));
        }
    }

  ACE_NEW_RETURN (this->ht_env_,
                  ACE::HTBP::Environment(0,
                                       use_registry,
                                       persist_file),
                  -1);

  if (config_file != 0)
    this->ht_env_->import_config (config_file);

  return 0;
}

TAO_Acceptor *
TAO::HTIOP::Protocol_Factory::make_acceptor (void)
{
  TAO_Acceptor *acceptor = 0;

  ACE_NEW_RETURN (acceptor,
                  TAO::HTIOP::Acceptor (this->ht_env_,
                                        this->inside_),
                  0);
  return acceptor;
}

TAO_Connector *
TAO::HTIOP::Protocol_Factory::make_connector (void)
{
  TAO_Connector *connector = 0;
  ACE_NEW_RETURN (connector,
                  TAO::HTIOP::Connector (this->ht_env_),
                  0);
  return connector;
}

int
TAO::HTIOP::Protocol_Factory::requires_explicit_endpoint (void) const
{
  return 0;
}


TAO_END_VERSIONED_NAMESPACE_DECL

ACE_STATIC_SVC_DEFINE (TAO_HTIOP_Protocol_Factory,
                       ACE_TEXT ("HTIOP_Factory"),
                       ACE_SVC_OBJ_T,
                       &ACE_SVC_NAME (TAO_HTIOP_Protocol_Factory),
                       ACE_Service_Type::DELETE_THIS |
                       ACE_Service_Type::DELETE_OBJ,
                       0)


// Since the actual class instantiated by the factory is scoped inside a
// namespace, this macro is used in place of ACE_FACTORY_DEFINE, athough
// the declaration macro is the same. Note that the second argument must
// match the name class name used in the ACE_FACTORY_DECLARE, and the
// third argument is the fully scoped class to be instantiated.
ACE_FACTORY_NAMESPACE_DEFINE (HTIOP,
                              TAO_HTIOP_Protocol_Factory,
                              TAO::HTIOP::Protocol_Factory)