qmlFrontend/hwengine.cpp
branchqmlfrontend
changeset 10402 3313336c1ee0
child 10404 1baaab44a0b2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/qmlFrontend/hwengine.cpp	Fri Sep 12 00:51:14 2014 +0400
@@ -0,0 +1,44 @@
+#include <QLibrary>
+#include <QtQml>
+
+#include "hwengine.h"
+
+extern "C" {
+    void (*RunEngine)(int argc, char ** argv);
+}
+
+HWEngine::HWEngine(QObject *parent) :
+    QObject(parent)
+{
+    QLibrary hwlib("hwengine");
+
+    if(!hwlib.load())
+        qWarning("Engine library not found");
+
+    RunEngine = (void (*)(int, char **))hwlib.resolve("RunEngine");
+}
+
+HWEngine::~HWEngine()
+{
+
+}
+
+void HWEngine::run()
+{
+    RunEngine(0, nullptr);
+}
+
+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);
+}