Sha256: e07e7ba480520cee64fd2060847477c28023539a61dce3c02928e679fb56ac03

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

#include <QApplication>
#include <QtDebug>
#include "sunscraperthread.h"
#include "sunscraperworker.h"

#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
pthread_t SunscraperThread::m_thread;
#endif

void SunscraperThread::invoke()
{
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
    pthread_create(&m_thread, NULL, &SunscraperThread::thread_routine, NULL);
#endif
}

void *SunscraperThread::thread_routine(void *)
{
    /* Better error messages. */
    int   argc   = 1;
    char *argv[] = { (char*) "Sunscraper", NULL};

    /* Why (char*)? Because argv can (theoretically) be modified. *
     * But Qt won't do that with argv[0]. I know, trust me.       */

    QApplication app(argc, argv);
    app.setApplicationName("Sunscraper-Embed");

    SunscraperWorker::unlock();

    /*
     * The magic value 42 means we want exit from the loop.
     * E.g. alerts from within the page may exit the loop with value 0.
     */
    while(app.exec() != 42);

    /* Our host application exits. */

    return NULL;
}

void SunscraperThread::commitSuicide()
{
    QApplication::exit(42);

#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
    pthread_join(m_thread, NULL);
#endif
}

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sunscraper-1.2.0.beta1 ext/embed/sunscraperthread.cpp