diff options
author | Jose <jose@zeroc.com> | 2015-12-17 17:52:44 +0100 |
---|---|---|
committer | Jose <jose@zeroc.com> | 2015-12-17 17:52:44 +0100 |
commit | 061e8b03290cd88b14943b30a372a28f3a7365e0 (patch) | |
tree | 0a0a2b10b9fc1f835c6ada152049d6848a92a28f /cpp | |
parent | Fix Python Ice/slicing/objects test (diff) | |
download | ice-061e8b03290cd88b14943b30a372a28f3a7365e0.tar.bz2 ice-061e8b03290cd88b14943b30a372a28f3a7365e0.tar.xz ice-061e8b03290cd88b14943b30a372a28f3a7365e0.zip |
C++11 DispatchInterceptor fixes
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/include/Ice/IncomingAsync.h | 13 | ||||
-rw-r--r-- | cpp/src/Ice/IncomingAsync.cpp | 20 | ||||
-rw-r--r-- | cpp/src/Ice/Object.cpp | 1 | ||||
-rw-r--r-- | cpp/src/slice2cpp/Gen.cpp | 2 | ||||
-rw-r--r-- | cpp/test/Ice/Makefile | 1 | ||||
-rw-r--r-- | cpp/test/Ice/Makefile.mak | 42 | ||||
-rw-r--r-- | cpp/test/Ice/interceptor/AMDInterceptorI.h | 3 | ||||
-rw-r--r-- | cpp/test/Ice/interceptor/Client.cpp | 26 | ||||
-rw-r--r-- | cpp/test/Ice/interceptor/InterceptorI.cpp | 3 | ||||
-rw-r--r-- | cpp/test/Ice/interceptor/InterceptorI.h | 3 | ||||
-rw-r--r-- | cpp/test/Ice/interceptor/MyObjectI.cpp | 109 | ||||
-rw-r--r-- | cpp/test/Ice/interceptor/MyObjectI.h | 8 |
12 files changed, 198 insertions, 33 deletions
diff --git a/cpp/include/Ice/IncomingAsync.h b/cpp/include/Ice/IncomingAsync.h index 6a097698db0..de7b5510793 100644 --- a/cpp/include/Ice/IncomingAsync.h +++ b/cpp/include/Ice/IncomingAsync.h @@ -43,9 +43,9 @@ class ICE_API IncomingAsync : public IncomingBase, #endif { public: + - IncomingAsync(Incoming&); // Adopts the argument. It must not be used afterwards. - + void __deactivate(Incoming&); virtual void ice_exception(const ::std::exception&); @@ -57,6 +57,15 @@ public: bool __validateResponse(bool); +#ifdef ICE_CPP11_MAPPING + static IncomingAsyncPtr create(Incoming&); // Adopts the argument. It must not be used afterwards. + +protected: + + IncomingAsync(Incoming&); // Adopts the argument. It must not be used afterwards. +#else + IncomingAsync(Incoming&); // Adopts the argument. It must not be used afterwards. +#endif private: // diff --git a/cpp/src/Ice/IncomingAsync.cpp b/cpp/src/Ice/IncomingAsync.cpp index 3b4820cdbbb..835963b9c0d 100644 --- a/cpp/src/Ice/IncomingAsync.cpp +++ b/cpp/src/Ice/IncomingAsync.cpp @@ -64,12 +64,32 @@ IceInternal::IncomingAsync::IncomingAsync(Incoming& in) : _retriable(in.isRetriable()), _active(true) { +#ifndef ICE_CPP11_MAPPING if(_retriable) { + // + // With C++11 maping we cannot call setActive from the ctor as + // it creates a smart pointer to this object, and with shared_ptr + // this requires a fully constructed object. + // in.setActive(*this); } +#endif } +#ifdef ICE_CPP11_MAPPING +IncomingAsyncPtr +IceInternal::IncomingAsync::create(Incoming& in) +{ + IncomingAsyncPtr self(new IncomingAsync(in)); + if(in.isRetriable()) + { + in.setActive(*self.get()); + } + return self; +} +#endif + void IceInternal::IncomingAsync::__deactivate(Incoming& in) { diff --git a/cpp/src/Ice/Object.cpp b/cpp/src/Ice/Object.cpp index 7378d7e4e75..a4d28141c6e 100644 --- a/cpp/src/Ice/Object.cpp +++ b/cpp/src/Ice/Object.cpp @@ -182,7 +182,6 @@ Ice::Object::ice_dispatch(Request& request, const DispatchInterceptorAsyncCallba IceInternal::Incoming& in = dynamic_cast<IceInternal::IncomingRequest&>(request)._in; - PushCb pusbCb(in, cb); in.startOver(); // may raise ResponseSentException return __dispatch(in, in.getCurrent()); diff --git a/cpp/src/slice2cpp/Gen.cpp b/cpp/src/slice2cpp/Gen.cpp index 9b3567b0c59..e34d25b5361 100644 --- a/cpp/src/slice2cpp/Gen.cpp +++ b/cpp/src/slice2cpp/Gen.cpp @@ -8255,7 +8255,7 @@ Slice::Gen::Cpp11InterfaceVisitor::visitOperation(const OperationPtr& p) } else { - C << nl << "auto inS = ::std::make_shared<::IceInternal::IncomingAsync>(__inS);"; + C << nl << "auto inS = ::IceInternal::IncomingAsync::create(__inS);"; C << nl << "auto __exception = [inS](::std::exception_ptr e)"; C << sb; C << nl << "try"; diff --git a/cpp/test/Ice/Makefile b/cpp/test/Ice/Makefile index 69b09cc8402..5085b670842 100644 --- a/cpp/test/Ice/Makefile +++ b/cpp/test/Ice/Makefile @@ -33,6 +33,7 @@ SUBDIRS = proxy \ timeout \ acm \ servantLocator \ + interceptor \ udp \ defaultServant \ defaultValue \ diff --git a/cpp/test/Ice/Makefile.mak b/cpp/test/Ice/Makefile.mak index 8a81a6b4170..dd501ce099d 100644 --- a/cpp/test/Ice/Makefile.mak +++ b/cpp/test/Ice/Makefile.mak @@ -13,17 +13,37 @@ top_srcdir = ..\.. !if "$(CPP11_MAPPING)" == "yes" SUBDIRS = proxy \ - operations \ - exceptions \ - ami \ - info \ - inheritance \ - facets \ - objects \ - properties \ - admin \ - enums \ - faultTolerance + operations \ + exceptions \ + ami \ + info \ + inheritance \ + facets \ + objects \ + faultTolerance \ + location \ + adapterDeactivation \ + slicing \ + hash \ + checksum \ + dispatcher \ + hold \ + binding \ + retry \ + timeout \ + acm \ + servantLocator \ + interceptor \ + udp \ + defaultServant \ + defaultValue \ + properties \ + plugin \ + admin \ + enums \ + logger \ + networkProxy \ + services !else SUBDIRS = proxy \ operations \ diff --git a/cpp/test/Ice/interceptor/AMDInterceptorI.h b/cpp/test/Ice/interceptor/AMDInterceptorI.h index 9204b820a92..1cd62fafd4b 100644 --- a/cpp/test/Ice/interceptor/AMDInterceptorI.h +++ b/cpp/test/Ice/interceptor/AMDInterceptorI.h @@ -37,8 +37,7 @@ private: IceUtil::Mutex _mutex; }; - -typedef IceUtil::Handle<AMDInterceptorI> AMDInterceptorIPtr; +ICE_DEFINE_PTR(AMDInterceptorIPtr, AMDInterceptorI); class DispatchInterceptorAsyncCallbackI : public Ice::DispatchInterceptorAsyncCallback { diff --git a/cpp/test/Ice/interceptor/Client.cpp b/cpp/test/Ice/interceptor/Client.cpp index 7653c369306..9aecb8e3609 100644 --- a/cpp/test/Ice/interceptor/Client.cpp +++ b/cpp/test/Ice/interceptor/Client.cpp @@ -86,8 +86,8 @@ public: private: - int run(const Test::MyObjectPrx&, const InterceptorIPtr&); - int runAmd(const Test::MyObjectPrx&, const AMDInterceptorIPtr&); + int run(const Test::MyObjectPrxPtr&, const InterceptorIPtr&); + int runAmd(const Test::MyObjectPrxPtr&, const AMDInterceptorIPtr&); }; #ifndef _WIN32 @@ -152,12 +152,12 @@ Client::run(int, char*[]) // Ice::ObjectAdapterPtr oa = communicator()->createObjectAdapterWithEndpoints("MyOA", "tcp -h localhost"); - Ice::ObjectPtr servant = new MyObjectI; - InterceptorIPtr interceptor = new InterceptorI(servant); - AMDInterceptorIPtr amdInterceptor = new AMDInterceptorI(servant); + Ice::ObjectPtr servant = ICE_MAKE_SHARED(MyObjectI); + InterceptorIPtr interceptor = ICE_MAKE_SHARED(InterceptorI, servant); + AMDInterceptorIPtr amdInterceptor = ICE_MAKE_SHARED(AMDInterceptorI, servant); - Test::MyObjectPrx prx = Test::MyObjectPrx::uncheckedCast(oa->addWithUUID(interceptor)); - Test::MyObjectPrx prxForAMD = Test::MyObjectPrx::uncheckedCast(oa->addWithUUID(amdInterceptor)); + Test::MyObjectPrxPtr prx = ICE_UNCHECKED_CAST(Test::MyObjectPrx, oa->addWithUUID(interceptor)); + Test::MyObjectPrxPtr prxForAMD = ICE_UNCHECKED_CAST(Test::MyObjectPrx, oa->addWithUUID(amdInterceptor)); cout << "Collocation optimization on" << endl; int rs = run(prx, interceptor); @@ -177,7 +177,7 @@ Client::run(int, char*[]) cout << "Collocation optimization off" << endl; interceptor->clear(); - prx = Test::MyObjectPrx::uncheckedCast(prx->ice_collocationOptimized(false)); + prx = ICE_UNCHECKED_CAST(Test::MyObjectPrx, prx->ice_collocationOptimized(false)); rs = run(prx, interceptor); if(rs != 0) { @@ -186,7 +186,7 @@ Client::run(int, char*[]) cout << "Now with AMD" << endl; amdInterceptor->clear(); - prxForAMD = Test::MyObjectPrx::uncheckedCast(prxForAMD->ice_collocationOptimized(false)); + prxForAMD = ICE_UNCHECKED_CAST(Test::MyObjectPrx, prxForAMD->ice_collocationOptimized(false)); rs = runAmd(prxForAMD, amdInterceptor); return rs; @@ -194,7 +194,7 @@ Client::run(int, char*[]) int -Client::run(const Test::MyObjectPrx& prx, const InterceptorIPtr& interceptor) +Client::run(const Test::MyObjectPrxPtr& prx, const InterceptorIPtr& interceptor) { cout << "testing simple interceptor... " << flush; test(interceptor->getLastOperation().empty()); @@ -271,11 +271,11 @@ Client::run(const Test::MyObjectPrx& prx, const InterceptorIPtr& interceptor) test(interceptor->getLastStatus() == Ice::DispatchAsync); cout << "ok" << endl; - return 0; + return EXIT_SUCCESS; } int -Client::runAmd(const Test::MyObjectPrx& prx, const AMDInterceptorIPtr& interceptor) +Client::runAmd(const Test::MyObjectPrxPtr& prx, const AMDInterceptorIPtr& interceptor) { cout << "testing simple interceptor... " << flush; test(interceptor->getLastOperation().empty()); @@ -340,5 +340,5 @@ Client::runAmd(const Test::MyObjectPrx& prx, const AMDInterceptorIPtr& intercept test(interceptor->getActualStatus() == Ice::DispatchAsync); test(dynamic_cast<MySystemException*>(interceptor->getException()) != 0); cout << "ok" << endl; - return 0; + return EXIT_SUCCESS; } diff --git a/cpp/test/Ice/interceptor/InterceptorI.cpp b/cpp/test/Ice/interceptor/InterceptorI.cpp index ad72d14a0c1..e618db8d34c 100644 --- a/cpp/test/Ice/interceptor/InterceptorI.cpp +++ b/cpp/test/Ice/interceptor/InterceptorI.cpp @@ -11,6 +11,8 @@ #include <Test.h> #include <TestCommon.h> +using namespace std; + InterceptorI::InterceptorI(const Ice::ObjectPtr& servant) : _servant(servant), _lastStatus(Ice::DispatchAsync) @@ -43,7 +45,6 @@ InterceptorI::dispatch(Ice::Request& request) current.ctx["retry"] = "no"; } - _lastStatus = _servant->ice_dispatch(request); return _lastStatus; } diff --git a/cpp/test/Ice/interceptor/InterceptorI.h b/cpp/test/Ice/interceptor/InterceptorI.h index 2e1c877685d..fc6d6572732 100644 --- a/cpp/test/Ice/interceptor/InterceptorI.h +++ b/cpp/test/Ice/interceptor/InterceptorI.h @@ -31,7 +31,6 @@ protected: std::string _lastOperation; Ice::DispatchStatus _lastStatus; }; - -typedef IceUtil::Handle<InterceptorI> InterceptorIPtr; +ICE_DEFINE_PTR(InterceptorIPtr, InterceptorI); #endif diff --git a/cpp/test/Ice/interceptor/MyObjectI.cpp b/cpp/test/Ice/interceptor/MyObjectI.cpp index 7b89d4a3534..b007ff938eb 100644 --- a/cpp/test/Ice/interceptor/MyObjectI.cpp +++ b/cpp/test/Ice/interceptor/MyObjectI.cpp @@ -77,9 +77,117 @@ MyObjectI::badSystemAdd(int, int, const Ice::Current&) { throw MySystemException(__FILE__, __LINE__); } + +#ifdef ICE_CPP11_MAPPING +void +MyObjectI::amdAdd_async(int x, + int y, + function<void (int)> response, + function<void (exception_ptr)>, + const Ice::Current&) +{ + thread t( + [x, y, response]() + { + this_thread::sleep_for(chrono::milliseconds(10)); + response(x + y); + }); + t.detach(); +} + +void +MyObjectI::amdAddWithRetry_async(int x, + int y, + function<void (int)> response, + function<void (exception_ptr)>, + const Ice::Current& current) +{ + thread t( + [x, y, response]() + { + this_thread::sleep_for(chrono::milliseconds(10)); + response(x + y); + }); + t.detach(); + + Ice::Context::const_iterator p = current.ctx.find("retry"); + if(p == current.ctx.end() || p->second != "no") + { + throw Test::RetryException(__FILE__, __LINE__); + } +} + +void +MyObjectI::amdBadAdd_async(int x, + int y, + function<void (int)>, + function<void (exception_ptr)> error, + const Ice::Current&) +{ + thread t( + [x, y, error]() + { + this_thread::sleep_for(chrono::milliseconds(10)); + try + { + throw Test::InvalidInputException(); + } + catch(...) + { + error(current_exception()); + } + }); + t.detach(); +} void +MyObjectI::amdNotExistAdd_async(int x, + int y, + function<void (int)>, + function<void (exception_ptr)> error, + const Ice::Current&) +{ + thread t( + [x, y, error]() + { + this_thread::sleep_for(chrono::milliseconds(10)); + try + { + throw Ice::ObjectNotExistException(__FILE__, __LINE__); + } + catch(...) + { + error(current_exception()); + } + }); + t.detach(); +} + +void +MyObjectI::amdBadSystemAdd_async(int x, + int y, + function<void (int)>, + function<void (exception_ptr)> error, + const Ice::Current&) +{ + thread t( + [x, y, error]() + { + this_thread::sleep_for(chrono::milliseconds(10)); + try + { + throw MySystemException(__FILE__, __LINE__); + } + catch(...) + { + error(current_exception()); + } + }); + t.detach(); +} +#else +void MyObjectI::amdAdd_async(const Test::AMD_MyObject_amdAddPtr& cb, int x, int y, const Ice::Current&) { class ThreadI : public Thread @@ -219,3 +327,4 @@ MyObjectI::amdBadSystemAdd_async(const Test::AMD_MyObject_amdBadSystemAddPtr& cb ThreadPtr thread = new ThreadI(cb); thread->start().detach(); } +#endif diff --git a/cpp/test/Ice/interceptor/MyObjectI.h b/cpp/test/Ice/interceptor/MyObjectI.h index 90e2bb5f370..711bc0111df 100644 --- a/cpp/test/Ice/interceptor/MyObjectI.h +++ b/cpp/test/Ice/interceptor/MyObjectI.h @@ -35,11 +35,19 @@ public: virtual int notExistAdd(int, int, const Ice::Current&); virtual int badSystemAdd(int, int, const Ice::Current&); +#ifdef ICE_CPP11_MAPPING + virtual void amdAdd_async(int, int, std::function<void (int)>, std::function<void (std::exception_ptr)>, const Ice::Current&); + virtual void amdAddWithRetry_async(int, int, std::function<void (int)>, std::function<void (std::exception_ptr)>, const Ice::Current&); + virtual void amdBadAdd_async(int, int, std::function<void (int)>, std::function<void (std::exception_ptr)>, const Ice::Current&); + virtual void amdNotExistAdd_async(int, int, std::function<void (int)>, std::function<void (std::exception_ptr)>, const Ice::Current&); + virtual void amdBadSystemAdd_async(int, int, std::function<void (int)>, std::function<void (std::exception_ptr)>, const Ice::Current&); +#else virtual void amdAdd_async(const Test::AMD_MyObject_amdAddPtr&, int, int, const Ice::Current&); virtual void amdAddWithRetry_async(const Test::AMD_MyObject_amdAddWithRetryPtr&, int, int, const Ice::Current&); virtual void amdBadAdd_async(const Test::AMD_MyObject_amdBadAddPtr&, int, int, const Ice::Current&); virtual void amdNotExistAdd_async(const Test::AMD_MyObject_amdNotExistAddPtr&, int, int, const Ice::Current&); virtual void amdBadSystemAdd_async(const Test::AMD_MyObject_amdBadSystemAddPtr&, int, int, const Ice::Current&); +#endif }; #endif |