summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/EndpointFactoryManager.cpp
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2002-04-26 02:53:33 +0000
committerMark Spruiell <mes@zeroc.com>2002-04-26 02:53:33 +0000
commit0d715a1edd4484c9b7074c9c3cb283d468a538bc (patch)
tree45934688c11aa189731ae51f07032050affd12ef /cpp/src/Ice/EndpointFactoryManager.cpp
parentWin32 fix (diff)
downloadice-0d715a1edd4484c9b7074c9c3cb283d468a538bc.tar.bz2
ice-0d715a1edd4484c9b7074c9c3cb283d468a538bc.tar.xz
ice-0d715a1edd4484c9b7074c9c3cb283d468a538bc.zip
Renaming Ice.Trace.Security to IceSSL.Trace.Security Cleaning up IceSSL
dependencies on Ice core
Diffstat (limited to 'cpp/src/Ice/EndpointFactoryManager.cpp')
-rw-r--r--cpp/src/Ice/EndpointFactoryManager.cpp137
1 files changed, 137 insertions, 0 deletions
diff --git a/cpp/src/Ice/EndpointFactoryManager.cpp b/cpp/src/Ice/EndpointFactoryManager.cpp
new file mode 100644
index 00000000000..0df3361d3a5
--- /dev/null
+++ b/cpp/src/Ice/EndpointFactoryManager.cpp
@@ -0,0 +1,137 @@
+// **********************************************************************
+//
+// Copyright (c) 2002
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#include <Ice/EndpointFactoryManager.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(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;
+}
+
+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();
+}