示例#1
0
        int Player::play(const Gameboard &state) {
            Q_UNUSED(state);

            emit holeSelectionRequested();

            waitForSignal(this, SIGNAL(holeSelected()));

            return _playedHoleNumber;
        }
示例#2
0
void DHT11::read_data(){
    handshake();
    waitForSignal(HIGH, 100);
    waitForSignal(LOW, 100);
    uint8_t values[5];
    for (int i = 0; i < 5; i++){
        values[i] = 0;
        for (int j = 0; j < 8; j++){
            waitForSignal(HIGH, 60);
            timeval_t init = get_time();
            waitForSignal(LOW, 100);
            timeval_t end = get_time();
            if (has_timeout(init, end, 40))
                values[i] |= 1 << (7 - j);
        }
    }
    if (values[0] + values[2] != values[4]){
        this->error = 1;
    } else {
        this->temperature = values[2];
        this->humidity = values[0];
        this->error = 0;
    }
}
示例#3
0
// downloadHostIcon does nothing if the icon is available already, so how to test this?
// We could delete the icon first, but given that we have a different KDEHOME than the kded module,
// that's not really easy...
void FavIconTest::testDownloadHostIcon()
{
    if ( !checkNetworkAccess() )
        QSKIP( "no network access", SkipAll );

    QSignalSpy spy( &m_favIconModule, SIGNAL(iconChanged(bool,QString,QString)) );
    QVERIFY( spy.isValid() );
    QCOMPARE( spy.count(), 0 );

    qDebug( "called downloadHostIcon, waiting" );
    m_favIconModule.downloadHostIcon( QString( s_hostUrl ) );
    waitForSignal();

    QCOMPARE( spy.count(), 1 );
    QCOMPARE( mgr.m_isHost, true );
    QCOMPARE( mgr.m_hostOrURL, KUrl( s_hostUrl ).host() );
    qDebug( "icon: %s", qPrintable( mgr.m_iconName ) );
}
/**
 * Get and set the rating of a temp file
 */
