blob: bb8a784e9ab5585de8cc5c83fdef44065141081c (
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
|
// **********************************************************************
//
// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
#include <Ice/EndpointFactoryManager.h>
#include <Ice/Endpoint.h>
#include <Ice/UnknownEndpointI.h>
#include <Ice/BasicStream.h>
#include <Ice/LocalException.h>
#include <Ice/Instance.h>
#include <Ice/Properties.h>
#include <Ice/DefaultsAndOverrides.h>
using namespace std;
using namespace Ice;
using namespace IceInternal;
void IceInternal::incRef(EndpointFactoryManager* p) { p->__incRef(); }
void IceInternal::decRef(EndpointFactoryManager* p) { p->__decRef(); }
IceInternal::EndpointFactoryManager::EndpointFactoryManager(const InstancePtr& instance)
: _instance(instance)
{
}
void
IceInternal::EndpointFactoryManager::add(const EndpointFactoryPtr& factory)
{
IceUtil::Mutex::Lock sync(*this); // TODO: Necessary?
//
// TODO: Optimize with a map?
//
for(vector<EndpointFactoryPtr>::size_type i = 0; i < _factories.size(); i++)
{
if(_factories[i]->type() == factory->type())
{
assert(false); // TODO: Exception?
}
}
_factories.push_back(factory);
}
EndpointFactoryPtr
IceInternal::EndpointFactoryManager::get(Short type) const
{
IceUtil::Mutex::Lock sync(*this); // TODO: Necessary?
//
// TODO: Optimize with a map?
//
for(vector<EndpointFactoryPtr>::size_type i = 0; i < _factories.size(); i++)
{
if(_factories[i]->type() == type)
{
return _factories[i];
}
}
return 0;
}
EndpointIPtr
IceInternal::EndpointFactoryManager::create(const string& str) const
{
IceUtil::Mutex::Lock sync(*this); // TODO: Necessary?
const string delim = " \t\n\r";
string::size_type beg = str.find_first_not_of(delim);
if(beg == string::npos)
{
EndpointParseException ex(__FILE__, __LINE__);
ex.str = str;
throw ex;
}
string::size_type end = str.find_first_of(delim, beg);
if(end == string::npos)
{
end = str.length();
}
string protocol = str.substr(beg, end - beg);
if(protocol == "default")
{
protocol = _instance->defaultsAndOverrides()->defaultProtocol;
}
//
// TODO: Optimize with a map?
//
for(vector<EndpointFactoryPtr>::size_type i = 0; i < _factories.size(); i++)
{
if(_factories[i]->protocol() == protocol)
{
return _factories[i]->create(str.substr(end));
}
}
return 0;
}
EndpointIPtr
IceInternal::EndpointFactoryManager::read(BasicStream* s) const
{
IceUtil::Mutex::Lock sync(*this); // TODO: Necessary?
Short type;
s->read(type);
//
// TODO: Optimize with a map?
//
for(vector<EndpointFactoryPtr>::size_type i = 0; i < _factories.size(); i++)
{
if(_factories[i]->type() == type)
{
return _factories[i]->read(s);
}
}
return new UnknownEndpointI(type, s);
}
void
IceInternal::EndpointFactoryManager::destroy()
{
for(vector<EndpointFactoryPtr>::size_type i = 0; i < _factories.size(); i++)
{
_factories[i]->destroy();
}
_factories.clear();
}
|