diff options
Diffstat (limited to 'cpp')
42 files changed, 609 insertions, 199 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 diff --git a/cpp/include/Ice/Handle.h b/cpp/include/Ice/Handle.h index b66a3023079..b94cd81e079 100644 --- a/cpp/include/Ice/Handle.h +++ b/cpp/include/Ice/Handle.h @@ -30,13 +30,14 @@ namespace IceInternal { template<typename T> -class Handle +class Handle : public ::IceUtil::HandleBase<T> { public: - Handle(T* p = 0) : - _ptr(p) + Handle(T* p = 0) { + _ptr = p; + if (_ptr) { incRef(_ptr); @@ -44,9 +45,10 @@ public: } template<typename Y> - Handle(const Handle<Y>& r) : - _ptr(r._ptr) + Handle(const Handle<Y>& r) { + _ptr = r._ptr; + if (_ptr) { incRef(_ptr); @@ -54,9 +56,10 @@ public: } template<typename Y> - Handle(const ::IceUtil::Handle<Y>& r) : - _ptr(r._ptr) + Handle(const ::IceUtil::Handle<Y>& r) { + _ptr = r._ptr; + if (_ptr) { incRef(_ptr); @@ -65,12 +68,13 @@ public: #ifdef WIN32 // COMPILERBUG: Is VC++ or GNU C++ right here??? template<> - Handle(const Handle<T>& r) : + Handle(const Handle<T>& r) #else - Handle(const Handle& r) : + Handle(const Handle& r) #endif - _ptr(r._ptr) { + _ptr = r._ptr; + if (_ptr) { incRef(_ptr); @@ -169,7 +173,7 @@ public: } template<class Y> - static Handle dynamicCast(const Handle<Y>& r) + static Handle dynamicCast(const ::IceUtil::HandleBase<Y>& r) { return Handle(dynamic_cast<T*>(r._ptr)); } @@ -179,16 +183,6 @@ public: { return Handle(dynamic_cast<T*>(p)); } - - typedef T element_type; - - T* get() const { return _ptr; } - T* operator->() const { return _ptr; } - operator bool() const { return _ptr ? true : false; } - - void swap(Handle& other) { std::swap(_ptr, other._ptr); } - - T* _ptr; }; template<typename T, typename U> diff --git a/cpp/include/IceUtil/Handle.h b/cpp/include/IceUtil/Handle.h index 5def4862568..732fbe03606 100644 --- a/cpp/include/IceUtil/Handle.h +++ b/cpp/include/IceUtil/Handle.h @@ -22,13 +22,30 @@ namespace IceUtil { template<typename T> -class Handle +class HandleBase +{ +public: + + typedef T element_type; + + T* get() const { return _ptr; } + T* operator->() const { return _ptr; } + operator bool() const { return _ptr ? true : false; } + + void swap(HandleBase& other) { std::swap(_ptr, other._ptr); } + + T* _ptr; +}; + +template<typename T> +class Handle : public HandleBase<T> { public: - Handle(T* p = 0) : - _ptr(p) + Handle(T* p = 0) { + _ptr = p; + if (_ptr) { _ptr->__incRef(); @@ -36,9 +53,10 @@ public: } template<typename Y> - Handle(const Handle<Y>& r) : - _ptr(r._ptr) + Handle(const Handle<Y>& r) { + _ptr = r._ptr; + if (_ptr) { _ptr->__incRef(); @@ -47,12 +65,13 @@ public: #ifdef WIN32 // COMPILERBUG: Is VC++ or GNU C++ right here??? template<> - Handle(const Handle<T>& r) : + Handle(const Handle<T>& r) #else - Handle(const Handle& r) : + Handle(const Handle& r) #endif - _ptr(r._ptr) { + _ptr = r._ptr; + if (_ptr) { _ptr->__incRef(); @@ -131,7 +150,7 @@ public: } template<class Y> - static Handle dynamicCast(const Handle<Y>& r) + static Handle dynamicCast(const HandleBase<Y>& r) { return Handle(dynamic_cast<T*>(r._ptr)); } @@ -141,16 +160,6 @@ public: { return Handle(dynamic_cast<T*>(p)); } - - typedef T element_type; - - T* get() const { return _ptr; } - T* operator->() const { return _ptr; } - operator bool() const { return _ptr ? true : false; } - - void swap(Handle& other) { std::swap(_ptr, other._ptr); } - - T* _ptr; }; template<typename T, typename U> diff --git a/cpp/slice/Ice/Logger.ice b/cpp/slice/Ice/Logger.ice index 01c527296c4..cb1f56a4338 100644 --- a/cpp/slice/Ice/Logger.ice +++ b/cpp/slice/Ice/Logger.ice @@ -16,7 +16,7 @@ module Ice /** * - * The Ice message logger. Applications can provide their own logger + * The Ice message logger. Applications can provide their own Logger * by implementing this interface and installing it with with a * Communicator. * @@ -58,6 +58,16 @@ local class Logger * **/ void error(string message); + + /** + * + * Called when the Communicator this Logger is installed with is + * destroyed. + * + * @see Communicator::destroy + * + **/ + void destroy(); }; }; diff --git a/cpp/slice/Ice/ObjectAdapter.ice b/cpp/slice/Ice/ObjectAdapter.ice index 52ada36efba..f214b8ae9a8 100644 --- a/cpp/slice/Ice/ObjectAdapter.ice +++ b/cpp/slice/Ice/ObjectAdapter.ice @@ -282,6 +282,18 @@ local class ServantLocator * **/ void finished(ObjectAdapter adapter, string identity, Object servant, Object cookie); + + /** + * + * Called when the Object Adapter this Servant Locator is + * installed with is deactivated. + * + * @see ObjectAdapter::deactivate + * @see Communicator::shutdown + * @see Communicator::destroy + * + **/ + void deactivate(); }; }; diff --git a/cpp/slice/Ice/ServantFactory.ice b/cpp/slice/Ice/ServantFactory.ice index 3739283bee9..a413032ed12 100644 --- a/cpp/slice/Ice/ServantFactory.ice +++ b/cpp/slice/Ice/ServantFactory.ice @@ -46,6 +46,16 @@ local class ServantFactory * **/ Object create(string type); + + /** + * + * Called when the Communicator this Servant Factory is installed + * with is destroyed. + * + * @see Communicator::destroy + * + **/ + void destroy(); }; }; diff --git a/cpp/src/Freeze/DBI.cpp b/cpp/src/Freeze/DBI.cpp index 4ea2d552ba0..fc8b1510083 100644 --- a/cpp/src/Freeze/DBI.cpp +++ b/cpp/src/Freeze/DBI.cpp @@ -11,6 +11,7 @@ #include <Freeze/DBI.h> #include <Ice/Stream.h> #include <sys/stat.h> +#include <sstream> using namespace std; using namespace Ice; @@ -31,7 +32,10 @@ Freeze::DBI::~DBI() { if (_db) { - _communicator->getLogger()->warning("database has not been closed"); + ostringstream s; + s << "Freeze::DB(\"" << _name << "\"): "; + s << "\"" << _name << "\" has not been closed"; + _communicator->getLogger()->warning(s.str()); } } @@ -47,8 +51,11 @@ Freeze::DBI::put(const std::string& key, const ::Ice::ObjectPtr& servant) if(!_db) { + ostringstream s; + s << "Freeze::DB(\"" << _name << "\"): "; + s << "\"" << _name << "\" has been closed"; DBException ex; - ex.message = "Freeze::DB::open: database has been closed"; + ex.message = s.str(); throw ex; } @@ -77,9 +84,11 @@ Freeze::DBI::put(const std::string& key, const ::Ice::ObjectPtr& servant) ret = txn_begin(_dbenv, 0, &tid, 0); if (ret != 0) { + ostringstream s; + s << "Freeze::DB(\"" << _name << "\"): "; + s << "txn_begin: " << db_strerror(ret); DBException ex; - ex.message = "txn_begin: "; - ex.message += db_strerror(ret); + ex.message = s.str(); throw ex; } @@ -94,9 +103,11 @@ Freeze::DBI::put(const std::string& key, const ::Ice::ObjectPtr& servant) ret = txn_commit(tid, 0); if (ret != 0) { + ostringstream s; + s << "Freeze::DB(\"" << _name << "\"): "; + s << "txn_commit: " << db_strerror(ret); DBException ex; - ex.message = "txn_commit: "; - ex.message += db_strerror(ret); + ex.message = s.str(); throw ex; } return; // We're done @@ -110,9 +121,11 @@ Freeze::DBI::put(const std::string& key, const ::Ice::ObjectPtr& servant) ret = txn_abort(tid); if (ret != 0) { + ostringstream s; + s << "Freeze::DB(\"" << _name << "\"): "; + s << "txn_abort: " << db_strerror(ret); DBException ex; - ex.message = "txn_abort: "; - ex.message += db_strerror(ret); + ex.message = s.str(); throw ex; } break; // Repeat @@ -123,9 +136,11 @@ Freeze::DBI::put(const std::string& key, const ::Ice::ObjectPtr& servant) // // Error, run recovery // + ostringstream s; + s << "Freeze::DB(\"" << _name << "\"): "; + s << "DB->put: " << db_strerror(ret); DBException ex; - ex.message = "DB->put: "; - ex.message += db_strerror(ret); + ex.message = s.str(); throw ex; } } @@ -144,8 +159,11 @@ Freeze::DBI::get(const std::string& key) if(!_db) { + ostringstream s; + s << "Freeze::DB(\"" << _name << "\"): "; + s << "\"" << _name << "\" has been closed"; DBException ex; - ex.message = "Freeze::DB::open: database has been closed"; + ex.message = s.str(); throw ex; } @@ -204,12 +222,11 @@ Freeze::DBI::get(const std::string& key) default: { - // - // Error, run recovery - // + ostringstream s; + s << "Freeze::DB(\"" << _name << "\"): "; + s << "DB->get: " << db_strerror(ret); DBException ex; - ex.message = "DB->get: "; - ex.message += db_strerror(ret); + ex.message = s.str(); throw ex; } } @@ -227,8 +244,11 @@ Freeze::DBI::del(const std::string& key) if(!_db) { + ostringstream s; + s << "Freeze::DB(\"" << _name << "\"): "; + s << "\"" << _name << "\" has been closed"; DBException ex; - ex.message = "Freeze::DB::open: database has been closed"; + ex.message = s.str(); throw ex; } } @@ -246,9 +266,11 @@ Freeze::DBI::close() int ret = _db->close(_db, 0); if(ret != 0) { + ostringstream s; + s << "Freeze::DB(\"" << _name << "\"): "; + s << "DB->close: " << db_strerror(ret); DBException ex; - ex.message = "DB->close: "; - ex.message += db_strerror(ret); + ex.message = s.str(); throw ex; } @@ -263,26 +285,26 @@ Freeze::DBEnvI::DBEnvI(const CommunicatorPtr& communicator, const PropertiesPtr& _properties(properties), _dbenv(0) { + _directory = _properties->getProperty("Freeze.Directory"); + if (_directory.empty()) + { + _directory = "."; + } + int ret; ret = db_env_create(&_dbenv, 0); if (ret != 0) { + ostringstream s; + s << "Freeze::DBEnv(\"" << _directory << "\"): "; + s << "db_env_create: " << db_strerror(ret); DBException ex; - ex.message = "db_env_create: "; - ex.message += db_strerror(ret); + ex.message = s.str(); throw ex; } - _directory = _properties->getProperty("Freeze.Directory"); - - const char* dir = 0; - if (!_directory.empty()) - { - dir = _directory.c_str(); - } - - ret = _dbenv->open(_dbenv, dir, + ret = _dbenv->open(_dbenv, _directory.c_str(), DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | @@ -293,9 +315,11 @@ Freeze::DBEnvI::DBEnvI(const CommunicatorPtr& communicator, const PropertiesPtr& S_IRUSR | S_IWUSR); if (ret != 0) { + ostringstream s; + s << "Freeze::DBEnv(\"" << _directory << "\"): "; + s << "DB_ENV->open: " << db_strerror(ret); DBException ex; - ex.message = "DB_ENV->open: "; - ex.message += db_strerror(ret); + ex.message = s.str(); throw ex; } } @@ -304,7 +328,10 @@ Freeze::DBEnvI::~DBEnvI() { if (_dbenv) { - _communicator->getLogger()->warning("database environment object has not been closed"); + ostringstream s; + s << "Freeze::DBEnv(\"" << _directory << "\"): "; + s << "\"" << _directory << "\" has not been closed"; + _communicator->getLogger()->warning(s.str()); } } @@ -315,8 +342,11 @@ Freeze::DBEnvI::open(const string& name) if(!_dbenv) { + ostringstream s; + s << "Freeze::DBEnv(\"" << _directory << "\"): "; + s << "\"" << _directory << "\" has been closed"; DBException ex; - ex.message = "Freeze::DBEnv::open: database environment has been closed"; + ex.message = s.str(); throw ex; } @@ -332,18 +362,22 @@ Freeze::DBEnvI::open(const string& name) ret = db_create(&db, _dbenv, 0); if(ret != 0) { + ostringstream s; + s << "Freeze::DBEnv(\"" << _directory << "\"): "; + s << "db_create: " << db_strerror(ret); DBException ex; - ex.message = "db_create: "; - ex.message += db_strerror(ret); + ex.message = s.str(); throw ex; } ret = db->open(db, name.c_str(), 0, DB_BTREE, DB_CREATE | DB_THREAD, S_IRUSR | S_IWUSR); if(ret != 0) { + ostringstream s; + s << "Freeze::DBEnv(\"" << _directory << "\"): "; + s << "DB->open: " << db_strerror(ret); DBException ex; - ex.message = "DB->open: "; - ex.message += db_strerror(ret); + ex.message = s.str(); throw ex; } @@ -371,9 +405,11 @@ Freeze::DBEnvI::close() int ret = _dbenv->close(_dbenv, 0); if(ret != 0) { + ostringstream s; + s << "Freeze::DBEnv(\"" << _directory << "\"): "; + s << "DB_ENV->close: " << db_strerror(ret); DBException ex; - ex.message = "DB_ENV->close: "; - ex.message += db_strerror(ret); + ex.message = s.str(); throw ex; } diff --git a/cpp/src/Ice/CommunicatorI.cpp b/cpp/src/Ice/CommunicatorI.cpp index 14e8016b7f6..05d1aaecc6f 100644 --- a/cpp/src/Ice/CommunicatorI.cpp +++ b/cpp/src/Ice/CommunicatorI.cpp @@ -114,7 +114,7 @@ Ice::CommunicatorI::installServantFactory(const ServantFactoryPtr& factory, cons { throw CommunicatorDestroyedException(__FILE__, __LINE__); } - _instance->valueFactoryManager()->install(factory, id); + _instance->servantFactoryManager()->install(factory, id); } PropertiesPtr diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index d6e71b97d6a..5be7f7c3dca 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -122,10 +122,10 @@ IceInternal::Instance::emitterFactory() } ServantFactoryManagerPtr -IceInternal::Instance::valueFactoryManager() +IceInternal::Instance::servantFactoryManager() { JTCSyncT<JTCMutex> sync(*this); - return _valueFactoryManager; + return _servantFactoryManager; } ObjectAdapterFactoryPtr @@ -262,7 +262,7 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Prope _proxyFactory = new ProxyFactory(this); _threadPool = new ThreadPool(this); _emitterFactory = new EmitterFactory(this); - _valueFactoryManager = new ServantFactoryManager(); + _servantFactoryManager = new ServantFactoryManager(); _objectAdapterFactory = new ObjectAdapterFactory(this); _pickler = new PicklerI(this); } @@ -282,7 +282,7 @@ IceInternal::Instance::~Instance() assert(!_proxyFactory); assert(!_threadPool); assert(!_emitterFactory); - assert(!_valueFactoryManager); + assert(!_servantFactoryManager); assert(!_objectAdapterFactory); assert(!_pickler); @@ -350,8 +350,7 @@ IceInternal::Instance::destroy() if(_logger) { - // No destroy function defined - // _logger->destroy(); + _logger->destroy(); _logger = 0; } @@ -375,10 +374,10 @@ IceInternal::Instance::destroy() _emitterFactory = 0; } - if(_valueFactoryManager) + if(_servantFactoryManager) { - _valueFactoryManager->destroy(); - _valueFactoryManager = 0; + _servantFactoryManager->destroy(); + _servantFactoryManager = 0; } if(_objectAdapterFactory) diff --git a/cpp/src/Ice/Instance.h b/cpp/src/Ice/Instance.h index 640156c2e29..162f483d9d4 100644 --- a/cpp/src/Ice/Instance.h +++ b/cpp/src/Ice/Instance.h @@ -46,7 +46,7 @@ public: ProxyFactoryPtr proxyFactory(); ThreadPoolPtr threadPool(); EmitterFactoryPtr emitterFactory(); - ServantFactoryManagerPtr valueFactoryManager(); + ServantFactoryManagerPtr servantFactoryManager(); ObjectAdapterFactoryPtr objectAdapterFactory(); ::Ice::PicklerPtr pickler(); @@ -64,7 +64,7 @@ private: ProxyFactoryPtr _proxyFactory; ThreadPoolPtr _threadPool; EmitterFactoryPtr _emitterFactory; - ServantFactoryManagerPtr _valueFactoryManager; + ServantFactoryManagerPtr _servantFactoryManager; ObjectAdapterFactoryPtr _objectAdapterFactory; ::Ice::PicklerPtr _pickler; diff --git a/cpp/src/Ice/LoggerI.cpp b/cpp/src/Ice/LoggerI.cpp index 94fe46eabd5..931ff715ec9 100644 --- a/cpp/src/Ice/LoggerI.cpp +++ b/cpp/src/Ice/LoggerI.cpp @@ -41,3 +41,9 @@ Ice::LoggerI::error(const string& message) JTCSyncT<JTCMutex> sync(*this); cerr << "error: " << message << endl; } + +void +Ice::LoggerI::destroy() +{ + // Nothing to do +} diff --git a/cpp/src/Ice/LoggerI.h b/cpp/src/Ice/LoggerI.h index dfc41b82e90..9cc18bcc5fa 100644 --- a/cpp/src/Ice/LoggerI.h +++ b/cpp/src/Ice/LoggerI.h @@ -23,6 +23,7 @@ public: virtual void trace(const std::string&, const std::string&); virtual void warning(const std::string&); virtual void error(const std::string&); + virtual void destroy(); }; } diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp index 6a52c0ef8f8..877472ddbb1 100644 --- a/cpp/src/Ice/ObjectAdapterI.cpp +++ b/cpp/src/Ice/ObjectAdapterI.cpp @@ -85,6 +85,8 @@ Ice::ObjectAdapterI::deactivate() _collectorFactories.clear(); _activeServantMap.clear(); _activeServantMapHint = _activeServantMap.begin(); + _locator->deactivate(); + _locator = 0; } ObjectPrx diff --git a/cpp/src/Ice/ServantFactoryManager.cpp b/cpp/src/Ice/ServantFactoryManager.cpp index 924f8729a3e..5064eef27c0 100644 --- a/cpp/src/Ice/ServantFactoryManager.cpp +++ b/cpp/src/Ice/ServantFactoryManager.cpp @@ -49,5 +49,9 @@ void IceInternal::ServantFactoryManager::destroy() { JTCSyncT<JTCMutex> sync(*this); + for (map<string, ::Ice::ServantFactoryPtr>::iterator p = 0; p != _factories.end(); ++p) + { + p->second->destroy(); + } _factories.clear(); } diff --git a/cpp/src/Ice/Stream.cpp b/cpp/src/Ice/Stream.cpp index f544a4c2541..cf3b50a53ef 100644 --- a/cpp/src/Ice/Stream.cpp +++ b/cpp/src/Ice/Stream.cpp @@ -820,7 +820,7 @@ IceInternal::Stream::read(ObjectPtr& v, const string& type) vector<string>::const_iterator p; for (p = classIds.begin(); p != classIds.end(); ++p) { - ServantFactoryPtr factory = _instance->valueFactoryManager()->lookup(*p); + ServantFactoryPtr factory = _instance->servantFactoryManager()->lookup(*p); if (factory) { diff --git a/cpp/src/Ice/SysLoggerI.cpp b/cpp/src/Ice/SysLoggerI.cpp index 05281f68617..0dcab397509 100644 --- a/cpp/src/Ice/SysLoggerI.cpp +++ b/cpp/src/Ice/SysLoggerI.cpp @@ -42,3 +42,9 @@ Ice::SysLoggerI::error(const string& message) JTCSyncT<JTCMutex> sync(*this); syslog(LOG_ERR, "%s", message.c_str()); } + +void +Ice::SysLoggerI::destroy() +{ + // Nothing to do +} diff --git a/cpp/src/Ice/SysLoggerI.h b/cpp/src/Ice/SysLoggerI.h index 2dc7b04542a..f77ead921f6 100644 --- a/cpp/src/Ice/SysLoggerI.h +++ b/cpp/src/Ice/SysLoggerI.h @@ -23,6 +23,7 @@ public: virtual void trace(const std::string&, const std::string&); virtual void warning(const std::string&); virtual void error(const std::string&); + virtual void destroy(); }; } diff --git a/cpp/src/Ice/TraceLevels.cpp b/cpp/src/Ice/TraceLevels.cpp index e35c30c3a96..05eaecbfa9d 100644 --- a/cpp/src/Ice/TraceLevels.cpp +++ b/cpp/src/Ice/TraceLevels.cpp @@ -31,15 +31,21 @@ IceInternal::TraceLevels::TraceLevels(const PropertiesPtr& properties) : value = properties->getProperty(keyBase + networkCat); if (!value.empty()) + { const_cast<int&>(network) = atoi(value.c_str()); + } value = properties->getProperty(keyBase + protocolCat); if (!value.empty()) + { const_cast<int&>(protocol) = atoi(value.c_str()); + } value = properties->getProperty(keyBase + retryCat); if (!value.empty()) + { const_cast<int&>(retry) = atoi(value.c_str()); + } } IceInternal::TraceLevels::~TraceLevels() diff --git a/cpp/src/IcePack/Client.cpp b/cpp/src/IcePack/Client.cpp index c4853e153d1..79053fcdcee 100644 --- a/cpp/src/IcePack/Client.cpp +++ b/cpp/src/IcePack/Client.cpp @@ -122,16 +122,16 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator) } PropertiesPtr properties = communicator->getProperties(); - - string adminEndpoints = properties->getProperty("Ice.Adapter.Admin.Endpoints"); - if (adminEndpoints.length() == 0) + const char* adminEndpointsProperty = "Ice.Adapter.Admin.Endpoints"; + string adminEndpoints = properties->getProperty(adminEndpointsProperty); + if (adminEndpoints.empty()) { - cerr << argv[0] << ": `Ice.Adapter.Admin.Endpoints' property is not set" << endl; + cerr << argv[0] << ": property `" << adminEndpointsProperty << "' is not set" << endl; return EXIT_FAILURE; } - Ice::ObjectPrx adminBase = communicator->stringToProxy("admin:" + adminEndpoints); - AdminPrx admin = AdminPrx::checkedCast(adminBase); + Ice::ObjectPrx base = communicator->stringToProxy("admin:" + adminEndpoints); + AdminPrx admin = AdminPrx::checkedCast(base); if (!admin) { cerr << argv[0] << ": `" << adminEndpoints << "' are no valid administrative endpoints" << endl; diff --git a/cpp/src/IcePack/Forward.cpp b/cpp/src/IcePack/Forward.cpp index 6f35d679ef1..4cc4669d356 100644 --- a/cpp/src/IcePack/Forward.cpp +++ b/cpp/src/IcePack/Forward.cpp @@ -46,9 +46,6 @@ IcePack::Forward::Forward(const CommunicatorPtr& communicator, const AdminPtr& a IcePack::Forward::~Forward() { -#ifndef WIN32 - _activator->destroy(); -#endif } ObjectPtr @@ -69,6 +66,9 @@ IcePack::Forward::locate(const ObjectAdapterPtr& adapter, const string& identity } #ifndef WIN32 + + assert(_activator); + // // We only try to activate if we have a path for the server // @@ -153,6 +153,7 @@ IcePack::Forward::locate(const ObjectAdapterPtr& adapter, const string& identity _communicator->getLogger()->error(s.str()); } } + #endif throw LocationForward(desc.object); @@ -163,3 +164,12 @@ IcePack::Forward::finished(const ObjectAdapterPtr&, const string&, const ObjectP { // Nothing to do } + +void +IcePack::Forward::deactivate() +{ +#ifndef WIN32 + _activator->destroy(); + _activator = 0; +#endif +} diff --git a/cpp/src/IcePack/Forward.h b/cpp/src/IcePack/Forward.h index 11bae523b36..990e200d250 100644 --- a/cpp/src/IcePack/Forward.h +++ b/cpp/src/IcePack/Forward.h @@ -29,6 +29,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: diff --git a/cpp/src/IcePack/Parser.cpp b/cpp/src/IcePack/Parser.cpp index 377c0ca2546..821ded8ead3 100644 --- a/cpp/src/IcePack/Parser.cpp +++ b/cpp/src/IcePack/Parser.cpp @@ -39,14 +39,13 @@ void IcePack::Parser::usage() { cout << - "help Print this message.\n" - "exit, quit Exit this program.\n" - "add proxy [path [args...]] Add a proxy with an optional path and program\n" - " arguments.\n" - "remove proxy Remove a proxy.\n" - "list List all server descriptions.\n" - "shutdown Shutdown the IcePack server.\n" - << endl; + "help Print this message.\n" + "exit, quit Exit this program.\n" + "add PROXY [PATH [ARGS...]] Add PROXY with an optional PATH and program\n" + " arguments ARGS.\n" + "remove PROXY Remove PROXY.\n" + "list List all server descriptions.\n" + "shutdown Shut the IcePack server down.\n"; } void @@ -54,8 +53,7 @@ IcePack::Parser::add(const list<string>& args) { if (args.empty()) { - error("`add' requires at least a proxy argument\n" - "(type `help' for more info)"); + error("`add' requires at least one argument (type `help' for more info)"); return; } @@ -87,8 +85,7 @@ IcePack::Parser::remove(const list<string>& args) { if (args.size() != 1) { - error("`remove' requires exactly one proxy argument\n" - "(type `help' for more info)"); + error("`remove' requires exactly one argument (type `help' for more info)"); return; } diff --git a/cpp/src/IcePack/Server.cpp b/cpp/src/IcePack/Server.cpp index d9e35785e68..0af2b57fec3 100644 --- a/cpp/src/IcePack/Server.cpp +++ b/cpp/src/IcePack/Server.cpp @@ -58,16 +58,19 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator) PropertiesPtr properties = communicator->getProperties(); - string adminEndpoints = properties->getProperty("Ice.Adapter.Admin.Endpoints"); - if (adminEndpoints.length() != 0 && !nowarn) + const char* adminEndpointsProperty = "Ice.Adapter.Admin.Endpoints"; + string adminEndpoints = properties->getProperty(adminEndpointsProperty); + if (!adminEndpoints.empty() && !nowarn) { - cerr << argv[0] << ": warning: administrative endpoints `Ice.Adapter.Admin.Endpoints' enabled" << endl; + cerr << argv[0] << ": warning: administrative endpoints property `" << adminEndpointsProperty << "' enabled" + << endl; } - string forwardEndpoints = properties->getProperty("Ice.Adapter.Forward.Endpoints"); - if (forwardEndpoints.length() == 0) + const char* forwardEndpointsProperty = "Ice.Adapter.Forward.Endpoints"; + string forwardEndpoints = properties->getProperty(forwardEndpointsProperty); + if (forwardEndpoints.empty()) { - cerr << argv[0] << ": `Ice.Adapter.Forward.Endpoints' property is not set" << endl; + cerr << argv[0] << ": property `" << forwardEndpointsProperty << "' is not set" << endl; return EXIT_FAILURE; } |