diff options
author | Bernard Normier <bernard@zeroc.com> | 2007-05-16 19:14:39 +0000 |
---|---|---|
committer | Bernard Normier <bernard@zeroc.com> | 2007-05-16 19:14:39 +0000 |
commit | 93349d8446a3847d38c8bed0cefb71cdecb0570a (patch) | |
tree | 1426813a2e221e92dc7ce56c36d4aba240ed0c96 /cpp/test/Ice/interceptor/MyObjectI.cpp | |
parent | Bug 1996 - multihomed hostnames (diff) | |
download | ice-93349d8446a3847d38c8bed0cefb71cdecb0570a.tar.bz2 ice-93349d8446a3847d38c8bed0cefb71cdecb0570a.tar.xz ice-93349d8446a3847d38c8bed0cefb71cdecb0570a.zip |
New Dispatch Interceptor (see bug #2126)
Diffstat (limited to 'cpp/test/Ice/interceptor/MyObjectI.cpp')
-rw-r--r-- | cpp/test/Ice/interceptor/MyObjectI.cpp | 202 |
1 files changed, 202 insertions, 0 deletions
diff --git a/cpp/test/Ice/interceptor/MyObjectI.cpp b/cpp/test/Ice/interceptor/MyObjectI.cpp new file mode 100644 index 00000000000..8e396190df7 --- /dev/null +++ b/cpp/test/Ice/interceptor/MyObjectI.cpp @@ -0,0 +1,202 @@ +// ********************************************************************** +// +// Copyright (c) 2003-2007 ZeroC, Inc. All rights reserved. +// +// This copy of Ice is licensed to you under the terms described in the +// ICE_LICENSE file included in this distribution. +// +// ********************************************************************** + +#include <Ice/Ice.h> +#include <MyObjectI.h> +#include <TestCommon.h> +#include <IceUtil/IceUtil.h> +#include <iostream> + +using namespace IceUtil; +using namespace std; + +void +Test::RetryException::ice_print(ostream& out) const +{ + Ice::Exception::ice_print(out); + out << ":\nretry dispatch"; +} + +int +MyObjectI::add(int x, int y, const Ice::Current&) +{ + return x + y; +} + +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__); + } + return x + y; +} + +int +MyObjectI::badAdd(int, int, const Ice::Current&) +{ + throw Test::InvalidInputException(); +} + +int +MyObjectI::notExistAdd(int, int, const Ice::Current&) +{ + throw Ice::ObjectNotExistException(__FILE__, __LINE__); +} + +int +MyObjectI::badSystemAdd(int, int, const Ice::Current&) +{ + throw Ice::InitializationException(__FILE__, __LINE__, "testing"); +} + + +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), + _y(y) + { + } + + void run() + { + ThreadControl::sleep(Time::milliSeconds(10)); + _cb->ice_response(_x + _y); + } + private: + Test::AMD_MyObject_amdAddPtr _cb; + int _x; + int _y; + }; + + ThreadPtr thread = new ThreadI(cb, x, y); + thread->start().detach(); +} + +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), + _y(y) + { + } + + void run() + { + ThreadControl::sleep(Time::milliSeconds(10)); + _cb->ice_response(_x + _y); + } + private: + Test::AMD_MyObject_amdAddWithRetryPtr _cb; + int _x; + int _y; + }; + + ThreadPtr thread = new ThreadI(cb, x, y); + 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 +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) + { + } + + void run() + { + ThreadControl::sleep(Time::milliSeconds(10)); + Test::InvalidInputException e; + _cb->ice_exception(e); + } + private: + Test::AMD_MyObject_amdBadAddPtr _cb; + }; + + ThreadPtr thread = new ThreadI(cb); + thread->start().detach(); +} + +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) + { + } + + void run() + { + ThreadControl::sleep(Time::milliSeconds(10)); + _cb->ice_exception(Ice::ObjectNotExistException(__FILE__, __LINE__)); + } + private: + Test::AMD_MyObject_amdNotExistAddPtr _cb; + }; + + ThreadPtr thread = new ThreadI(cb); + thread->start().detach(); +} + +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) + { + } + + void run() + { + ThreadControl::sleep(Time::milliSeconds(10)); + _cb->ice_exception(Ice::InitializationException(__FILE__, __LINE__, "just testing")); + } + private: + Test::AMD_MyObject_amdBadSystemAddPtr _cb; + }; + + ThreadPtr thread = new ThreadI(cb); + thread->start().detach(); +} |