diff options
author | Mark Spruiell <mes@zeroc.com> | 2010-01-05 20:17:33 -0800 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2010-01-05 20:17:33 -0800 |
commit | cf24e681e8c52cd20d81fe750ff258e67ee65734 (patch) | |
tree | 8411820ce3a257272d6ffa0d3dcdab9ce106609a /cpp | |
parent | Fixed bug 4576 - add NPTL options only on Rhel4 (diff) | |
download | ice-cf24e681e8c52cd20d81fe750ff258e67ee65734.tar.bz2 ice-cf24e681e8c52cd20d81fe750ff258e67ee65734.tar.xz ice-cf24e681e8c52cd20d81fe750ff258e67ee65734.zip |
bug 4495 - clean up book demos
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/demo/book/evictor_filesystem/Client.cpp | 13 | ||||
-rw-r--r-- | cpp/demo/book/evictor_filesystem/Parser.h | 2 | ||||
-rw-r--r-- | cpp/demo/book/evictor_filesystem/PersistentFilesystemI.cpp | 10 | ||||
-rw-r--r-- | cpp/demo/book/lifecycle/Client.cpp | 10 | ||||
-rw-r--r-- | cpp/demo/book/lifecycle/FilesystemI.cpp | 1 | ||||
-rw-r--r-- | cpp/demo/book/lifecycle/FilesystemI.h | 2 | ||||
-rw-r--r-- | cpp/demo/book/lifecycle/Parser.h | 2 | ||||
-rw-r--r-- | cpp/demo/book/lifecycle/Server.cpp | 15 | ||||
-rw-r--r-- | cpp/demo/book/map_filesystem/Client.cpp | 13 | ||||
-rw-r--r-- | cpp/demo/book/map_filesystem/FilesystemI.cpp | 8 | ||||
-rw-r--r-- | cpp/demo/book/map_filesystem/FilesystemI.h | 4 | ||||
-rw-r--r-- | cpp/demo/book/map_filesystem/Server.cpp | 7 | ||||
-rw-r--r-- | cpp/demo/book/printer/Client.cpp | 28 | ||||
-rw-r--r-- | cpp/demo/book/printer/Server.cpp | 38 | ||||
-rw-r--r-- | cpp/demo/book/simple_filesystem/Client.cpp | 50 | ||||
-rw-r--r-- | cpp/demo/book/simple_filesystem/FilesystemI.h | 26 | ||||
-rw-r--r-- | cpp/demo/book/simple_filesystem/Server.cpp | 26 |
17 files changed, 161 insertions, 94 deletions
diff --git a/cpp/demo/book/evictor_filesystem/Client.cpp b/cpp/demo/book/evictor_filesystem/Client.cpp index ee09e42dcbd..e50a92a50bb 100644 --- a/cpp/demo/book/evictor_filesystem/Client.cpp +++ b/cpp/demo/book/evictor_filesystem/Client.cpp @@ -26,19 +26,12 @@ public: { } - virtual int run(int, char * []) { - - // Create a proxy for the root directory + virtual int run(int, char*[]) + { // - Ice::ObjectPrx base = communicator()->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); + DirectoryPrx rootDir = DirectoryPrx::checkedCast(communicator()->propertyToProxy("RootDir.Proxy")); if(!rootDir) { throw "Invalid proxy"; diff --git a/cpp/demo/book/evictor_filesystem/Parser.h b/cpp/demo/book/evictor_filesystem/Parser.h index 648812abfaa..091de235481 100644 --- a/cpp/demo/book/evictor_filesystem/Parser.h +++ b/cpp/demo/book/evictor_filesystem/Parser.h @@ -46,6 +46,7 @@ typedef IceUtil::Handle<Parser> ParserPtr; class Parser : public IceUtil::SimpleShared { public: + Parser(const Filesystem::DirectoryPrx&); void usage(); @@ -72,6 +73,7 @@ public: int parse(bool = false); private: + ::std::list<Filesystem::DirectoryPrx> _dirs; bool _continue; diff --git a/cpp/demo/book/evictor_filesystem/PersistentFilesystemI.cpp b/cpp/demo/book/evictor_filesystem/PersistentFilesystemI.cpp index 4813ca17573..95e62606da5 100644 --- a/cpp/demo/book/evictor_filesystem/PersistentFilesystemI.cpp +++ b/cpp/demo/book/evictor_filesystem/PersistentFilesystemI.cpp @@ -40,11 +40,11 @@ Filesystem::FileI::destroy(const Ice::Current& c) { IceUtil::Mutex::Lock lock(_mutex); - if(_destroyed) - { - throw Ice::ObjectNotExistException(__FILE__, __LINE__, c.id, c.facet, c.operation); - } - _destroyed = true; + if(_destroyed) + { + throw Ice::ObjectNotExistException(__FILE__, __LINE__, c.id, c.facet, c.operation); + } + _destroyed = true; } // diff --git a/cpp/demo/book/lifecycle/Client.cpp b/cpp/demo/book/lifecycle/Client.cpp index 7bc228ee012..1576da83e91 100644 --- a/cpp/demo/book/lifecycle/Client.cpp +++ b/cpp/demo/book/lifecycle/Client.cpp @@ -26,16 +26,14 @@ public: { } - virtual int run(int, char * []) { - + virtual int run(int, char*[]) + { + // // Create a proxy for the root directory // Ice::ObjectPrx base = communicator()->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); diff --git a/cpp/demo/book/lifecycle/FilesystemI.cpp b/cpp/demo/book/lifecycle/FilesystemI.cpp index c48ba2f227d..89aaf6a2808 100644 --- a/cpp/demo/book/lifecycle/FilesystemI.cpp +++ b/cpp/demo/book/lifecycle/FilesystemI.cpp @@ -43,6 +43,7 @@ FilesystemI::NodeI::id() const FilesystemI::NodeI::NodeI(const string& name, const DirectoryIPtr& parent) : _name(name), _parent(parent), _destroyed(false) { + // // Create an identity. The root directory has the fixed identity "RootDir". // if(parent != 0) diff --git a/cpp/demo/book/lifecycle/FilesystemI.h b/cpp/demo/book/lifecycle/FilesystemI.h index e8abc5b9978..ce55c799c0e 100644 --- a/cpp/demo/book/lifecycle/FilesystemI.h +++ b/cpp/demo/book/lifecycle/FilesystemI.h @@ -37,7 +37,6 @@ namespace FilesystemI Ice::Identity _id; IceUtil::Mutex _m; }; - typedef IceUtil::Handle<NodeI> NodeIPtr; class FileI : virtual public Filesystem::File, virtual public NodeI @@ -54,7 +53,6 @@ namespace FilesystemI Filesystem::Lines _lines; }; - typedef IceUtil::Handle<FileI> FileIPtr; class DirectoryI : virtual public NodeI, virtual public Filesystem::Directory diff --git a/cpp/demo/book/lifecycle/Parser.h b/cpp/demo/book/lifecycle/Parser.h index 648812abfaa..091de235481 100644 --- a/cpp/demo/book/lifecycle/Parser.h +++ b/cpp/demo/book/lifecycle/Parser.h @@ -46,6 +46,7 @@ typedef IceUtil::Handle<Parser> ParserPtr; class Parser : public IceUtil::SimpleShared { public: + Parser(const Filesystem::DirectoryPrx&); void usage(); @@ -72,6 +73,7 @@ public: int parse(bool = false); private: + ::std::list<Filesystem::DirectoryPrx> _dirs; bool _continue; diff --git a/cpp/demo/book/lifecycle/Server.cpp b/cpp/demo/book/lifecycle/Server.cpp index 88445a1bb4e..317b4388fe1 100644 --- a/cpp/demo/book/lifecycle/Server.cpp +++ b/cpp/demo/book/lifecycle/Server.cpp @@ -14,19 +14,24 @@ using namespace std; using namespace Filesystem; using namespace FilesystemI; -class FilesystemApp : virtual public Ice::Application { +class FilesystemApp : virtual public Ice::Application +{ public: - virtual int run(int, char* []) { + + virtual int run(int, char*[]) + { + // // Terminate cleanly on receipt of a signal // shutdownOnInterrupt(); + // // Create an object adapter. // Ice::ObjectAdapterPtr adapter = - communicator()->createObjectAdapterWithEndpoints( - "SimpleFilesystem", "default -h 127.0.0.1 -p 10000"); + communicator()->createObjectAdapterWithEndpoints("SimpleFilesystem", "default -h 127.0.0.1 -p 10000"); + // // Create the root directory. // DirectoryIPtr root = new DirectoryI; @@ -34,10 +39,12 @@ public: id.name = "RootDir"; adapter->add(root, id); + // // All objects are created, allow client requests now. // adapter->activate(); + // // Wait until we are done. // communicator()->waitForShutdown(); diff --git a/cpp/demo/book/map_filesystem/Client.cpp b/cpp/demo/book/map_filesystem/Client.cpp index 3dd084104a4..5f0a29bc17b 100644 --- a/cpp/demo/book/map_filesystem/Client.cpp +++ b/cpp/demo/book/map_filesystem/Client.cpp @@ -27,19 +27,12 @@ public: { } - virtual int run(int, char * []) { - - // Create a proxy for the root directory + virtual int run(int, char*[]) + { // - Ice::ObjectPrx base = communicator()->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); + DirectoryPrx rootDir = DirectoryPrx::checkedCast(communicator()->propertyToProxy("RootDir.Proxy")); if(!rootDir) { throw "Invalid proxy"; diff --git a/cpp/demo/book/map_filesystem/FilesystemI.cpp b/cpp/demo/book/map_filesystem/FilesystemI.cpp index f37dcf8fdd7..d9ee20a6b55 100644 --- a/cpp/demo/book/map_filesystem/FilesystemI.cpp +++ b/cpp/demo/book/map_filesystem/FilesystemI.cpp @@ -120,6 +120,7 @@ FileI::destroy(const Ice::Current& c) { try { + // // The transaction is necessary since we are altering two // records in one atomic action. // @@ -178,6 +179,7 @@ DirectoryI::DirectoryI(const Ice::CommunicatorPtr& communicator, const string& e const Freeze::ConnectionPtr connection = Freeze::createConnection(_communicator, _envName); IdentityDirectoryEntryMap dirDB(connection, directoriesDB()); + // // Create the record for the root directory if necessary. // for(;;) @@ -250,8 +252,7 @@ DirectoryI::list(const Ice::Current& c) throw Ice::ObjectNotExistException(__FILE__, __LINE__); } NodeDescSeq result; - for(StringNodeDescDict::const_iterator q = p->second.nodes.begin(); - q != p->second.nodes.end(); ++q) + for(StringNodeDescDict::const_iterator q = p->second.nodes.begin(); q != p->second.nodes.end(); ++q) { result.push_back(q->second); } @@ -311,6 +312,7 @@ DirectoryI::createDirectory(const string& name, const Ice::Current& c) { try { + // // The transaction is necessary since we are altering two // records in one atomic action. // @@ -371,6 +373,7 @@ DirectoryI::createFile(const string& name, const Ice::Current& c) { try { + // // The transaction is necessary since we are altering two // records in one atomic action. // @@ -431,6 +434,7 @@ DirectoryI::destroy(const Ice::Current& c) { try { + // // The transaction is necessary since we are altering two // records in one atomic action. // diff --git a/cpp/demo/book/map_filesystem/FilesystemI.h b/cpp/demo/book/map_filesystem/FilesystemI.h index 6eab56d3eeb..769cf4ad422 100644 --- a/cpp/demo/book/map_filesystem/FilesystemI.h +++ b/cpp/demo/book/map_filesystem/FilesystemI.h @@ -7,8 +7,8 @@ // // ********************************************************************** -#ifndef PERSISTENT_FILESYSTEM_I_H -#define PERSISTENT_FILESYSTEM_I_H +#ifndef FILESYSTEM_I_H +#define FILESYSTEM_I_H #include <Filesystem.h> #include <Freeze/Freeze.h> diff --git a/cpp/demo/book/map_filesystem/Server.cpp b/cpp/demo/book/map_filesystem/Server.cpp index 2897afc6458..76d2cd30168 100644 --- a/cpp/demo/book/map_filesystem/Server.cpp +++ b/cpp/demo/book/map_filesystem/Server.cpp @@ -28,14 +28,17 @@ public: virtual int run(int, char*[]) { + // // Terminate cleanly on receipt of a signal // shutdownOnInterrupt(); + // // Create an object adapter // Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("MapFilesystem"); + // // Open a connection to the files and directories database. This should remain open // for the duration of the application for performance reasons. // @@ -43,19 +46,23 @@ public: const IdentityFileEntryMap fileDB(connection, FileI::filesDB()); const IdentityDirectoryEntryMap dirDB(connection, DirectoryI::directoriesDB()); + // // Add default servants for the file and directory. // adapter->addDefaultServant(new FileI(communicator(), _envName), "file"); adapter->addDefaultServant(new DirectoryI(communicator(), _envName), ""); + // // Ready to accept requests now // adapter->activate(); + // // Wait until we are done // communicator()->waitForShutdown(); + // // Clean up // if(interrupted()) diff --git a/cpp/demo/book/printer/Client.cpp b/cpp/demo/book/printer/Client.cpp index e7190622a6b..7a2d07297e0 100644 --- a/cpp/demo/book/printer/Client.cpp +++ b/cpp/demo/book/printer/Client.cpp @@ -18,26 +18,36 @@ main(int argc, char * argv[]) { int status = 0; Ice::CommunicatorPtr ic; - try { + try + { ic = Ice::initialize(argc, argv); - Ice::ObjectPrx base = ic->stringToProxy( - "SimplePrinter:default -p 10000"); + Ice::ObjectPrx base = ic->stringToProxy("SimplePrinter:default -p 10000"); PrinterPrx printer = PrinterPrx::checkedCast(base); - if (!printer) + if(!printer) + { throw "Invalid proxy"; + } printer->printString("Hello World!"); - } 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; } - if (ic) { - try { + if(ic) + { + try + { ic->destroy(); - } catch (const Ice::Exception & ex) { + } + catch (const Ice::Exception& ex) + { cerr << ex << endl; status = 1; } diff --git a/cpp/demo/book/printer/Server.cpp b/cpp/demo/book/printer/Server.cpp index c4330b12499..e5018cc82ab 100644 --- a/cpp/demo/book/printer/Server.cpp +++ b/cpp/demo/book/printer/Server.cpp @@ -13,15 +13,16 @@ using namespace std; using namespace Demo; -class PrinterI : public Printer { +class PrinterI : public Printer +{ public: - virtual void printString(const string & s, - const Ice::Current &); + + virtual void printString(const string &, const Ice::Current&); }; void PrinterI:: -printString(const string & s, const Ice::Current &) +printString(const string &s, const Ice::Current&) { cout << s << endl; } @@ -31,27 +32,34 @@ main(int argc, char* argv[]) { int status = 0; Ice::CommunicatorPtr ic; - try { + try + { ic = Ice::initialize(argc, argv); - Ice::ObjectAdapterPtr adapter - = ic->createObjectAdapterWithEndpoints( - "SimplePrinterAdapter", "default -p 10000"); + Ice::ObjectAdapterPtr adapter = + ic->createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -p 10000"); Ice::ObjectPtr object = new PrinterI; - adapter->add(object, - ic->stringToIdentity("SimplePrinter")); + adapter->add(object, ic->stringToIdentity("SimplePrinter")); adapter->activate(); ic->waitForShutdown(); - } catch (const Ice::Exception & e) { + } + catch(const Ice::Exception& e) + { cerr << e << endl; status = 1; - } catch (const char * msg) { + } + catch(const char* msg) + { cerr << msg << endl; status = 1; } - if (ic) { - try { + if(ic) + { + try + { ic->destroy(); - } catch (const Ice::Exception & e) { + } + catch(const Ice::Exception& e) + { cerr << e << endl; status = 1; } 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; } diff --git a/cpp/demo/book/simple_filesystem/FilesystemI.h b/cpp/demo/book/simple_filesystem/FilesystemI.h index e848eb55062..5bf02a3c1dd 100644 --- a/cpp/demo/book/simple_filesystem/FilesystemI.h +++ b/cpp/demo/book/simple_filesystem/FilesystemI.h @@ -13,46 +13,54 @@ #include <Ice/Ice.h> #include <Filesystem.h> -namespace Filesystem { - +namespace Filesystem +{ class DirectoryI; typedef IceUtil::Handle<DirectoryI> DirectoryIPtr; - class NodeI : virtual public Node { + class NodeI : virtual public Node + { public: + virtual std::string name(const Ice::Current&); NodeI(const Ice::CommunicatorPtr&, const std::string&, const DirectoryIPtr&); void activate(const Ice::ObjectAdapterPtr&); + private: + std::string _name; Ice::Identity _id; DirectoryIPtr _parent; NodeI(const NodeI&); // Copy forbidden void operator=(const NodeI&); // Assignment forbidden }; - typedef IceUtil::Handle<NodeI> NodeIPtr; - class FileI : virtual public File, - virtual public NodeI { + class FileI : virtual public File, virtual public NodeI + { public: + virtual Lines read(const Ice::Current&); virtual void write(const Lines&, const Ice::Current& = Ice::Current()); FileI(const Ice::CommunicatorPtr&, const std::string&, const DirectoryIPtr&); + private: + Lines _lines; }; - typedef IceUtil::Handle<FileI> FileIPtr; - class DirectoryI : virtual public Directory, - virtual public NodeI { + class DirectoryI : virtual public Directory, virtual public NodeI + { public: + virtual NodeSeq list(const Ice::Current&); DirectoryI(const Ice::CommunicatorPtr&, const std::string&, const DirectoryIPtr&); void addChild(const Filesystem::NodePrx&); + private: + Filesystem::NodeSeq _contents; }; } diff --git a/cpp/demo/book/simple_filesystem/Server.cpp b/cpp/demo/book/simple_filesystem/Server.cpp index 5bc72089edb..bde7861d29a 100644 --- a/cpp/demo/book/simple_filesystem/Server.cpp +++ b/cpp/demo/book/simple_filesystem/Server.cpp @@ -13,24 +13,30 @@ using namespace std; using namespace Filesystem; -class FilesystemApp : virtual public Ice::Application { +class FilesystemApp : virtual public Ice::Application +{ public: - virtual int run(int, char*[]) { + + virtual int run(int, char*[]) + { + // // Terminate cleanly on receipt of a signal // shutdownOnInterrupt(); + // // Create an object adapter. // Ice::ObjectAdapterPtr adapter = - communicator()->createObjectAdapterWithEndpoints( - "SimpleFilesystem", "default -h 127.0.0.1 -p 10000"); + communicator()->createObjectAdapterWithEndpoints("SimpleFilesystem", "default -h 127.0.0.1 -p 10000"); + // // Create the root directory (with name "/" and no parent) // DirectoryIPtr root = new DirectoryI(communicator(), "/", 0); root->activate(adapter); + // // Create a file called "README" in the root directory // FileIPtr file = new FileI(communicator(), "README", root); @@ -39,11 +45,13 @@ public: file->write(text); file->activate(adapter); + // // Create a directory called "Coleridge" in the root directory // DirectoryIPtr coleridge = new DirectoryI(communicator(), "Coleridge", root); coleridge->activate(adapter); + // // Create a file called "Kubla_Khan" in the Coleridge directory // file = new FileI(communicator(), "Kubla_Khan", coleridge); @@ -56,20 +64,22 @@ public: file->write(text); file->activate(adapter); + // // All objects are created, allow client requests now // adapter->activate(); + // // Wait until we are done // communicator()->waitForShutdown(); - if (interrupted()) { - cerr << appName() - << ": received signal, shutting down" << endl; + if(interrupted()) + { + cerr << appName() << ": received signal, shutting down" << endl; } return 0; - }; + } }; int |