⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 twowaysami.cpp

📁 ICE-3.2 一个开源的中间件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// **********************************************************************//// 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 <TestCommon.h>#include <Test.h>#include <limits>//// Stupid Visual C++ defines min and max as macros :-(//#ifdef min#   undef min#endif#ifdef max#   undef max#endifusing namespace std;class CallbackBase : public IceUtil::Monitor<IceUtil::Mutex>{public:    CallbackBase() :        _called(false)    {    }    virtual ~CallbackBase()    {    }    bool check()    {        IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);        while(!_called)        {            if(!timedWait(IceUtil::Time::seconds(5)))            {                return false;            }        }        _called = false;        return true;    }protected:    void called()    {        IceUtil::Monitor<IceUtil::Mutex>::Lock sync(*this);        assert(!_called);        _called = true;        notify();    }private:    bool _called;};class AMI_MyClass_opVoidI : public Test::AMI_MyClass_opVoid, public CallbackBase{public:    virtual void ice_response()    {        called();    }    virtual void ice_exception(const ::Ice::Exception&)    {        test(false);    }};typedef IceUtil::Handle<AMI_MyClass_opVoidI> AMI_MyClass_opVoidIPtr;class AMI_MyClass_opVoidExI : public Test::AMI_MyClass_opVoid, public CallbackBase{public:    virtual void ice_response()    {        test(false);    }    virtual void ice_exception(const ::Ice::Exception& ex)    {        test(dynamic_cast<const ::Ice::TwowayOnlyException*>(&ex));        called();    }};typedef IceUtil::Handle<AMI_MyClass_opVoidExI> AMI_MyClass_opVoidExIPtr;class AMI_MyClass_opByteI : public Test::AMI_MyClass_opByte, public CallbackBase{public:    virtual void ice_response(::Ice::Byte r, ::Ice::Byte b)    {        test(b == Ice::Byte(0xf0));        test(r == Ice::Byte(0xff));        called();    }    virtual void ice_exception(const ::Ice::Exception&)    {        test(false);    }};typedef IceUtil::Handle<AMI_MyClass_opByteI> AMI_MyClass_opByteIPtr;class AMI_MyClass_opByteExI : public Test::AMI_MyClass_opByte, public CallbackBase{public:    virtual void ice_response(::Ice::Byte r, ::Ice::Byte b)    {        test(false);    }    virtual void ice_exception(const ::Ice::Exception& ex)    {        test(dynamic_cast<const ::Ice::TwowayOnlyException*>(&ex));        called();    }};typedef IceUtil::Handle<AMI_MyClass_opByteExI> AMI_MyClass_opByteExIPtr;class AMI_MyClass_opBoolI : public Test::AMI_MyClass_opBool, public CallbackBase{public:    virtual void ice_response(bool r, bool b)    {        test(b);        test(!r);        called();    }    virtual void ice_exception(const ::Ice::Exception&)    {        test(false);    }};typedef IceUtil::Handle<AMI_MyClass_opBoolI> AMI_MyClass_opBoolIPtr;class AMI_MyClass_opShortIntLongI : public Test::AMI_MyClass_opShortIntLong, public CallbackBase{public:    virtual void ice_response(::Ice::Long r, ::Ice::Short s, ::Ice::Int i, ::Ice::Long l)    {        test(s == 10);        test(i == 11);        test(l == 12);        test(r == 12);        called();    }    virtual void ice_exception(const ::Ice::Exception&)    {        test(false);    }};typedef IceUtil::Handle<AMI_MyClass_opShortIntLongI> AMI_MyClass_opShortIntLongIPtr;class AMI_MyClass_opFloatDoubleI : public Test::AMI_MyClass_opFloatDouble, public CallbackBase{public:    virtual void ice_response(::Ice::Double r, ::Ice::Float f, ::Ice::Double d)    {        test(f == Ice::Float(3.14));        test(d == Ice::Double(1.1E10));        test(r == Ice::Double(1.1E10));        called();    }    virtual void ice_exception(const ::Ice::Exception&)    {        test(false);    }};typedef IceUtil::Handle<AMI_MyClass_opFloatDoubleI> AMI_MyClass_opFloatDoubleIPtr;class AMI_MyClass_opStringI : public Test::AMI_MyClass_opString, public CallbackBase{public:    virtual void ice_response(const ::std::string& r, const ::std::string& s)    {        test(s == "world hello");        test(r == "hello world");        called();    }    virtual void ice_exception(const ::Ice::Exception&)    {        test(false);    }};typedef IceUtil::Handle<AMI_MyClass_opStringI> AMI_MyClass_opStringIPtr;class AMI_MyClass_opMyEnumI : public Test::AMI_MyClass_opMyEnum, public CallbackBase{public:    virtual void ice_response(::Test::MyEnum r, ::Test::MyEnum e)    {        test(e == Test::enum2);        test(r == Test::enum3);        called();    }    virtual void ice_exception(const ::Ice::Exception&)    {        test(false);    }};typedef IceUtil::Handle<AMI_MyClass_opMyEnumI> AMI_MyClass_opMyEnumIPtr;class AMI_MyClass_opMyClassI : public Test::AMI_MyClass_opMyClass, public CallbackBase{public:    AMI_MyClass_opMyClassI(const Ice::CommunicatorPtr& communicator) :        _communicator(communicator)    {    }    virtual void ice_response(const ::Test::MyClassPrx& r, const ::Test::MyClassPrx& c1, const ::Test::MyClassPrx& c2)    {        test(c1->ice_getIdentity() == _communicator->stringToIdentity("test"));        test(c2->ice_getIdentity() == _communicator->stringToIdentity("noSuchIdentity"));        test(r->ice_getIdentity() == _communicator->stringToIdentity("test"));        // We can't do the callbacks below in thread per connection mode.        if(!_communicator->getProperties()->getPropertyAsInt("Ice.ThreadPerConnection"))        {            r->opVoid();            c1->opVoid();            try            {                c2->opVoid();                test(false);            }            catch(const Ice::ObjectNotExistException&)            {            }        }        called();    }    virtual void ice_exception(const ::Ice::Exception&)    {        test(false);    }private:    Ice::CommunicatorPtr _communicator;};typedef IceUtil::Handle<AMI_MyClass_opMyClassI> AMI_MyClass_opMyClassIPtr;class AMI_MyClass_opStructI : public Test::AMI_MyClass_opStruct, public CallbackBase{public:    AMI_MyClass_opStructI(const Ice::CommunicatorPtr& communicator) :        _communicator(communicator)    {    }    virtual void ice_response(const ::Test::Structure& rso, const ::Test::Structure& so)    {        test(rso.p == 0);        test(rso.e == Test::enum2);        test(rso.s.s == "def");        test(so.e == Test::enum3);        test(so.s.s == "a new string");        // We can't do the callbacks below in thread per connection mode.        if(!_communicator->getProperties()->getPropertyAsInt("Ice.ThreadPerConnection"))        {            so.p->opVoid();        }        called();    }    virtual void ice_exception(const ::Ice::Exception&)    {        test(false);    }private:    Ice::CommunicatorPtr _communicator;};typedef IceUtil::Handle<AMI_MyClass_opStructI> AMI_MyClass_opStructIPtr;class AMI_MyClass_opByteSI : public Test::AMI_MyClass_opByteS, public CallbackBase{public:    virtual void ice_response(const ::Test::ByteS& rso, const ::Test::ByteS& bso)    {        test(bso.size() == 4);        test(bso[0] == Ice::Byte(0x22));        test(bso[1] == Ice::Byte(0x12));        test(bso[2] == Ice::Byte(0x11));        test(bso[3] == Ice::Byte(0x01));        test(rso.size() == 8);        test(rso[0] == Ice::Byte(0x01));        test(rso[1] == Ice::Byte(0x11));        test(rso[2] == Ice::Byte(0x12));        test(rso[3] == Ice::Byte(0x22));        test(rso[4] == Ice::Byte(0xf1));        test(rso[5] == Ice::Byte(0xf2));        test(rso[6] == Ice::Byte(0xf3));        test(rso[7] == Ice::Byte(0xf4));        called();    }    virtual void ice_exception(const ::Ice::Exception&)    {        test(false);    }};typedef IceUtil::Handle<AMI_MyClass_opByteSI> AMI_MyClass_opByteSIPtr;class AMI_MyClass_opBoolSI : public Test::AMI_MyClass_opBoolS, public CallbackBase{public:    virtual void ice_response(const ::Test::BoolS& rso, const ::Test::BoolS& bso)    {        test(bso.size() == 4);        test(bso[0]);        test(bso[1]);        test(!bso[2]);        test(!bso[3]);        test(rso.size() == 3);        test(!rso[0]);        test(rso[1]);        test(rso[2]);        called();    }    virtual void ice_exception(const ::Ice::Exception&)    {        test(false);    }};typedef IceUtil::Handle<AMI_MyClass_opBoolSI> AMI_MyClass_opBoolSIPtr;class AMI_MyClass_opShortIntLongSI : public Test::AMI_MyClass_opShortIntLongS, public CallbackBase{public:    virtual void ice_response(const ::Test::LongS& rso, const ::Test::ShortS& sso, const ::Test::IntS& iso,                              const ::Test::LongS& lso)    {        test(sso.size() == 3);        test(sso[0] == 1);        test(sso[1] == 2);        test(sso[2] == 3);        test(iso.size() == 4);        test(iso[0] == 8);        test(iso[1] == 7);        test(iso[2] == 6);        test(iso[3] == 5);        test(lso.size() == 6);        test(lso[0] == 10);        test(lso[1] == 30);        test(lso[2] == 20);        test(lso[3] == 10);        test(lso[4] == 30);        test(lso[5] == 20);        test(rso.size() == 3);        test(rso[0] == 10);        test(rso[1] == 30);        test(rso[2] == 20);        called();    }    virtual void ice_exception(const ::Ice::Exception&)    {        test(false);    }};typedef IceUtil::Handle<AMI_MyClass_opShortIntLongSI> AMI_MyClass_opShortIntLongSIPtr;class AMI_MyClass_opFloatDoubleSI : public Test::AMI_MyClass_opFloatDoubleS, public CallbackBase{public:    virtual void ice_response(const ::Test::DoubleS& rso, const ::Test::FloatS& fso, const ::Test::DoubleS& dso)    {        test(fso.size() == 2);        test(fso[0] == ::Ice::Float(3.14));        test(fso[1] == ::Ice::Float(1.11));        test(dso.size() == 3);        test(dso[0] == ::Ice::Double(1.3E10));        test(dso[1] == ::Ice::Double(1.2E10));        test(dso[2] == ::Ice::Double(1.1E10));        test(rso.size() == 5);        test(rso[0] == ::Ice::Double(1.1E10));        test(rso[1] == ::Ice::Double(1.2E10));        test(rso[2] == ::Ice::Double(1.3E10));        test(::Ice::Float(rso[3]) == ::Ice::Float(3.14));        test(::Ice::Float(rso[4]) == ::Ice::Float(1.11));        called();    }    virtual void ice_exception(const ::Ice::Exception&)    {        test(false);    }};typedef IceUtil::Handle<AMI_MyClass_opFloatDoubleSI> AMI_MyClass_opFloatDoubleSIPtr;class AMI_MyClass_opStringSI : public Test::AMI_MyClass_opStringS, public CallbackBase{public:    virtual void ice_response(const ::Test::StringS& rso, const ::Test::StringS& sso)    {        test(sso.size() == 4);        test(sso[0] == "abc");        test(sso[1] == "de");        test(sso[2] == "fghi");        test(sso[3] == "xyz");        test(rso.size() == 3);        test(rso[0] == "fghi");        test(rso[1] == "de");        test(rso[2] == "abc");        called();    }    virtual void ice_exception(const ::Ice::Exception&)    {        test(false);    }};typedef IceUtil::Handle<AMI_MyClass_opStringSI> AMI_MyClass_opStringSIPtr;class AMI_MyClass_opByteSSI : public Test::AMI_MyClass_opByteSS, public CallbackBase{public:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -