Пример #1
0
int main() {
  
  list<data_t> liste;
  data_t t ;
  t.x=2;
  
  liste.push_front(t);
  //liste.remove(&t);
  list<data_t>::iterator it = liste.begin();
  liste.erase(it);
  
  assert(liste.size() == 0);
  
  
  
  const int thread_count =6;
  
  
  Acting::Actor::Init();
  
  Ping* ping = new Ping();
  Ping* pong = new Ping();
  
  ping->SetName(string("PING"));
  pong->SetName(string("PONG"));
  
  ping->SetPong(pong);
  pong->SetPong(ping);
  

  /*
    renommer cette methode comme méthode d'instance, ivoquant une méthode 
    static
   */

  /**
     En gros faire en sorte que:
     ping->start();
     pong->start();
   */
  ping->start();
  pong->start();
  
  
  
  //////////////////////////////////////////////////
  Acting::Actor::Finit();
  
  
  return 0;
}
Пример #2
0
bool ConnectionTester::Private::canPing(const QString &host, int *averagePing) const
{
    // TODO: invoke scheduler or tell scheduler something is going on outside of its control
    PingDefinitionPtr pingDef(new PingDefinition(host, 4, 200, 1000, 64, 0, 0, 0, ping::System));
    Ping ping;
    ping.prepare(NULL, pingDef);
    ping.start();
    ping.waitForFinished();

    int resultAvg = ping.averagePingTime();

    if (averagePing)
    {
        *averagePing = resultAvg;
    }

    if (resultAvg > 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}
Пример #3
0
int main()
{
    Message::Ptr mm( new Message() );
    MsgA::Ptr ma( new MsgA() );
    MsgB::Ptr mb( new MsgB() );

    MyAction::Ptr action(new MyAction("myAction"));
    std::string op;

    cout << "Test Slot dynamic cast : ";

    op = "   Invoke action m_slotMsgM with mm";
    action->m_slotMsgM( mm );
    action->expectDynamicType( op, "Message" );
    action->expectStaticType( op, "Message" );

    op = "   Invoke action m_slotMsgM with ma";
    action->m_slotMsgM( ma );
    action->expectDynamicType( op, "MsgA" );
    action->expectStaticType( op, "Message" );

    op = "   Invoke action m_slotMsgM with mb";
    action->m_slotMsgM( mb );
    action->expectDynamicType( op, "MsgB" );
    action->expectStaticType( op, "Message" );

    op = "   Invoke action m_slotMsgA with mm";
    action->m_slotMsgA( mm );
    action->expectDynamicType( op, "" );
    action->expectStaticType( op, "" );

    op = "   Invoke action m_slotMsgA with ma";
    action->m_slotMsgA( ma );
    action->expectDynamicType( op, "MsgA" );
    action->expectStaticType( op, "MsgA" );

    op = "   Invoke action m_slotMsgA with mb";
    action->m_slotMsgA( mb );
    action->expectDynamicType( op, "MsgB" );
    action->expectStaticType( op, "MsgA" );

    op = "   Invoke action m_slotMsgB with mm";
    action->m_slotMsgB( mm );
    action->expectDynamicType( op, "" );
    action->expectStaticType( op, "" );

    op = "   Invoke action m_slotMsgB with ma";
    action->m_slotMsgB( ma );
    action->expectDynamicType( op, "" );
    action->expectStaticType( op, "" );

    op = "   Invoke action m_slotMsgB with mb";
    action->m_slotMsgB( mb );
    action->expectDynamicType( op, "MsgB" );
    action->expectStaticType( op, "MsgB" );
    cout << "Ok" << endl;


    cout << "Test Slot static cast  : ";

    op = "   Invoke action m_slotMsgM with mm";
    action->m_slotMsgM.getStaticCastFunction()( mm, nullptr );
    action->expectDynamicType( op, "Message" );
    action->expectStaticType( op, "Message" );

    op = "   Invoke action m_slotMsgM with ma";
    action->m_slotMsgM.getStaticCastFunction()( ma, nullptr );
    action->expectDynamicType( op, "MsgA" );
    action->expectStaticType( op, "Message" );

    op = "   Invoke action m_slotMsgM with mb";
    action->m_slotMsgM.getStaticCastFunction()( mb, nullptr );
    action->expectDynamicType( op, "MsgB" );
    action->expectStaticType( op, "Message" );

    //op = "   Invoke action m_slotMsgA with mm";
    //action->m_slotMsgA( mm ); is not a valid static cast

    op = "   Invoke action m_slotMsgA with ma";
    action->m_slotMsgA.getStaticCastFunction()( ma, nullptr );
    action->expectDynamicType( op, "MsgA" );
    action->expectStaticType( op, "MsgA" );

    op = "   Invoke action m_slotMsgA with mb";
    action->m_slotMsgA.getStaticCastFunction()( mb, nullptr );
    action->expectDynamicType( op, "MsgB" );
    action->expectStaticType( op, "MsgA" );

    //op = "   Invoke action m_slotMsgB with mm";
    //action->m_slotMsgB( mm ); is not a valid static cast

    //op = "   Invoke action m_slotMsgB with ma";
    //action->m_slotMsgB( ma ); is not a valid static cast

    op = "   Invoke action m_slotMsgB with mb";
    action->m_slotMsgB.getStaticCastFunction()( mb, nullptr );
    action->expectDynamicType( op, "MsgB" );
    action->expectStaticType( op, "MsgB" );
    cout << "Ok" << endl;


    // Note: Without links emission has no effect
    cout << "Test Signal type check : ";

    action->m_signalMsgM.emit( mm );
    action->m_signalMsgM.emit( ma );
    action->m_signalMsgM.emit( mb );

    // action->m_signalMsgA.emit( mm ); // Ok: static Error
    action->m_signalMsgA.emit( ma );
    action->m_signalMsgA.emit( mb );

    // action->m_signalMsgB.emit( mm ); // Ok: static Error
    // action->m_signalMsgB.emit( ma ); // Ok: static Error
    action->m_signalMsgB.emit( mb );

    cout << "Ok" << endl;

    cout << "Test connecting links  : ";

    try
    {
        if( Link::isConnected( "myAction::signalMsgM", "myAction::slotMsgM") )
        {
            cout << "Failed!" << endl;
            cout << "   Link myAction::signalMsgM -> myAction::slotMsgM exist." << endl;
            exit(1);
        }

        Link::connect( "myAction::signalMsgM", "myAction::slotMsgM");

        if( !Link::isConnected( "myAction::signalMsgM", "myAction::slotMsgM") )
        {
            cout << "Failed!" << endl;
            cout << "   Link myAction::signalMsgM -> myAction::slotMsgM not created." << endl;
            exit(1);
        }

        if( !Link::disconnect( "myAction::signalMsgM", "myAction::slotMsgM") )
        {
            cout << "Failed!" << endl;
            cout << "   Link myAction::signalMsgM -> myAction::slotMsgM not disconnected." << endl;
            exit(1);
        }

        if( Link::isConnected( "myAction::signalMsgM", "myAction::slotMsgM") )
        {
            cout << "Failed!" << endl;
            cout << "   Link myAction::signalMsgM -> myAction::slotMsgM exist." << endl;
            exit(1);
        }
        cout << "Ok" << endl;


        cout << "Test emit message      : ";

        Link::connect( "myAction::signalMsgM", "myAction::slotMsgM");
        op = "   Invoke action m_signalMsgM with mb";
        action->m_signalMsgM.emit( mb );
        while( Message::processNext() );
        action->expectDynamicType( op, "MsgB" );
        action->expectStaticType( op, "Message" );
        Link::disconnect( "myAction::signalMsgM", "myAction::slotMsgM");
        cout << "Ok" << endl;

        cout << "Test Action network    : ";

        Ping* ping = new Ping("Ping");
        Pong* pong = new Pong("Pong");
        Link::connect( "Ping::output", "Pong::input");
        Link::connect( "Pong::output", "Ping::input");

        if( !Link::isConnected("Ping::output", "Pong::input") )
        {
            cout << "Failed!" << endl;
            cout << "   Link Ping::output -> Pong::input not connected." << endl;
            exit(1);
        }
        if( !Link::isConnected("Pong::output", "Ping::input") )
        {
            cout << "Failed!" << endl;
            cout << "   Link Pong::output -> Ping::input not connected." << endl;
            exit(1);
        }

        Ball::Ptr ball( new Ball() );

        ping->start( ball, 15 );

        while( Message::processNext() );

        if( ball->pingCnt != ball->maxCount )
        {
            cout << "Failed!" << endl;
            cout << "   Ball ping counter is not " <<  ball->maxCount
                 << ". Found " << ball->pingCnt << endl;
            exit(1);
        }

        if( ball->pongCnt != ball->maxCount )
        {
            cout << "Failed!" << endl;
            cout << "   Ball pong counter is not " <<  ball->maxCount
                 <<". Found " << ball->pongCnt << endl;
            exit(1);
        }

        // Add a pong object instance duplicating the message ping transactions
        // Will double the ping pong transactions
        Pong* pong2 = new Pong("Pong2");
        Link::connect( "Ping::output", "Pong2::input");
        Link::connect( "Pong2::output", "Ping::input");

        ping->start( ball, 15 );
        while( Message::processNext() );

        if( ball->pingCnt != ball->maxCount )
        {
            cout << "Failed!" << endl;
            cout << "   Ball ping counter is not " <<  ball->maxCount
                 << ". Found " << ball->pingCnt << endl;
            exit(1);
        }

        if( ball->pongCnt != 2*ball->maxCount )
        {
            cout << "Failed!" << endl;
            cout << "   Ball pong counter is not " <<  2*ball->maxCount
                 <<". Found " << ball->pongCnt << endl;
            exit(1);
        }
        cout << "Ok" << endl;

        cout << "Test free functions    : ";

        SlotFunction<Ball,&catchBall> slotBall;
        Signal<Ball> signalBall;

        if( nbrBallCatched != 0 )
        {
            cout << "Failed!" << endl;
            cout << "   nbrBallCatched counter is not 0"
                 << ". Found " << nbrBallCatched << endl;
            exit(1);
        }

        // Establish a direct connecting between signal and slot
        Link::connect( &signalBall, &slotBall );

        while( Message::processNext() );
        signalBall.emit( ball );
        while( Message::processNext() );

        if( nbrBallCatched != 1 )
        {
            cout << "Failed!" << endl;
            cout << "   nbrBallCatched counter is not 1"
                 << ". Found " << nbrBallCatched << endl;
            exit(1);
        }

        Link::disconnect( &signalBall, &slotBall );

        // Retest using named Signal and slot
        slotBall.setName( "Ball slot" );
        signalBall.setName( "Ball signal" );
        Link::connect( "Ball signal", "Ball slot" );
        while( Message::processNext() );
        signalBall.emit( ball );
        while( Message::processNext() );
        if( nbrBallCatched != 2 )
        {
            cout << "Failed!" << endl;
            cout << "   nbrBallCatched counter is not 2"
                 << ". Found " << nbrBallCatched << endl;
            exit(1);
        }
        cout << "Ok" << endl;


        // destroy all objects
        Action::clearActions();
    }
    catch( std::exception& e )
    {
        cout << "Failed!" << endl;
        cout << "   Exception: " << e.what() << endl;
        exit(1);
    }
    catch( ... )
    {
        cout << "Failed!" << endl;
        cout << "   Unknown exception" << endl;
        exit(1);
    }


    {
        int nbr = 1000000;
        cout << "Timing for " << nbr << " MPO signal ping pong : ";
        cout.flush();
        class Timer {
            double m_start, m_stop;
        public:
            Timer() { start(); stop(); }
            double getTime()
            {
                struct timeval t;
                ::gettimeofday( &t, NULL );
                return double(t.tv_sec) + double(t.tv_usec)/1000000.;
            }

            void start() { m_start = getTime(); }
            void stop() { m_stop = getTime(); }
            double getDelta() { return m_stop - m_start; }
        } timer;

        Ping* ping = new Ping("Ping");
        Pong* pong = new Pong("Pong");
        Link::connect( "Ping::output", "Pong::input");
        Link::connect( "Pong::output", "Ping::input");

        Ball::Ptr ball( new Ball() );
        ping->start( ball, nbr );

        timer.start();
        while( Message::processNext() );
        timer.stop();

        cout << timer.getDelta() << " seconds " << endl;

    }




    return 0;
}