Example #1
0
int main( int argc, char **argv ) {
    SodaClient sc( QHostAddress::Any, 8890 );
    if ( not sc.connected() )
        return 1;

    MP mp = sc.load( "/pouet" );
    srand( time( NULL ) );
    // mp.clear();

    static_cast<TypedArray<double> *>( mp.model() )->_data.resize( 4 * 40000 );
    static_cast<TypedArray<double> *>( mp.model() )->_data[ 0 ] = rand();
    static_cast<TypedArray<double> *>( mp.model() )->_size[ 1 ] = 40000;
    mp.signal_change();

    // mp.flush();
}
void Updater::exec( const MP &mp ) {
    // nothing to compute ?
    quint64 req = mp[ "_computation_req_date" ];
    quint64 rep = mp[ "_computation_rep_date" ];
    qDebug() << req << rep;
    if ( req <= rep )
        return;

    quint64 cm = mp[ "_computation_mode" ];
    quint64 cs = mp[ "_computation_state" ];
    qDebug() << cm << " s=" << cs;
    if ( cm == false && cs == false )
        return;

    // waiting for another computation ?
    ++Model::_cur_op_id;
    if ( has_something_to_compute_else_than( mp.model(), mp.model() ) ) {
        qDebug() << "something to compute !";
        //mp[ "_computation_mode" ] = true;
//         sleep(1);
//         quint64 mp_server_id = mp.get_server_id();
//         mp = sc.load_ptr(mp_server_id);
        return;
    }

    //
    clear_error_list( mp );

    qDebug() << "run" << type();

    // sdl::set( "toto", "1" );
    // QHttp
    // system( "wget ..." );

    quint64 ac = mp[ "auto_compute" ];
    mp[ "_ready_state" ]       = false;
    mp[ "_computation_state" ] = false;
    mp[ "_pending_state" ]     = false;
    mp[ "_processing_state" ]  = true;
    mp[ "_finish_state" ]      = false;
    mp[ "_stop_state" ]        = false;
    if ( ac == 0 )
        mp[ "_computation_mode" ]  = 0;
    
    
    run( mp );

    mp[ "_computation_rep_date" ] = req;
    //         add_message( mp, ET_Info, "done" );
    if ( cm == false and cs == true )
        mp[ "_computation_state" ] = false;
    
    mp[ "_ready_state" ]        = false;
    mp[ "_computation_state" ]  = false;
    mp[ "_pending_state" ]      = false;
    mp[ "_processing_state" ]   = false;
    mp[ "_finish_state" ]       = true;
    mp[ "_stop_state" ]         = false;
    if ( ac == 0 )
        mp[ "_computation_mode" ] = 0; 
    //sdl::set( "done", "1" );
    
    
    qDebug() << "model_computation_state : " << mp[ "_computation_state" ];
    qDebug() << "model_computation_mode : " << mp[ "_computation_mode" ];
}