rename dir
This commit is contained in:
26
doric-Qt/doric/driver/driver.h
Normal file
26
doric-Qt/doric/driver/driver.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef DRIVER_H
|
||||
#define DRIVER_H
|
||||
|
||||
#include <QtPlugin>
|
||||
|
||||
#include "registry.h"
|
||||
|
||||
class Driver {
|
||||
|
||||
public:
|
||||
virtual void createContext(int contextId, QString *script) = 0;
|
||||
virtual void destroyContext(int contextId) = 0;
|
||||
|
||||
virtual void invokeContextEntityMethod(int contextId, QString *method, ...) = 0;
|
||||
virtual void invokeDoricMethod(QString *method, ...) = 0;
|
||||
|
||||
virtual Registry *getRegistry() = 0;
|
||||
|
||||
virtual ~Driver() = default;
|
||||
};
|
||||
|
||||
#define DriverInterface "pub.doric.DriverInterface"
|
||||
|
||||
Q_DECLARE_INTERFACE(Driver, DriverInterface)
|
||||
|
||||
#endif // DRIVER_H
|
58
doric-Qt/doric/driver/native_driver.cpp
Normal file
58
doric-Qt/doric/driver/native_driver.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include <QDebug>
|
||||
|
||||
#include "stdarg.h"
|
||||
|
||||
#include "native_driver.h"
|
||||
#include "utility/utility.h"
|
||||
|
||||
NativeDriver::NativeDriver() {
|
||||
qDebug() << "NativeDriver constructor";
|
||||
}
|
||||
|
||||
NativeDriver::~NativeDriver() {
|
||||
qDebug() << "NativeDriver destructor";
|
||||
}
|
||||
|
||||
void NativeDriver::createContext(int contextId, QString *script) {
|
||||
jsEngine->prepareContext(contextId, script);
|
||||
}
|
||||
|
||||
void NativeDriver::destroyContext(int contextId) {
|
||||
jsEngine->destroyContext(contextId);
|
||||
}
|
||||
|
||||
void NativeDriver::invokeContextEntityMethod(int contextId, QString *method, ...) {
|
||||
QJSValueList *arguments = new QJSValueList();
|
||||
arguments->append(QJSValue(QString::number(contextId)));
|
||||
arguments->append(QJSValue(*method));
|
||||
|
||||
va_list vaList;
|
||||
va_start(vaList, method);
|
||||
auto argument = va_arg(vaList, QVariant*);
|
||||
while (argument != nullptr) {
|
||||
if (QString(typeid(QJsonObject).name()).contains(QString(argument->typeName()))) {
|
||||
QJsonObject *jsonObject = static_cast<QJsonObject*>(argument->data());
|
||||
QJsonValue *jsonValue = new QJsonValue(*jsonObject);
|
||||
QJSValue jsValue = Utility::convert(jsEngine->engine, *jsonValue);
|
||||
delete jsonValue;
|
||||
arguments->append(jsValue);
|
||||
}
|
||||
argument = va_arg(vaList, QVariant*);
|
||||
}
|
||||
va_end(vaList);
|
||||
|
||||
QJSValue result = jsEngine->engine->globalObject()
|
||||
.property(Constant::GLOBAL_DORIC)
|
||||
.property(Constant::DORIC_CONTEXT_INVOKE)
|
||||
.call(*arguments);
|
||||
qDebug() << "invokeContextEntityMethod: " + result.toString();
|
||||
delete arguments;
|
||||
}
|
||||
|
||||
void NativeDriver::invokeDoricMethod(QString *method, ...) {
|
||||
|
||||
}
|
||||
|
||||
Registry* NativeDriver::getRegistry() {
|
||||
return jsEngine->registry;
|
||||
}
|
33
doric-Qt/doric/driver/native_driver.h
Normal file
33
doric-Qt/doric/driver/native_driver.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#ifndef NATIVE_DRIVER_H
|
||||
#define NATIVE_DRIVER_H
|
||||
|
||||
#include "driver.h"
|
||||
#include "engine/js_engine.h"
|
||||
|
||||
class NativeDriver : public Driver {
|
||||
Q_INTERFACES(Driver)
|
||||
|
||||
private:
|
||||
static NativeDriver *local_instance;
|
||||
NativeDriver();
|
||||
|
||||
~NativeDriver() override;
|
||||
|
||||
JSEngine *jsEngine = new JSEngine();
|
||||
|
||||
public:
|
||||
static NativeDriver *getInstance() {
|
||||
static NativeDriver locla_s;
|
||||
return &locla_s;
|
||||
}
|
||||
|
||||
void createContext(int contextId, QString *script) override;
|
||||
void destroyContext(int contextId) override;
|
||||
|
||||
void invokeContextEntityMethod(int contextId, QString *method, ...) override;
|
||||
void invokeDoricMethod(QString *method, ...) override;
|
||||
|
||||
Registry * getRegistry() override;
|
||||
};
|
||||
|
||||
#endif // NATIVE_DRIVER_H
|
Reference in New Issue
Block a user