qmlFrontend/hwengine.cpp
author unc0rr
Thu, 18 Sep 2014 23:02:05 +0400
branchqmlfrontend
changeset 10412 9a8d4efcf3fa
parent 10404 1baaab44a0b2
child 10416 1c301054694d
permissions -rw-r--r--
- More flib IPC routines - Rework engine's uIO to use new IPC mechanism

#include <QLibrary>
#include <QtQml>
#include <QDebug>

#include "hwengine.h"

extern "C" {
    void (*RunEngine)(int argc, char ** argv);
}

HWEngine::HWEngine(QObject *parent) :
    QObject(parent)
{
    QLibrary hwlib("./libhwengine.so");

    if(!hwlib.load())
        qWarning() << "Engine library not found" << hwlib.errorString();

    RunEngine = (void (*)(int, char **))hwlib.resolve("RunEngine");
}

HWEngine::~HWEngine()
{

}

void HWEngine::run()
{
    char* args[2] = {"", "--help"};
    RunEngine(2, args);
}

static QObject *hwengine_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
    Q_UNUSED(engine)
    Q_UNUSED(scriptEngine)

    HWEngine *hwengine = new HWEngine();
    return hwengine;
}

void HWEngine::exposeToQML()
{
    qDebug("HWEngine::exposeToQML");
    qmlRegisterSingletonType<HWEngine>("Hedgewars.Engine", 1, 0, "HWEngine", hwengine_singletontype_provider);
}