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


C++ AbiCollabSessionManager::constructBuddy方法代码示例

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


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

示例1: _handleSessionTakeover

bool AbiCollab::_handleSessionTakeover(AbstractSessionTakeoverPacket* pPacket, BuddyPtr collaborator)
{
    UT_DEBUGMSG(("AbiCollab::_handleSessionTakeover()\n"));
    UT_return_val_if_fail(pPacket, false);
    UT_return_val_if_fail(collaborator, false);

    AbiCollabSessionManager* pManager = AbiCollabSessionManager::getManager();
    UT_return_val_if_fail(pManager, false);

    switch (m_eTakeoveState)
    {
    case STS_NONE:
    {
        // we only accept a SessionTakeoverRequest or MasterChangeRequest packet
        UT_return_val_if_fail(pPacket->getClassType() == PCT_SessionTakeoverRequestPacket, false);
        // we can only allow such a packet from the controller
        UT_return_val_if_fail(m_pController == collaborator, false);

        // handle the SessionTakeoverRequestPacket packet
        m_pProposedController = BuddyPtr();
        m_vApprovedReconnectBuddies.clear();
        SessionTakeoverRequestPacket* strp = static_cast<SessionTakeoverRequestPacket*>(pPacket);
        m_bProposedController = strp->promote();
        if (m_bProposedController)
        {
            for (std::vector<std::string>::const_iterator cit = strp->getBuddyIdentifiers().begin(); cit != strp->getBuddyIdentifiers().end(); cit++)
                m_vApprovedReconnectBuddies[*cit] = false;
        }
        else
        {
            UT_return_val_if_fail(strp->getBuddyIdentifiers().size() == 1, false);
            BuddyPtr pBuddy = pManager->constructBuddy(strp->getBuddyIdentifiers()[0], collaborator);
            UT_return_val_if_fail(pBuddy, false);
            m_pProposedController = pBuddy;
        }

        // inform the master that we received the takeover request
        SessionTakeoverAckPacket stap(m_sId, m_pDoc->getDocUUIDString());
        collaborator->getHandler()->send(&stap, collaborator);

        m_eTakeoveState = STS_SENT_TAKEOVER_ACK;
        return true;
    }
    return false;
    case STS_SENT_TAKEOVER_REQUEST:
    {
        // we only accept SessionTakeoverAck packets
        UT_return_val_if_fail(pPacket->getClassType() == PCT_SessionTakeoverAckPacket, false);
        // we can only receive SessionTakeoverAck packets when we are the master
        UT_return_val_if_fail(!m_pController, false);
        // we should have a proposed master
        UT_return_val_if_fail(m_pProposedController, false);
        // a slave should only ack once
        UT_return_val_if_fail(!_hasAckedSessionTakeover(collaborator), false);

        // handle the SessionTakeoverAck packet
        m_mAckedSessionTakeoverBuddies[collaborator] = true;

        // check if every slave has acknowledged the session takeover
        // TODO: handle dropouts
        if (m_vCollaborators.size() == 1 ||
                m_mAckedSessionTakeoverBuddies.size() == m_vCollaborators.size())
        {
            // ... our tour of duty is done
            _shutdownAsMaster();
            m_eTakeoveState = STS_NONE;
            return true;
        }
    }

    return true;
    case STS_SENT_TAKEOVER_ACK:
        // we only accept a SessionFlushed or SessionReconnectRequest packet
        UT_return_val_if_fail(
            pPacket->getClassType() == PCT_SessionFlushedPacket ||
            pPacket->getClassType() == PCT_SessionReconnectRequestPacket,
            false
        );

        if (pPacket->getClassType() == PCT_SessionReconnectRequestPacket)
        {
            // we only accept a SessionReconnectRequest when we are the proposed master
            UT_return_val_if_fail(m_bProposedController, false);

            // we only allow an incoming SessionReconnectRequest packet from a buddy
            // that is in the buddy list we received from the master, and we didn't receive
            // such a packet from him before
            bool allow = false;
            for (std::map<std::string, bool>::iterator it = m_vApprovedReconnectBuddies.begin(); it != m_vApprovedReconnectBuddies.end(); it++)
            {
                // TODO: is it a good idea to compare descriptors with full session information?
                if ((*it).first == collaborator->getDescriptor(true) && (*it).second == false)
                {
                    (*it).second = true;
                    allow = true;
                    break;
                }
            }
            UT_return_val_if_fail(allow, false);

//.........这里部分代码省略.........
开发者ID:monkeyiq,项目名称:odf-2011-track-changes-git-svn,代码行数:101,代码来源:AbiCollab.cpp


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