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


C++ MessagePtr::GetHandler方法代码示例

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


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

示例1: HandleRequest

///////////////////////////////////////////////////////////////////////////////
/// @fn CDispatcher::HandleRequest
/// @description Given an input property tree determine which handlers should
///   be given the message out of a pool of modules and deliever the message
///   as appropriate.
/// @pre Modules have registered their read handlers.
/// @post Message delievered to a module
/// @param msg The message to distribute to modules
///////////////////////////////////////////////////////////////////////////////
void CDispatcher::HandleRequest(MessagePtr msg)
{
    Logger.Trace << __PRETTY_FUNCTION__ << std::endl;
    ptree sub_;
    ptree::const_iterator it_;
    std::map< std::string, IReadHandler *>::const_iterator mapIt_;
    ptree p_mesg = static_cast<ptree>(*msg);
    bool processed = false;

    try
    {
        // Scoped lock, will release mutex at end of try {}
        //boost::lock_guard< boost::mutex > scopedLock_( m_rMutex );

        // This allows for a handler to process all messages using
        // the special keyword "any"
        for( mapIt_ = m_readHandlers.lower_bound( "any" );
             mapIt_ != m_readHandlers.upper_bound( "any" );
             ++mapIt_ )
        {
            CBroker::BoundScheduleable x = boost::bind(&CDispatcher::ReadHandlerCallback,
                this, mapIt_->second, msg);
            CBroker::Instance().Schedule(m_handlerToModule[mapIt_->second],x);
            processed = true;
        }

	    // Loop through all submessages of this message to call its
        // handler
        std::string handler = msg->GetHandler();

        Logger.Debug << "Processing " << handler << std::endl;

        // Special keyword any which gives the submessage to all modules.
        if(handler.find("any") == 0)
        {
            for( mapIt_ =  m_readHandlers.begin();
                 mapIt_ != m_readHandlers.end();
                 ++mapIt_)
            {
                if(mapIt_->first == "any")
                {
                    //Prevents modules with any flags from processing some messages twice
                    continue;
                }
                CBroker::BoundScheduleable x = boost::bind(&CDispatcher::ReadHandlerCallback,
                    this, mapIt_->second, msg);
                CBroker::Instance().Schedule(m_handlerToModule[mapIt_->second],x);
                processed = true;
            }
        }
        else
        {
            for( mapIt_ = m_readHandlers.begin();
                mapIt_ != m_readHandlers.end(); ++mapIt_ )
            {
                if(handler.find(mapIt_->first) == 0)
                {
                    CBroker::BoundScheduleable x = boost::bind(&CDispatcher::ReadHandlerCallback,
                        this, mapIt_->second, msg);
                    CBroker::Instance().Schedule(m_handlerToModule[mapIt_->second],x);
                    processed = true;
                }
            }
        }
        // XXX Should anything be done if the message didn't have any submessages?
        if( sub_.begin() == sub_.end() )
        {
            // Just log this for now
            Logger.Debug << "Message had no submessages.";
        }
        if( processed == false)
        {
            Logger.Warn << "Message was not processed by any module" << std::endl;
        }
    }
    catch( boost::property_tree::ptree_bad_path &e )
    {
        Logger.Error
            << "Malformed message. Does not contain 'submessages'."
            << std::endl << "\t" << e.what() << std::endl;
    }

}
开发者ID:Annovae,项目名称:FREEDM,代码行数:92,代码来源:CDispatcher.cpp


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