//---------------------------------------------------------------------
    void DefaultWorkQueue::shutdown()
    {
        LogManager::getSingleton().stream() <<
            "DefaultWorkQueue('" << mName << "') shutting down.";

        mShuttingDown = true;
        mTaskGroup.cancel();
        abortAllRequests();

        // wait until all tasks have finished.
        mTaskGroup.wait();

#if OGRE_NO_TBB_SCHEDULER == 0
        if (mTaskScheduler.is_active())
            mTaskScheduler.terminate();
#endif

        if (mWorkerFunc)
        {
            OGRE_DELETE_T(mWorkerFunc, WorkerFunc, MEMCATEGORY_GENERAL);
            mWorkerFunc = 0;
        }
            
        mIsRunning = false;

    }
    //---------------------------------------------------------------------
    void DefaultWorkQueue::shutdown()
    {
        if( !mIsRunning )
            return;

        LogManager::getSingleton().stream() <<
            "DefaultWorkQueue('" << mName << "') shutting down on thread " <<
#if OGRE_THREAD_SUPPORT
            OGRE_THREAD_CURRENT_ID
#else
            "main"
#endif
            << ".";

        mShuttingDown = true;
        abortAllRequests();
#if OGRE_THREAD_SUPPORT
        // wake all threads (they should check shutting down as first thing after wait)
        OGRE_THREAD_NOTIFY_ALL(mRequestCondition);

        // all our threads should have been woken now, so join
        for (WorkerThreadList::iterator i = mWorkers.begin(); i != mWorkers.end(); ++i)
        {
            (*i)->join();
            OGRE_THREAD_DESTROY(*i);
        }
        mWorkers.clear();
#endif

        OGRE_DELETE_T(mWorkerFunc, WorkerFunc, MEMCATEGORY_GENERAL);
        mWorkerFunc = 0;

        mIsRunning = false;
    }
Beispiel #3
0
// Upload a file to a connected account
int ShareOnline::Imgur::upload(QString filename) {

    if(imgurClientID == "" || imgurClientSecret == "") {
        int ret = obtainClientIdSecret();
        if(ret != IMGUR_NOERROR) {
            emit abortAllRequests();
            emit uploadError(QNetworkReply::UnknownServerError);
            return ret;
        }
    }

    // Ensure an access token is set
    if(access_token == "") {
        if(debug)
            LOG << CURDATE << "ERROR! Unable to upload image, no access_token set... Did you connect to an account?" << NL;
        return IMGUR_ACCESS_TOKEN_ERROR;
    }

    // Ensure that filename is not empty and that the file exists
    if(filename.trimmed() == "" || !QFileInfo(filename).exists()) {
        if(debug)
            LOG << CURDATE << QString("ERROR! Filename '%1' for uploading to imgur.com is invalid").arg(filename).toStdString() << NL;
        return IMGUR_FILENAME_ERROR;
    }

    // Initiate file and open for reading
    QFile file(filename);
    if(!file.open(QIODevice::ReadOnly)) {
        if(debug)
            LOG << CURDATE << QString("ERROR! Can't open file '%1' for reading to upload to imgur.com").arg(filename).toStdString() << NL;
        return IMGUR_FILE_OPEN_ERROR;
    }

    // Read binary data of file to bytearray
    QByteArray byteArray = file.readAll();
    file.close();

    // Setup network request, use XML format
    QNetworkRequest req(QUrl("https://api.imgur.com/3/image.xml"));
    // the following is not necessary (it's the default), but avoids an error message on standard output
    req.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
    // Set access_token to prove authorisation to connect to account
    req.setRawHeader("Authorization", QByteArray("Bearer ") + access_token.toLatin1());

    // Send upload request and connect to feedback signals
    QNetworkReply *reply = networkManager->post(req, byteArray);
    connect(reply, &QNetworkReply::finished, this, &ShareOnline::Imgur::uploadFinished);
    connect(reply, &QNetworkReply::uploadProgress, this, &ShareOnline::Imgur::uploadProgress);
    // The following has to use the old syntax, as there is also a accessor member (not a signal) to access the error with the same name
    connect(reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), this, &Imgur::uploadError);
    connect(this, &ShareOnline::Imgur::abortAllRequests, reply, &QNetworkReply::abort);

    // Phew, no error occured!
    return IMGUR_NOERROR;

}
Beispiel #4
0
// Abort all network requests and stop
void ShareOnline::Imgur::abort() {
    // We do it twice spaced out, in case we were just before a networkrequest to really cancel everything
    emit abortAllRequests();
    QTimer::singleShot(500, this, &ShareOnline::Imgur::abortAllRequests);
}