diff options
author | Mark Spruiell <mes@zeroc.com> | 2002-04-24 21:13:00 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2002-04-24 21:13:00 +0000 |
commit | 5409c1ecef0f226dedc77721c0d2fc8dfe9e85de (patch) | |
tree | 97ba75bc47a143726d6d8382be3a462e51716700 /cpp/src/Ice/EndpointFactory.cpp | |
parent | cleaning up sample impls (diff) | |
download | ice-5409c1ecef0f226dedc77721c0d2fc8dfe9e85de.tar.bz2 ice-5409c1ecef0f226dedc77721c0d2fc8dfe9e85de.tar.xz ice-5409c1ecef0f226dedc77721c0d2fc8dfe9e85de.zip |
merging from plugins branch
Diffstat (limited to 'cpp/src/Ice/EndpointFactory.cpp')
-rw-r--r-- | cpp/src/Ice/EndpointFactory.cpp | 147 |
1 files changed, 147 insertions, 0 deletions
diff --git a/cpp/src/Ice/EndpointFactory.cpp b/cpp/src/Ice/EndpointFactory.cpp new file mode 100644 index 00000000000..364d0f13142 --- /dev/null +++ b/cpp/src/Ice/EndpointFactory.cpp @@ -0,0 +1,147 @@ +// ********************************************************************** +// +// Copyright (c) 2002 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include <Ice/EndpointFactory.h> +#include <Ice/Endpoint.h> +#include <Ice/UnknownEndpoint.h> +#include <Ice/Network.h> +#include <Ice/BasicStream.h> +#include <Ice/LocalException.h> +#include <Ice/Instance.h> + +using namespace std; +using namespace Ice; +using namespace IceInternal; + +void IceInternal::incRef(EndpointFactory* p) { p->__incRef(); } +void IceInternal::decRef(EndpointFactory* p) { p->__decRef(); } +void IceInternal::incRef(EndpointFactoryManager* p) { p->__incRef(); } +void IceInternal::decRef(EndpointFactoryManager* p) { p->__decRef(); } + +IceInternal::EndpointFactory::EndpointFactory() +{ +} + +IceInternal::EndpointFactory::~EndpointFactory() +{ +} + +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; +} + +EndpointPtr +IceInternal::EndpointFactoryManager::create(const string& str) const +{ + IceUtil::Mutex::Lock sync(*this); // TODO: Necessary? + + static const string delim = " \t\n\r"; + + string::size_type beg = str.find_first_not_of(delim); + if (beg == string::npos) + { + throw EndpointParseException(__FILE__, __LINE__); + } + + 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->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)); + } + } + + throw EndpointParseException(__FILE__, __LINE__); +} + +EndpointPtr +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 UnknownEndpoint(type, s); +} + +void +IceInternal::EndpointFactoryManager::destroy() +{ + for (vector<EndpointFactoryPtr>::size_type i = 0; i < _factories.size(); i++) + { + _factories[i]->destroy(); + } + _factories.clear(); +} |