Exemple #1
0
bool SystemSuspendPrivate::suspendSystem()
{
    if(!handlersValid) {
        handlers = qtopiaTasks<SystemSuspendHandler>();
        handlersValid = true;
        for(int ii = 0; ii < handlers.count(); ++ii) {
            QObject::connect(handlers.at(ii), SIGNAL(operationCompleted()),
                             this, SLOT(operationCompleted()));
        }
    }

    // Check can suspend
    for(int ii = handlers.count(); ii > 0; --ii) {
        if(!handlers.at(ii - 1)->canSuspend()) {
            emit systemSuspendCanceled();
            return false;
        }
    }

    // abort suspension if we see an input event
    inputEvent = false;

    // Do suspend
    emit systemSuspending();
    for(int ii = handlers.count(); ii > 0; --ii) {
        waitingOn = handlers.at(ii - 1);
        if(!waitingOn->suspend()) {
            while(waitingOn)
                QApplication::instance()->processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents);
            if (inputEvent)
                break;
        } else {
            waitingOn = 0;
        }
    }

    // Do wakeup
    emit systemWaking();

    for(int ii = 0; ii < handlers.count(); ++ii) {
        waitingOn = handlers.at(ii);
        if(!waitingOn->wake()) {
            while(waitingOn)
                QApplication::instance()->processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents);
        } else {
            waitingOn = 0;
        }
    }

    // Done
    emit systemActive();

    return true;
}
Exemple #2
0
bool SystemSuspendPrivate::suspendSystem()
{
    if(!handlersValid) {
        handlers = qtopiaTasks<SystemSuspendHandler>();
        handlersValid = true;
        for(int ii = 0; ii < handlers.count(); ++ii) {
            QObject::connect(handlers.at(ii), SIGNAL(operationCompleted()),
                             this, SLOT(operationCompleted()));
        }
    }

    // Check can suspend
    for(int ii = handlers.count(); ii > 0; --ii) {
        qLog(PowerManagement) << handlers.at(ii - 1) << "checking whether canSuspend...";
        if(!handlers.at(ii - 1)->canSuspend()) {
            qLog(PowerManagement) << " ...refused, canceling suspend";
            emit systemSuspendCanceled();
            return false;
        }
    }

    // abort suspension if we see an input event
    inputEvent = false;

    // Do suspend
    emit systemSuspending();
    for(int ii = handlers.count(); ii > 0; --ii) {
        waitingOn = handlers.at(ii - 1);
        qLog(PowerManagement) << waitingOn << "suspending...";
        if(!waitingOn->suspend()) {
            qLog(PowerManagement) << " ...waiting for completion...";
            while(waitingOn) {
                QApplication::instance()->processEvents(QEventLoop::AllEvents |
                                                        QEventLoop::WaitForMoreEvents);
                //qLog(PowerManagement) << "  ...processEvents done";
            }
            if (inputEvent) {
                qLog(PowerManagement) << "canceling suspend on inputevent";
                break;
            }
        } else {
            waitingOn = 0;
        }
    }

    // Do wakeup
    emit systemWaking();

    for(int ii = 0; ii < handlers.count(); ++ii) {
        waitingOn = handlers.at(ii);
        qLog(PowerManagement) << handlers.at(ii) << "waking up...";
        if(!waitingOn->wake()) {
            qLog(PowerManagement) << " ...waiting for completion...";
            while(waitingOn)
                QApplication::instance()->processEvents(QEventLoop::AllEvents |
                                                        QEventLoop::WaitForMoreEvents);
        } else {
            waitingOn = 0;
        }
    }

    // Done
    emit systemActive();

    return true;
}