From f453785066eff4e8d9f5c7fd63bd01b4260020ed Mon Sep 17 00:00:00 2001 From: Marc Laukien Date: Mon, 14 Jan 2002 18:43:01 +0000 Subject: glacier intergration --- cpp/src/Ice/RouterInfo.cpp | 181 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 cpp/src/Ice/RouterInfo.cpp (limited to 'cpp/src/Ice/RouterInfo.cpp') diff --git a/cpp/src/Ice/RouterInfo.cpp b/cpp/src/Ice/RouterInfo.cpp new file mode 100644 index 00000000000..70cad21fbd6 --- /dev/null +++ b/cpp/src/Ice/RouterInfo.cpp @@ -0,0 +1,181 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include +#include +#include + +using namespace std; +using namespace Ice; +using namespace IceInternal; + +void IceInternal::incRef(RouterManager* p) { p->__incRef(); } +void IceInternal::decRef(RouterManager* p) { p->__decRef(); } + +void IceInternal::incRef(RouterInfo* p) { p->__incRef(); } +void IceInternal::decRef(RouterInfo* p) { p->__decRef(); } + +IceInternal::RouterManager::RouterManager() : + _tableHint(_table.end()) +{ +} + +void +IceInternal::RouterManager::destroy() +{ + IceUtil::Mutex::Lock sync(*this); + + _table.clear(); + _tableHint = _table.end(); +} + +RouterInfoPtr +IceInternal::RouterManager::get(const RouterPrx& rtr) +{ + if (!rtr) + { + return 0; + } + + RouterPrx router = RouterPrx::uncheckedCast(rtr->ice_router(0)); // The router cannot be routed. + + IceUtil::Mutex::Lock sync(*this); + + map::iterator p = _table.end(); + + if (_tableHint != _table.end()) + { + if (_tableHint->first == router) + { + p = _tableHint; + } + } + + if (p == _table.end()) + { + p = _table.find(router); + } + + if (p == _table.end()) + { + _tableHint = _table.insert(_tableHint, make_pair(router, new RouterInfo(router))); + } + else + { + _tableHint = p; + } + + return _tableHint->second; +} + +IceInternal::RouterInfo::RouterInfo(const RouterPrx& router) : + _router(router), + _routingTable(new RoutingTable) +{ + assert(_router); +} + +bool +IceInternal::RouterInfo::operator==(const RouterInfo& rhs) const +{ + return _router == rhs._router; +} + +bool +IceInternal::RouterInfo::operator!=(const RouterInfo& rhs) const +{ + return _router != rhs._router; +} + +bool +IceInternal::RouterInfo::operator<(const RouterInfo& rhs) const +{ + return _router < rhs._router; +} + +RouterPrx +IceInternal::RouterInfo::getRouter() +{ + // + // No mutex lock necessary, _router is immutable. + // + return _router; +} + +ObjectPrx +IceInternal::RouterInfo::getClientProxy() +{ + IceUtil::Mutex::Lock sync(*this); + + if (!_clientProxy) // Lazy initialization. + { + _clientProxy = _router->getClientProxy(); + assert(_clientProxy); + _clientProxy = _clientProxy->ice_router(0); // The client proxy cannot be routed. + } + + return _clientProxy; +} + +void +IceInternal::RouterInfo::setClientProxy(const ObjectPrx& clientProxy) +{ + IceUtil::Mutex::Lock sync(*this); + _clientProxy = clientProxy->ice_router(0); // The client proxy cannot be routed. +} + +ObjectPrx +IceInternal::RouterInfo::getServerProxy() +{ + IceUtil::Mutex::Lock sync(*this); + + if (!_serverProxy) // Lazy initialization. + { + _serverProxy = _router->getServerProxy(); + assert(_serverProxy); + _serverProxy = _serverProxy->ice_router(0); // The server proxy cannot be routed. + } + + return _serverProxy; +} + +void +IceInternal::RouterInfo::setServerProxy(const ObjectPrx& serverProxy) +{ + IceUtil::Mutex::Lock sync(*this); + _serverProxy = serverProxy->ice_router(0); // The server proxy cannot be routed. +} + +void +IceInternal::RouterInfo::addProxy(const ObjectPrx& proxy) +{ + // + // No mutex lock necessary, _routingTable is immutable, and + // RoutingTable is mutex protected. + // + if (_routingTable->add(proxy)) // Only add the proxy to the router if it's not already in the routing table. + { + _router->addProxy(proxy); + } +} + +void +IceInternal::RouterInfo::setAdapter(const ObjectAdapterPtr& adapter) +{ + IceUtil::Mutex::Lock sync(*this); + _adapter = adapter; +} + +ObjectAdapterPtr +IceInternal::RouterInfo::getAdapter() +{ + IceUtil::Mutex::Lock sync(*this); + return _adapter; +} -- cgit v1.2.3