author | unc0rr |
Sun, 21 Sep 2014 00:37:50 +0400 | |
branch | qmlfrontend |
changeset 10418 | 091d2c0216c3 |
parent 10416 | 1c301054694d |
child 10420 | 02c573d19224 |
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) |
|
10418
091d2c0216c3
Move away from passing shortstrings into C code, now IPC works
unc0rr
parents:
10416
diff
changeset
|
48 |
m_args[i] = m_argsList[i].constData(); |
10416 | 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 |
{ |
|
10418
091d2c0216c3
Move away from passing shortstrings into C code, now IPC works
unc0rr
parents:
10416
diff
changeset
|
71 |
quint8 len = b.size() > 255 ? 255 : b.size(); |
091d2c0216c3
Move away from passing shortstrings into C code, now IPC works
unc0rr
parents:
10416
diff
changeset
|
72 |
qDebug() << "sendIPC: len = " << len; |
10416 | 73 |
|
10418
091d2c0216c3
Move away from passing shortstrings into C code, now IPC works
unc0rr
parents:
10416
diff
changeset
|
74 |
ipcToEngine(len, b.constData()); |
10416 | 75 |
} |
76 |
||
10418
091d2c0216c3
Move away from passing shortstrings into C code, now IPC works
unc0rr
parents:
10416
diff
changeset
|
77 |
void HWEngine::engineMessageCallback(void *context, quint8 len, const char *msg) |
10416 | 78 |
{ |
10418
091d2c0216c3
Move away from passing shortstrings into C code, now IPC works
unc0rr
parents:
10416
diff
changeset
|
79 |
QByteArray b = QByteArray::fromRawData(msg, len); |
10416 | 80 |
|
81 |
qDebug() << "FLIPC in" << b; |
|
82 |
} |