summaryrefslogtreecommitdiff
path: root/cpp/src/IceBox/Admin.cpp
diff options
context:
space:
mode:
authorAustin Henriksen <austin.r.henriksen79@gmail.com>2018-09-19 10:56:16 -0400
committerGitHub <noreply@github.com>2018-09-19 10:56:16 -0400
commitf71fcb1ab9477721b5599b7b76dff498841ce10f (patch)
tree9b15158398b416d16126de313ed69315d43caf7b /cpp/src/IceBox/Admin.cpp
parentFix slice2objc bogus generated code for Ice::Value data member (diff)
downloadice-f71fcb1ab9477721b5599b7b76dff498841ce10f.tar.bz2
ice-f71fcb1ab9477721b5599b7b76dff498841ce10f.tar.xz
ice-f71fcb1ab9477721b5599b7b76dff498841ce10f.zip
Removed Application from Ice Services (#196)
Removed Application from Ice services, fixes #50
Diffstat (limited to 'cpp/src/IceBox/Admin.cpp')
-rw-r--r--cpp/src/IceBox/Admin.cpp117
1 files changed, 65 insertions, 52 deletions
diff --git a/cpp/src/IceBox/Admin.cpp b/cpp/src/IceBox/Admin.cpp
index e6fcb866ae6..e679c1ed9f2 100644
--- a/cpp/src/IceBox/Admin.cpp
+++ b/cpp/src/IceBox/Admin.cpp
@@ -7,44 +7,57 @@
//
// **********************************************************************
-#include <Ice/Application.h>
+#include <Ice/Ice.h>
#include <Ice/SliceChecksums.h>
#include <Ice/ConsoleUtil.h>
#include <IceUtil/Options.h>
#include <IceBox/IceBox.h>
using namespace std;
-using namespace Ice;
using namespace IceInternal;
-class Client : public Ice::Application
-{
-public:
+int run(const Ice::StringSeq&);
- void usage();
- virtual int run(int, char*[]);
-};
+Ice::CommunicatorPtr communicator;
-#ifdef _WIN32
+void
+destroyCommunicator(int)
+{
+ communicator->destroy();
+}
int
+#ifdef _WIN32
wmain(int argc, wchar_t* argv[])
-
#else
-
-int
main(int argc, char* argv[])
-
#endif
{
- Client app;
- return app.main(argc, argv);
+ int status = 0;
+
+ try
+ {
+ Ice::CtrlCHandler ctrlCHandler;
+ Ice::CommunicatorHolder ich(argc, argv);
+ communicator = ich.communicator();
+
+ ctrlCHandler.setCallback(&destroyCommunicator);
+
+ status = run(Ice::argsToStringSeq(argc, argv));
+ }
+ catch(const std::exception& ex)
+ {
+ consoleErr << ex.what() << endl;
+ status = 1;
+ }
+
+ return status;
}
void
-Client::usage()
+usage(const string& name)
{
- consoleErr << "Usage: " << appName() << " [options] [command...]\n";
+ consoleErr << "Usage: " << name << " [options] [command...]\n";
consoleErr <<
"Options:\n"
"-h, --help Show this message.\n"
@@ -58,7 +71,7 @@ Client::usage()
}
int
-Client::run(int argc, char* argv[])
+run(const Ice::StringSeq& args)
{
IceUtilInternal::Options opts;
opts.addOpt("h", "help");
@@ -67,33 +80,33 @@ Client::run(int argc, char* argv[])
vector<string> commands;
try
{
- commands = opts.parse(argc, const_cast<const char**>(argv));
+ commands = opts.parse(args);
}
catch(const IceUtilInternal::BadOptException& e)
{
consoleErr << e.reason << endl;
- usage();
- return EXIT_FAILURE;
+ usage(args[0]);
+ return 1;
}
if(opts.isSet("help"))
{
- usage();
- return EXIT_SUCCESS;
+ usage(args[0]);
+ return 0;
}
if(opts.isSet("version"))
{
consoleOut << ICE_STRING_VERSION << endl;
- return EXIT_SUCCESS;
+ return 0;
}
if(commands.empty())
{
- usage();
- return EXIT_FAILURE;
+ usage(args[0]);
+ return 1;
}
- ObjectPrxPtr base = communicator()->propertyToProxy("IceBoxAdmin.ServiceManager.Proxy");
+ Ice::ObjectPrxPtr base = communicator->propertyToProxy("IceBoxAdmin.ServiceManager.Proxy");
if(base == 0)
{
@@ -101,9 +114,9 @@ Client::run(int argc, char* argv[])
// The old deprecated way to retrieve the service manager proxy
//
- PropertiesPtr properties = communicator()->getProperties();
+ Ice::PropertiesPtr properties = communicator->getProperties();
- Identity managerIdentity;
+ Ice::Identity managerIdentity;
managerIdentity.category = properties->getPropertyWithDefault("IceBox.InstanceName", "IceBox");
managerIdentity.name = "ServiceManager";
@@ -113,32 +126,32 @@ Client::run(int argc, char* argv[])
string managerEndpoints = properties->getProperty("IceBox.ServiceManager.Endpoints");
if(managerEndpoints.empty())
{
- consoleErr << appName() << ": property `IceBoxAdmin.ServiceManager.Proxy' is not set" << endl;
- return EXIT_FAILURE;
+ consoleErr << args[0] << ": property `IceBoxAdmin.ServiceManager.Proxy' is not set" << endl;
+ return 1;
}
- managerProxy = "\"" + communicator()->identityToString(managerIdentity) + "\" :" + managerEndpoints;
+ managerProxy = "\"" + communicator->identityToString(managerIdentity) + "\" :" + managerEndpoints;
}
else
{
string managerAdapterId = properties->getProperty("IceBox.ServiceManager.AdapterId");
if(managerAdapterId.empty())
{
- consoleErr << appName() << ": property `IceBoxAdmin.ServiceManager.Proxy' is not set" << endl;
- return EXIT_FAILURE;
+ consoleErr << args[0] << ": property `IceBoxAdmin.ServiceManager.Proxy' is not set" << endl;
+ return 1;
}
- managerProxy = "\"" + communicator()->identityToString(managerIdentity) + "\" @" + managerAdapterId;
+ managerProxy = "\"" + communicator->identityToString(managerIdentity) + "\" @" + managerAdapterId;
}
- base = communicator()->stringToProxy(managerProxy);
+ base = communicator->stringToProxy(managerProxy);
}
IceBox::ServiceManagerPrxPtr manager = ICE_CHECKED_CAST(IceBox::ServiceManagerPrx, base);
if(!manager)
{
- consoleErr << appName() << ": `" << base << "' is not an IceBox::ServiceManager" << endl;
- return EXIT_FAILURE;
+ consoleErr << args[0] << ": `" << base << "' is not an IceBox::ServiceManager" << endl;
+ return 1;
}
for(vector<string>::const_iterator r = commands.begin(); r != commands.end(); ++r)
@@ -151,8 +164,8 @@ Client::run(int argc, char* argv[])
{
if(++r == commands.end())
{
- consoleErr << appName() << ": no service name specified." << endl;
- return EXIT_FAILURE;
+ consoleErr << args[0] << ": no service name specified." << endl;
+ return 1;
}
try
@@ -161,20 +174,20 @@ Client::run(int argc, char* argv[])
}
catch(const IceBox::NoSuchServiceException&)
{
- consoleErr << appName() << ": unknown service `" << *r << "'" << endl;
- return EXIT_FAILURE;
+ consoleErr << args[0] << ": unknown service `" << *r << "'" << endl;
+ return 1;
}
catch(const IceBox::AlreadyStartedException&)
{
- consoleErr << appName() << ": service already started." << endl;
+ consoleErr << args[0] << ": service already started." << endl;
}
}
else if((*r) == "stop")
{
if(++r == commands.end())
{
- consoleErr << appName() << ": no service name specified." << endl;
- return EXIT_FAILURE;
+ consoleErr << args[0] << ": no service name specified." << endl;
+ return 1;
}
try
@@ -183,21 +196,21 @@ Client::run(int argc, char* argv[])
}
catch(const IceBox::NoSuchServiceException&)
{
- consoleErr << appName() << ": unknown service `" << *r << "'" << endl;
- return EXIT_FAILURE;
+ consoleErr << args[0] << ": unknown service `" << *r << "'" << endl;
+ return 1;
}
catch(const IceBox::AlreadyStoppedException&)
{
- consoleErr << appName() << ": service already stopped." << endl;
+ consoleErr << args[0] << ": service already stopped." << endl;
}
}
else
{
- consoleErr << appName() << ": unknown command `" << *r << "'" << endl;
- usage();
- return EXIT_FAILURE;
+ consoleErr << args[0] << ": unknown command `" << *r << "'" << endl;
+ usage(args[0]);
+ return 1;
}
}
- return EXIT_SUCCESS;
+ return 0;
}