diff options
Diffstat (limited to 'cpp/test/Ice/interceptor/MyObjectI.cpp')
-rw-r--r-- | cpp/test/Ice/interceptor/MyObjectI.cpp | 167 |
1 files changed, 143 insertions, 24 deletions
diff --git a/cpp/test/Ice/interceptor/MyObjectI.cpp b/cpp/test/Ice/interceptor/MyObjectI.cpp index 7a4d9142a33..a452568dbcb 100644 --- a/cpp/test/Ice/interceptor/MyObjectI.cpp +++ b/cpp/test/Ice/interceptor/MyObjectI.cpp @@ -12,7 +12,7 @@ #include <TestCommon.h> #include <IceUtil/IceUtil.h> -using namespace IceUtil; +using namespace IceUtil; using namespace std; MySystemException::MySystemException(const char* file, int line) : @@ -20,21 +20,25 @@ MySystemException::MySystemException(const char* file, int line) : { } -MySystemException::~MySystemException() throw() +string +MySystemException::ice_id() const { + return "::MySystemException"; } -string -MySystemException::ice_name() const +#ifdef ICE_CPP11_MAPPING +IceUtil::Exception* +MySystemException::ice_cloneImpl() const { - return "MySystemException"; + return new MySystemException(*this); } - +#else MySystemException* MySystemException::ice_clone() const { return new MySystemException(*this); } +#endif void MySystemException::ice_throw() const @@ -42,17 +46,17 @@ MySystemException::ice_throw() const throw *this; } -int +int MyObjectI::add(int x, int y, const Ice::Current&) { return x + y; } -int +int MyObjectI::addWithRetry(int x, int y, const Ice::Current& current) { Ice::Context::const_iterator p = current.ctx.find("retry"); - + if(p == current.ctx.end() || p->second != "no") { throw Test::RetryException(__FILE__, __LINE__); @@ -60,32 +64,146 @@ MyObjectI::addWithRetry(int x, int y, const Ice::Current& current) return x + y; } -int +int MyObjectI::badAdd(int, int, const Ice::Current&) { throw Test::InvalidInputException(); } -int +int MyObjectI::notExistAdd(int, int, const Ice::Current&) { throw Ice::ObjectNotExistException(__FILE__, __LINE__); } -int +int MyObjectI::badSystemAdd(int, int, const Ice::Current&) { throw MySystemException(__FILE__, __LINE__); } - -void +#ifdef ICE_CPP11_MAPPING +void +MyObjectI::amdAddAsync(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::amdAddWithRetryAsync(int x, + int y, + function<void(int)> response, + function<void(exception_ptr)>, + const Ice::Current& current) +{ + thread t( + [x, y, response]() + { + try + { + this_thread::sleep_for(chrono::milliseconds(10)); + response(x + y); + } + catch(Ice::ResponseSentException&) + { + } + }); + 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::amdBadAddAsync(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::amdNotExistAddAsync(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::amdBadSystemAddAsync(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 { public: - + ThreadI(const Test::AMD_MyObject_amdAddPtr& cb, int x, int y) : _cb(cb), _x(x), @@ -108,13 +226,13 @@ MyObjectI::amdAdd_async(const Test::AMD_MyObject_amdAddPtr& cb, int x, int y, co thread->start().detach(); } -void +void MyObjectI::amdAddWithRetry_async(const Test::AMD_MyObject_amdAddWithRetryPtr& cb, int x, int y, const Ice::Current& current) { class ThreadI : public Thread { public: - + ThreadI(const Test::AMD_MyObject_amdAddWithRetryPtr& cb, int x, int y) : _cb(cb), _x(x), @@ -137,20 +255,20 @@ MyObjectI::amdAddWithRetry_async(const Test::AMD_MyObject_amdAddWithRetryPtr& cb thread->start().detach(); Ice::Context::const_iterator p = current.ctx.find("retry"); - + if(p == current.ctx.end() || p->second != "no") { throw Test::RetryException(__FILE__, __LINE__); } } -void +void MyObjectI::amdBadAdd_async(const Test::AMD_MyObject_amdBadAddPtr& cb, int, int, const Ice::Current&) { class ThreadI : public Thread { public: - + ThreadI(const Test::AMD_MyObject_amdBadAddPtr& cb) : _cb(cb) { @@ -170,13 +288,13 @@ MyObjectI::amdBadAdd_async(const Test::AMD_MyObject_amdBadAddPtr& cb, int, int, thread->start().detach(); } -void +void MyObjectI::amdNotExistAdd_async(const Test::AMD_MyObject_amdNotExistAddPtr& cb, int, int, const Ice::Current&) { class ThreadI : public Thread { public: - + ThreadI(const Test::AMD_MyObject_amdNotExistAddPtr& cb) : _cb(cb) { @@ -195,13 +313,13 @@ MyObjectI::amdNotExistAdd_async(const Test::AMD_MyObject_amdNotExistAddPtr& cb, thread->start().detach(); } -void +void MyObjectI::amdBadSystemAdd_async(const Test::AMD_MyObject_amdBadSystemAddPtr& cb, int, int, const Ice::Current&) { class ThreadI : public Thread { public: - + ThreadI(const Test::AMD_MyObject_amdBadSystemAddPtr& cb) : _cb(cb) { @@ -219,3 +337,4 @@ MyObjectI::amdBadSystemAdd_async(const Test::AMD_MyObject_amdBadSystemAddPtr& cb ThreadPtr thread = new ThreadI(cb); thread->start().detach(); } +#endif |