summaryrefslogtreecommitdiff
path: root/cpp/demo/book/freeze_filesystem/Client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/demo/book/freeze_filesystem/Client.cpp')
-rw-r--r--cpp/demo/book/freeze_filesystem/Client.cpp52
1 files changed, 31 insertions, 21 deletions
diff --git a/cpp/demo/book/freeze_filesystem/Client.cpp b/cpp/demo/book/freeze_filesystem/Client.cpp
index 53f360f38b3..f9ff7944e43 100644
--- a/cpp/demo/book/freeze_filesystem/Client.cpp
+++ b/cpp/demo/book/freeze_filesystem/Client.cpp
@@ -13,6 +13,31 @@
using namespace std;
using namespace Filesystem;
+// Recursively print the contents of directory "dir" in tree fashion.
+// For files, show the contents of each file. The "depth"
+// parameter is the current nesting level (for indentation).
+
+static void
+listRecursive(const DirectoryPrx & dir, int depth = 0)
+{
+ string indent(++depth, '\t');
+
+ NodeDescSeq contents = dir->list();
+
+ for (NodeDescSeq::const_iterator i = contents.begin(); i != contents.end(); ++i) {
+ DirectoryPrx dir = DirectoryPrx::checkedCast(i->proxy);
+ FilePrx file = FilePrx::uncheckedCast(i->proxy);
+ cout << indent << i->name << (dir ? " (directory):" : " (file):") << endl;
+ if (dir) {
+ listRecursive(dir, depth);
+ } else {
+ Lines text = file->read();
+ for (Lines::const_iterator j = text.begin(); j != text.end(); ++j)
+ cout << indent << "\t" << *j << endl;
+ }
+ }
+}
+
class FilesystemClient : public Ice::Application
{
public:
@@ -79,7 +104,7 @@ FilesystemClient::run(int argc, char* argv[])
}
catch(const NameInUse&)
{
- NodeDesc desc = rootDir->resolve("Coleridge");
+ NodeDesc desc = rootDir->find("Coleridge");
coleridge = DirectoryPrx::checkedCast(desc.proxy);
assert(coleridge);
}
@@ -107,31 +132,16 @@ FilesystemClient::run(int argc, char* argv[])
}
cout << "Contents of filesystem:" << endl;
- NodeDict contents = rootDir->list(RecursiveList);
- NodeDict::iterator p;
- for(p = contents.begin(); p != contents.end(); ++p)
- {
- cout << " " << p->first << endl;
- }
-
- NodeDesc desc = rootDir->resolve("Coleridge/Kubla_Khan");
- FilePrx file = FilePrx::checkedCast(desc.proxy);
- assert(file);
- Lines text = file->read();
- cout << "Contents of file Coleridge/Kubla_Khan:" << endl;
- for(Lines::iterator i = text.begin(); i != text.end(); ++i)
- {
- cout << " " << *i << endl;
- }
+ listRecursive(rootDir);
//
// Destroy the filesystem.
//
- contents = rootDir->list(NormalList);
- for(p = contents.begin(); p != contents.end(); ++p)
+ NodeDescSeq contents = rootDir->list();
+ for(NodeDescSeq::iterator i = contents.begin(); i != contents.end(); ++i)
{
- cout << "Destroying " << p->first << "..." << endl;
- p->second.proxy->destroy();
+ cout << "Destroying " << i->name << endl;
+ i->proxy->destroy();
}
return EXIT_SUCCESS;