summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/EndpointFactory.cpp
blob: d040c737b8a0a867233e6c7ccfa634251f2436a2 (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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
// **********************************************************************
//
// Copyright (c) 2003-present ZeroC, Inc. All rights reserved.
//
// **********************************************************************

#include <Ice/EndpointFactory.h>
#include <Ice/Instance.h>
#include <Ice/EndpointFactoryManager.h>
#include <Ice/ProtocolInstance.h>

using namespace std;
using namespace Ice;
using namespace IceInternal;

IceUtil::Shared* IceInternal::upCast(EndpointFactory* p) { return p; }

IceInternal::EndpointFactory::EndpointFactory()
{
}

IceInternal::EndpointFactory::~EndpointFactory()
{
}

void
IceInternal::EndpointFactory::initialize()
{
    // Nothing to do, can be overriden by specialization to finish initialization.
}

IceInternal::EndpointFactoryPlugin::EndpointFactoryPlugin(const CommunicatorPtr& communicator,
                                                          const EndpointFactoryPtr& factory)
{
    assert(communicator);
    getInstance(communicator)->endpointFactoryManager()->add(factory);
}

void
IceInternal::EndpointFactoryPlugin::initialize()
{
}

void
IceInternal::EndpointFactoryPlugin::destroy()
{
}

IceInternal::EndpointFactoryWithUnderlying::EndpointFactoryWithUnderlying(const ProtocolInstancePtr& instance,
                                                                          Short type) :
    _instance(instance), _type(type)
{
}

void
IceInternal::EndpointFactoryWithUnderlying::initialize()
{
    //
    // Get the endpoint factory for the underlying type and clone it with
    // our protocol instance.
    //
    EndpointFactoryPtr factory = _instance->getEndpointFactory(_type);
    if(factory)
    {
        _underlying = factory->clone(_instance);
        _underlying->initialize();
    }
}

Short
IceInternal::EndpointFactoryWithUnderlying::type() const
{
    return _instance->type();
}

string
IceInternal::EndpointFactoryWithUnderlying::protocol() const
{
    return _instance->protocol();
}

EndpointIPtr
IceInternal::EndpointFactoryWithUnderlying::create(vector<string>& args, bool oaEndpoint) const
{
    if(!_underlying)
    {
        return 0; // Can't create an endpoint without underlying factory.
    }
    return createWithUnderlying(_underlying->create(args, oaEndpoint), args, oaEndpoint);
}

EndpointIPtr
IceInternal::EndpointFactoryWithUnderlying::read(InputStream* s) const
{
    if(!_underlying)
    {
        return 0; // Can't create an endpoint without underlying factory.
    }
    return readWithUnderlying(_underlying->read(s), s);
}

void
IceInternal::EndpointFactoryWithUnderlying::destroy()
{
    if(_underlying)
    {
        _underlying->destroy();
    }
    _instance = 0;
}

EndpointFactoryPtr
IceInternal::EndpointFactoryWithUnderlying::clone(const ProtocolInstancePtr& instance) const
{
    return cloneWithUnderlying(instance, _type);
}

IceInternal::UnderlyingEndpointFactory::UnderlyingEndpointFactory(const ProtocolInstancePtr& instance,
                                                                  Short type,
                                                                  Short underlying) :
    _instance(instance), _type(type), _underlying(underlying)
{
}

void
IceInternal::UnderlyingEndpointFactory::initialize()
{
    //
    // Get the endpoint factory of the given endpoint type. If it's a factory that
    // delegates to an underlying endpoint, clone it and instruct it to delegate to
    // our underlying factory.
    //
    EndpointFactoryPtr factory = _instance->getEndpointFactory(_type);
    if(factory)
    {
        EndpointFactoryWithUnderlying* f = dynamic_cast<EndpointFactoryWithUnderlying*>(factory.get());
        if(f)
        {
            _factory = f->cloneWithUnderlying(_instance, _underlying);
            _factory->initialize();
        }
    }
}

Short
IceInternal::UnderlyingEndpointFactory::type() const
{
    return _instance->type();
}

string
IceInternal::UnderlyingEndpointFactory::protocol() const
{
    return _instance->protocol();
}

EndpointIPtr
IceInternal::UnderlyingEndpointFactory::create(vector<string>& args, bool oaEndpoint) const
{
    if(!_factory)
    {
        return 0;
    }
    return _factory->create(args, oaEndpoint);
}

EndpointIPtr
IceInternal::UnderlyingEndpointFactory::read(InputStream* s) const
{
    if(!_factory)
    {
        return 0;
    }
    return _factory->read(s);
}

void
IceInternal::UnderlyingEndpointFactory::destroy()
{
    if(_factory)
    {
        _factory->destroy();
    }
    _instance = 0;
}

EndpointFactoryPtr
IceInternal::UnderlyingEndpointFactory::clone(const ProtocolInstancePtr& instance) const
{
    return new UnderlyingEndpointFactory(instance, _type, _underlying);
}