qmlFrontend/hwengine.cpp
author unc0rr
Fri, 12 Sep 2014 00:51:14 +0400
branchqmlfrontend
changeset 10402 3313336c1ee0
child 10404 1baaab44a0b2
permissions -rw-r--r--
Let's get it started
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     1
#include <QLibrary>
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     2
#include <QtQml>
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     3
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     4
#include "hwengine.h"
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     5
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     6
extern "C" {
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     7
    void (*RunEngine)(int argc, char ** argv);
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     8
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     9
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    10
HWEngine::HWEngine(QObject *parent) :
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    11
    QObject(parent)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    12
{
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    13
    QLibrary hwlib("hwengine");
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    14
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    15
    if(!hwlib.load())
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    16
        qWarning("Engine library not found");
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    17
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    18
    RunEngine = (void (*)(int, char **))hwlib.resolve("RunEngine");
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    19
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    20
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    21
HWEngine::~HWEngine()
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    22
{
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    23
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    24
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    25
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    26
void HWEngine::run()
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    27
{
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    28
    RunEngine(0, nullptr);
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    29
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    30
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    31
static QObject *hwengine_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    32
{
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    33
    Q_UNUSED(engine)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    34
    Q_UNUSED(scriptEngine)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    35
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    36
    HWEngine *hwengine = new HWEngine();
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    37
    return hwengine;
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    38
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    39
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    40
void HWEngine::exposeToQML()
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    41
{
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    42
    qDebug("HWEngine::exposeToQML");
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    43
    qmlRegisterSingletonType<HWEngine>("Hedgewars.Engine", 1, 0, "HWEngine", hwengine_singletontype_provider);
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    44
}