diff options
Diffstat (limited to 'cpp/src/IceGrid/Client.cpp')
-rw-r--r-- | cpp/src/IceGrid/Client.cpp | 644 |
1 files changed, 322 insertions, 322 deletions
diff --git a/cpp/src/IceGrid/Client.cpp b/cpp/src/IceGrid/Client.cpp index 965fc931a3b..08f1b384dd1 100644 --- a/cpp/src/IceGrid/Client.cpp +++ b/cpp/src/IceGrid/Client.cpp @@ -33,7 +33,7 @@ class SessionKeepAliveThread : public IceUtil::Thread, public IceUtil::Monitor<I public: SessionKeepAliveThread(const AdminSessionPrx& session, long timeout) : - _session(session), + _session(session), _timeout(IceUtil::Time::seconds(timeout)), _destroy(false) { @@ -48,15 +48,15 @@ public: timedWait(_timeout); if(_destroy) { - break; - } + break; + } try { _session->keepAlive(); } catch(const Ice::Exception&) { - break; + break; } } } @@ -103,7 +103,7 @@ static void interruptCallback(int signal) IceUtil::StaticMutex::Lock lock(_staticMutex); if(_globalClient) { - _globalClient->interrupted(); + _globalClient->interrupted(); } } @@ -118,23 +118,23 @@ void Client::usage() { cerr << "Usage: " << appName() << " [options] [file...]\n"; - cerr << - "Options:\n" - "-h, --help Show this message.\n" - "-v, --version Display the Ice version.\n" - "-DNAME Define NAME as 1.\n" - "-DNAME=DEF Define NAME as DEF.\n" - "-UNAME Remove any definition for NAME.\n" - "-IDIR Put DIR in the include file search path.\n" - "-e COMMANDS Execute COMMANDS.\n" - "-d, --debug Print debug messages.\n" + cerr << + "Options:\n" + "-h, --help Show this message.\n" + "-v, --version Display the Ice version.\n" + "-DNAME Define NAME as 1.\n" + "-DNAME=DEF Define NAME as DEF.\n" + "-UNAME Remove any definition for NAME.\n" + "-IDIR Put DIR in the include file search path.\n" + "-e COMMANDS Execute COMMANDS.\n" + "-d, --debug Print debug messages.\n" "-s, --server Start icegridadmin as a server (to parse XML files).\n" "-u, --username Login with the given username.\n" "-p, --password Login with the given password.\n" "-s, --ssl Authenticate through SSL.\n" "-r, --routed Login through a Glacier2 router.\n" "-R, --replica NAME Connect to the replica NAME.\n" - ; + ; } int @@ -144,74 +144,74 @@ Client::main(int argc, char* argv[]) try { - _appName = argv[0]; - _communicator = Ice::initialize(argc, argv); - - { - IceUtil::StaticMutex::Lock sync(_staticMutex); - _globalClient = this; - } - _ctrlCHandler.setCallback(interruptCallback); - - try - { - run(argc, argv); - } - catch(const Ice::CommunicatorDestroyedException&) - { - // Expected if the client is interrupted during the initialization. - } + _appName = argv[0]; + _communicator = Ice::initialize(argc, argv); + + { + IceUtil::StaticMutex::Lock sync(_staticMutex); + _globalClient = this; + } + _ctrlCHandler.setCallback(interruptCallback); + + try + { + run(argc, argv); + } + catch(const Ice::CommunicatorDestroyedException&) + { + // Expected if the client is interrupted during the initialization. + } } catch(const IceUtil::Exception& ex) { - cerr << _appName << ": " << ex << endl; - status = EXIT_FAILURE; + cerr << _appName << ": " << ex << endl; + status = EXIT_FAILURE; } catch(const std::exception& ex) { - cerr << _appName << ": std::exception: " << ex.what() << endl; - status = EXIT_FAILURE; + cerr << _appName << ": std::exception: " << ex.what() << endl; + status = EXIT_FAILURE; } catch(const std::string& msg) { - cerr << _appName << ": " << msg << endl; - status = EXIT_FAILURE; + cerr << _appName << ": " << msg << endl; + status = EXIT_FAILURE; } catch(const char* msg) { - cerr << _appName << ": " << msg << endl; - status = EXIT_FAILURE; + cerr << _appName << ": " << msg << endl; + status = EXIT_FAILURE; } catch(...) { - cerr << _appName << ": unknown exception" << endl; - status = EXIT_FAILURE; + cerr << _appName << ": unknown exception" << endl; + status = EXIT_FAILURE; } if(_communicator) { - try - { - _communicator->destroy(); - } - catch(const Ice::CommunicatorDestroyedException&) - { - } - catch(const Ice::Exception& ex) - { - cerr << ex << endl; - status = EXIT_FAILURE; - } + try + { + _communicator->destroy(); + } + catch(const Ice::CommunicatorDestroyedException&) + { + } + catch(const Ice::Exception& ex) + { + cerr << ex << endl; + status = EXIT_FAILURE; + } } _ctrlCHandler.setCallback(0); { - IceUtil::StaticMutex::Lock sync(_staticMutex); - _globalClient = 0; + IceUtil::StaticMutex::Lock sync(_staticMutex); + _globalClient = 0; } return status; - + } void @@ -220,21 +220,21 @@ Client::interrupted() Lock sync(*this); if(_parser) // If there's an interactive parser, notify the parser. { - _parser->interrupt(); + _parser->interrupt(); } else { - // - // Otherwise, destroy the communicator. - // - assert(_communicator); - try - { - _communicator->destroy(); - } - catch(const Ice::Exception&) - { - } + // + // Otherwise, destroy the communicator. + // + assert(_communicator); + try + { + _communicator->destroy(); + } + catch(const Ice::Exception&) + { + } } } @@ -263,103 +263,103 @@ Client::run(int argc, char* argv[]) vector<string> args; try { - args = opts.parse(argc, (const char**)argv); + args = opts.parse(argc, (const char**)argv); } catch(const IceUtil::BadOptException& e) { cerr << e.reason << endl; - usage(); - return EXIT_FAILURE; + usage(); + return EXIT_FAILURE; } if(opts.isSet("help")) { - usage(); - return EXIT_SUCCESS; + usage(); + return EXIT_SUCCESS; } if(opts.isSet("version")) { - cout << ICE_STRING_VERSION << endl; - return EXIT_SUCCESS; + cout << ICE_STRING_VERSION << endl; + return EXIT_SUCCESS; } if(opts.isSet("server")) { - ObjectAdapterPtr adapter = communicator()->createObjectAdapterWithEndpoints("FileParser", "tcp -h localhost"); - adapter->activate(); - ObjectPrx proxy = adapter->add(new FileParserI, communicator()->stringToIdentity("FileParser")); - cout << proxy << endl; + ObjectAdapterPtr adapter = communicator()->createObjectAdapterWithEndpoints("FileParser", "tcp -h localhost"); + adapter->activate(); + ObjectPrx proxy = adapter->add(new FileParserI, communicator()->stringToIdentity("FileParser")); + cout << proxy << endl; - communicator()->waitForShutdown(); - return EXIT_SUCCESS; + communicator()->waitForShutdown(); + return EXIT_SUCCESS; } if(opts.isSet("D")) { - vector<string> optargs = opts.argVec("D"); - for(vector<string>::const_iterator i = optargs.begin(); i != optargs.end(); ++i) - { - cpp += " -D" + *i; - } + vector<string> optargs = opts.argVec("D"); + for(vector<string>::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + { + cpp += " -D" + *i; + } } if(opts.isSet("U")) { - vector<string> optargs = opts.argVec("U"); - for(vector<string>::const_iterator i = optargs.begin(); i != optargs.end(); ++i) - { - cpp += " -U" + *i; - } + vector<string> optargs = opts.argVec("U"); + for(vector<string>::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + { + cpp += " -U" + *i; + } } if(opts.isSet("I")) { - vector<string> optargs = opts.argVec("I"); - for(vector<string>::const_iterator i = optargs.begin(); i != optargs.end(); ++i) - { - cpp += " -I" + *i; - } + vector<string> optargs = opts.argVec("I"); + for(vector<string>::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + { + cpp += " -I" + *i; + } } if(opts.isSet("e")) { - vector<string> optargs = opts.argVec("e"); - for(vector<string>::const_iterator i = optargs.begin(); i != optargs.end(); ++i) - { - commands += *i + ";"; - } + vector<string> optargs = opts.argVec("e"); + for(vector<string>::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + { + commands += *i + ";"; + } } debug = opts.isSet("debug"); if(!args.empty() && !commands.empty()) { - cerr << appName() << ": `-e' option cannot be used if input files are given" << endl; - usage(); - return EXIT_FAILURE; + cerr << appName() << ": `-e' option cannot be used if input files are given" << endl; + usage(); + return EXIT_FAILURE; } string instanceName; if(communicator()->getDefaultLocator()) { - instanceName = communicator()->getDefaultLocator()->ice_getIdentity().category; + instanceName = communicator()->getDefaultLocator()->ice_getIdentity().category; } else { - instanceName = communicator()->getProperties()->getPropertyWithDefault("IceGrid.InstanceName", "IceGrid"); + instanceName = communicator()->getProperties()->getPropertyWithDefault("IceGrid.InstanceName", "IceGrid"); } bool ssl = communicator()->getProperties()->getPropertyAsInt("IceGridAdmin.AuthenticateUsingSSL"); if(opts.isSet("ssl")) { - ssl = true; + ssl = true; } string id = communicator()->getProperties()->getProperty("IceGridAdmin.Username"); if(!opts.optArg("username").empty()) { - id = opts.optArg("username"); + id = opts.optArg("username"); } string password = communicator()->getProperties()->getProperty("IceGridAdmin.Password"); if(!opts.optArg("password").empty()) { - password = opts.optArg("password"); + password = opts.optArg("password"); } // @@ -370,12 +370,12 @@ Client::run(int argc, char* argv[]) bool routed = properties->getPropertyAsIntWithDefault("IceGridAdmin.Routed", communicator()->getDefaultRouter()); if(opts.isSet("routed")) { - routed = true; + routed = true; } string replica = properties->getProperty("IceGridAdmin.Replica"); if(!opts.optArg("replica").empty()) { - replica = opts.optArg("replica"); + replica = opts.optArg("replica"); } AdminSessionPrx session; @@ -383,227 +383,227 @@ Client::run(int argc, char* argv[]) int status = EXIT_SUCCESS; try { - int timeout; - if(routed) - { - Glacier2::RouterPrx router = Glacier2::RouterPrx::checkedCast(communicator()->getDefaultRouter()); - if(!router) - { - cerr << argv[0] << ": configured router is not a Glacier2 router" << endl; - return EXIT_FAILURE; - } - - // Use SSL if available. - try - { - router = Glacier2::RouterPrx::checkedCast(router->ice_secure(true)); - } - catch(const Ice::NoEndpointException&) - { - } - - if(ssl) - { - session = AdminSessionPrx::uncheckedCast(router->createSessionFromSecureConnection()); - if(!session) - { - cerr << argv[0] - << ": Glacier2 returned a null session, please set the Glacier2.SSLSessionManager property" - << endl; - return EXIT_FAILURE; - } - } - else - { - while(id.empty()) - { - cout << "user id: " << flush; - getline(cin, id); - id = trim(id); - } - - if(password.empty()) - { - cout << "password: " << flush; - getline(cin, password); - password = trim(password); - } - - session = AdminSessionPrx::uncheckedCast(router->createSession(id, password)); - if(!session) - { - cerr << argv[0] - << ": Glacier2 returned a null session, please set the Glacier2.SessionManager property" - << endl; - return EXIT_FAILURE; - } - } - timeout = static_cast<int>(router->getSessionTimeout()); - } - else - { - Identity registryId; - registryId.category = instanceName; - registryId.name = "Registry"; - if(!replica.empty() && replica != "Master") - { - registryId.name += "-" + replica; - } - - RegistryPrx registry; - try - { - registry = RegistryPrx::checkedCast( - communicator()->stringToProxy("\"" + communicator()->identityToString(registryId) + "\"")); - if(!registry) - { - cerr << argv[0] << ": could not contact registry" << endl; - return EXIT_FAILURE; - } - } - catch(const Ice::NotRegisteredException&) - { - cerr << argv[0] << ": no active registry replica named `" << replica << "'" << endl; - return EXIT_FAILURE; - } - - // Use SSL if available. - try - { - registry = RegistryPrx::checkedCast(registry->ice_secure(true)); - } - catch(const Ice::NoEndpointException&) - { - } - - if(ssl) - { - session = registry->createAdminSessionFromSecureConnection(); - } - else - { - while(id.empty()) - { - cout << "user id: " << flush; - getline(cin, id); - id = trim(id); - } - - if(password.empty()) - { - cout << "password: " << flush; - getline(cin, password); - password = trim(password); - } - - session = registry->createAdminSession(id, password); - } - assert(session); - timeout = registry->getSessionTimeout(); - } - - keepAlive = new SessionKeepAliveThread(session, timeout / 2); - keepAlive->start(); - - AdminPrx admin = session->getAdmin(); - - Ice::SliceChecksumDict serverChecksums = admin->getSliceChecksums(); - Ice::SliceChecksumDict localChecksums = Ice::sliceChecksums(); - - // - // The following slice types are only used by the admin CLI. - // - localChecksums.erase("::IceGrid::FileParser"); - localChecksums.erase("::IceGrid::ParseException"); - - for(Ice::SliceChecksumDict::const_iterator q = localChecksums.begin(); q != localChecksums.end(); ++q) - { - Ice::SliceChecksumDict::const_iterator r = serverChecksums.find(q->first); - if(r == serverChecksums.end()) - { - cerr << 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; - } - } - - { - Lock sync(*this); - _parser = Parser::createParser(communicator(), session, admin, args.empty() && commands.empty()); - } - - if(!args.empty()) // Files given - { - // Process files given on the command line - for(vector<string>::const_iterator i = args.begin(); i != args.end(); ++i) - { - ifstream test(i->c_str()); - if(!test) - { - cerr << appName() << ": can't open `" << *i << "' for reading: " << strerror(errno) << endl; - return EXIT_FAILURE; - } - test.close(); - - string cmd = cpp + " " + *i; + int timeout; + if(routed) + { + Glacier2::RouterPrx router = Glacier2::RouterPrx::checkedCast(communicator()->getDefaultRouter()); + if(!router) + { + cerr << argv[0] << ": configured router is not a Glacier2 router" << endl; + return EXIT_FAILURE; + } + + // Use SSL if available. + try + { + router = Glacier2::RouterPrx::checkedCast(router->ice_secure(true)); + } + catch(const Ice::NoEndpointException&) + { + } + + if(ssl) + { + session = AdminSessionPrx::uncheckedCast(router->createSessionFromSecureConnection()); + if(!session) + { + cerr << argv[0] + << ": Glacier2 returned a null session, please set the Glacier2.SSLSessionManager property" + << endl; + return EXIT_FAILURE; + } + } + else + { + while(id.empty()) + { + cout << "user id: " << flush; + getline(cin, id); + id = trim(id); + } + + if(password.empty()) + { + cout << "password: " << flush; + getline(cin, password); + password = trim(password); + } + + session = AdminSessionPrx::uncheckedCast(router->createSession(id, password)); + if(!session) + { + cerr << argv[0] + << ": Glacier2 returned a null session, please set the Glacier2.SessionManager property" + << endl; + return EXIT_FAILURE; + } + } + timeout = static_cast<int>(router->getSessionTimeout()); + } + else + { + Identity registryId; + registryId.category = instanceName; + registryId.name = "Registry"; + if(!replica.empty() && replica != "Master") + { + registryId.name += "-" + replica; + } + + RegistryPrx registry; + try + { + registry = RegistryPrx::checkedCast( + communicator()->stringToProxy("\"" + communicator()->identityToString(registryId) + "\"")); + if(!registry) + { + cerr << argv[0] << ": could not contact registry" << endl; + return EXIT_FAILURE; + } + } + catch(const Ice::NotRegisteredException&) + { + cerr << argv[0] << ": no active registry replica named `" << replica << "'" << endl; + return EXIT_FAILURE; + } + + // Use SSL if available. + try + { + registry = RegistryPrx::checkedCast(registry->ice_secure(true)); + } + catch(const Ice::NoEndpointException&) + { + } + + if(ssl) + { + session = registry->createAdminSessionFromSecureConnection(); + } + else + { + while(id.empty()) + { + cout << "user id: " << flush; + getline(cin, id); + id = trim(id); + } + + if(password.empty()) + { + cout << "password: " << flush; + getline(cin, password); + password = trim(password); + } + + session = registry->createAdminSession(id, password); + } + assert(session); + timeout = registry->getSessionTimeout(); + } + + keepAlive = new SessionKeepAliveThread(session, timeout / 2); + keepAlive->start(); + + AdminPrx admin = session->getAdmin(); + + Ice::SliceChecksumDict serverChecksums = admin->getSliceChecksums(); + Ice::SliceChecksumDict localChecksums = Ice::sliceChecksums(); + + // + // The following slice types are only used by the admin CLI. + // + localChecksums.erase("::IceGrid::FileParser"); + localChecksums.erase("::IceGrid::ParseException"); + + for(Ice::SliceChecksumDict::const_iterator q = localChecksums.begin(); q != localChecksums.end(); ++q) + { + Ice::SliceChecksumDict::const_iterator r = serverChecksums.find(q->first); + if(r == serverChecksums.end()) + { + cerr << 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; + } + } + + { + Lock sync(*this); + _parser = Parser::createParser(communicator(), session, admin, args.empty() && commands.empty()); + } + + if(!args.empty()) // Files given + { + // Process files given on the command line + for(vector<string>::const_iterator i = args.begin(); i != args.end(); ++i) + { + ifstream test(i->c_str()); + if(!test) + { + cerr << appName() << ": can't open `" << *i << "' for reading: " << strerror(errno) << endl; + return EXIT_FAILURE; + } + test.close(); + + string cmd = cpp + " " + *i; #ifdef _WIN32 - FILE* cppHandle = _popen(cmd.c_str(), "r"); + FILE* cppHandle = _popen(cmd.c_str(), "r"); #else - FILE* cppHandle = popen(cmd.c_str(), "r"); + FILE* cppHandle = popen(cmd.c_str(), "r"); #endif - if(cppHandle == NULL) - { - cerr << appName() << ": can't run C++ preprocessor: " << strerror(errno) << endl; - return EXIT_FAILURE; - } - - int parseStatus = _parser->parse(cppHandle, debug); - + if(cppHandle == NULL) + { + cerr << appName() << ": can't run C++ preprocessor: " << strerror(errno) << endl; + return EXIT_FAILURE; + } + + int parseStatus = _parser->parse(cppHandle, debug); + #ifdef _WIN32 - _pclose(cppHandle); + _pclose(cppHandle); #else - pclose(cppHandle); + pclose(cppHandle); #endif - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - } - } - else if(!commands.empty()) // Commands were given - { - int parseStatus = _parser->parse(commands, debug); - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - } - else // No commands, let's use standard input - { - _parser->showBanner(); - - int parseStatus = _parser->parse(stdin, debug); - if(parseStatus == EXIT_FAILURE) - { - status = EXIT_FAILURE; - } - } + if(parseStatus == EXIT_FAILURE) + { + status = EXIT_FAILURE; + } + } + } + else if(!commands.empty()) // Commands were given + { + int parseStatus = _parser->parse(commands, debug); + if(parseStatus == EXIT_FAILURE) + { + status = EXIT_FAILURE; + } + } + else // No commands, let's use standard input + { + _parser->showBanner(); + + int parseStatus = _parser->parse(stdin, debug); + if(parseStatus == EXIT_FAILURE) + { + status = EXIT_FAILURE; + } + } } catch(const IceGrid::PermissionDeniedException& ex) { - cout << "permission denied:\n" << ex.reason << endl; - return EXIT_FAILURE; + cout << "permission denied:\n" << ex.reason << endl; + return EXIT_FAILURE; } catch(...) { - if(keepAlive) - { - keepAlive->destroy(); - keepAlive->getThreadControl().join(); - } + if(keepAlive) + { + keepAlive->destroy(); + keepAlive->getThreadControl().join(); + } if(session) { @@ -615,7 +615,7 @@ Client::run(int argc, char* argv[]) { } } - throw; + throw; } keepAlive->destroy(); |