diff options
Diffstat (limited to 'cpp/demo/book/simple_filesystem/Client.cpp')
-rw-r--r-- | cpp/demo/book/simple_filesystem/Client.cpp | 50 |
1 files changed, 38 insertions, 12 deletions
diff --git a/cpp/demo/book/simple_filesystem/Client.cpp b/cpp/demo/book/simple_filesystem/Client.cpp index 24865abb023..007e4b11cfa 100644 --- a/cpp/demo/book/simple_filesystem/Client.cpp +++ b/cpp/demo/book/simple_filesystem/Client.cpp @@ -26,16 +26,22 @@ listRecursive(const DirectoryPrx& dir, int depth = 0) NodeSeq contents = dir->list(); - for (NodeSeq::const_iterator i = contents.begin(); i != contents.end(); ++i) { + for(NodeSeq::const_iterator i = contents.begin(); i != contents.end(); ++i) + { DirectoryPrx dir = DirectoryPrx::checkedCast(*i); FilePrx file = FilePrx::uncheckedCast(*i); cout << indent << (*i)->name() << (dir ? " (directory):" : " (file):") << endl; - if (dir) { + if(dir) + { listRecursive(dir, depth); - } else { + } + else + { Lines text = file->read(); - for (Lines::const_iterator j = text.begin(); j != text.end(); ++j) + for(Lines::const_iterator j = text.begin(); j != text.end(); ++j) + { cout << indent << "\t" << *j << endl; + } } } } @@ -45,39 +51,59 @@ main(int argc, char* argv[]) { int status = 0; Ice::CommunicatorPtr ic; - try { + try + { + // // Create a communicator // ic = Ice::initialize(argc, argv); + // // Create a proxy for the root directory // Ice::ObjectPrx base = ic->stringToProxy("RootDir:default -p 10000"); - if (!base) - throw "Could not create proxy"; + // // Down-cast the proxy to a Directory proxy // DirectoryPrx rootDir = DirectoryPrx::checkedCast(base); - if (!rootDir) + if(!rootDir) + { throw "Invalid proxy"; + } + // // Recursively list the contents of the root directory // cout << "Contents of root directory:" << endl; listRecursive(rootDir); - } catch (const Ice::Exception & ex) { + } + catch(const Ice::Exception& ex) + { cerr << ex << endl; status = 1; - } catch (const char * msg) { + } + catch(const char* msg) + { cerr << msg << endl; status = 1; } + // // Clean up // - if (ic) - ic->destroy(); + if(ic) + { + try + { + ic->destroy(); + } + catch(const Ice::Exception& e) + { + cerr << e << endl; + status = 1; + } + } return status; } |