当前位置: 首页>>代码示例>>C++>>正文


C++ ConnectionPtr::setAdapter方法代码示例

本文整理汇总了C++中ice::ConnectionPtr::setAdapter方法的典型用法代码示例。如果您正苦于以下问题:C++ ConnectionPtr::setAdapter方法的具体用法?C++ ConnectionPtr::setAdapter怎么用?C++ ConnectionPtr::setAdapter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ice::ConnectionPtr的用法示例。


在下文中一共展示了ConnectionPtr::setAdapter方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: if

int
TalkApp::run(int argc, char*[])
{
    if(argc > 1)
    {
        cerr << appName() << ": too many arguments" << endl;
        return EXIT_FAILURE;
    }

    //
    // Create an object adapter with the name "Talk". Its endpoint is defined
    // in the configuration file 'config'.
    //
    Ice::ObjectAdapterPtr adapter = communicator()->createObjectAdapter("Talk");

    //
    // Install a servant with the well-known identity "peer".
    //
    PeerIPtr incomingPeer = new IncomingPeerI;
    PeerIPtr peer = incomingPeer;
    adapter->add(peer, communicator()->stringToIdentity("peer"));
    adapter->activate();

    usage();

    cout << ">>>> Ready." << endl;

    do
    {
        string s;
        cout << "";
        getline(cin, s);

        if(!s.empty())
        {
            if(s[0] == '/')
            {
                if(s.size() > 8 && s.substr(0, 8) == "/connect")
                {
                    string::size_type sp = s.find(' ');
                    if(sp == string::npos)
                    {
                        usage();
                        continue;
                    }
                    sp = s.find_first_not_of(' ', sp);
                    if(sp == string::npos)
                    {
                        usage();
                        continue;
                    }
                    string addr = s.substr(sp);

                    //
                    // Generate a UUID for our callback servant. We have to pass this identity to
                    // the remote peer so that it can invoke callbacks on the servant over a
                    // bidirectional connection.
                    //
                    Ice::Identity id = communicator()->stringToIdentity(IceUtil::generateUUID());
                    PeerIPtr servant;

                    try
                    {
                        //
                        // Create a proxy for the remote peer using the address given by the user
                        // and the well-known UUID for the talk service.
                        //
                        Talk::PeerPrx prx = Talk::PeerPrx::uncheckedCast(
                            communicator()->stringToProxy(
                                "peer:bt -a \"" + addr + "\" -u 6a193943-1754-4869-8d0a-ddc5f9a2b294"));
                        cout << ">>>> Connecting to " << addr << endl;

                        //
                        // Configure an object adapter for the connection and add the servant. This enables
                        // us to receive callbacks via this connection. Calling ice_getConnection() blocks
                        // until the connection to the peer is established.
                        //
                        Ice::ConnectionPtr con = prx->ice_getConnection();
                        con->setAdapter(adapter);
                        servant = new OutgoingPeerI(adapter, id, prx);
                        adapter->add(servant, id);

                        //
                        // Now we're ready to notify the peer that we'd like to connect.
                        //
                        prx->connect(id);
                        peer = servant;
                        cout << ">>>> Connected to " << addr << endl;
                    }
                    catch(const Ice::Exception& ex)
                    {
                        cout << ">>>> " << ex << endl;
                        if(servant)
                        {
                            adapter->remove(id);
                        }
                    }
                }
                else if(s == "/disconnect")
                {
//.........这里部分代码省略.........
开发者ID:RonsonNamek,项目名称:ice-demos,代码行数:101,代码来源:App.cpp


注:本文中的ice::ConnectionPtr::setAdapter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。