diff options
Diffstat (limited to 'cpp/demo/book/freeze_filesystem/PersistentFilesystemI.cpp')
-rw-r--r-- | cpp/demo/book/freeze_filesystem/PersistentFilesystemI.cpp | 70 |
1 files changed, 45 insertions, 25 deletions
diff --git a/cpp/demo/book/freeze_filesystem/PersistentFilesystemI.cpp b/cpp/demo/book/freeze_filesystem/PersistentFilesystemI.cpp index 472500d2761..1cc4ec00f00 100644 --- a/cpp/demo/book/freeze_filesystem/PersistentFilesystemI.cpp +++ b/cpp/demo/book/freeze_filesystem/PersistentFilesystemI.cpp @@ -17,12 +17,12 @@ using namespace std; Freeze::EvictorPtr Filesystem::NodeI::_evictor; Filesystem::NodeI::NodeI() - : _id(Ice::Identity()) + : _destroyed(false), _id(Ice::Identity()) { } Filesystem::NodeI::NodeI(const Ice::Identity& id) - : _id(id) + : _destroyed(false), _id(id) { } @@ -30,29 +30,58 @@ Filesystem::NodeI::NodeI(const Ice::Identity& id) // Filesystem::FileI // string -Filesystem::FileI::name(const Ice::Current&) +Filesystem::FileI::name(const Ice::Current& c) { + IceUtil::Mutex::Lock lock(*this); + + if(_destroyed) + { + throw Ice::ObjectNotExistException(__FILE__, __LINE__, c.id, c.facet, c.operation); + } + return nodeName; } void -Filesystem::FileI::destroy(const Ice::Current&) +Filesystem::FileI::destroy(const Ice::Current& c) { + { + IceUtil::Mutex::Lock lock(*this); + + if(_destroyed) + { + throw Ice::ObjectNotExistException(__FILE__, __LINE__, c.id, c.facet, c.operation); + } + _destroyed = true; + } + parent->removeNode(nodeName); _evictor->remove(_id); } Filesystem::Lines -Filesystem::FileI::read(const Ice::Current&) +Filesystem::FileI::read(const Ice::Current& c) { IceUtil::Mutex::Lock lock(*this); + + if(_destroyed) + { + throw Ice::ObjectNotExistException(__FILE__, __LINE__, c.id, c.facet, c.operation); + } + return text; } void -Filesystem::FileI::write(const Filesystem::Lines& text, const Ice::Current&) +Filesystem::FileI::write(const Filesystem::Lines& text, const Ice::Current& c) { IceUtil::Mutex::Lock lock(*this); + + if(_destroyed) + { + throw Ice::ObjectNotExistException(__FILE__, __LINE__, c.id, c.facet, c.operation); + } + this->text = text; } @@ -89,8 +118,6 @@ Filesystem::DirectoryI::destroy(const Ice::Current& c) throw Filesystem::PermissionDenied("cannot destroy root directory"); } - NodeDict children; - { IceUtil::Mutex::Lock lock(*this); @@ -98,21 +125,13 @@ Filesystem::DirectoryI::destroy(const Ice::Current& c) { throw Ice::ObjectNotExistException(__FILE__, __LINE__, c.id, c.facet, c.operation); } - - children = nodes; + if(!nodes.empty()) + { + throw Filesystem::PermissionDenied("cannot destroy non-empty directory"); + } _destroyed = true; } - // - // We must iterate over the children outside the synchronization. - // - for(NodeDict::iterator p = children.begin(); p != children.end(); ++p) - { - p->second.proxy->destroy(); - } - - assert(nodes.empty()); - parent->removeNode(nodeName); _evictor->remove(_id); } @@ -169,7 +188,8 @@ Filesystem::DirectoryI::createDirectory(const string& name, const Ice::Current& throw NameInUse(name); } - Ice::Identity id = c.adapter->getCommunicator()->stringToIdentity(IceUtil::generateUUID()); + Ice::Identity id; + id.name = IceUtil::generateUUID(); PersistentDirectoryPtr dir = new DirectoryI(id); dir->nodeName = name; dir->parent = PersistentDirectoryPrx::uncheckedCast(c.adapter->createProxy(c.id)); @@ -199,7 +219,8 @@ Filesystem::DirectoryI::createFile(const string& name, const Ice::Current& c) throw NameInUse(name); } - Ice::Identity id = c.adapter->getCommunicator()->stringToIdentity(IceUtil::generateUUID()); + Ice::Identity id; + id.name = IceUtil::generateUUID(); PersistentFilePtr file = new FileI(id); file->nodeName = name; file->parent = PersistentDirectoryPrx::uncheckedCast(c.adapter->createProxy(c.id)); @@ -224,13 +245,12 @@ Filesystem::DirectoryI::removeNode(const string& name, const Ice::Current&) nodes.erase(p); } -Filesystem::DirectoryI::DirectoryI() : - _destroyed(false) +Filesystem::DirectoryI::DirectoryI() { } Filesystem::DirectoryI::DirectoryI(const Ice::Identity& id) : - NodeI(id), _destroyed(false) + NodeI(id) { } |