diff options
author | Jose <jose@zeroc.com> | 2017-05-15 19:33:38 +0200 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2017-05-15 19:33:38 +0200 |
commit | 1b7a03f125e5cb22e6de716f145b2ec2d62a75ca (patch) | |
tree | 30ccc5f85359a75c99eef0bbb6ddb852a427b724 /cpp | |
parent | Fix (ICE-7878) - Add support for IceSSL OpenSSL with VS2013 (diff) | |
download | ice-1b7a03f125e5cb22e6de716f145b2ec2d62a75ca.tar.bz2 ice-1b7a03f125e5cb22e6de716f145b2ec2d62a75ca.tar.xz ice-1b7a03f125e5cb22e6de716f145b2ec2d62a75ca.zip |
Fix (ICE-7873) - Port Glacier2/sessionHelper test to C++11
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/msbuild/ice.test.sln | 4 | ||||
-rw-r--r-- | cpp/src/Glacier2Lib/SessionHelper.cpp | 4 | ||||
-rw-r--r-- | cpp/test/Glacier2/sessionHelper/Client.cpp | 68 | ||||
-rw-r--r-- | cpp/test/Glacier2/sessionHelper/Server.cpp | 6 |
4 files changed, 60 insertions, 22 deletions
diff --git a/cpp/msbuild/ice.test.sln b/cpp/msbuild/ice.test.sln index 3e4546542e7..aff13163b98 100644 --- a/cpp/msbuild/ice.test.sln +++ b/cpp/msbuild/ice.test.sln @@ -2805,8 +2805,10 @@ Global {40C0ABA8-A839-4988-AC60-04F649B44C54}.Release|x64.Build.0 = Release|x64 {BF42E24D-954E-47A6-8699-B2F764939757}.Cpp11-Debug|Win32.ActiveCfg = Cpp11-Debug|Win32 {BF42E24D-954E-47A6-8699-B2F764939757}.Cpp11-Debug|x64.ActiveCfg = Cpp11-Debug|x64 + {BF42E24D-954E-47A6-8699-B2F764939757}.Cpp11-Debug|x64.Build.0 = Cpp11-Debug|x64 {BF42E24D-954E-47A6-8699-B2F764939757}.Cpp11-Release|Win32.ActiveCfg = Cpp11-Release|Win32 {BF42E24D-954E-47A6-8699-B2F764939757}.Cpp11-Release|x64.ActiveCfg = Cpp11-Release|x64 + {BF42E24D-954E-47A6-8699-B2F764939757}.Cpp11-Release|x64.Build.0 = Cpp11-Release|x64 {BF42E24D-954E-47A6-8699-B2F764939757}.Debug|Win32.ActiveCfg = Debug|Win32 {BF42E24D-954E-47A6-8699-B2F764939757}.Debug|Win32.Build.0 = Debug|Win32 {BF42E24D-954E-47A6-8699-B2F764939757}.Debug|x64.ActiveCfg = Debug|x64 @@ -2817,8 +2819,10 @@ Global {BF42E24D-954E-47A6-8699-B2F764939757}.Release|x64.Build.0 = Release|x64 {D3978518-2640-48BE-9D42-F664742BCB45}.Cpp11-Debug|Win32.ActiveCfg = Cpp11-Debug|Win32 {D3978518-2640-48BE-9D42-F664742BCB45}.Cpp11-Debug|x64.ActiveCfg = Cpp11-Debug|x64 + {D3978518-2640-48BE-9D42-F664742BCB45}.Cpp11-Debug|x64.Build.0 = Cpp11-Debug|x64 {D3978518-2640-48BE-9D42-F664742BCB45}.Cpp11-Release|Win32.ActiveCfg = Cpp11-Release|Win32 {D3978518-2640-48BE-9D42-F664742BCB45}.Cpp11-Release|x64.ActiveCfg = Cpp11-Release|x64 + {D3978518-2640-48BE-9D42-F664742BCB45}.Cpp11-Release|x64.Build.0 = Cpp11-Release|x64 {D3978518-2640-48BE-9D42-F664742BCB45}.Debug|Win32.ActiveCfg = Debug|Win32 {D3978518-2640-48BE-9D42-F664742BCB45}.Debug|Win32.Build.0 = Debug|Win32 {D3978518-2640-48BE-9D42-F664742BCB45}.Debug|x64.ActiveCfg = Debug|x64 diff --git a/cpp/src/Glacier2Lib/SessionHelper.cpp b/cpp/src/Glacier2Lib/SessionHelper.cpp index 6cb7787cc8a..3891e31ab7f 100644 --- a/cpp/src/Glacier2Lib/SessionHelper.cpp +++ b/cpp/src/Glacier2Lib/SessionHelper.cpp @@ -877,9 +877,9 @@ SessionHelperI::dispatchCallbackAndWait(const Ice::DispatcherCallPtr& call, cons IceUtilInternal::CountDownLatch cdl(1); Ice::DispatcherCallPtr callWait = new DispatcherCallWait(cdl, call); #ifdef ICE_CPP11_MAPPING - _initData.dispatcher([call]() + _initData.dispatcher([callWait]() { - call->run(); + callWait->run(); }, conn); #else diff --git a/cpp/test/Glacier2/sessionHelper/Client.cpp b/cpp/test/Glacier2/sessionHelper/Client.cpp index 7fed4f5bc9d..42770fb280f 100644 --- a/cpp/test/Glacier2/sessionHelper/Client.cpp +++ b/cpp/test/Glacier2/sessionHelper/Client.cpp @@ -38,7 +38,11 @@ public: Notify* instance = 0; -class Dispatcher : public Ice::Dispatcher, public IceUtil::Thread +class Dispatcher : +#ifndef ICE_CPP11_MAPPING + public Ice::Dispatcher, +#endif + public IceUtil::Thread { public: @@ -48,9 +52,13 @@ public: { } - virtual void - dispatch(const Ice::DispatcherCallPtr& call, - const Ice::ConnectionPtr&) + virtual void dispatch( +#ifdef ICE_CPP11_MAPPING + std::function<void()> call, +#else + const Ice::DispatcherCallPtr& call, +#endif + const Ice::ConnectionPtr&) { IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); if(_queue.empty()) @@ -73,18 +81,31 @@ public: { while(1) { +#ifdef ICE_CPP11_MAPPING + auto item = nextItem(); + if (!item) + { + break; + } + item(); +#else Ice::DispatcherCallPtr item = nextItem(); if(!item) { break; } item->run(); +#endif } } private: +#ifdef ICE_CPP11_MAPPING + std::function<void()> +#else Ice::DispatcherCallPtr +#endif nextItem() { IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); @@ -92,18 +113,26 @@ private: { if(_destroyed) { - return 0; + return ICE_NULLPTR; } _monitor.wait(); } +#ifdef ICE_CPP11_MAPPING + auto item = _queue.front(); +#else Ice::DispatcherCallPtr item = _queue.front(); +#endif _queue.pop_front(); return item; } IceUtil::Monitor<IceUtil::Mutex> _monitor; +#ifdef ICE_CPP11_MAPPING + list<std::function<void()>> _queue; +#else list<Ice::DispatcherCallPtr> _queue; +#endif bool _destroyed; }; typedef IceUtil::Handle<Dispatcher> DispatcherPtr; @@ -281,9 +310,15 @@ public: DispatcherPtr dispatcher = new Dispatcher(); dispatcher->start(); +#ifdef ICE_CPP11_MAPPING + _initData.dispatcher = [dispatcher](std::function<void()> call, const std::shared_ptr<Ice::Connection>& conn) + { + dispatcher->dispatch(call, conn); + }; +#else _initData.dispatcher = dispatcher; - - _factory = new Glacier2::SessionFactoryHelper(_initData, new FailSessionCallback()); +#endif + _factory = ICE_MAKE_SHARED(Glacier2::SessionFactoryHelper, _initData, ICE_MAKE_SHARED(FailSessionCallback)); // // Test to create a session with wrong userid/password @@ -295,7 +330,6 @@ public: cout << "testing SessionHelper connect with wrong userid/password... " << flush; _session = _factory->connect("userid", "xxx"); - // // Wait for connectFailed callback // @@ -310,7 +344,7 @@ public: // _initData.properties->setProperty("Ice.Default.Router", ""); - _factory = new Glacier2::SessionFactoryHelper(_initData, new InterruptConnectCallback()); + _factory = ICE_MAKE_SHARED(Glacier2::SessionFactoryHelper, _initData, ICE_MAKE_SHARED(InterruptConnectCallback)); { IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); @@ -331,7 +365,7 @@ public: } _factory->destroy(); - _factory = new Glacier2::SessionFactoryHelper(_initData, new SuccessSessionCallback()); + _factory = ICE_MAKE_SHARED(Glacier2::SessionFactoryHelper, _initData, ICE_MAKE_SHARED(SuccessSessionCallback)); { IceUtil::Monitor<IceUtil::Mutex>::Lock lock(_monitor); @@ -371,8 +405,8 @@ public: // } cout << "testing stringToProxy for server object... " << flush; - Ice::ObjectPrx base = _session->communicator()->stringToProxy("callback:" + - getTestEndpoint(_session->communicator(), 0)); + Ice::ObjectPrxPtr base = + _session->communicator()->stringToProxy("callback:" + getTestEndpoint(_session->communicator(), 0)); cout << "ok" << endl; cout << "pinging server after session creation... " << flush; @@ -380,7 +414,7 @@ public: cout << "ok" << endl; cout << "testing checked cast for server object... " << flush; - CallbackPrx twoway = CallbackPrx::checkedCast(base); + CallbackPrxPtr twoway = ICE_CHECKED_CAST(CallbackPrx, base); test(twoway); cout << "ok" << endl; @@ -452,7 +486,7 @@ public: communicator()->setDefaultRouter(0); cout << "ok" << endl; - Ice::ObjectPrx processBase; + Ice::ObjectPrxPtr processBase; { cout << "testing stringToProxy for process object... " << flush; processBase = communicator()->stringToProxy("Glacier2/admin -f Process:" + @@ -461,10 +495,10 @@ public: } - Ice::ProcessPrx process; + Ice::ProcessPrxPtr process; { cout << "testing checked cast for admin object... " << flush; - process = Ice::ProcessPrx::checkedCast(processBase); + process = ICE_CHECKED_CAST(Ice::ProcessPrx, processBase); test(process != 0); cout << "ok" << endl; } @@ -484,7 +518,7 @@ public: _factory->destroy(); - _factory = new Glacier2::SessionFactoryHelper(_initData, new AfterShutdownSessionCallback()); + _factory = ICE_MAKE_SHARED(Glacier2::SessionFactoryHelper, _initData, ICE_MAKE_SHARED(AfterShutdownSessionCallback)); // // Wait a bit to ensure glaci2router has been shutdown. diff --git a/cpp/test/Glacier2/sessionHelper/Server.cpp b/cpp/test/Glacier2/sessionHelper/Server.cpp index 7170519fc8d..d7605227a48 100644 --- a/cpp/test/Glacier2/sessionHelper/Server.cpp +++ b/cpp/test/Glacier2/sessionHelper/Server.cpp @@ -31,13 +31,13 @@ class CallbackI : public Callback public: virtual void - initiateCallback(const CallbackReceiverPrx& proxy, const Ice::Current& current) + initiateCallback(ICE_IN(CallbackReceiverPrxPtr) proxy, const Ice::Current& current) { proxy->callback(current.ctx); } virtual void - initiateCallbackEx(const CallbackReceiverPrx& proxy, const Ice::Current& current) + initiateCallbackEx(ICE_IN(CallbackReceiverPrxPtr) proxy, const Ice::Current& current) { proxy->callbackEx(current.ctx); } @@ -59,7 +59,7 @@ SessionHelperServer::run(int, char**) communicator()->getProperties()->setProperty("CallbackAdapter.Endpoints", getTestEndpoint(communicator(), 0)); Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("CallbackAdapter"); - adapter->add(new CallbackI(), Ice::stringToIdentity("callback")); + adapter->add(ICE_MAKE_SHARED(CallbackI), Ice::stringToIdentity("callback")); adapter->activate(); communicator()->waitForShutdown(); |