add files from main project

This commit is contained in:
pengfei.zhou
2019-12-04 15:51:46 +08:00
parent 2ca38388f3
commit dbdd1770ef
19 changed files with 579 additions and 0 deletions

19
doric/driver/driver.h Normal file
View File

@@ -0,0 +1,19 @@
#ifndef DRIVER_H
#define DRIVER_H
#include <QtPlugin>
class Driver {
public:
virtual void createContext(int contextId, QString* script) = 0;
virtual void destroyContext(int contextId) = 0;
virtual ~Driver() = default;
};
#define DriverInterface "pub.doric.DriverInterface"
Q_DECLARE_INTERFACE(Driver, DriverInterface)
#endif // DRIVER_H

View File

@@ -0,0 +1,13 @@
#include "native_driver.h"
NativeDriver::~NativeDriver() {
qDebug() << "NativeDriver destructor";
}
void NativeDriver::createContext(int contextId, QString *script) {
jsEngine->prepareContext(contextId, script);
}
void NativeDriver::destroyContext(int contextId) {
jsEngine->destroyContext(contextId);
}

View File

@@ -0,0 +1,33 @@
#ifndef NATIVE_DRIVER_H
#define NATIVE_DRIVER_H
#include <QDebug>
#include "driver.h"
#include "engine/js_engine.h"
class NativeDriver : public Driver {
Q_INTERFACES(Driver)
private:
static NativeDriver *local_instance;
NativeDriver() {
qDebug() << "NativeDriver constructor";
}
~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;
};
#endif // NATIVE_DRIVER_H