diff options
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/demo/Freeze/phonebook/.depend | 3 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/Makefile | 1 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/ServantFactory.cpp | 8 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/ServantFactory.h | 10 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/ServantInitializer.cpp | 27 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/ServantInitializer.h | 29 | ||||
-rw-r--r-- | cpp/demo/Freeze/phonebook/Server.cpp | 40 |
7 files changed, 49 insertions, 69 deletions
diff --git a/cpp/demo/Freeze/phonebook/.depend b/cpp/demo/Freeze/phonebook/.depend index c4ed03e13cb..76177f68595 100644 --- a/cpp/demo/Freeze/phonebook/.depend +++ b/cpp/demo/Freeze/phonebook/.depend @@ -5,5 +5,4 @@ Parser.o: Parser.cpp ../../../include/Ice/Ice.h ../../../include/Ice/Communicato Client.o: Client.cpp Parser.h ../../../include/IceUtil/Handle.h ../../../include/IceUtil/Config.h ../../../include/Ice/Ice.h ../../../include/Ice/Communicator.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Native.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/LoggerF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/PicklerF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/ServantFactoryF.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/ServantFactory.h ../../../include/Ice/Pickler.h ../../../include/Ice/Initialize.h ../../../include/Ice/InstanceF.h PhoneBook.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/EmitterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Stream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h PhoneBookI.o: PhoneBookI.cpp PhoneBookI.h ../../../include/Ice/Ice.h ../../../include/Ice/Communicator.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/Config.h ../../../include/IceUtil/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Native.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/LoggerF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/PicklerF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/ServantFactoryF.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/ServantFactory.h ../../../include/Ice/Pickler.h ../../../include/Ice/Initialize.h ../../../include/Ice/InstanceF.h ../../../include/IceUtil/IceUtil.h ../../../include/IceUtil/Functional.h ../../../include/Freeze/Freeze.h ../../../include/Freeze/Initialize.h ../../../include/Freeze/DBF.h ../../../include/Freeze/DB.h ../../../include/Freeze/EvictorF.h ../../../include/Freeze/Evictor.h PhoneBook.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/EmitterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Stream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h ServantFactory.o: ServantFactory.cpp ServantFactory.h PhoneBookI.h ../../../include/Ice/Ice.h ../../../include/Ice/Communicator.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/Config.h ../../../include/IceUtil/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Native.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/LoggerF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/PicklerF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/ServantFactoryF.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/ServantFactory.h ../../../include/Ice/Pickler.h ../../../include/Ice/Initialize.h ../../../include/Ice/InstanceF.h ../../../include/IceUtil/IceUtil.h ../../../include/IceUtil/Functional.h ../../../include/Freeze/Freeze.h ../../../include/Freeze/Initialize.h ../../../include/Freeze/DBF.h ../../../include/Freeze/DB.h ../../../include/Freeze/EvictorF.h ../../../include/Freeze/Evictor.h PhoneBook.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/EmitterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Stream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h -ServantInitializer.o: ServantInitializer.cpp ServantInitializer.h PhoneBookI.h ../../../include/Ice/Ice.h ../../../include/Ice/Communicator.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/Config.h ../../../include/IceUtil/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Native.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/LoggerF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/PicklerF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/ServantFactoryF.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/ServantFactory.h ../../../include/Ice/Pickler.h ../../../include/Ice/Initialize.h ../../../include/Ice/InstanceF.h ../../../include/IceUtil/IceUtil.h ../../../include/IceUtil/Functional.h ../../../include/Freeze/Freeze.h ../../../include/Freeze/Initialize.h ../../../include/Freeze/DBF.h ../../../include/Freeze/DB.h ../../../include/Freeze/EvictorF.h ../../../include/Freeze/Evictor.h PhoneBook.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/EmitterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Stream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h -Server.o: Server.cpp ServantFactory.h PhoneBookI.h ../../../include/Ice/Ice.h ../../../include/Ice/Communicator.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/Config.h ../../../include/IceUtil/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Native.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/LoggerF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/PicklerF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/ServantFactoryF.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/ServantFactory.h ../../../include/Ice/Pickler.h ../../../include/Ice/Initialize.h ../../../include/Ice/InstanceF.h ../../../include/IceUtil/IceUtil.h ../../../include/IceUtil/Functional.h ../../../include/Freeze/Freeze.h ../../../include/Freeze/Initialize.h ../../../include/Freeze/DBF.h ../../../include/Freeze/DB.h ../../../include/Freeze/EvictorF.h ../../../include/Freeze/Evictor.h PhoneBook.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/EmitterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Stream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h ServantInitializer.h +Server.o: Server.cpp ServantFactory.h PhoneBookI.h ../../../include/Ice/Ice.h ../../../include/Ice/Communicator.h ../../../include/Ice/ProxyF.h ../../../include/Ice/ProxyHandle.h ../../../include/Ice/Config.h ../../../include/IceUtil/Config.h ../../../include/Ice/ObjectF.h ../../../include/Ice/Handle.h ../../../include/IceUtil/Handle.h ../../../include/Ice/LocalObjectF.h ../../../include/Ice/Native.h ../../../include/Ice/LocalObject.h ../../../include/IceUtil/Shared.h ../../../include/Ice/LoggerF.h ../../../include/Ice/ObjectAdapterF.h ../../../include/Ice/PicklerF.h ../../../include/Ice/PropertiesF.h ../../../include/Ice/ServantFactoryF.h ../../../include/Ice/ObjectAdapter.h ../../../include/Ice/CommunicatorF.h ../../../include/Ice/LocalException.h ../../../include/Ice/Properties.h ../../../include/Ice/Logger.h ../../../include/Ice/ServantFactory.h ../../../include/Ice/Pickler.h ../../../include/Ice/Initialize.h ../../../include/Ice/InstanceF.h ../../../include/IceUtil/IceUtil.h ../../../include/IceUtil/Functional.h ../../../include/Freeze/Freeze.h ../../../include/Freeze/Initialize.h ../../../include/Freeze/DBF.h ../../../include/Freeze/DB.h ../../../include/Freeze/EvictorF.h ../../../include/Freeze/Evictor.h PhoneBook.h ../../../include/Ice/Proxy.h ../../../include/Ice/ProxyFactoryF.h ../../../include/Ice/EmitterF.h ../../../include/Ice/ReferenceF.h ../../../include/Ice/Object.h ../../../include/Ice/Outgoing.h ../../../include/Ice/Stream.h ../../../include/Ice/Buffer.h ../../../include/Ice/Incoming.h diff --git a/cpp/demo/Freeze/phonebook/Makefile b/cpp/demo/Freeze/phonebook/Makefile index 6c10085d89f..7a1b889f002 100644 --- a/cpp/demo/Freeze/phonebook/Makefile +++ b/cpp/demo/Freeze/phonebook/Makefile @@ -24,7 +24,6 @@ COBJS = Grammer.o \ SOBJS = PhoneBookI.o \ ServantFactory.o \ - ServantInitializer.o \ Server.o SRCS = $(OBJS:.o=.cpp) \ diff --git a/cpp/demo/Freeze/phonebook/ServantFactory.cpp b/cpp/demo/Freeze/phonebook/ServantFactory.cpp index f8807fdddba..dee76943d00 100644 --- a/cpp/demo/Freeze/phonebook/ServantFactory.cpp +++ b/cpp/demo/Freeze/phonebook/ServantFactory.cpp @@ -51,3 +51,11 @@ ContactFactory::destroy() { // Nothing to do } + +void +ContactFactory::initialize(const ObjectAdapterPtr&, const string& identity, const ObjectPtr& servant) +{ + ContactIPtr contact = ContactIPtr::dynamicCast(servant); + assert(contact); + contact->setIdentity(identity); +} diff --git a/cpp/demo/Freeze/phonebook/ServantFactory.h b/cpp/demo/Freeze/phonebook/ServantFactory.h index 095a96096bf..89be717cca2 100644 --- a/cpp/demo/Freeze/phonebook/ServantFactory.h +++ b/cpp/demo/Freeze/phonebook/ServantFactory.h @@ -28,15 +28,23 @@ private: Freeze::EvictorPtr _evictor; }; -class ContactFactory : public Ice::ServantFactory +class ContactFactory : virtual public Ice::ServantFactory, virtual public Freeze::ServantInitializer { public: ContactFactory(const PhoneBookIPtr&, const Freeze::EvictorPtr&); + // + // Operations from ServantFactory + // virtual Ice::ObjectPtr create(const std::string&); virtual void destroy(); + // + // Operations from ServantInitializer + // + virtual void initialize(const Ice::ObjectAdapterPtr&, const std::string&, const Ice::ObjectPtr&); + private: PhoneBookIPtr _phoneBook; diff --git a/cpp/demo/Freeze/phonebook/ServantInitializer.cpp b/cpp/demo/Freeze/phonebook/ServantInitializer.cpp deleted file mode 100644 index f3387c4b1dc..00000000000 --- a/cpp/demo/Freeze/phonebook/ServantInitializer.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2001 -// MutableRealms, Inc. -// Huntsville, AL, USA -// -// All Rights Reserved -// -// ********************************************************************** - -#include <ServantInitializer.h> - -using namespace std; -using namespace Ice; - -ContactInitializer::ContactInitializer(const PhoneBookIPtr& phoneBook) : - _phoneBook(phoneBook) -{ -} - -void -ContactInitializer::initialize(const ObjectAdapterPtr&, const string& identity, const ObjectPtr& servant) -{ - ContactIPtr entry = ContactIPtr::dynamicCast(servant); - assert(entry); - entry->setIdentity(identity); -} diff --git a/cpp/demo/Freeze/phonebook/ServantInitializer.h b/cpp/demo/Freeze/phonebook/ServantInitializer.h deleted file mode 100644 index 0624d6eefff..00000000000 --- a/cpp/demo/Freeze/phonebook/ServantInitializer.h +++ /dev/null @@ -1,29 +0,0 @@ -// ********************************************************************** -// -// Copyright (c) 2001 -// MutableRealms, Inc. -// Huntsville, AL, USA -// -// All Rights Reserved -// -// ********************************************************************** - -#ifndef SERVANT_INITIALIZER_H -#define SERVANT_INITIALIZER_H - -#include <PhoneBookI.h> - -class ContactInitializer : public Freeze::ServantInitializer -{ -public: - - ContactInitializer(const PhoneBookIPtr&); - - virtual void initialize(const Ice::ObjectAdapterPtr&, const std::string&, const Ice::ObjectPtr&); - -private: - - PhoneBookIPtr _phoneBook; -}; - -#endif diff --git a/cpp/demo/Freeze/phonebook/Server.cpp b/cpp/demo/Freeze/phonebook/Server.cpp index 34b844d5152..d942c6cfec3 100644 --- a/cpp/demo/Freeze/phonebook/Server.cpp +++ b/cpp/demo/Freeze/phonebook/Server.cpp @@ -9,7 +9,6 @@ // ********************************************************************** #include <ServantFactory.h> -#include <ServantInitializer.h> static Ice::CommunicatorPtr communicator; @@ -87,17 +86,33 @@ run(int argc, char* argv[], const DBEnvPtr& dbenv) cout << "starting up..." << endl; ignoreInterrupt(); + // + // Open the phonebook database. + // DBPtr db = dbenv->open("phonebook"); + // + // Create an Evictor. + // EvictorPtr evictor = db->createEvictor(); evictor->setSize(3); - + + // + // Create an Object Adapter, use the Evictor as Servant Locator. ObjectAdapterPtr adapter = communicator->createObjectAdapter("PhoneBookAdapter"); adapter->setServantLocator(evictor); - + + // + // Create and install a factory for the phonebook. + // ServantFactoryPtr phoneBookFactory = new PhoneBookFactory(adapter, evictor); communicator->installServantFactory(phoneBookFactory, "::PhoneBook"); + // + // Try to load the phonebook from the database. If none exists in + // the database yet, create a new one. Then add the phonebook + // Servant to the Object Adapter. + // PhoneBookIPtr phoneBook; ObjectPtr servant = db->get("phonebook"); if (!servant) @@ -111,21 +126,28 @@ run(int argc, char* argv[], const DBEnvPtr& dbenv) assert(phoneBook); adapter->add(phoneBook, "phonebook"); + // + // Create and install a factory and initializer for contacts. + // ServantFactoryPtr contactFactory = new ContactFactory(phoneBook, evictor); + ServantInitializerPtr contactInitializer = ServantInitializerPtr::dynamicCast(contactFactory); communicator->installServantFactory(contactFactory, "::Contact"); - - ServantInitializerPtr contactInitializer = new ContactInitializer(phoneBook); evictor->installServantInitializer(contactInitializer); + // + // Everything ok, let's go. + // adapter->activate(); - shutdownOnInterrupt(); communicator->waitForShutdown(); cout << "shutting down..." << endl; ignoreInterrupt(); + // + // Application has shut down, save the phonebook in the database + // and exit. + // db->put("phonebook", phoneBook); - return EXIT_SUCCESS; } @@ -149,7 +171,7 @@ main(int argc, char* argv[]) } catch(const DBException& ex) { - cerr << "Berkeley DB error: " << ex.message << endl; + cerr << ex.message << endl; status = EXIT_FAILURE; } @@ -166,7 +188,7 @@ main(int argc, char* argv[]) } catch(const DBException& ex) { - cerr << "Berkeley DB error: " << ex.message << endl; + cerr << ex.message << endl; status = EXIT_FAILURE; } } |