summaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'cpp')
-rw-r--r--cpp/demo/Freeze/phonebook/.depend4
-rw-r--r--cpp/demo/Freeze/phonebook/Client.cpp58
-rw-r--r--cpp/demo/Freeze/phonebook/Server.cpp260
-rw-r--r--cpp/include/Ice/Application.h70
-rw-r--r--cpp/src/Ice/.depend1
-rw-r--r--cpp/src/Ice/Application.cpp182
-rw-r--r--cpp/src/Ice/Makefile3
7 files changed, 374 insertions, 204 deletions
diff --git a/cpp/demo/Freeze/phonebook/.depend b/cpp/demo/Freeze/phonebook/.depend
index 7d81c011d48..9cd06b430a1 100644
--- a/cpp/demo/Freeze/phonebook/.depend
+++ b/cpp/demo/Freeze/phonebook/.depend
@@ -2,8 +2,8 @@ PhoneBook.o: PhoneBook.cpp PhoneBook.h ../../../include/Ice/ProxyF.h ../../../in
Grammer.o: Grammer.cpp ../../../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 Parser.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 ../../../include/Freeze/DBException.h
Scanner.o: Scanner.cpp ../../../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 Parser.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 ../../../include/Freeze/DBException.h Grammer.h
Parser.o: Parser.cpp ../../../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 Parser.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 ../../../include/Freeze/DBException.h
-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 ../../../include/Freeze/DBException.h
+Client.o: Client.cpp ../../../include/Ice/Application.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 Parser.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 ../../../include/Freeze/DBException.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/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 ../../../include/Freeze/DBException.h ../../../include/Freeze/EvictorF.h ../../../include/Freeze/Evictor.h PhoneBook.h NameIdentitiesDict.h
NameIdentitiesDict.o: NameIdentitiesDict.cpp NameIdentitiesDict.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/Ice/Stream.h ../../../include/Ice/Buffer.h ../../../include/Freeze/DB.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/Incoming.h ../../../include/Freeze/DBException.h ../../../include/Freeze/DBF.h ../../../include/Freeze/EvictorF.h PhoneBook.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/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 ../../../include/Freeze/DBException.h ../../../include/Freeze/EvictorF.h ../../../include/Freeze/Evictor.h PhoneBook.h NameIdentitiesDict.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/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 ../../../include/Freeze/DBException.h ../../../include/Freeze/EvictorF.h ../../../include/Freeze/Evictor.h PhoneBook.h NameIdentitiesDict.h
+Server.o: Server.cpp ../../../include/Ice/Application.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 ServantFactory.h PhoneBookI.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/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 ../../../include/Freeze/DBException.h ../../../include/Freeze/EvictorF.h ../../../include/Freeze/Evictor.h PhoneBook.h NameIdentitiesDict.h
diff --git a/cpp/demo/Freeze/phonebook/Client.cpp b/cpp/demo/Freeze/phonebook/Client.cpp
index 56a89f135f9..9f7758de244 100644
--- a/cpp/demo/Freeze/phonebook/Client.cpp
+++ b/cpp/demo/Freeze/phonebook/Client.cpp
@@ -8,15 +8,22 @@
//
// **********************************************************************
+#include <Ice/Application.h>
#include <Parser.h>
using namespace std;
using namespace Ice;
+class PhoneBookClient : public Application
+{
+ void usage();
+ int run(int argc, char* argv[]);
+};
+
void
-usage(const char* n)
+PhoneBookClient::usage()
{
- cerr << "Usage: " << n << " [options] [file...]\n";
+ cerr << "Usage: " << appName() << " [options] [file...]\n";
cerr <<
"Options:\n"
"-h, --help Show this message.\n"
@@ -27,7 +34,7 @@ usage(const char* n)
}
int
-run(int argc, char* argv[], const CommunicatorPtr& communicator)
+PhoneBookClient::run(int argc, char* argv[])
{
string commands;
bool debug = false;
@@ -37,7 +44,7 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
{
if (strcmp(argv[idx], "-h") == 0 || strcmp(argv[idx], "--help") == 0)
{
- usage(argv[0]);
+ usage();
return EXIT_SUCCESS;
}
else if (strcmp(argv[idx], "-v") == 0 || strcmp(argv[idx], "--version") == 0)
@@ -50,7 +57,7 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
if (idx + 1 >= argc)
{
cerr << argv[0] << ": argument expected for`" << argv[idx] << "'" << endl;
- usage(argv[0]);
+ usage();
return EXIT_FAILURE;
}
@@ -75,7 +82,7 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
else if (argv[idx][0] == '-')
{
cerr << argv[0] << ": unknown option `" << argv[idx] << "'" << endl;
- usage(argv[0]);
+ usage();
return EXIT_FAILURE;
}
else
@@ -87,11 +94,11 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
if (argc >= 2 && !commands.empty())
{
cerr << argv[0] << ": `-e' option cannot be used if input files are given" << endl;
- usage(argv[0]);
+ usage();
return EXIT_FAILURE;
}
- PropertiesPtr properties = communicator->getProperties();
+ PropertiesPtr properties = communicator()->getProperties();
const char* refProperty = "PhoneBook.PhoneBook";
string ref = properties->getProperty(refProperty);
if (ref.empty())
@@ -100,7 +107,7 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
return EXIT_FAILURE;
}
- ObjectPrx base = communicator->stringToProxy(ref);
+ ObjectPrx base = communicator()->stringToProxy(ref);
PhoneBookPrx phoneBook = PhoneBookPrx::checkedCast(base);
if (!phoneBook)
{
@@ -108,7 +115,7 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
return EXIT_FAILURE;
}
- ParserPtr parser = Parser::createParser(communicator, phoneBook);
+ ParserPtr parser = Parser::createParser(communicator(), phoneBook);
int status = EXIT_SUCCESS;
if (argc < 2) // No files given
@@ -158,33 +165,6 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
int
main(int argc, char* argv[])
{
- int status;
- CommunicatorPtr communicator;
-
- try
- {
- PropertiesPtr properties = createPropertiesFromFile(argc, argv, "config");
- communicator = initializeWithProperties(properties);
- status = run(argc, argv, communicator);
- }
- catch(const LocalException& ex)
- {
- cerr << ex << endl;
- status = EXIT_FAILURE;
- }
-
- if (communicator)
- {
- try
- {
- communicator->destroy();
- }
- catch(const LocalException& ex)
- {
- cerr << ex << endl;
- status = EXIT_FAILURE;
- }
- }
-
- return status;
+ PhoneBookClient app;
+ app.main(argc, argv, "config");
}
diff --git a/cpp/demo/Freeze/phonebook/Server.cpp b/cpp/demo/Freeze/phonebook/Server.cpp
index 7d56e7992fc..325979d60a0 100644
--- a/cpp/demo/Freeze/phonebook/Server.cpp
+++ b/cpp/demo/Freeze/phonebook/Server.cpp
@@ -8,197 +8,133 @@
//
// **********************************************************************
+#include <Ice/Application.h>
#include <ServantFactory.h>
-static Ice::CommunicatorPtr communicator;
-
-#ifdef WIN32
-
-static BOOL WINAPI
-interruptHandler(DWORD)
-{
- assert(communicator);
- communicator->shutdown();
- return TRUE;
-}
-
-static void
-shutdownOnInterrupt()
-{
- SetConsoleCtrlHandler(NULL, FALSE);
- SetConsoleCtrlHandler(interruptHandler, TRUE);
-}
-
-static void
-ignoreInterrupt()
-{
- SetConsoleCtrlHandler(NULL, TRUE);
-}
-
-#else
-
-# include <signal.h>
-
-static void
-interruptHandler(int)
-{
- assert(communicator);
- communicator->shutdown();
-}
-
-static void
-shutdownOnInterrupt()
-{
- struct sigaction action;
- action.sa_handler = interruptHandler;
- sigemptyset(&action.sa_mask);
- sigaddset(&action.sa_mask, SIGHUP);
- sigaddset(&action.sa_mask, SIGINT);
- sigaddset(&action.sa_mask, SIGTERM);
- action.sa_flags = 0;
- sigaction(SIGHUP, &action, 0);
- sigaction(SIGINT, &action, 0);
- sigaction(SIGTERM, &action, 0);
-}
-
-static void
-ignoreInterrupt()
-{
- struct sigaction action;
- action.sa_handler = SIG_IGN;
- sigemptyset(&action.sa_mask);
- action.sa_flags = 0;
- sigaction(SIGHUP, &action, 0);
- sigaction(SIGINT, &action, 0);
- sigaction(SIGTERM, &action, 0);
-}
-
-#endif
-
+using namespace std;
using namespace Ice;
using namespace Freeze;
-using namespace std;
+
+class PhoneBookServer : public Application
+{
+ int run(int argc, char* argv[]);
+};
int
-run(int argc, char* argv[], const DBEnvironmentPtr& dbEnv)
+PhoneBookServer::run(int argc, char* argv[])
{
cout << "starting up..." << endl;
ignoreInterrupt();
-
- PropertiesPtr properties = communicator->getProperties();
- string value;
-
- //
- // Open the phonebook and contacts database.
- //
- DBPtr dbPhoneBook = dbEnv->openDB("phonebook");
- DBPtr dbContacts = dbEnv->openDB("contacts");
-
- //
- // Create an Evictor for contacts.
- //
- EvictorPtr evictor = dbContacts->createEvictor();
- value = properties->getProperty("PhoneBook.EvictorSize");
- if(!value.empty())
+
+ int status;
+ DBEnvironmentPtr dbEnv;
+
+ try
+ {
+ PropertiesPtr properties = communicator()->getProperties();
+ string value;
+
+ //
+ // Open the database environment and the phonebook and
+ // contacts database within this environment.
+ //
+ dbEnv = Freeze::initialize(communicator(), "db");
+ DBPtr dbPhoneBook = dbEnv->openDB("phonebook");
+ DBPtr dbContacts = dbEnv->openDB("contacts");
+
+ //
+ // Create an Evictor for contacts.
+ //
+ EvictorPtr evictor = dbContacts->createEvictor();
+ value = properties->getProperty("PhoneBook.EvictorSize");
+ if(!value.empty())
+ {
+ evictor->setSize(atoi(value.c_str()));
+ }
+ value = properties->getProperty("PhoneBook.SaveAfterMutatingOperation");
+ if(!value.empty() && atoi(value.c_str()) > 0)
+ {
+ evictor->setPersistenceMode(SaveAfterMutatingOperation);
+ }
+ else
+ {
+ evictor->setPersistenceMode(SaveUponEviction);
+ }
+
+ //
+ // Create an Object Adapter, use the Evictor as Servant Locator.
+ //
+ ObjectAdapterPtr adapter = communicator()->createObjectAdapter("PhoneBookAdapter");
+ adapter->setServantLocator(evictor);
+
+ //
+ // Create the phonebook, and add it to the Object Adapter.
+ //
+ PhoneBookIPtr phoneBook = new PhoneBookI(adapter, dbPhoneBook, evictor);
+ 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");
+ evictor->installServantInitializer(contactInitializer);
+
+ //
+ // Everything ok, let's go.
+ //
+ adapter->activate();
+ shutdownOnInterrupt();
+ communicator()->waitForShutdown();
+ ignoreInterrupt();
+ status = EXIT_SUCCESS;
+ }
+ catch(const LocalException& ex)
{
- evictor->setSize(atoi(value.c_str()));
+ cerr << argv[0] << ": local exception: " << ex << endl;
+ status = EXIT_FAILURE;
}
- value = properties->getProperty("PhoneBook.SaveAfterMutatingOperation");
- if(!value.empty() && atoi(value.c_str()) > 0)
+ catch(const DBExceptionPtrE& ex)
{
- evictor->setPersistenceMode(SaveAfterMutatingOperation);
+ cerr << argv[0] << ": database exception: " << ex->message << endl;
+ status = EXIT_FAILURE;
}
- else
+ catch(...)
{
- evictor->setPersistenceMode(SaveUponEviction);
+ cerr << argv[0] << ": unknown exception" << endl;
+ status = EXIT_FAILURE;
}
- //
- // Create an Object Adapter, use the Evictor as Servant Locator.
- //
- ObjectAdapterPtr adapter = communicator->createObjectAdapter("PhoneBookAdapter");
- adapter->setServantLocator(evictor);
-
- //
- // Create the phonebook, and add it to the Object Adapter.
- //
- PhoneBookIPtr phoneBook = new PhoneBookI(adapter, dbPhoneBook, evictor);
- 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");
- evictor->installServantInitializer(contactInitializer);
-
- //
- // Everything ok, let's go.
- //
- adapter->activate();
- shutdownOnInterrupt();
- communicator->waitForShutdown();
- cout << "shutting down..." << endl;
- ignoreInterrupt();
- return EXIT_SUCCESS;
-}
-
-int
-main(int argc, char* argv[])
-{
- int status;
- DBEnvironmentPtr dbEnv;
-
try
{
- PropertiesPtr properties = createPropertiesFromFile(argc, argv, "config");
- communicator = Ice::initializeWithProperties(properties);
- dbEnv = Freeze::initialize(communicator, "db");
- status = run(argc, argv, dbEnv);
+ dbEnv->close();
}
catch(const LocalException& ex)
{
- cerr << ex << endl;
+ cerr << argv[0] << ": local exception: " << ex << endl;
status = EXIT_FAILURE;
}
- catch(const DBException& ex)
+ catch(const DBExceptionPtrE& ex)
{
- cerr << ex.message << endl;
+ cerr << argv[0] << ": database exception: " << ex->message << endl;
status = EXIT_FAILURE;
}
-
- if (dbEnv)
+ catch(...)
{
- try
- {
- dbEnv->close();
- }
- catch(const LocalException& ex)
- {
- cerr << ex << endl;
- status = EXIT_FAILURE;
- }
- catch(const DBException& ex)
- {
- cerr << ex.message << endl;
- status = EXIT_FAILURE;
- }
+ cerr << argv[0] << ": unknown exception" << endl;
+ status = EXIT_FAILURE;
}
- if (communicator)
- {
- try
- {
- communicator->destroy();
- communicator = 0;
- }
- catch(const LocalException& ex)
- {
- cerr << ex << endl;
- status = EXIT_FAILURE;
- }
- }
+ defaultInterrupt();
+ cout << "shutting down..." << endl;
return status;
}
+
+int
+main(int argc, char* argv[])
+{
+ PhoneBookServer app;
+ app.main(argc, argv, "config");
+}
diff --git a/cpp/include/Ice/Application.h b/cpp/include/Ice/Application.h
new file mode 100644
index 00000000000..124dec9b4bb
--- /dev/null
+++ b/cpp/include/Ice/Application.h
@@ -0,0 +1,70 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#ifndef ICE_APPLICATION_H
+#define ICE_APPLICATION_H
+
+#include <Ice/Ice.h>
+
+namespace Ice
+{
+
+class ICE_API Application : public IceUtil::noncopyable
+{
+public:
+
+ Application();
+ virtual ~Application();
+
+ //
+ // This main() must be called by the global main(). main()
+ // initializes the Communicator, calls run() as a template method,
+ // and destroys the Communicator upon return from run(). It
+ // thereby handles all exceptions properly, i.e., error messages
+ // are printed if exceptions propagate to main(), and the
+ // Communicator is always destroyed, regardless of exceptions.
+ //
+ int main(int, char*[], const char* = 0);
+ virtual int run(int, char*[]) = 0;
+
+ //
+ // Return the application name, i.e., argv[0].
+ //
+ static const char* appName();
+
+ //
+ // One limitation of this class is that there can only be one
+ // Application instance, with one global Communicator, accessible
+ // with this communicator() operation. This limitiation is due to
+ // how the signal handling functions below operate. If you require
+ // multiple Communicators, then you cannot use this Application
+ // framework class.
+ //
+ static CommunicatorPtr communicator();
+
+ //
+ // These methods can be used to set a signal handler that calls
+ // communicator()->shutdown() upon interrupt (to make
+ // communicator()->waitForShutdown() return), to ignore
+ // interrupts, or to set interrupts back to default behavior.
+ //
+ static void shutdownOnInterrupt();
+ static void ignoreInterrupt();
+ static void defaultInterrupt();
+
+private:
+
+ static const char* _appName;
+ static CommunicatorPtr _communicator;
+};
+
+};
+
+#endif
diff --git a/cpp/src/Ice/.depend b/cpp/src/Ice/.depend
index b343394e2aa..cf5dc22bab6 100644
--- a/cpp/src/Ice/.depend
+++ b/cpp/src/Ice/.depend
@@ -1,3 +1,4 @@
+Application.o: Application.cpp ../../include/Ice/Application.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
Stream.o: Stream.cpp ../../include/Ice/Stream.h ../../include/Ice/InstanceF.h ../../include/Ice/Handle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/Ice/Buffer.h ../Ice/Instance.h ../../include/IceUtil/Shared.h ../../include/Ice/CommunicatorF.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Native.h ../../include/Ice/LocalObject.h ../../include/Ice/PropertiesF.h ../../include/Ice/LoggerF.h ../Ice/TraceLevelsF.h ../../include/Ice/ProxyFactoryF.h ../Ice/ThreadPoolF.h ../../include/Ice/EmitterF.h ../Ice/ServantFactoryManagerF.h ../../include/Ice/ObjectAdapterFactoryF.h ../../include/Ice/PicklerF.h ../../include/Ice/Object.h ../../include/Ice/Proxy.h ../../include/Ice/ReferenceF.h ../Ice/ProxyFactory.h ../../include/Ice/ServantFactory.h ../Ice/ServantFactoryManager.h ../../include/Ice/ServantFactoryF.h ../../include/Ice/LocalException.h
LocalException.o: LocalException.cpp ../../include/Ice/LocalException.h ../../include/Ice/Config.h ../../include/IceUtil/Config.h ../Ice/Network.h
Pickler.o: Pickler.cpp ../../include/Ice/Pickler.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/Stream.h ../../include/Ice/InstanceF.h ../../include/Ice/Buffer.h
diff --git a/cpp/src/Ice/Application.cpp b/cpp/src/Ice/Application.cpp
new file mode 100644
index 00000000000..fdb7ec3d3b6
--- /dev/null
+++ b/cpp/src/Ice/Application.cpp
@@ -0,0 +1,182 @@
+// **********************************************************************
+//
+// Copyright (c) 2001
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#include <Ice/Application.h>
+#ifndef WIN32
+# include <signal.h>
+#endif
+
+using namespace std;
+using namespace Ice;
+
+const char* Application::_appName;
+CommunicatorPtr Application::_communicator;
+
+Ice::Application::Application()
+{
+}
+
+Ice::Application::~Application()
+{
+}
+
+int
+Ice::Application::main(int argc, char* argv[], const char* configFile)
+{
+ if (_communicator && _appName)
+ {
+ cerr << argv[0] << ": only one instance of the Application class can be used" << endl;
+ return EXIT_FAILURE;
+ }
+
+ _appName = argv[0];
+
+ int status;
+
+ try
+ {
+ if (configFile)
+ {
+ PropertiesPtr properties = createPropertiesFromFile(argc, argv, configFile);
+ _communicator = initializeWithProperties(properties);
+ }
+ else
+ {
+ _communicator = initialize(argc, argv);
+ }
+ status = run(argc, argv);
+ }
+ catch(const LocalException& ex)
+ {
+ cerr << _appName << ": local exception: " << ex << endl;
+ status = EXIT_FAILURE;
+ }
+ catch(...)
+ {
+ cerr << _appName << ": unknown exception" << endl;
+ status = EXIT_FAILURE;
+ }
+
+ if (_communicator)
+ {
+ try
+ {
+ _communicator->destroy();
+ }
+ catch(const LocalException& ex)
+ {
+ cerr << _appName << ": local exception: " << ex << endl;
+ status = EXIT_FAILURE;
+ }
+ catch(...)
+ {
+ cerr << _appName << ": unknown exception" << endl;
+ status = EXIT_FAILURE;
+ }
+ _communicator = 0;
+ }
+
+ _appName = 0;
+
+ return status;
+}
+
+const char*
+Ice::Application::appName()
+{
+ return _appName;
+}
+
+CommunicatorPtr
+Ice::Application::communicator()
+{
+ return _communicator;
+}
+
+#ifdef WIN32
+
+static BOOL WINAPI
+interruptHandler(DWORD)
+{
+ assert(Application::communicator());
+ Application::communicator()->shutdown();
+ return TRUE;
+}
+
+void
+Ice::Application::shutdownOnInterrupt()
+{
+ SetConsoleCtrlHandler(NULL, FALSE);
+ SetConsoleCtrlHandler(interruptHandler, TRUE);
+}
+
+void
+Ice::Application::ignoreInterrupt()
+{
+ SetConsoleCtrlHandler(interruptHandler, FALSE);
+ SetConsoleCtrlHandler(NULL, TRUE);
+}
+
+void
+Ice::Application::defaultInterrupt()
+{
+ SetConsoleCtrlHandler(interruptHandler, FALSE);
+ SetConsoleCtrlHandler(NULL, FALSE);
+}
+
+#else
+
+static void
+interruptHandler(int)
+{
+ assert(Application::communicator());
+ Application::communicator()->shutdown();
+}
+
+void
+Ice::Application::shutdownOnInterrupt()
+{
+ struct sigaction action;
+ action.sa_handler = interruptHandler;
+ sigemptyset(&action.sa_mask);
+ sigaddset(&action.sa_mask, SIGHUP);
+ sigaddset(&action.sa_mask, SIGINT);
+ sigaddset(&action.sa_mask, SIGTERM);
+ action.sa_flags = 0;
+ sigaction(SIGHUP, &action, 0);
+ sigaction(SIGINT, &action, 0);
+ sigaction(SIGTERM, &action, 0);
+}
+
+void
+Ice::Application::ignoreInterrupt()
+{
+ struct sigaction action;
+ action.sa_handler = SIG_IGN;
+ sigemptyset(&action.sa_mask);
+ action.sa_flags = 0;
+ sigaction(SIGHUP, &action, 0);
+ sigaction(SIGINT, &action, 0);
+ sigaction(SIGTERM, &action, 0);
+}
+
+void
+Ice::Application::defaultInterrupt()
+{
+ struct sigaction action;
+ action.sa_handler = SIG_DFL;
+ sigemptyset(&action.sa_mask);
+ action.sa_flags = 0;
+ sigaction(SIGHUP, &action, 0);
+ sigaction(SIGINT, &action, 0);
+ sigaction(SIGTERM, &action, 0);
+}
+
+#endif
diff --git a/cpp/src/Ice/Makefile b/cpp/src/Ice/Makefile
index 3da541e9d3d..14632f1000f 100644
--- a/cpp/src/Ice/Makefile
+++ b/cpp/src/Ice/Makefile
@@ -18,7 +18,8 @@ VERSIONED_NAME = $(top_srcdir)/lib/$(VERSIONED_BASE)
TARGETS = $(NAME) $(VERSIONED_NAME)
-OBJS = Stream.o \
+OBJS = Application.o \
+ Stream.o \
LocalException.o \
Pickler.o \
PicklerI.o \