Example #1
0
File: daemon.cpp Project: spito/dp
void Daemon::run( InputMessage &message, Channel channel ) {
    NOTE();

    {
        OutputMessage response( MessageType::Control );
        if ( _state != State::Grouped ) {
            Logger::log( "command Run came at bad moment" );
            response.tag( Code::Refuse );
            channel->send( response );
            return;
        }
        response.tag( Code::OK );
        channel->send( response );


        channel->receive( message, [&,this] ( size_t length ) {
            char *arg = new char[ length + 1 ]();
            _arguments.emplace_back( arg );
            return arg;
        } );
        message.clear();

        channel->receiveHeader( message );

        if ( message.tag< Code >() != Code::Start ) {
            throw ResponseException( { Code::Start }, message.tag< Code >() );
        }
    }
    _runMain = true;
}