diff options
Diffstat (limited to 'cpp/src/IceGrid/Client.cpp')
-rw-r--r-- | cpp/src/IceGrid/Client.cpp | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/cpp/src/IceGrid/Client.cpp b/cpp/src/IceGrid/Client.cpp index 8dafd14f4ed..06326032ea2 100644 --- a/cpp/src/IceGrid/Client.cpp +++ b/cpp/src/IceGrid/Client.cpp @@ -12,6 +12,7 @@ #include <IceUtil/CtrlCHandler.h> #include <IceUtil/Thread.h> #include <IceUtil/StringUtil.h> +#include <Ice/ConsoleUtil.h> #include <Ice/UUID.h> #include <IceUtil/Mutex.h> #include <IceUtil/MutexPtrLock.h> @@ -37,6 +38,7 @@ using namespace std; using namespace Ice; +using namespace IceInternal; using namespace IceLocatorDiscovery; using namespace IceGrid; @@ -277,8 +279,8 @@ main(int argc, char* argv[]) void Client::usage() { - cerr << "Usage: " << appName() << " [options]\n"; - cerr << + consoleErr << "Usage: " << appName() << " [options]\n"; + consoleErr << "Options:\n" "-h, --help Show this message.\n" "-v, --version Display the Ice version.\n" @@ -326,27 +328,27 @@ Client::main(StringSeq& args) } catch(const IceUtil::Exception& ex) { - cerr << _appName << ": " << ex << endl; + consoleErr << _appName << ": " << ex << endl; status = EXIT_FAILURE; } catch(const std::exception& ex) { - cerr << _appName << ": std::exception: " << ex.what() << endl; + consoleErr << _appName << ": std::exception: " << ex.what() << endl; status = EXIT_FAILURE; } catch(const std::string& msg) { - cerr << _appName << ": " << msg << endl; + consoleErr << _appName << ": " << msg << endl; status = EXIT_FAILURE; } catch(const char* msg) { - cerr << _appName << ": " << msg << endl; + consoleErr << _appName << ": " << msg << endl; status = EXIT_FAILURE; } catch(...) { - cerr << _appName << ": unknown exception" << endl; + consoleErr << _appName << ": unknown exception" << endl; status = EXIT_FAILURE; } @@ -361,7 +363,7 @@ Client::main(StringSeq& args) } catch(const Exception& ex) { - cerr << ex << endl; + consoleErr << ex << endl; status = EXIT_FAILURE; } } @@ -427,13 +429,13 @@ Client::run(StringSeq& originalArgs) } catch(const IceUtilInternal::BadOptException& e) { - cerr << e.reason << endl; + consoleErr << e.reason << endl; usage(); return EXIT_FAILURE; } if(!args.empty()) { - cerr << _appName << ": too many arguments" << endl; + consoleErr << _appName << ": too many arguments" << endl; usage(); return EXIT_FAILURE; } @@ -445,7 +447,7 @@ Client::run(StringSeq& originalArgs) } if(opts.isSet("version")) { - cout << ICE_STRING_VERSION << endl; + consoleOut << ICE_STRING_VERSION << endl; return EXIT_SUCCESS; } @@ -455,7 +457,7 @@ Client::run(StringSeq& originalArgs) communicator()->createObjectAdapterWithEndpoints("FileParser", "tcp -h localhost"); adapter->activate(); ObjectPrx proxy = adapter->add(new FileParserI, stringToIdentity("FileParser")); - cout << proxy << endl; + consoleOut << proxy << endl; communicator()->waitForShutdown(); return EXIT_SUCCESS; @@ -506,7 +508,7 @@ Client::run(StringSeq& originalArgs) istringstream is(opts.optArg("port")); if(!(is >> port)) { - cerr << _appName << ": given port number is not a numeric value" << endl; + consoleErr << _appName << ": given port number is not a numeric value" << endl; return EXIT_FAILURE; } } @@ -547,8 +549,8 @@ Client::run(StringSeq& originalArgs) if(!instanceName.empty() && communicator()->getDefaultLocator()->ice_getIdentity().category != instanceName) { - cerr << _appName << ": registry running on `" << host << "' uses a different instance name:\n"; - cerr << communicator()->getDefaultLocator()->ice_getIdentity().category << endl; + consoleErr << _appName << ": registry running on `" << host << "' uses a different instance name:\n"; + consoleErr << communicator()->getDefaultLocator()->ice_getIdentity().category << endl; return EXIT_FAILURE; } } @@ -616,7 +618,7 @@ Client::run(StringSeq& originalArgs) } catch(const Ice::LocalException& ex) { - cerr << _appName << ": registry discovery failed:\n" << ex << endl; + consoleErr << _appName << ": registry discovery failed:\n" << ex << endl; return EXIT_FAILURE; } adapter->destroy(); @@ -624,17 +626,17 @@ Client::run(StringSeq& originalArgs) vector<Ice::LocatorPrx> locators = reply->getLocators(); if(locators.size() > 1) { - cout << "found " << locators.size() << " Ice locators:" << endl; + consoleOut << "found " << locators.size() << " Ice locators:" << endl; unsigned int num = 0; for(vector<Ice::LocatorPrx>::const_iterator p = locators.begin(); p != locators.end(); ++p) { - cout << ++num << ": proxy = `" << *p << "'" <<endl; + consoleOut << ++num << ": proxy = `" << *p << "'" << endl; } num = 0; while(num == 0 && cin.good()) { - cout << "please enter the locator number to use: " << flush; + consoleOut << "please enter the locator number to use: " << flush; string line; getline(cin, line); if(!cin.good() || line.empty()) @@ -656,7 +658,7 @@ Client::run(StringSeq& originalArgs) } else if(locators.size() == 1) { - cout << "using discovered locator:\nproxy = `" << locators[0] << "'" << endl; + consoleOut << "using discovered locator:\nproxy = `" << locators[0] << "'" << endl; communicator()->setDefaultLocator(locators[0]); } } @@ -670,13 +672,13 @@ Client::run(StringSeq& originalArgs) router = Glacier2::RouterPrx::checkedCast(communicator()->getDefaultRouter()->ice_preferSecure(true)); if(!router) { - cerr << _appName << ": configured router is not a Glacier2 router" << endl; + consoleErr << _appName << ": configured router is not a Glacier2 router" << endl; return EXIT_FAILURE; } } catch(const LocalException& ex) { - cerr << _appName << ": could not contact the default router:" << endl << ex << endl; + consoleErr << _appName << ": could not contact the default router:" << endl << ex << endl; return EXIT_FAILURE; } @@ -685,7 +687,7 @@ Client::run(StringSeq& originalArgs) session = AdminSessionPrx::uncheckedCast(router->createSessionFromSecureConnection()); if(!session) { - cerr << _appName + consoleErr << _appName << ": Glacier2 returned a null session, please set the Glacier2.SSLSessionManager property" << endl; return EXIT_FAILURE; @@ -695,7 +697,7 @@ Client::run(StringSeq& originalArgs) { while(id.empty() && cin.good()) { - cout << "user id: " << flush; + consoleOut << "user id: " << flush; getline(cin, id); if(!cin.good()) { @@ -720,7 +722,7 @@ Client::run(StringSeq& originalArgs) if(!session) { - cerr << _appName + consoleErr << _appName << ": Glacier2 returned a null session, please set the Glacier2.SessionManager property" << endl; return EXIT_FAILURE; @@ -760,14 +762,14 @@ Client::run(StringSeq& originalArgs) locator = IceGrid::LocatorPrx::checkedCast(communicator()->getDefaultLocator()); if(!locator) { - cerr << _appName << ": configured locator is not an IceGrid locator" << endl; + consoleErr << _appName << ": configured locator is not an IceGrid locator" << endl; return EXIT_FAILURE; } localRegistry = locator->getLocalRegistry(); } catch(const LocalException& ex) { - cerr << _appName << ": could not contact the default locator:" << endl << ex << endl; + consoleErr << _appName << ": could not contact the default locator:" << endl << ex << endl; return EXIT_FAILURE; } @@ -787,20 +789,20 @@ Client::run(StringSeq& originalArgs) registry = RegistryPrx::checkedCast(locator->findObjectById(registryId)); if(!registry) { - cerr << _appName << ": could not contact an IceGrid registry" << endl; + consoleErr << _appName << ": could not contact an IceGrid registry" << endl; } } catch(const ObjectNotFoundException&) { - cerr << _appName << ": no active registry replica named `" << replica << "'" << endl; + consoleErr << _appName << ": no active registry replica named `" << replica << "'" << endl; return EXIT_FAILURE; } catch(const LocalException& ex) { if(!replica.empty()) { - cerr << _appName << ": could not contact the registry replica named `" << replica << "':\n"; - cerr << ex << endl; + consoleErr << _appName << ": could not contact the registry replica named `" << replica << "':\n"; + consoleErr << ex << endl; return EXIT_FAILURE; } else @@ -816,7 +818,7 @@ Client::run(StringSeq& originalArgs) { name = name.substr(prefix.size()); } - cerr << _appName << ": warning: could not contact master, using slave `" << name << "'" << endl; + consoleErr << _appName << ": warning: could not contact master, using slave `" << name << "'" << endl; } } } @@ -845,7 +847,7 @@ Client::run(StringSeq& originalArgs) { while(id.empty() && cin.good()) { - cout << "user id: " << flush; + consoleOut << "user id: " << flush; getline(cin, id); if(!cin.good()) { @@ -880,8 +882,8 @@ Client::run(StringSeq& originalArgs) } else // No default locator or router set. { - cerr << _appName << ": could not contact the registry:" << endl; - cerr << "no default locator or router configured" << endl; + consoleErr << _appName << ": could not contact the registry:" << endl; + consoleErr << "no default locator or router configured" << endl; return EXIT_FAILURE; } @@ -911,11 +913,11 @@ Client::run(StringSeq& originalArgs) SliceChecksumDict::const_iterator r = serverChecksums.find(q->first); if(r == serverChecksums.end()) { - cerr << appName() << ": server is using unknown Slice type `" << q->first << "'" << endl; + consoleErr << appName() << ": server is using unknown Slice type `" << q->first << "'" << endl; } else if(q->second != r->second) { - cerr << appName() << ": server is using a different Slice definition of `" << q->first << "'" << endl; + consoleErr << appName() << ": server is using a different Slice definition of `" << q->first << "'" << endl; } } @@ -945,17 +947,17 @@ Client::run(StringSeq& originalArgs) } catch(const IceGrid::PermissionDeniedException& ex) { - cout << "permission denied:\n" << ex.reason << endl; + consoleOut << "permission denied:\n" << ex.reason << endl; return EXIT_FAILURE; } catch(const Glacier2::PermissionDeniedException& ex) { - cout << "permission denied:\n" << ex.reason << endl; + consoleOut << "permission denied:\n" << ex.reason << endl; return EXIT_FAILURE; } catch(const Glacier2::CannotCreateSessionException& ex) { - cout << "session creation failed:\n" << ex.reason << endl; + consoleOut << "session creation failed:\n" << ex.reason << endl; return EXIT_FAILURE; } catch(...) @@ -1015,7 +1017,7 @@ Client::run(StringSeq& originalArgs) string Client::getPassword(const string& prompt) { - cout << prompt << flush; + consoleOut << prompt << flush; string password; #ifndef _WIN32 struct termios oldConf; @@ -1033,6 +1035,6 @@ Client::getPassword(const string& prompt) password += c; } #endif - cout << endl; + consoleOut << endl; return IceUtilInternal::trim(password); } |