summaryrefslogtreecommitdiff
path: root/cpp/src/IcePatch/Server.cpp
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2002-04-03 21:22:52 +0000
committerMarc Laukien <marc@zeroc.com>2002-04-03 21:22:52 +0000
commit4178ad80a3978cfbd2f53a7e47bf0120ded7d4d5 (patch)
tree94813a418f0973f780a2620d70e975a97bfc8b6d /cpp/src/IcePatch/Server.cpp
parentstarted with IcePatch (diff)
downloadice-4178ad80a3978cfbd2f53a7e47bf0120ded7d4d5.tar.bz2
ice-4178ad80a3978cfbd2f53a7e47bf0120ded7d4d5.tar.xz
ice-4178ad80a3978cfbd2f53a7e47bf0120ded7d4d5.zip
started with IcePatch
Diffstat (limited to 'cpp/src/IcePatch/Server.cpp')
-rw-r--r--cpp/src/IcePatch/Server.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/cpp/src/IcePatch/Server.cpp b/cpp/src/IcePatch/Server.cpp
new file mode 100644
index 00000000000..467655e7fa7
--- /dev/null
+++ b/cpp/src/IcePatch/Server.cpp
@@ -0,0 +1,115 @@
+// **********************************************************************
+//
+// Copyright (c) 2002
+// MutableRealms, Inc.
+// Huntsville, AL, USA
+//
+// All Rights Reserved
+//
+// **********************************************************************
+
+#include <Ice/Application.h>
+#include <IcePatch/NodeLocator.h>
+
+using namespace std;
+using namespace Ice;
+using namespace IcePatch;
+
+namespace IcePatch
+{
+
+class Server : public Application
+{
+public:
+
+ void usage();
+ virtual int run(int, char*[]);
+};
+
+};
+
+void
+IcePatch::Server::usage()
+{
+ cerr << "Usage: " << appName() << " [options]\n";
+ cerr <<
+ "Options:\n"
+ "-h, --help Show this message.\n"
+ "-v, --version Display the Ice version.\n"
+ ;
+}
+
+int
+IcePatch::Server::run(int argc, char* argv[])
+{
+ for (int i = 1; i < argc; ++i)
+ {
+ if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0)
+ {
+ usage();
+ return EXIT_SUCCESS;
+ }
+ else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0)
+ {
+ cout << ICE_STRING_VERSION << endl;
+ return EXIT_SUCCESS;
+ }
+ else
+ {
+ cerr << appName() << ": unknown option `" << argv[i] << "'" << endl;
+ usage();
+ return EXIT_FAILURE;
+ }
+ }
+
+ PropertiesPtr properties = communicator()->getProperties();
+
+ //
+ // Get the working directory and change to this directory.
+ //
+ const char* directoryProperty = "IcePatch.Directory";
+ string directory = properties->getProperty(directoryProperty);
+ if (directory.empty())
+ {
+ cerr << appName() << ": property `" << directoryProperty << "' is not set" << endl;
+ return EXIT_FAILURE;
+ }
+ if(chdir(directory.c_str()) == -1)
+ {
+ cerr << appName() << ": can't change to directory `" << directory << "': " << strerror(errno) << endl;
+ return EXIT_FAILURE;
+ }
+
+ //
+ // Initialize Object Adapter
+ //
+ const char* endpointsProperty = "IcePatch.Endpoints";
+ string endpoints = properties->getProperty(endpointsProperty);
+ if (endpoints.empty())
+ {
+ cerr << appName() << ": property `" << endpointsProperty << "' is not set" << endl;
+ return EXIT_FAILURE;
+ }
+ ObjectAdapterPtr adapter = communicator()->createObjectAdapterFromProperty("IcePatch", endpointsProperty);
+
+ //
+ // Create and add the node locator.
+ //
+ ServantLocatorPtr nodeLocator = new NodeLocator;
+ adapter->addServantLocator(nodeLocator, "IcePatch");
+
+ //
+ // We're done, let's wait for shutdown.
+ //
+ communicator()->waitForShutdown();
+
+ return EXIT_SUCCESS;
+}
+
+int
+main(int argc, char* argv[])
+{
+ addArgumentPrefix("IcePatch");
+ Server app;
+ return app.main(argc, argv);
+}