diff options
author | Marc Laukien <marc@zeroc.com> | 2001-09-17 22:04:17 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2001-09-17 22:04:17 +0000 |
commit | 60f51d6688e98ed87d24e6e9d1f179ca5db8f07a (patch) | |
tree | 7c99579afb6e99ea7a76cc5e564db694bdc6d8aa /cpp/demo | |
parent | fixes (diff) | |
download | ice-60f51d6688e98ed87d24e6e9d1f179ca5db8f07a.tar.bz2 ice-60f51d6688e98ed87d24e6e9d1f179ca5db8f07a.tar.xz ice-60f51d6688e98ed87d24e6e9d1f179ca5db8f07a.zip |
tons of fixes
Diffstat (limited to 'cpp/demo')
-rw-r--r-- | cpp/demo/Freeze/phonebook/Client.cpp | 14 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/Evictor.cpp | 55 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/Evictor.h | 5 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/Grammer.y | 20 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/Parser.cpp | 123 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/Parser.h | 4 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/PhoneBook.ice | 11 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/PhoneBookI.cpp | 89 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/PhoneBookI.h | 5 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/Scanner.l | 16 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/ServantFactory.cpp | 29 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/ServantFactory.h | 20 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/Server.cpp | 24 | ||||
-rw-r--r-- | cpp/demo/Ice/hello/Client.cpp | 10 | ||||
-rw-r--r-- | cpp/demo/Ice/latency/Client.cpp | 10 | ||||
-rw-r--r-- | cpp/demo/Ice/pickle/ServantFactory.cpp | 6 | ||||
-rw-r--r-- | cpp/demo/Ice/pickle/ServantFactory.h | 1 | ||||
-rw-r--r-- | cpp/demo/Ice/value/Client.cpp | 10 | ||||
-rw-r--r-- | cpp/demo/Ice/value/ServantFactory.cpp | 6 | ||||
-rw-r--r-- | cpp/demo/Ice/value/ServantFactory.h | 1 |
20 files changed, 381 insertions, 78 deletions
diff --git a/cpp/demo/Freeze/phonebook/Client.cpp b/cpp/demo/Freeze/phonebook/Client.cpp index 1e9768337fd..56a89f135f9 100644 --- a/cpp/demo/Freeze/phonebook/Client.cpp +++ b/cpp/demo/Freeze/phonebook/Client.cpp @@ -92,9 +92,21 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator) } PropertiesPtr properties = communicator->getProperties(); - std::string ref = properties->getProperty("PhoneBook.PhoneBook"); + const char* refProperty = "PhoneBook.PhoneBook"; + string ref = properties->getProperty(refProperty); + if (ref.empty()) + { + cerr << argv[0] << ": property `" << refProperty << "' not set" << endl; + return EXIT_FAILURE; + } + ObjectPrx base = communicator->stringToProxy(ref); PhoneBookPrx phoneBook = PhoneBookPrx::checkedCast(base); + if (!phoneBook) + { + cerr << argv[0] << ": invalid object reference" << endl; + return EXIT_FAILURE; + } ParserPtr parser = Parser::createParser(communicator, phoneBook); int status = EXIT_SUCCESS; diff --git a/cpp/demo/Freeze/phonebook/Evictor.cpp b/cpp/demo/Freeze/phonebook/Evictor.cpp index 534c09acef4..b74bd5c0711 100644 --- a/cpp/demo/Freeze/phonebook/Evictor.cpp +++ b/cpp/demo/Freeze/phonebook/Evictor.cpp @@ -26,7 +26,7 @@ void Evictor::createObject(const string& identity, const ObjectPtr& servant) { // - // Put the Ice Object in the database. + // Save the new Ice Object to the database. // _db->put(identity, servant); @@ -52,8 +52,7 @@ Evictor::destroyObject(const string& identity) map<string, EvictorEntry>::iterator p = _evictorMap.find(identity); if (p != _evictorMap.end()) { - assert(*(p->second._position) == identity); - _evictorList.erase(p->second._position); + _evictorList.erase(p->second.position); _evictorMap.erase(p); } } @@ -70,15 +69,14 @@ Evictor::locate(const ObjectAdapterPtr&, const string& identity, ObjectPtr&) // Ice Object found in evictor map. Push it to the front of // the evictor list, so that it will be evicted last. // - assert(*(p->second._position) == identity); - _evictorList.erase(p->second._position); + _evictorList.erase(p->second.position); _evictorList.push_front(identity); - p->second._position = _evictorList.begin(); + p->second.position = _evictorList.begin(); // // Return the servant for the Ice Object. // - return p->second._servant; + return p->second.servant; } else { @@ -105,7 +103,7 @@ Evictor::locate(const ObjectAdapterPtr&, const string& identity, ObjectPtr&) // // TODO: That's the only PhoneBook specific stuff! // - EntryI* entry = dynamic_cast<EntryI*>(servant.get()); + EntryIPtr entry = EntryIPtr::dynamicCast(servant); assert(entry); entry->setIdentity(identity); @@ -124,6 +122,24 @@ Evictor::locate(const ObjectAdapterPtr&, const string& identity, ObjectPtr&) void Evictor::finished(const ObjectAdapterPtr&, const string&, const ObjectPtr&, const ObjectPtr&) { + //JTCSyncT<JTCMutex> sync(*this); +} + +void +Evictor::deactivate() +{ + JTCSyncT<JTCMutex> sync(*this); + + // + // Save all Ice Objects in the database upon deactivation, and + // clear the evictor map and list. + // + for (map<string, EvictorEntry>::iterator p = _evictorMap.begin(); p != _evictorMap.end(); ++p) + { + _db->put(*(p->second.position), p->second.servant); + } + _evictorMap.clear(); + _evictorList.clear(); } void @@ -136,14 +152,25 @@ Evictor::evict() if (_evictorMap.size() > _evictorSize) { // - // Evictor size exceeded. Save and remove last element. + // Evictor size exceeded. Remove last element from the evictor list. // string identity = _evictorList.back(); + _evictorList.pop_back(); + + // + // Find corresponding element in the evictor map + // map<string, EvictorEntry>::iterator p = _evictorMap.find(identity); assert(p != _evictorMap.end()); - assert(*(p->second._position) == identity); - _db->put(identity, p->second._servant); - _evictorList.pop_back(); + + // + // Save the evicted Ice Object to the database. + // + _db->put(identity, p->second.servant); + + // + // Remove the element from the evictor map. + // _evictorMap.erase(identity); assert(_evictorMap.size() == _evictorSize); } @@ -158,7 +185,7 @@ Evictor::add(const string& identity, const ObjectPtr& servant) // _evictorList.push_front(identity); EvictorEntry evictorEntry; - evictorEntry._servant = servant; - evictorEntry._position = _evictorList.begin(); + evictorEntry.servant = servant; + evictorEntry.position = _evictorList.begin(); _evictorMap[identity] = evictorEntry; } diff --git a/cpp/demo/Freeze/phonebook/Evictor.h b/cpp/demo/Freeze/phonebook/Evictor.h index 24b994d11f5..f97eb9c030e 100644 --- a/cpp/demo/Freeze/phonebook/Evictor.h +++ b/cpp/demo/Freeze/phonebook/Evictor.h @@ -30,6 +30,7 @@ public: virtual Ice::ObjectPtr locate(const Ice::ObjectAdapterPtr&, const std::string&, Ice::ObjectPtr&); virtual void finished(const Ice::ObjectAdapterPtr&, const std::string&, const Ice::ObjectPtr&, const Ice::ObjectPtr&); + virtual void deactivate(); private: @@ -40,8 +41,8 @@ private: struct EvictorEntry { - Ice::ObjectPtr _servant; - std::list<std::string>::iterator _position; + Ice::ObjectPtr servant; + std::list<std::string>::iterator position; }; std::map<std::string, EvictorEntry> _evictorMap; std::list<std::string> _evictorList; diff --git a/cpp/demo/Freeze/phonebook/Grammer.y b/cpp/demo/Freeze/phonebook/Grammer.y index 9558db43842..996e7b47545 100644 --- a/cpp/demo/Freeze/phonebook/Grammer.y +++ b/cpp/demo/Freeze/phonebook/Grammer.y @@ -32,8 +32,12 @@ yyerror(const char* s) %token TOK_FIND_ENTRIES %token TOK_NEXT_FOUND_ENTRY %token TOK_PRINT_CURRENT +%token TOK_SET_CURRENT_NAME +%token TOK_SET_CURRENT_ADDRESS +%token TOK_SET_CURRENT_PHONE %token TOK_REMOVE_CURRENT %token TOK_LIST_NAMES +%token TOK_SHUTDOWN %token TOK_STRING %% @@ -87,6 +91,18 @@ command { parser->printCurrent(); } +| TOK_SET_CURRENT_NAME strings ';' +{ + parser->setCurrentName($2); +} +| TOK_SET_CURRENT_ADDRESS strings ';' +{ + parser->setCurrentAddress($2); +} +| TOK_SET_CURRENT_PHONE strings ';' +{ + parser->setCurrentPhone($2); +} | TOK_REMOVE_CURRENT ';' { parser->removeCurrent(); @@ -95,6 +111,10 @@ command { parser->listNames(); } +| TOK_SHUTDOWN ';' +{ + parser->shutdown(); +} | error ';' { yyerrok; diff --git a/cpp/demo/Freeze/phonebook/Parser.cpp b/cpp/demo/Freeze/phonebook/Parser.cpp index b0acf0e686b..8d0b1c02303 100644 --- a/cpp/demo/Freeze/phonebook/Parser.cpp +++ b/cpp/demo/Freeze/phonebook/Parser.cpp @@ -27,16 +27,19 @@ void Parser::usage() { cout << - "help Print this message.\n" - "exit, quit Exit this program.\n" - "add names... Create new entries in the phonebooks.\n" - "find name Find all entries in the phonebook that match the given name.\n" - " Set the current entry to the first one found.\n" - "next Set the current entry to the next one that was found.\n" - "current Display the current entry.\n" - "remove Permanently remove the current entry from the phonebook.\n" - "list List all names in the phonebook.\n" - << endl; + "help Print this message.\n" + "exit, quit Exit this program.\n" + "add NAMES... Create new entries for NAMES in the phonebook.\n" + "find NAME Find all entries in the phonebook that match NAME.\n" + " Set the current entry to the first one found.\n" + "next Set the current entry to the next one that was found.\n" + "current Display the current entry.\n" + "name NAME Set the name for the current entry to NAME.\n" + "address ADDRESS Set the address for the current entry to ADDRESS.\n" + "phone PHONE Set the phone number for the current entry to PHONE.\n" + "remove Permanently remove the current entry from the phonebook.\n" + "list List all names in the phonebook.\n" + "shutdown Shut the phonebook server down.\n"; } ParserPtr @@ -50,8 +53,7 @@ Parser::addEntries(const std::list<std::string>& args) { if (args.empty()) { - error("`add' requires at least one name as argument\n" - "(type `help' for more info)"); + error("`add' requires at least one rgument (type `help' for more info)"); return; } @@ -75,8 +77,7 @@ Parser::findEntries(const std::list<std::string>& args) { if (args.size() != 1) { - error("`find' requires exactly one name as argument\n" - "(type `help' for more info)"); + error("`find' requires exactly one argument (type `help' for more info)"); return; } @@ -127,6 +128,87 @@ Parser::printCurrent() } void +Parser::setCurrentName(const std::list<std::string>& args) +{ + if (args.size() != 1) + { + error("`name' requires exactly one argument (type `help' for more info)"); + return; + } + + try + { + if (_current != _foundEntries.end()) + { + (*_current)->setName(args.front()); + cout << "changed name to `" << args.front() << "'" << endl; + } + else + { + cout << "no current entry" << endl; + } + } + catch(const LocalException& ex) + { + error(ex.toString()); + } +} + +void +Parser::setCurrentAddress(const std::list<std::string>& args) +{ + if (args.size() != 1) + { + error("`address' requires exactly one argument (type `help' for more info)"); + return; + } + + try + { + if (_current != _foundEntries.end()) + { + (*_current)->setAddress(args.front()); + cout << "changed address to `" << args.front() << "'" << endl; + } + else + { + cout << "no current entry" << endl; + } + } + catch(const LocalException& ex) + { + error(ex.toString()); + } +} + +void +Parser::setCurrentPhone(const std::list<std::string>& args) +{ + if (args.size() != 1) + { + error("`phone' requires exactly one argument (type `help' for more info)"); + return; + } + + try + { + if (_current != _foundEntries.end()) + { + (*_current)->setPhone(args.front()); + cout << "changed phone number to `" << args.front() << "'" << endl; + } + else + { + cout << "no current entry" << endl; + } + } + catch(const LocalException& ex) + { + error(ex.toString()); + } +} + +void Parser::removeCurrent() { try @@ -165,6 +247,19 @@ Parser::listNames() } void +Parser::shutdown() +{ + try + { + _phoneBook->shutdown(); + } + catch(const LocalException& ex) + { + error(ex.toString()); + } +} + +void Parser::getInput(char* buf, int& result, int maxSize) { if (!_commands.empty()) diff --git a/cpp/demo/Freeze/phonebook/Parser.h b/cpp/demo/Freeze/phonebook/Parser.h index 0571cba93a3..64d087e682e 100644 --- a/cpp/demo/Freeze/phonebook/Parser.h +++ b/cpp/demo/Freeze/phonebook/Parser.h @@ -58,8 +58,12 @@ public: void findEntries(const std::list<std::string>&); void nextFoundEntry(); void printCurrent(); + void setCurrentName(const std::list<std::string>&); + void setCurrentAddress(const std::list<std::string>&); + void setCurrentPhone(const std::list<std::string>&); void removeCurrent(); void listNames(); + void shutdown(); void getInput(char*, int&, int); void nextLine(); diff --git a/cpp/demo/Freeze/phonebook/PhoneBook.ice b/cpp/demo/Freeze/phonebook/PhoneBook.ice index 21eff50518a..d50297a9a53 100644 --- a/cpp/demo/Freeze/phonebook/PhoneBook.ice +++ b/cpp/demo/Freeze/phonebook/PhoneBook.ice @@ -13,13 +13,13 @@ class Entry { - string getName(); + nonmutating string getName(); void setName(string name); - string getAddress(); + nonmutating string getAddress(); void setAddress(string address); - string getPhone(); + nonmutating string getPhone(); void setPhone(string phone); void destroy(); @@ -37,8 +37,9 @@ sequence<string> Names; class PhoneBook { Entry* createEntry(); - Entries findEntries(string name); - Names getAllNames(); + nonmutating Entries findEntries(string name); + nonmutating Names getAllNames(); + void shutdown(); NameIdentitiesDict _nameIdentitiesDict; }; diff --git a/cpp/demo/Freeze/phonebook/PhoneBookI.cpp b/cpp/demo/Freeze/phonebook/PhoneBookI.cpp index fe9b66ecd4d..f4ecf6742fa 100644 --- a/cpp/demo/Freeze/phonebook/PhoneBookI.cpp +++ b/cpp/demo/Freeze/phonebook/PhoneBookI.cpp @@ -38,6 +38,7 @@ void EntryI::setName(const string& name) { JTCSyncT<JTCMutex> sync(*this); // TODO: Reader/Writer lock + assert(!_identity.empty()); _phoneBook->move(_identity, _name, name); _name = name; } @@ -74,6 +75,7 @@ void EntryI::destroy() { JTCSyncT<JTCMutex> sync(*this); // TODO: Reader/Writer lock + assert(!_identity.empty()); _phoneBook->remove(_identity, _name); _evictor->destroyObject(_identity); } @@ -85,30 +87,6 @@ PhoneBookI::PhoneBookI(const ObjectAdapterPtr& adapter, const EvictorPtr& evicto { } -EntryPrx -PhoneBookI::createEntry() -{ - JTCSyncT<JTCRecursiveMutex> sync(*this); // TODO: Reader/Writer lock - - -#ifdef WIN32 // COMPILERBUG - char s[20]; - sprintf(s, "%I64d", _nextEntryIdentity++); - string identity = s; -#else - ostringstream s; - s << _nextEntryIdentity++; - string identity = s.str(); -#endif - - EntryPtr entry = new EntryI(this, _evictor); - _evictor->createObject(identity, entry); - - add(identity, ""); - - return EntryPrx::uncheckedCast(_adapter->createProxy(identity)); -} - class IdentityToEntry { public: @@ -128,11 +106,59 @@ private: ObjectAdapterPtr _adapter; }; +EntryPrx +PhoneBookI::createEntry() +{ + JTCSyncT<JTCRecursiveMutex> sync(*this); // TODO: Reader/Writer lock + + // + // Get a unique ID + // + string identity = "phonebook.entry#"; +#ifdef WIN32 // COMPILERBUG + char s[20]; + sprintf(s, "%I64d", _nextEntryIdentity++); + identity += s; +#else + ostringstream s; + s << _nextEntryIdentity++; + identity += s.str(); +#endif + + // + // Create a new entry Servant. + // + EntryIPtr entry = new EntryI(this, _evictor); + entry->setIdentity(identity); + + // + // Create a new Ice Object in the evictor, using the new identity + // and the new Servant. + // + _evictor->createObject(identity, entry); + + // + // Add identity to our name/identity map. The initial name is the + // empty string. + // + _nameIdentitiesDict[""].push_back(identity); + + // + // Turn the identity into a Proxy and return the Proxy to the + // caller. + // + return IdentityToEntry(_adapter)(identity); +} + Entries PhoneBookI::findEntries(const string& name) { JTCSyncT<JTCRecursiveMutex> sync(*this); // TODO: Reader/Writer lock + // + // Lookup all phone book entries that match a name, and return + // them to the caller. + // NameIdentitiesDict::iterator p = _nameIdentitiesDict.find(name); if (p != _nameIdentitiesDict.end()) { @@ -152,6 +178,9 @@ PhoneBookI::getAllNames() { JTCSyncT<JTCRecursiveMutex> sync(*this); // TODO: Reader/Writer lock + // + // Get all names from this phone book. + // Names names; for (NameIdentitiesDict::iterator p = _nameIdentitiesDict.begin(); p != _nameIdentitiesDict.end(); ++p) { @@ -169,11 +198,11 @@ PhoneBookI::getAllNames() } void -PhoneBookI::add(const string& identity, const string& name) +PhoneBookI::shutdown() { JTCSyncT<JTCRecursiveMutex> sync(*this); // TODO: Reader/Writer lock - _nameIdentitiesDict[name].push_back(identity); + _adapter->getCommunicator()->shutdown(); } void @@ -181,6 +210,9 @@ PhoneBookI::remove(const string& identity, const string& name) { JTCSyncT<JTCRecursiveMutex> sync(*this); // TODO: Reader/Writer lock + // + // Called by EntryI to remove itself from the phone book. + // NameIdentitiesDict::iterator p = _nameIdentitiesDict.find(name); assert(p != _nameIdentitiesDict.end()); p->second.erase(remove_if(p->second.begin(), p->second.end(), bind2nd(equal_to<string>(), identity)), @@ -192,6 +224,9 @@ PhoneBookI::move(const string& identity, const string& oldName, const string& ne { JTCSyncT<JTCRecursiveMutex> sync(*this); // TODO: Reader/Writer lock + // + // Called by EntryI in case the name has been changed. + // remove(identity, oldName); - add(identity, newName); + _nameIdentitiesDict[newName].push_back(identity); } diff --git a/cpp/demo/Freeze/phonebook/PhoneBookI.h b/cpp/demo/Freeze/phonebook/PhoneBookI.h index a708f463243..5385c76383c 100644 --- a/cpp/demo/Freeze/phonebook/PhoneBookI.h +++ b/cpp/demo/Freeze/phonebook/PhoneBookI.h @@ -20,6 +20,9 @@ class PhoneBookI; typedef IceUtil::Handle<PhoneBookI> PhoneBookIPtr; +class EntryI; +typedef IceUtil::Handle<EntryI> EntryIPtr; + class EntryI : public Entry, public JTCMutex { public: @@ -55,8 +58,8 @@ public: virtual EntryPrx createEntry(); virtual Entries findEntries(const std::string&); virtual Names getAllNames(); + virtual void shutdown(); - void add(const std::string&, const std::string&); void remove(const std::string&, const std::string&); void move(const std::string&, const std::string&, const std::string&); diff --git a/cpp/demo/Freeze/phonebook/Scanner.l b/cpp/demo/Freeze/phonebook/Scanner.l index 5d010509236..6f2e35834f8 100644 --- a/cpp/demo/Freeze/phonebook/Scanner.l +++ b/cpp/demo/Freeze/phonebook/Scanner.l @@ -207,6 +207,18 @@ L [a-zA-Z_] return TOK_PRINT_CURRENT; } +"name" { + return TOK_SET_CURRENT_NAME; +} + +"address" { + return TOK_SET_CURRENT_ADDRESS; +} + +"phone" { + return TOK_SET_CURRENT_PHONE; +} + "remove" { return TOK_REMOVE_CURRENT; } @@ -215,6 +227,10 @@ L [a-zA-Z_] return TOK_LIST_NAMES; } +"shutdown" { + return TOK_SHUTDOWN; +} + {WS}*(\\{WS}*{NL})? { int len = strlen(yytext); for (int i = 0; i < len; ++i) diff --git a/cpp/demo/Freeze/phonebook/ServantFactory.cpp b/cpp/demo/Freeze/phonebook/ServantFactory.cpp index fc7e1d97a86..d00ff8098a5 100644 --- a/cpp/demo/Freeze/phonebook/ServantFactory.cpp +++ b/cpp/demo/Freeze/phonebook/ServantFactory.cpp @@ -12,15 +12,40 @@ using namespace std; -ServantFactory::ServantFactory(const PhoneBookIPtr& phoneBook, const EvictorPtr& evictor) : +PhoneBookFactory::PhoneBookFactory(const Ice::ObjectAdapterPtr& adapter, const EvictorPtr& evictor) : + _adapter(adapter), + _evictor(evictor) +{ +} + +Ice::ObjectPtr +PhoneBookFactory::create(const string& type) +{ + assert(type == "::PhoneBook"); + return new PhoneBookI(_adapter, _evictor); +} + +void +PhoneBookFactory::destroy() +{ + // Nothing to do +} + +EntryFactory::EntryFactory(const PhoneBookIPtr& phoneBook, const EvictorPtr& evictor) : _phoneBook(phoneBook), _evictor(evictor) { } Ice::ObjectPtr -ServantFactory::create(const string& type) +EntryFactory::create(const string& type) { assert(type == "::Entry"); return new EntryI(_phoneBook, _evictor); } + +void +EntryFactory::destroy() +{ + // Nothing to do +} diff --git a/cpp/demo/Freeze/phonebook/ServantFactory.h b/cpp/demo/Freeze/phonebook/ServantFactory.h index 75c2708c37b..569d968c648 100644 --- a/cpp/demo/Freeze/phonebook/ServantFactory.h +++ b/cpp/demo/Freeze/phonebook/ServantFactory.h @@ -13,13 +13,29 @@ #include <PhoneBookI.h> -class ServantFactory : public Ice::ServantFactory +class PhoneBookFactory : public Ice::ServantFactory { public: - ServantFactory(const PhoneBookIPtr&, const EvictorPtr&); + PhoneBookFactory(const Ice::ObjectAdapterPtr&, const EvictorPtr&); virtual Ice::ObjectPtr create(const std::string&); + virtual void destroy(); + +private: + + Ice::ObjectAdapterPtr _adapter; + EvictorPtr _evictor; +}; + +class EntryFactory : public Ice::ServantFactory +{ +public: + + EntryFactory(const PhoneBookIPtr&, const EvictorPtr&); + + virtual Ice::ObjectPtr create(const std::string&); + virtual void destroy(); private: diff --git a/cpp/demo/Freeze/phonebook/Server.cpp b/cpp/demo/Freeze/phonebook/Server.cpp index a36090d29cf..ff411e46d44 100644 --- a/cpp/demo/Freeze/phonebook/Server.cpp +++ b/cpp/demo/Freeze/phonebook/Server.cpp @@ -19,18 +19,34 @@ int run(int argc, char* argv[], const CommunicatorPtr& communicator, const DBEnvPtr& dbenv) { ObjectAdapterPtr adapter = communicator->createObjectAdapter("PhoneBookAdapter"); - DBPtr db = dbenv->open("entries"); + DBPtr db = dbenv->open("phonebook"); EvictorPtr evictor = new Evictor(db, 3); // TODO: Evictor size must be configurable adapter->setServantLocator(evictor); - PhoneBookIPtr phoneBook = new PhoneBookI(adapter, evictor); + ServantFactoryPtr phoneBookFactory = new PhoneBookFactory(adapter, evictor); + communicator->installServantFactory(phoneBookFactory, "::PhoneBook"); + + PhoneBookIPtr phoneBook; + ObjectPtr servant = db->get("phonebook"); + if (!servant) + { + PhoneBookIPtr phoneBook = new PhoneBookI(adapter, evictor); + } + else + { + phoneBook = PhoneBookIPtr::dynamicCast(servant); + } + assert(phoneBook); adapter->add(phoneBook, "phonebook"); - ServantFactoryPtr factory = new ::ServantFactory(phoneBook, evictor); - communicator->installServantFactory(factory, "::Entry"); + ServantFactoryPtr entryFactory = new EntryFactory(phoneBook, evictor); + communicator->installServantFactory(entryFactory, "::Entry"); adapter->activate(); communicator->waitForShutdown(); + + db->put("phonebook", phoneBook); + return EXIT_SUCCESS; } diff --git a/cpp/demo/Ice/hello/Client.cpp b/cpp/demo/Ice/hello/Client.cpp index ecc5680cd77..f02cc612d48 100644 --- a/cpp/demo/Ice/hello/Client.cpp +++ b/cpp/demo/Ice/hello/Client.cpp @@ -35,9 +35,15 @@ int run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) { Ice::PropertiesPtr properties = communicator->getProperties(); - std::string ref = properties->getProperty("Hello.Hello"); - Ice::ObjectPrx base = communicator->stringToProxy(ref); + const char* refProperty = "Hello.Hello"; + std::string ref = properties->getProperty(refProperty); + if (ref.empty()) + { + cerr << argv[0] << ": property `" << refProperty << "' not set" << endl; + return EXIT_FAILURE; + } + Ice::ObjectPrx base = communicator->stringToProxy(ref); HelloPrx twoway = HelloPrx::checkedCast(base); if (!twoway) { diff --git a/cpp/demo/Ice/latency/Client.cpp b/cpp/demo/Ice/latency/Client.cpp index 78d6734d948..0af75905205 100644 --- a/cpp/demo/Ice/latency/Client.cpp +++ b/cpp/demo/Ice/latency/Client.cpp @@ -22,9 +22,15 @@ int run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) { Ice::PropertiesPtr properties = communicator->getProperties(); - std::string ref = properties->getProperty("Latency.Ping"); - Ice::ObjectPrx base = communicator->stringToProxy(ref); + const char* refProperty = "Latency.Ping"; + std::string ref = properties->getProperty(refProperty); + if (ref.empty()) + { + cerr << argv[0] << ": property `" << refProperty << "' not set" << endl; + return EXIT_FAILURE; + } + Ice::ObjectPrx base = communicator->stringToProxy(ref); PingPrx ping = PingPrx::checkedCast(base); if (!ping) { diff --git a/cpp/demo/Ice/pickle/ServantFactory.cpp b/cpp/demo/Ice/pickle/ServantFactory.cpp index fd34ec210a7..906db19f5cd 100644 --- a/cpp/demo/Ice/pickle/ServantFactory.cpp +++ b/cpp/demo/Ice/pickle/ServantFactory.cpp @@ -20,3 +20,9 @@ ServantFactory::create(const string& type) assert(type == "::Persistent"); return new Persistent; } + +void +ServantFactory::destroy() +{ + // Nothing to do +} diff --git a/cpp/demo/Ice/pickle/ServantFactory.h b/cpp/demo/Ice/pickle/ServantFactory.h index 74493f88848..67931bca3fb 100644 --- a/cpp/demo/Ice/pickle/ServantFactory.h +++ b/cpp/demo/Ice/pickle/ServantFactory.h @@ -16,6 +16,7 @@ class ServantFactory : public Ice::ServantFactory public: virtual Ice::ObjectPtr create(const std::string&); + virtual void destroy(); }; #endif diff --git a/cpp/demo/Ice/value/Client.cpp b/cpp/demo/Ice/value/Client.cpp index 8636b07b94f..246fcceb8bf 100644 --- a/cpp/demo/Ice/value/Client.cpp +++ b/cpp/demo/Ice/value/Client.cpp @@ -18,9 +18,15 @@ int run(int argc, char* argv[], const Ice::CommunicatorPtr& communicator) { Ice::PropertiesPtr properties = communicator->getProperties(); - string ref = properties->getProperty("Value.Initial"); - Ice::ObjectPrx base = communicator->stringToProxy(ref); + const char* refProperty = "Value.Initial"; + std::string ref = properties->getProperty(refProperty); + if (ref.empty()) + { + cerr << argv[0] << ": property `" << refProperty << "' not set" << endl; + return EXIT_FAILURE; + } + Ice::ObjectPrx base = communicator->stringToProxy(ref); InitialPrx initial = InitialPrx::checkedCast(base); if (!initial) { diff --git a/cpp/demo/Ice/value/ServantFactory.cpp b/cpp/demo/Ice/value/ServantFactory.cpp index 6f774c4a014..1f9768c08ed 100644 --- a/cpp/demo/Ice/value/ServantFactory.cpp +++ b/cpp/demo/Ice/value/ServantFactory.cpp @@ -30,3 +30,9 @@ ServantFactory::create(const string& type) assert(false); return 0; } + +void +ServantFactory::destroy() +{ + // Nothing to do +} diff --git a/cpp/demo/Ice/value/ServantFactory.h b/cpp/demo/Ice/value/ServantFactory.h index 74493f88848..67931bca3fb 100644 --- a/cpp/demo/Ice/value/ServantFactory.h +++ b/cpp/demo/Ice/value/ServantFactory.h @@ -16,6 +16,7 @@ class ServantFactory : public Ice::ServantFactory public: virtual Ice::ObjectPtr create(const std::string&); + virtual void destroy(); }; #endif |