author | unc0rr |
Sat, 20 Sep 2014 00:56:54 +0400 | |
branch | qmlfrontend |
changeset 10416 | 1c301054694d |
parent 10404 | 1baaab44a0b2 |
child 10418 | 091d2c0216c3 |
permissions | -rw-r--r-- |
10402 | 1 |
#include <QLibrary> |
2 |
#include <QtQml> |
|
10404
1baaab44a0b2
- Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents:
10402
diff
changeset
|
3 |
#include <QDebug> |
10402 | 4 |
|
5 |
#include "hwengine.h" |
|
6 |
||
7 |
extern "C" { |
|
10416 | 8 |
RunEngine_t *RunEngine; |
9 |
registerIPCCallback_t *registerIPCCallback; |
|
10 |
ipcToEngine_t *ipcToEngine; |
|
11 |
flibInit_t *flibInit; |
|
10402 | 12 |
} |
13 |
HWEngine::HWEngine(QObject *parent) : |
|
14 |
QObject(parent) |
|
15 |
{ |
|
10404
1baaab44a0b2
- Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents:
10402
diff
changeset
|
16 |
QLibrary hwlib("./libhwengine.so"); |
10402 | 17 |
|
18 |
if(!hwlib.load()) |
|
10404
1baaab44a0b2
- Fix arguments parsing in engine assuming paramcount > 0
unc0rr
parents:
10402
diff
changeset
|
19 |
qWarning() << "Engine library not found" << hwlib.errorString(); |
10402 | 20 |
|
10416 | 21 |
RunEngine = (RunEngine_t*) hwlib.resolve("RunEngine"); |
22 |
registerIPCCallback = (registerIPCCallback_t*) hwlib.resolve("registerIPCCallback"); |
|
23 |
ipcToEngine = (ipcToEngine_t*) hwlib.resolve("ipcToEngine"); |
|
24 |
flibInit = (flibInit_t*) hwlib.resolve("flibInit"); |
|
25 |
||
26 |
flibInit(); |
|
27 |
registerIPCCallback(this, &engineMessageCallback); |
|
10402 | 28 |
} |
29 |
||
30 |
HWEngine::~HWEngine() |
|
31 |
{ |
|
32 |
||
33 |
} |
|
34 |
||
35 |
void HWEngine::run() |
|
36 |
{ |
|
10416 | 37 |
m_argsList.clear(); |
38 |
m_argsList << ""; |
|
39 |
m_argsList << "--internal"; |
|
40 |
//m_argsList << "--user-prefix"; |
|
41 |
//m_argsList << cfgdir->absolutePath(); |
|
42 |
//m_argsList << "--prefix"; |
|
43 |
//m_argsList << datadir->absolutePath(); |
|
44 |
m_argsList << "--landpreview"; |
|
45 |
||
46 |
m_args.resize(m_argsList.size()); |
|
47 |
for(int i = m_argsList.size() - 1; i >=0; --i) |
|
48 |
m_args[i] = m_argsList[i].data(); |
|
49 |
||
50 |
RunEngine(m_args.size(), m_args.data()); |
|
51 |
sendIPC("!"); |
|
10402 | 52 |
} |
53 |
||
54 |
static QObject *hwengine_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine) |
|
55 |
{ |
|
56 |
Q_UNUSED(engine) |
|
57 |
Q_UNUSED(scriptEngine) |
|
58 |
||
59 |
HWEngine *hwengine = new HWEngine(); |
|
60 |
return hwengine; |
|
61 |
} |
|
62 |
||
63 |
void HWEngine::exposeToQML() |
|
64 |
{ |
|
65 |
qDebug("HWEngine::exposeToQML"); |
|
66 |
qmlRegisterSingletonType<HWEngine>("Hedgewars.Engine", 1, 0, "HWEngine", hwengine_singletontype_provider); |
|
67 |
} |
|
10416 | 68 |
|
69 |
void HWEngine::sendIPC(const QByteArray & b) |
|
70 |
{ |
|
71 |
string255 str; |
|
72 |
str.len = b.size() > 255 ? 255 : b.size(); |
|
73 |
qDebug() << "semdIPC: len = " << str.len; |
|
74 |
qCopy(b.data(), &(b.data()[str.len - 1]), &(str.str[0])); |
|
75 |
||
76 |
ipcToEngine(str); |
|
77 |
} |
|
78 |
||
79 |
void HWEngine::engineMessageCallback(void *context, string255 str) |
|
80 |
{ |
|
81 |
QByteArray b = QByteArray::fromRawData((const char *)&str.s, str.len + 1); |
|
82 |
||
83 |
qDebug() << "FLIPC in" << b; |
|
84 |
} |