complete pure call
This commit is contained in:
@@ -1,13 +1,31 @@
|
||||
#include "DoricAsyncResult.h"
|
||||
|
||||
#include <QWaitCondition>
|
||||
|
||||
DoricAsyncResult::DoricAsyncResult() {}
|
||||
|
||||
void DoricAsyncResult::setResult(QString result) { this->result = result; }
|
||||
void DoricAsyncResult::setResult(QString result) {
|
||||
this->result = result;
|
||||
this->resultCallback();
|
||||
}
|
||||
|
||||
void DoricAsyncResult::setError(QString exception) { this->result = exception; }
|
||||
|
||||
bool DoricAsyncResult::hasResult() { return !(result == EMPTY); }
|
||||
bool DoricAsyncResult::hasResult() { return !(result.isEmpty()); }
|
||||
|
||||
QJSValue DoricAsyncResult::getResult() { return this->result; }
|
||||
QString DoricAsyncResult::getResult() { return this->result; }
|
||||
|
||||
DoricSettableFuture *DoricAsyncResult::synchronous() { return NULL; }
|
||||
QString DoricAsyncResult::waitUntilResult() {
|
||||
if (hasResult()) {
|
||||
return this->result;
|
||||
}
|
||||
|
||||
QMutex mutex;
|
||||
QWaitCondition condition;
|
||||
this->resultCallback = [&condition]() { condition.wakeAll(); };
|
||||
|
||||
mutex.lock();
|
||||
condition.wait(&mutex);
|
||||
mutex.unlock();
|
||||
return this->result;
|
||||
}
|
||||
|
@@ -1,17 +1,13 @@
|
||||
#ifndef ASYNCRESULT_H
|
||||
#define ASYNCRESULT_H
|
||||
|
||||
#include <QJSValue>
|
||||
#include <QString>
|
||||
|
||||
#include "DoricExport.h"
|
||||
|
||||
#include "DoricSettableFuture.h"
|
||||
|
||||
static QString EMPTY("");
|
||||
|
||||
class DORIC_EXPORT DoricAsyncResult {
|
||||
private:
|
||||
QString result = EMPTY;
|
||||
QString result;
|
||||
|
||||
public:
|
||||
std::function<void()> resultCallback;
|
||||
@@ -26,9 +22,9 @@ public:
|
||||
|
||||
bool hasResult();
|
||||
|
||||
QJSValue getResult();
|
||||
QString getResult();
|
||||
|
||||
DoricSettableFuture *synchronous();
|
||||
QString waitUntilResult();
|
||||
};
|
||||
|
||||
#endif // ASYNCRESULT_H
|
||||
|
@@ -1,17 +0,0 @@
|
||||
#include <QDebug>
|
||||
|
||||
#include "DoricSettableFuture.h"
|
||||
|
||||
void DoricSettableFuture::set(QJSValue result) {
|
||||
if (mReadyLatch == NULL) {
|
||||
qDebug() << "Result has already been set!";
|
||||
return;
|
||||
}
|
||||
mResult = result;
|
||||
delete mReadyLatch;
|
||||
}
|
||||
|
||||
QJSValue DoricSettableFuture::get() {
|
||||
mReadyLatch->lock();
|
||||
return mResult;
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
#ifndef SETTABLE_FUTURE_H
|
||||
#define SETTABLE_FUTURE_H
|
||||
|
||||
#include <QJSValue>
|
||||
|
||||
#include "DoricExport.h"
|
||||
|
||||
#include "utils/DoricCountDownLatch.h"
|
||||
|
||||
class DORIC_EXPORT DoricSettableFuture {
|
||||
private:
|
||||
QJSValue mResult;
|
||||
DoricCountDownLatch *mReadyLatch = new DoricCountDownLatch();
|
||||
|
||||
public:
|
||||
void set(QJSValue result);
|
||||
|
||||
QJSValue get();
|
||||
};
|
||||
|
||||
#endif // SETTABLE_FUTURE_H
|
@@ -26,7 +26,6 @@ SOURCES += \
|
||||
DoricPanel.cpp \
|
||||
DoricRegistry.cpp \
|
||||
async/DoricAsyncResult.cpp \
|
||||
async/DoricSettableFuture.cpp \
|
||||
engine/DoricBridgeExtension.cpp \
|
||||
engine/DoricJSEngine.cpp \
|
||||
engine/DoricNativeEmpty.cpp \
|
||||
@@ -105,7 +104,6 @@ HEADERS += \
|
||||
DoricRegistry.h \
|
||||
async/DoricAsyncCall.h \
|
||||
async/DoricAsyncResult.h \
|
||||
async/DoricSettableFuture.h \
|
||||
engine/DoricBridgeExtension.h \
|
||||
engine/DoricInterfaceJSE.h \
|
||||
engine/DoricJSEngine.h \
|
||||
|
@@ -1,6 +1,8 @@
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Controls 2.5
|
||||
|
||||
import "util.mjs" as Util
|
||||
|
||||
SwipeView {
|
||||
property var wrapper
|
||||
|
||||
|
@@ -232,8 +232,8 @@ DoricViewNode::pureCallJSResponse(QString funcId, QVariantList args) {
|
||||
foreach (const QVariant &arg, args)
|
||||
nArgs.append(arg);
|
||||
|
||||
return getContext()->callEntity(DoricConstant::DORIC_CONTEXT_INVOKE_PURE,
|
||||
nArgs);
|
||||
return getContext()->getDriver()->invokeDoricMethod(
|
||||
DoricConstant::DORIC_CONTEXT_INVOKE_PURE, nArgs);
|
||||
}
|
||||
|
||||
void DoricViewNode::onClick() {
|
||||
|
@@ -32,15 +32,33 @@ void DoricSliderNode::blendSubNode(QJsonValue subProperties) {
|
||||
}
|
||||
}
|
||||
|
||||
void DoricSliderNode::blend(QJsonValue jsValue) {}
|
||||
|
||||
void DoricSliderNode::blend(QQuickItem *view, QString name, QJsonValue prop) {}
|
||||
void DoricSliderNode::blend(QQuickItem *view, QString name, QJsonValue prop) {
|
||||
if (name == "itemCount") {
|
||||
this->itemCount = prop.toInt();
|
||||
} else if (name == "renderPage") {
|
||||
if (prop.toString() != this->renderPageFuncId) {
|
||||
this->childNodes.clear();
|
||||
this->renderPageFuncId = prop.toString();
|
||||
}
|
||||
} else if (name == "batchCount") {
|
||||
this->batchCount = prop.toInt();
|
||||
} else if (name == "onPageSlided") {
|
||||
this->onPageSelectedFuncId = prop.toString();
|
||||
} else if (name == "loop") {
|
||||
this->loop = prop.toBool();
|
||||
} else {
|
||||
DoricViewNode::blend(view, name, prop);
|
||||
}
|
||||
}
|
||||
|
||||
void DoricSliderNode::afterBlended(QJsonValue prop) {
|
||||
if (this->childNodes.length() != this->itemCount) {
|
||||
QVariantList args;
|
||||
args.append(this->childNodes.length());
|
||||
args.append(this->itemCount);
|
||||
this->pureCallJSResponse("renderBunchedItems", args);
|
||||
std::shared_ptr<DoricAsyncResult> asyncResult =
|
||||
this->pureCallJSResponse("renderBunchedItems", args);
|
||||
QString result = asyncResult->waitUntilResult();
|
||||
qDebug() << result;
|
||||
}
|
||||
}
|
||||
|
@@ -25,8 +25,6 @@ public:
|
||||
|
||||
virtual void blendSubNode(QJsonValue subProperties) override;
|
||||
|
||||
virtual void blend(QJsonValue jsValue) override;
|
||||
|
||||
virtual void blend(QQuickItem *view, QString name, QJsonValue prop) override;
|
||||
|
||||
virtual void afterBlended(QJsonValue prop) override;
|
||||
|
Reference in New Issue
Block a user