void SemanticInfoBackEndTest::testRating()
{
    QTemporaryFile temp("XXXXXX.metadatabackendtest");
    QVERIFY(temp.open());

    QUrl url;
    url.setPath(temp.fileName());

    SemanticInfoBackEndClient client(mBackEnd);
    QSignalSpy spy(mBackEnd, SIGNAL(semanticInfoRetrieved(QUrl,SemanticInfo)));
    mBackEnd->retrieveSemanticInfo(url);
    QVERIFY(waitForSignal(spy));

    SemanticInfo semanticInfo = client.semanticInfoForUrl(url);
    QCOMPARE(semanticInfo.mRating, 0);

    semanticInfo.mRating = 5;
    mBackEnd->storeSemanticInfo(url, semanticInfo);
}
示例#5
0
SignalFD::~SignalFD()
{
    mEventPoll.removeFD(mFD);
    utils::close(mFD);

    // Unblock the signals that have been blocked previously, but also eat
    // them if they were pending. It seems that signals are delivered twice,
    // independently for signalfd and async. If we don't eat them before
    // unblocking they will be delivered immediately potentially doing harm.
    for (const int sigNum : mBlockedSignals) {
        waitForSignal(sigNum, 0);

        // Yes, there is a race here between waitForSignal and signalUnlock, but if
        // a signal is sent at this point it's not by us, signalFD is inactive. So
        // if that is the case I'd expect someone to have set some handler already.

        signalUnblock(sigNum);
    }
}
示例#6
0
文件: ex3.c 项目: dodgerDojo/Ex3
int main(int argc, char *argv[])
{
    const unsigned int EXPECTED_ARGC = 2;
    const unsigned int KEY_FILE_ARG_INDEX = 1;
    const unsigned char KEY_CHAR = 'H';

    const char ENDLINE[] = "\n";
    const char SEPERATOR[] = ",";

    key_t key = 0;
    char *shm_addr = NULL;
    int csv_fd = 0, queue_length = 0, shm_id = 0, sem_id = 0;
    int job_number = 0, rel_prio = 0, real_prio = 0;

    initSigactions();

    // Initialize the rand() seed.
    srand(time(NULL));

    if(argc != EXPECTED_ARGC)
    {
        // No checking needed, exits with error code.
        write(STDERR_FILENO, NOF_INPUTS_ERROR, sizeof(NOF_INPUTS_ERROR));
        exit(EXIT_ERROR_CODE);
    }

    // Create fifo.
    if(mkfifo(FIFO_NAME, ALLOW_READ_WRITE_TO_ALL) < 0)
    {
        // No checking needed, exits with error code.
        write(STDERR_FILENO, MKFIFO_ERROR, sizeof(MKFIFO_ERROR));
        exit(EXIT_ERROR_CODE);
    }

    writePidToFifo();

    // Wait for the queue process' singal.
    waitForSignal();

    printf("got signal from %d!\n", Queue_Pid);

    // Generate key from the given file
    key = ftok(argv[KEY_FILE_ARG_INDEX], KEY_CHAR);

    if(key < 0)
    {
        deleteFifo();
        // No checking needed, exits with error code.
        write(STDERR_FILENO, FTOK_ERROR, sizeof(FTOK_ERROR));
        exit(EXIT_ERROR_CODE);       
    }

    // Create shared memory.
    shm_addr = createSharedMemory(key, &shm_id);

    // Create semaphore.
    sem_id = createBinarySemaphore(key, shm_id);

    // Notify the queue.out process.
    if(kill(Queue_Pid, SIGUSR1) < 0)
    {
        deleteFifo();
        // No checking needed, exits with error code.
        write(STDERR_FILENO, KILL_ERROR, sizeof(KILL_ERROR) - 1);
        exit(EXIT_ERROR_CODE);
    }

    queue_length = readQueueLengthFromFifo();

    printf("Got N: %d\n", queue_length);

    // Done using the fifo - delete it.
    deleteFifo();

    // Game Started!
    handleGame(shm_id, shm_addr, sem_id, queue_length, &job_number, \
               &rel_prio, &real_prio);

    deleteResources(shm_id, sem_id);

    // Write results
    csv_fd = open(CSV_FILE_PATH, O_CREAT | O_APPEND | O_RDWR, ALLOW_READ_WRITE_TO_ALL);
    if(csv_fd < 0)
    {
        // No checking needed, exits with error code.
        write(STDERR_FILENO, OPEN_ERROR, sizeof(OPEN_ERROR) - 1);
        exit(EXIT_ERROR_CODE); 
    }


    writeIntWithEnding(csv_fd, queue_length, SEPERATOR);
    writeIntWithEnding(csv_fd, job_number, SEPERATOR);
    writeIntWithEnding(csv_fd, rel_prio, SEPERATOR);
    writeIntWithEnding(csv_fd, real_prio, ENDLINE);

    return EXIT_OK_CODE;
}
bool TestService::waitForRendering(QObject* _item, int timeout)
{
    QWindow* window = eventWindow(_item);
    return waitForSignal(window, "frameSwapped()", timeout);
}
bool waitForViewportReady(QQuickWebView* webView, int timeout)
{
    // The viewport is locked until the first frame of a page load is rendered.
    // The QQuickView needs to be shown for this to succeed.
    return waitForSignal(webView->experimental(), SIGNAL(loadVisuallyCommitted()), timeout);
}
/*!
   \internal
    Sends an \a event, \a message and \a data to the remote host and waits for up to
    \a timeout milliseconds for a reply.  If a reply is received, the reply's message
    string is placed in \a reply.
*/
bool QstProtocol::sendMessage( const QstMessage &message, QstMessage &reply, int timeout )
{
    QstMessage msg(message);
    QPointer<QstProtocol> safeThis(this);
    bool safeDebugOn(debug_on);
    QString safeUniqueId(uniqueId());

    last_send_cmd = message.event();

    if (state() == ConnectingState) {
        wait(4000);
    }

    if (state() == ConnectedState) {
        msg.m_msg_id = tx_msg_id++;

        if (debug_on) {
            qDebug() << ( QString("%1 QstProtocol::sendMessage(%2) msgid=%3)").
                                arg(uniqueId()).
                                arg(msg.event()).
                                arg(msg.msgId()).
                                toLatin1());
        }

        send( msg );

        QTime t1;
        t1.start();
        QTime t2;
        t2.start();
        bool first_time = true;
        while ( (state() == ConnectedState) &&
               (timeout < 0 || t1.elapsed() < timeout) ) {

            if (debug_on) {
                if (first_time || t2.elapsed() > 1000) {
                    qDebug() << ( QString("%1 QstProtocol::sendMessage(%2) ... waiting for reply").
                                        arg(uniqueId()).
                                        arg(message.event()).toLatin1());
                    t2.start();
                    first_time = false;
                }
            }

            waitForSignal(this, SIGNAL(replyReceived()), 500);

            if (!safeThis) {
                if (safeDebugOn) {
                    qDebug() << ( QString("%1 QstProtocol::sendMessage(%2) ... object deleted unexpectedly").
                                        arg(safeUniqueId).
                                        arg(message.event()).toLatin1());
                }
                reply[QLatin1String("status")] = "ERROR: Connection was terminated unexpectedly. This may be caused by an application crash.";
                reply[QLatin1String("_q_inResponseTo")] = QString("%1\n%2").arg(message.event()).arg(message.toString());
                return false;
            } else {
                if (send_msg_replies.count() > 0) {
                    if (debug_on) {
                        qDebug() << ( QString("%1 QstProtocol::sendMessage(%2) ... check replies").
                                            arg(uniqueId()).
                                            arg(message.event()).toLatin1());
                    }
                    for (int i=0; i<send_msg_replies.size(); i++) {
                        QstMessage * possible_reply = send_msg_replies.at(i);
                        if (possible_reply && possible_reply->m_msg_id == msg.m_msg_id) {
                            reply = *possible_reply;
                            delete send_msg_replies.takeAt( i );
                            if (debug_on) {
                                qDebug() << ( QString("%1 QstProtocol::sendMessage(%2) ... reply received").
                                                    arg(uniqueId()).
                                                    arg(message.event()).toLatin1());
                            }

                            onReplyReceived(&reply);
                            return true;
                        }
                    }
                }
            }
        }
        if (state() != ConnectedState) {
            reply[QLatin1String("status")] = "ERROR: Connection lost. This is likely caused by a crash in the Application Under Test.";
            reply[QLatin1String("_q_inResponseTo")] = QString("%1\n%2").arg(message.event()).arg(message.toString());
        } else {
            qDebug() << "ERROR-REPLY-TIMEOUT: " << t1.elapsed() << t2.elapsed();
            reply[QLatin1String("status")] = QLatin1String("ERROR_REPLY_TIMEOUT");
            reply[QLatin1String("_q_inResponseTo")] = QString("%1\n%2").arg(message.event()).arg(message.toString());
        }
        reply[QLatin1String("location")] = QString("%1:%2").arg(__FILE__).arg(__LINE__);
    } else {
        reply[QLatin1String("status")] = QLatin1String("ERROR_NO_CONNECTION");
        reply[QLatin1String("_q_inResponseTo")] = QString("%1\n%2").arg(message.event()).arg(message.toString());
        reply[QLatin1String("location")] = QString("%1:%2").arg(__FILE__).arg(__LINE__);
    }

    if (debug_on) {
        qDebug() << ( QString("%1 QstProtocol::sendMessage(%2) ... done. Status: %3").
                            arg(uniqueId()).
                            arg(message.event()).arg(reply[QLatin1String("status")].toString()).toLatin1());
    }

    return false;
}