summaryrefslogtreecommitdiff
path: root/cpp/src/IcePack/Client.cpp
diff options
context:
space:
mode:
authorMarc Laukien <marc@zeroc.com>2001-11-30 19:17:29 +0000
committerMarc Laukien <marc@zeroc.com>2001-11-30 19:17:29 +0000
commitf9eda6f68a8251fb312e715f5eda443b56925657 (patch)
tree0ad697d27e22eeb42804ef7fd2b6b7cb53f36a34 /cpp/src/IcePack/Client.cpp
parentAdded DBCursor to the Freeze module. (diff)
downloadice-f9eda6f68a8251fb312e715f5eda443b56925657.tar.bz2
ice-f9eda6f68a8251fb312e715f5eda443b56925657.tar.xz
ice-f9eda6f68a8251fb312e715f5eda443b56925657.zip
converted some stuff to use Application.h
Diffstat (limited to 'cpp/src/IcePack/Client.cpp')
-rw-r--r--cpp/src/IcePack/Client.cpp84
1 files changed, 33 insertions, 51 deletions
diff --git a/cpp/src/IcePack/Client.cpp b/cpp/src/IcePack/Client.cpp
index f084c800e57..eeaf74e3001 100644
--- a/cpp/src/IcePack/Client.cpp
+++ b/cpp/src/IcePack/Client.cpp
@@ -8,7 +8,7 @@
//
// **********************************************************************
-#include <Ice/Ice.h>
+#include <Ice/Application.h>
#include <IcePack/Parser.h>
#include <fstream>
@@ -16,10 +16,25 @@ using namespace std;
using namespace Ice;
using namespace IcePack;
+class Client : public Application
+{
+public:
+
+ void usage();
+ virtual int run(int, char*[]);
+};
+
+int
+main(int argc, char* argv[])
+{
+ Client app;
+ return app.main(argc, argv);
+}
+
void
-usage(const char* n)
+Client::usage()
{
- cerr << "Usage: " << n << " [options] [file...]\n";
+ cerr << "Usage: " << appName() << " [options] [file...]\n";
cerr <<
"Options:\n"
"-h, --help Show this message.\n"
@@ -34,7 +49,7 @@ usage(const char* n)
}
int
-run(int argc, char* argv[], const CommunicatorPtr& communicator)
+Client::run(int argc, char* argv[])
{
string cpp("cpp");
string commands;
@@ -67,7 +82,7 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
}
else 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)
@@ -79,8 +94,8 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
{
if (idx + 1 >= argc)
{
- cerr << argv[0] << ": argument expected for`" << argv[idx] << "'" << endl;
- usage(argv[0]);
+ cerr << appName() << ": argument expected for`" << argv[idx] << "'" << endl;
+ usage();
return EXIT_FAILURE;
}
@@ -104,8 +119,8 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
}
else if (argv[idx][0] == '-')
{
- cerr << argv[0] << ": unknown option `" << argv[idx] << "'" << endl;
- usage(argv[0]);
+ cerr << appName() << ": unknown option `" << argv[idx] << "'" << endl;
+ usage();
return EXIT_FAILURE;
}
else
@@ -116,17 +131,17 @@ 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]);
+ cerr << appName() << ": `-e' option cannot be used if input files are given" << endl;
+ usage();
return EXIT_FAILURE;
}
- PropertiesPtr properties = communicator->getProperties();
+ PropertiesPtr properties = communicator()->getProperties();
const char* adminEndpointsProperty = "Ice.Adapter.Admin.Endpoints";
string adminEndpoints = properties->getProperty(adminEndpointsProperty);
if (adminEndpoints.empty())
{
- cerr << argv[0] << ": property `" << adminEndpointsProperty << "' is not set" << endl;
+ cerr << appName() << ": property `" << adminEndpointsProperty << "' is not set" << endl;
return EXIT_FAILURE;
}
@@ -137,15 +152,15 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
secureFlag = " -s ";
}
- Ice::ObjectPrx base = communicator->stringToProxy("admin" + secureFlag + ":" + adminEndpoints);
+ Ice::ObjectPrx base = communicator()->stringToProxy("admin" + secureFlag + ":" + adminEndpoints);
AdminPrx admin = AdminPrx::checkedCast(base);
if (!admin)
{
- cerr << argv[0] << ": `" << adminEndpoints << "' are no valid administrative endpoints" << endl;
+ cerr << appName() << ": `" << adminEndpoints << "' are no valid administrative endpoints" << endl;
return EXIT_FAILURE;
}
- ParserPtr parser = Parser::createParser(communicator, admin);
+ ParserPtr parser = Parser::createParser(communicator(), admin);
int status = EXIT_SUCCESS;
if (argc < 2) // No files given
@@ -174,7 +189,7 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
ifstream test(argv[idx]);
if (!test)
{
- cerr << argv[0] << ": can't open `" << argv[idx] << "' for reading: " << strerror(errno) << endl;
+ cerr << appName() << ": can't open `" << argv[idx] << "' for reading: " << strerror(errno) << endl;
return EXIT_FAILURE;
}
test.close();
@@ -187,7 +202,7 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
#endif
if (cppHandle == NULL)
{
- cerr << argv[0] << ": can't run C++ preprocessor: " << strerror(errno) << endl;
+ cerr << appName() << ": can't run C++ preprocessor: " << strerror(errno) << endl;
return EXIT_FAILURE;
}
@@ -208,36 +223,3 @@ run(int argc, char* argv[], const CommunicatorPtr& communicator)
return status;
}
-
-int
-main(int argc, char* argv[])
-{
- int status;
- CommunicatorPtr communicator;
-
- try
- {
- communicator = initialize(argc, argv);
- status = run(argc, argv, communicator);
- }
- catch(const Exception& ex)
- {
- cerr << ex << endl;
- status = EXIT_FAILURE;
- }
-
- if (communicator)
- {
- try
- {
- communicator->destroy();
- }
- catch(const Exception& ex)
- {
- cerr << ex << endl;
- status = EXIT_FAILURE;
- }
- }
-
- return status;
-}