diff options
author | Joe George <joe@zeroc.com> | 2021-01-28 16:26:44 -0500 |
---|---|---|
committer | Joe George <joe@zeroc.com> | 2021-02-01 16:59:30 -0500 |
commit | 92a6531e409f2691d82591e185a92299d415fc0f (patch) | |
tree | 60c79e2a8f327b8f0b6ebc06b06f48a2e8086f6a /cpp/src/IceGrid/Client.cpp | |
parent | Port Glacier2, IceBox, IceBridge, IceDB, IceXML, icegriddb (diff) | |
download | ice-92a6531e409f2691d82591e185a92299d415fc0f.tar.bz2 ice-92a6531e409f2691d82591e185a92299d415fc0f.tar.xz ice-92a6531e409f2691d82591e185a92299d415fc0f.zip |
IceGrid and IceStorm
Diffstat (limited to 'cpp/src/IceGrid/Client.cpp')
-rw-r--r-- | cpp/src/IceGrid/Client.cpp | 154 |
1 files changed, 61 insertions, 93 deletions
diff --git a/cpp/src/IceGrid/Client.cpp b/cpp/src/IceGrid/Client.cpp index 627cb87e95d..555e0ee7e4a 100644 --- a/cpp/src/IceGrid/Client.cpp +++ b/cpp/src/IceGrid/Client.cpp @@ -4,12 +4,9 @@ #include <IceUtil/Options.h> #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> #include <Ice/Ice.h> #include <IceGrid/Parser.h> #include <IceGrid/FileParserI.h> @@ -37,90 +34,46 @@ class Client; namespace { -IceUtil::Mutex* _staticMutex = 0; -Ice::CommunicatorPtr communicator; -IceGrid::ParserPtr parser; +mutex staticMutex; +shared_ptr<Ice::Communicator> communicator; +shared_ptr<IceGrid::Parser> parser; -class Init -{ -public: - - Init() - { - _staticMutex = new IceUtil::Mutex; - } - - ~Init() - { - delete _staticMutex; - _staticMutex = 0; - } }; -Init init; - -} - -class ReuseConnectionRouter : public Ice::Router +class ReuseConnectionRouter final : public Ice::Router { public: - ReuseConnectionRouter(const Ice::ObjectPrx& proxy) : _clientProxy(proxy) + ReuseConnectionRouter(shared_ptr<Ice::ObjectPrx> proxy) : _clientProxy(move(proxy)) { } - virtual Ice::ObjectPrx - getClientProxy(IceUtil::Optional<bool>& hasRoutingTable, const Ice::Current&) const + shared_ptr<Ice::ObjectPrx> + getClientProxy(IceUtil::Optional<bool>& hasRoutingTable, const Ice::Current&) const override { hasRoutingTable = false; return _clientProxy; } - virtual Ice::ObjectPrx - getServerProxy(const Ice::Current&) const - { - return 0; - } - - virtual void - addProxy(const Ice::ObjectPrx&, const Ice::Current&) + shared_ptr<Ice::ObjectPrx> + getServerProxy(const Ice::Current&) const override { + return nullptr; } - virtual Ice::ObjectProxySeq - addProxies(const Ice::ObjectProxySeq&, const Ice::Current&) + Ice::ObjectProxySeq + addProxies(Ice::ObjectProxySeq, const Ice::Current&) override { return Ice::ObjectProxySeq(); } private: - const Ice::ObjectPrx _clientProxy; + const shared_ptr<Ice::ObjectPrx> _clientProxy; }; int run(const Ice::StringSeq&); -// -// Callback for CtrlCHandler -// -static void -interruptCallback(int /*signal*/) -{ - IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(_staticMutex); - if(parser) // If there's an interactive parser, notify the parser. - { - parser->interrupt(); - } - else - { - // - // Otherwise, destroy the communicator. - // - assert(communicator); - communicator->destroy(); - } -} - int #ifdef _WIN32 wmain(int argc, wchar_t* argv[]) @@ -138,16 +91,31 @@ main(int argc, char* argv[]) try { - Ice::CtrlCHandler ctrlCHandler; - Ice::PropertiesPtr defaultProps = Ice::createProperties(); - defaultProps->setProperty("IceGridAdmin.Server.Endpoints", "tcp -h localhost"); + IceUtil::CtrlCHandler ctrlCHandler; + auto defaultProps = Ice::createProperties(); + defaultProps->setProperty("IceGridAdmin.Server.Endpoints", "tcp -h 127.0.0.1"); + defaultProps->setProperty("IceGridAdmin.Server.ServerName", "127.0.0.1"); Ice::InitializationData id; id.properties = createProperties(args, defaultProps); id.properties->setProperty("Ice.Warn.Endpoints", "0"); Ice::CommunicatorHolder ich(id); communicator = ich.communicator(); - ctrlCHandler.setCallback(interruptCallback); + ctrlCHandler.setCallback([](int) { + lock_guard lg(staticMutex); + if(parser) // If there's an interactive parser, notify the parser. + { + parser->interrupt(); + } + else + { + // + // Otherwise, destroy the communicator. + // + assert(communicator); + communicator->destroy(); + } + }); try { @@ -224,7 +192,7 @@ getPassword(const string& prompt) } extern "C" ICE_LOCATOR_DISCOVERY_API Ice::Plugin* -createIceLocatorDiscovery(const Ice::CommunicatorPtr&, const string&, const Ice::StringSeq&); +createIceLocatorDiscovery(const shared_ptr<Ice::Communicator>&, const string&, const Ice::StringSeq&); int run(const Ice::StringSeq& args) @@ -275,9 +243,9 @@ run(const Ice::StringSeq& args) if(opts.isSet("server")) { - Ice::ObjectAdapterPtr adapter = communicator->createObjectAdapter("IceGridAdmin.Server"); + auto adapter = communicator->createObjectAdapter("IceGridAdmin.Server"); adapter->activate(); - Ice::ObjectPrx proxy = adapter->add(new FileParserI, Ice::stringToIdentity("FileParser")); + auto proxy = adapter->add(make_shared<IceGrid::FileParserI>(), Ice::stringToIdentity("FileParser")); consoleOut << proxy << endl; communicator->waitForShutdown(); @@ -286,10 +254,9 @@ run(const Ice::StringSeq& args) if(opts.isSet("e")) { - vector<string> optargs = opts.argVec("e"); - for(vector<string>::const_iterator i = optargs.begin(); i != optargs.end(); ++i) + for(const auto& arg : opts.argVec("e")) { - commands += *i + ";"; + commands += arg + ";"; } } debug = opts.isSet("debug"); @@ -334,15 +301,15 @@ run(const Ice::StringSeq& args) } } - Ice::PropertiesPtr properties = communicator->getProperties(); + auto properties = communicator->getProperties(); string replica = properties->getProperty("IceGridAdmin.Replica"); if(!opts.optArg("replica").empty()) { replica = opts.optArg("replica"); } - Glacier2::RouterPrx router; - IceGrid::AdminSessionPrx session; + shared_ptr<Glacier2::RouterPrx> router; + shared_ptr<IceGrid::AdminSessionPrx> session; int status = 0; try { @@ -356,7 +323,7 @@ run(const Ice::StringSeq& args) os << "Ice/LocatorFinder" << (ssl ? " -s" : ""); os << ":tcp -h \"" << host << "\" -p " << (port == 0 ? 4061 : port) << " -t " << timeout; os << ":ssl -h \"" << host << "\" -p " << (port == 0 ? 4062 : port) << " -t " << timeout; - Ice::LocatorFinderPrx finder = Ice::LocatorFinderPrx::uncheckedCast(communicator->stringToProxy(os.str())); + auto finder = Ice::uncheckedCast<Ice::LocatorFinderPrx>(communicator->stringToProxy(os.str())); try { communicator->setDefaultLocator(finder->getLocator()); @@ -381,18 +348,19 @@ run(const Ice::StringSeq& args) // to lookup for locator proxies. We destroy the plugin, once we have selected a // locator. // - Ice::PluginPtr pluginObj = createIceLocatorDiscovery(communicator, "IceGridAdmin.Discovery", Ice::StringSeq()); - IceLocatorDiscovery::PluginPtr plugin = IceLocatorDiscovery::PluginPtr::dynamicCast(pluginObj); + shared_ptr<Ice::Plugin> pluginObj(createIceLocatorDiscovery(communicator, "IceGridAdmin.Discovery", + Ice::StringSeq())); + auto plugin = dynamic_pointer_cast<IceLocatorDiscovery::Plugin>(pluginObj); plugin->initialize(); - vector<Ice::LocatorPrx> locators = plugin->getLocators(instanceName, IceUtil::Time::milliSeconds(300)); + auto locators = plugin->getLocators(instanceName, IceUtil::Time::milliSeconds(300)); if(locators.size() > 1) { consoleOut << "found " << locators.size() << " Ice locators:" << endl; unsigned int num = 0; - for(vector<Ice::LocatorPrx>::const_iterator p = locators.begin(); p != locators.end(); ++p) + for(const auto& locator : locators) { - consoleOut << ++num << ": proxy = `" << *p << "'" << endl; + consoleOut << ++num << ": proxy = `" << locator << "'" << endl; } num = 0; @@ -440,7 +408,7 @@ run(const Ice::StringSeq& args) try { // Use SSL if available. - router = Glacier2::RouterPrx::checkedCast(communicator->getDefaultRouter()->ice_preferSecure(true)); + router = Ice::checkedCast<Glacier2::RouterPrx>(communicator->getDefaultRouter()->ice_preferSecure(true)); if(!router) { consoleErr << args[0] << ": configured router is not a Glacier2 router" << endl; @@ -455,7 +423,7 @@ run(const Ice::StringSeq& args) if(ssl) { - session = IceGrid::AdminSessionPrx::uncheckedCast(router->createSessionFromSecureConnection()); + session = Ice::uncheckedCast<IceGrid::AdminSessionPrx>(router->createSessionFromSecureConnection()); if(!session) { consoleErr << args[0] @@ -488,7 +456,7 @@ run(const Ice::StringSeq& args) #endif } - session = IceGrid::AdminSessionPrx::uncheckedCast(router->createSession(id, password)); + session = Ice::uncheckedCast<IceGrid::AdminSessionPrx>(router->createSession(id, password)); fill(password.begin(), password.end(), '\0'); // Zero the password string. if(!session) @@ -528,11 +496,11 @@ run(const Ice::StringSeq& args) // no need to go further. Otherwise, we get the proxy of local registry // proxy. // - IceGrid::LocatorPrx locator; - IceGrid::RegistryPrx localRegistry; + shared_ptr<IceGrid::LocatorPrx> locator; + shared_ptr<IceGrid::RegistryPrx> localRegistry; try { - locator = IceGrid::LocatorPrx::checkedCast(communicator->getDefaultLocator()); + locator = Ice::checkedCast<IceGrid::LocatorPrx>(communicator->getDefaultLocator()); if(!locator) { consoleErr << args[0] << ": configured locator is not an IceGrid locator" << endl; @@ -546,7 +514,7 @@ run(const Ice::StringSeq& args) return 1; } - IceGrid::RegistryPrx registry; + shared_ptr<IceGrid::RegistryPrx> registry; if(localRegistry->ice_getIdentity() == registryId) { registry = localRegistry; @@ -559,7 +527,7 @@ run(const Ice::StringSeq& args) try { - registry = IceGrid::RegistryPrx::checkedCast(locator->findObjectById(registryId)); + registry = Ice::checkedCast<IceGrid::RegistryPrx>(locator->findObjectById(registryId)); if(!registry) { consoleErr << args[0] << ": could not contact an IceGrid registry" << endl; @@ -603,9 +571,9 @@ run(const Ice::StringSeq& args) // if(registry->ice_getIdentity() == localRegistry->ice_getIdentity()) { - Ice::ObjectAdapterPtr colloc = communicator->createObjectAdapter(""); // colloc-only adapter - communicator->setDefaultRouter(Ice::RouterPrx::uncheckedCast( - colloc->addWithUUID(new ReuseConnectionRouter(locator)))); + auto colloc = communicator->createObjectAdapter(""); // colloc-only adapter + communicator->setDefaultRouter(Ice::uncheckedCast<Ice::RouterPrx>( + colloc->addWithUUID(make_shared<ReuseConnectionRouter>(locator)))); registry = registry->ice_router(communicator->getDefaultRouter()); } @@ -663,12 +631,12 @@ run(const Ice::StringSeq& args) if(acmTimeout > 0) { - session->ice_getConnection()->setACM(acmTimeout, IceUtil::None, Ice::ICE_ENUM(ACMHeartbeat, HeartbeatAlways)); + session->ice_getConnection()->setACM(acmTimeout, IceUtil::None, Ice::ACMHeartbeat::HeartbeatAlways); } { - IceUtilInternal::MutexPtrLock<IceUtil::Mutex> lock(_staticMutex); - parser = IceGrid::Parser::createParser(communicator, session, session->getAdmin(), commands.empty()); + lock_guard lock(staticMutex); + parser = make_shared<IceGrid::Parser>(communicator, session, session->getAdmin(), commands.empty()); } if(!commands.empty()) // Commands were given |