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/RoutingTable.cpp | 98 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 cpp/src/Ice/RoutingTable.cpp (limited to 'cpp/src/Ice/RoutingTable.cpp') diff --git a/cpp/src/Ice/RoutingTable.cpp b/cpp/src/Ice/RoutingTable.cpp new file mode 100644 index 00000000000..e1e88f5804c --- /dev/null +++ b/cpp/src/Ice/RoutingTable.cpp @@ -0,0 +1,98 @@ +// ********************************************************************** +// +// Copyright (c) 2001 +// MutableRealms, Inc. +// Huntsville, AL, USA +// +// All Rights Reserved +// +// ********************************************************************** + +#include +#include + +using namespace std; +using namespace Ice; +using namespace IceInternal; + +void IceInternal::incRef(RoutingTable* p) { p->__incRef(); } +void IceInternal::decRef(RoutingTable* p) { p->__decRef(); } + +IceInternal::RoutingTable::RoutingTable() : + _tableHint(_table.end()) +{ +} + +bool +IceInternal::RoutingTable::add(const ObjectPrx& prx) +{ + if (!prx) + { + return false; + } + + ObjectPrx proxy = prx->ice_default(); // We insert the proxy in it's default form into the routing table. + + IceUtil::Mutex::Lock sync(*this); + + map::iterator p = _table.end(); + + if (_tableHint != _table.end()) + { + if (_tableHint->first == proxy->ice_getIdentity()) + { + p = _tableHint; + } + } + + if (p == _table.end()) + { + p = _table.find(proxy->ice_getIdentity()); + } + + if (p == _table.end()) + { + _tableHint = _table.insert(_tableHint, make_pair(proxy->ice_getIdentity(), proxy)); + return true; + } + else + { + return false; + } +} + +ObjectPrx +IceInternal::RoutingTable::get(const Identity& ident) +{ + if (ident.name.empty()) + { + return 0; + } + + IceUtil::Mutex::Lock sync(*this); + + map::iterator p = _table.end(); + + if (_tableHint != _table.end()) + { + if (_tableHint->first == ident) + { + p = _tableHint; + } + } + + if (p == _table.end()) + { + p = _table.find(ident); + } + + if (p == _table.end()) + { + return 0; + } + else + { + _tableHint = p; + return p->second; + } +} -- cgit v1.2.3