Exemplo n.º 1
0
bool Dispatcher::dispatchCommand( ICommand& command )
{
    LBASSERT( command.isValid( ));

    LBVERB << "dispatch " << command << " on " << lunchbox::className( this )
           << std::endl;

    const uint32_t which = command.getCommand();
#ifndef NDEBUG
    if( which >= _impl->qTable.size( ))
    {
        LBABORT( "ICommand " << command
                 << " higher than number of registered command handlers ("
                 << _impl->qTable.size() << ") for object of type "
                 << lunchbox::className( this ) << std::endl );
        return false;
    }
#endif

    CommandQueue* queue = _impl->qTable[ which ];
    if( queue )
    {
        command.setDispatchFunction( _impl->fTable[ which ] );
        queue->push( command );
        return true;
    }
    // else

    LBCHECK( _impl->fTable[ which ]( command ));
    return true;
}
Exemplo n.º 2
0
//===========================================================================
// ICommand handling methods
//===========================================================================
void Server::handleCommands()
{
    _running = true;
    while( _running ) // set to false in _cmdShutdown()
    {
        const co::ICommands& commands = _mainThreadQueue.popAll();
        LBASSERT( !commands.empty( ));

        for( co::ICommandsCIter i = commands.begin(); i != commands.end(); ++i )
        {
            // We want to avoid a non-const copy of commands, hence the cast...
            co::ICommand& command = const_cast< co::ICommand& >( *i );

            if( !command( ))
            {
                LBABORT( "Error handling " << command );
            }
            if( !_running )
                break;
        }
    }
    _mainThreadQueue.flush();
}