diff options
author | Benoit Foucher <benoit@zeroc.com> | 2002-12-06 16:32:01 +0000 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2002-12-06 16:32:01 +0000 |
commit | a4d415aa985698fe744fdcab077311f144e8d62a (patch) | |
tree | 61850730df0b7152fa5b59fd6a1f0c4bd77c8afa /cpp/src/IcePack/ObjectRegistryI.cpp | |
parent | file exceptionsAMDS.dsp was initially added on branch amd. (diff) | |
download | ice-a4d415aa985698fe744fdcab077311f144e8d62a.tar.bz2 ice-a4d415aa985698fe744fdcab077311f144e8d62a.tar.xz ice-a4d415aa985698fe744fdcab077311f144e8d62a.zip |
Initial addition
Diffstat (limited to 'cpp/src/IcePack/ObjectRegistryI.cpp')
-rw-r--r-- | cpp/src/IcePack/ObjectRegistryI.cpp | 185 |
1 files changed, 185 insertions, 0 deletions
diff --git a/cpp/src/IcePack/ObjectRegistryI.cpp b/cpp/src/IcePack/ObjectRegistryI.cpp new file mode 100644 index 00000000000..9cad2e21f6e --- /dev/null +++ b/cpp/src/IcePack/ObjectRegistryI.cpp @@ -0,0 +1,185 @@ +// ********************************************************************** +// +// Copyright (c) 2002 +// ZeroC, Inc. +// Billerica, MA, USA +// +// All Rights Reserved. +// +// Ice is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License version 2 as published by +// the Free Software Foundation. +// +// ********************************************************************** + +#include <IcePack/ObjectRegistryI.h> +#include <IcePack/TraceLevels.h> + +using namespace std; +using namespace IcePack; + +IcePack::ObjectRegistryI::ObjectRegistryI(const Freeze::DBPtr& objDb, const Freeze::DBPtr& typeDb, + const TraceLevelsPtr& traceLevels) : + _objects(objDb), + _types(typeDb), + _traceLevels(traceLevels) +{ +} + +void +IcePack::ObjectRegistryI::add(const ObjectDescription& obj, const Ice::Current&) +{ + IceUtil::Mutex::Lock sync(*this); + + Ice::Identity id = obj.proxy->ice_getIdentity(); + + IdentityObjectDescDict::iterator p = _objects.find(id); + if(p != _objects.end()) + { + throw ObjectExistsException(); + } + + // + // Add the object to the object dictionary. + // + _objects.insert(make_pair(id, obj)); + + // + // Add the object to the interface dictionary. + // + if(!obj.type.empty()) + { + Ice::ObjectProxySeq seq; + + StringObjectProxySeqDict::iterator q = _types.find(obj.type); + if(q != _types.end()) + { + seq = q->second; + } + + seq.push_back(obj.proxy); + + if(q == _types.end()) + { + _types.insert(make_pair(obj.type, seq)); + } + else + { + q.set(seq); + } + } + + if(_traceLevels->objectRegistry > 0) + { + Ice::Trace out(_traceLevels->logger, _traceLevels->objectRegistryCat); + out << "added object `" << Ice::identityToString(id) << "'"; + } +} + +void +IcePack::ObjectRegistryI::remove(const Ice::ObjectPrx& object, const Ice::Current&) +{ + IceUtil::Mutex::Lock sync(*this); + + Ice::Identity id = object->ice_getIdentity(); + + IdentityObjectDescDict::iterator p = _objects.find(id); + if(p == _objects.end()) + { + throw ObjectNotExistException(); + } + + ObjectDescription obj = p->second; + + if(!obj.type.empty()) + { + // + // Remove the object from the interface dictionary. + // + StringObjectProxySeqDict::iterator q = _types.find(obj.type); + assert(q != _types.end()); + + Ice::ObjectProxySeq seq = q->second; + + Ice::ObjectProxySeq::iterator r; + for(r = seq.begin(); r != seq.end(); ++r) + { + if((*r)->ice_getIdentity() == id) + { + break; + } + } + + assert(r != seq.end()); + seq.erase(r); + + if(seq.size() == 0) + { + _types.erase(q); + } + else + { + q.set(seq); + } + } + + // + // Remove the object from the object dictionary. + // + _objects.erase(p); + + if(_traceLevels->objectRegistry > 0) + { + Ice::Trace out(_traceLevels->logger, _traceLevels->objectRegistryCat); + out << "removed object `" << id << "'"; + } +} + +ObjectDescription +IcePack::ObjectRegistryI::getObjectDescription(const Ice::Identity& id, const Ice::Current&) const +{ + IdentityObjectDescDict::const_iterator p = _objects.find(id); + if(p == _objects.end()) + { + throw ObjectNotExistException(); + } + + return p->second; +} + +Ice::ObjectPrx +IcePack::ObjectRegistryI::findById(const Ice::Identity& id, const Ice::Current&) const +{ + IdentityObjectDescDict::const_iterator p = _objects.find(id); + if(p == _objects.end()) + { + throw ObjectNotExistException(); + } + + return p->second.proxy; +} + +Ice::ObjectPrx +IcePack::ObjectRegistryI::findByType(const string& type, const Ice::Current&) const +{ + StringObjectProxySeqDict::const_iterator p = _types.find(type); + if(p == _types.end()) + { + throw ObjectNotExistException(); + } + + int r = rand() % p->second.size(); + return p->second[r]; +} + +Ice::ObjectProxySeq +IcePack::ObjectRegistryI::findAllWithType(const string& type, const Ice::Current&) const +{ + StringObjectProxySeqDict::const_iterator p = _types.find(type); + if(p == _types.end()) + { + throw ObjectNotExistException(); + } + + return p->second; +} |