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
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>
10404
1baaab44a0b2 - Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents: 10402
diff changeset
     3
#include <QDebug>
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     4
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     5
#include "hwengine.h"
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     6
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     7
extern "C" {
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     8
    void (*RunEngine)(int argc, char ** argv);
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
     9
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    10
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    11
HWEngine::HWEngine(QObject *parent) :
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    12
    QObject(parent)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    13
{
10404
1baaab44a0b2 - Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents: 10402
diff changeset
    14
    QLibrary hwlib("./libhwengine.so");
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    15
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    16
    if(!hwlib.load())
10404
1baaab44a0b2 - Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents: 10402
diff changeset
    17
        qWarning() << "Engine library not found" << hwlib.errorString();
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    18
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    19
    RunEngine = (void (*)(int, char **))hwlib.resolve("RunEngine");
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    20
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    21
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    22
HWEngine::~HWEngine()
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
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    27
void HWEngine::run()
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    28
{
10404
1baaab44a0b2 - Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents: 10402
diff changeset
    29
    char* args[2] = {"", "--help"};
1baaab44a0b2 - Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents: 10402
diff changeset
    30
    RunEngine(2, args);
10402
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    31
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    32
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    33
static QObject *hwengine_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    34
{
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    35
    Q_UNUSED(engine)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    36
    Q_UNUSED(scriptEngine)
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    37
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    38
    HWEngine *hwengine = new HWEngine();
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    39
    return hwengine;
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    40
}
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    41
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    42
void HWEngine::exposeToQML()
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    43
{
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    44
    qDebug("HWEngine::exposeToQML");
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    45
    qmlRegisterSingletonType<HWEngine>("Hedgewars.Engine", 1, 0, "HWEngine", hwengine_singletontype_provider);
3313336c1ee0 Let's get it started
unc0rr
parents:
diff changeset
    46
}