add shared ptr wrap for async result
This commit is contained in:
parent
3531a28f13
commit
33bec666a4
@ -54,7 +54,8 @@ void DoricContext::build(int width, int height) {
|
||||
callEntity(DoricConstant::DORIC_ENTITY_BUILD, args);
|
||||
}
|
||||
|
||||
void DoricContext::callEntity(QString methodName, QVariantList args) {
|
||||
std::shared_ptr<DoricAsyncResult> DoricContext::callEntity(QString methodName,
|
||||
QVariantList args) {
|
||||
return getDriver()->invokeContextEntityMethod(this->mContextId, methodName,
|
||||
args);
|
||||
}
|
||||
|
@ -34,7 +34,8 @@ public:
|
||||
|
||||
void build(int width, int height);
|
||||
|
||||
void callEntity(QString methodName, QVariantList args);
|
||||
std::shared_ptr<DoricAsyncResult> callEntity(QString methodName,
|
||||
QVariantList args);
|
||||
|
||||
DoricInterfaceDriver *getDriver();
|
||||
|
||||
|
@ -11,18 +11,21 @@
|
||||
|
||||
class DoricInterfaceDriver {
|
||||
public:
|
||||
virtual void invokeContextEntityMethod(QString contextId, QString method,
|
||||
QVariantList args) = 0;
|
||||
virtual std::shared_ptr<DoricAsyncResult>
|
||||
invokeContextEntityMethod(QString contextId, QString method,
|
||||
QVariantList args) = 0;
|
||||
|
||||
virtual void invokeDoricMethod(QString method, QVariantList args) = 0;
|
||||
virtual std::shared_ptr<DoricAsyncResult>
|
||||
invokeDoricMethod(QString method, QVariantList args) = 0;
|
||||
|
||||
virtual DoricAsyncResult *asyncCall(std::function<void()> lambda,
|
||||
DoricThreadMode mode) = 0;
|
||||
virtual std::shared_ptr<DoricAsyncResult>
|
||||
asyncCall(std::function<void()> lambda, DoricThreadMode mode) = 0;
|
||||
|
||||
virtual void createContext(QString contextId, QString script,
|
||||
QString source) = 0;
|
||||
virtual std::shared_ptr<DoricAsyncResult>
|
||||
createContext(QString contextId, QString script, QString source) = 0;
|
||||
|
||||
virtual void destroyContext(QString contextId) = 0;
|
||||
virtual std::shared_ptr<DoricAsyncResult>
|
||||
destroyContext(QString contextId) = 0;
|
||||
|
||||
virtual DoricRegistry *getRegistry() = 0;
|
||||
};
|
||||
|
@ -4,22 +4,26 @@
|
||||
#include "async/DoricAsyncCall.h"
|
||||
#include "utils/DoricConstant.h"
|
||||
|
||||
void DoricNativeDriver::invokeContextEntityMethod(QString contextId,
|
||||
QString method,
|
||||
QVariantList args) {
|
||||
std::shared_ptr<DoricAsyncResult>
|
||||
DoricNativeDriver::invokeContextEntityMethod(QString contextId, QString method,
|
||||
QVariantList args) {
|
||||
args.insert(0, QVariant(contextId));
|
||||
args.insert(1, QVariant(method));
|
||||
invokeDoricMethod(DoricConstant::DORIC_CONTEXT_INVOKE, args);
|
||||
return invokeDoricMethod(DoricConstant::DORIC_CONTEXT_INVOKE, args);
|
||||
}
|
||||
|
||||
void DoricNativeDriver::invokeDoricMethod(QString method, QVariantList args) {
|
||||
return DoricAsyncCall::ensureRunInThreadPool(
|
||||
std::shared_ptr<DoricAsyncResult>
|
||||
DoricNativeDriver::invokeDoricMethod(QString method, QVariantList args) {
|
||||
DoricAsyncCall::ensureRunInThreadPool(
|
||||
&jsEngine.mJSThreadPool,
|
||||
[this, method, args] { this->jsEngine.invokeDoricMethod(method, args); });
|
||||
|
||||
return std::make_shared<DoricAsyncResult>();
|
||||
}
|
||||
|
||||
DoricAsyncResult *DoricNativeDriver::asyncCall(std::function<void()> lambda,
|
||||
DoricThreadMode mode) {
|
||||
std::shared_ptr<DoricAsyncResult>
|
||||
DoricNativeDriver::asyncCall(std::function<void()> lambda,
|
||||
DoricThreadMode mode) {
|
||||
switch (mode) {
|
||||
case UI:
|
||||
DoricAsyncCall::ensureRunInMain(lambda);
|
||||
@ -31,18 +35,24 @@ DoricAsyncResult *DoricNativeDriver::asyncCall(std::function<void()> lambda,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void DoricNativeDriver::createContext(QString contextId, QString script,
|
||||
QString source) {
|
||||
std::shared_ptr<DoricAsyncResult>
|
||||
DoricNativeDriver::createContext(QString contextId, QString script,
|
||||
QString source) {
|
||||
DoricAsyncCall::ensureRunInThreadPool(
|
||||
&jsEngine.mJSThreadPool, [this, contextId, script, source] {
|
||||
this->jsEngine.prepareContext(contextId, script, source);
|
||||
});
|
||||
|
||||
return std::make_shared<DoricAsyncResult>();
|
||||
}
|
||||
|
||||
void DoricNativeDriver::destroyContext(QString contextId) {
|
||||
std::shared_ptr<DoricAsyncResult>
|
||||
DoricNativeDriver::destroyContext(QString contextId) {
|
||||
DoricAsyncCall::ensureRunInThreadPool(
|
||||
&jsEngine.mJSThreadPool,
|
||||
[this, contextId] { this->jsEngine.destroyContext(contextId); });
|
||||
|
||||
return std::make_shared<DoricAsyncResult>();
|
||||
}
|
||||
|
||||
DoricRegistry *DoricNativeDriver::getRegistry() {
|
||||
|
@ -21,18 +21,20 @@ public:
|
||||
return &instance;
|
||||
}
|
||||
|
||||
void invokeContextEntityMethod(QString contextId, QString method,
|
||||
QVariantList args) override;
|
||||
std::shared_ptr<DoricAsyncResult>
|
||||
invokeContextEntityMethod(QString contextId, QString method,
|
||||
QVariantList args) override;
|
||||
|
||||
void invokeDoricMethod(QString method, QVariantList args) override;
|
||||
std::shared_ptr<DoricAsyncResult>
|
||||
invokeDoricMethod(QString method, QVariantList args) override;
|
||||
|
||||
DoricAsyncResult *asyncCall(std::function<void()> lambda,
|
||||
DoricThreadMode mode) override;
|
||||
std::shared_ptr<DoricAsyncResult> asyncCall(std::function<void()> lambda,
|
||||
DoricThreadMode mode) override;
|
||||
|
||||
void createContext(QString contextId, QString script,
|
||||
QString source) override;
|
||||
std::shared_ptr<DoricAsyncResult>
|
||||
createContext(QString contextId, QString script, QString source) override;
|
||||
|
||||
void destroyContext(QString contextId) override;
|
||||
std::shared_ptr<DoricAsyncResult> destroyContext(QString contextId) override;
|
||||
|
||||
DoricRegistry *getRegistry() override;
|
||||
};
|
||||
|
@ -208,7 +208,8 @@ QList<QString> DoricViewNode::getIdList() {
|
||||
|
||||
void DoricViewNode::requestLayout() {}
|
||||
|
||||
void DoricViewNode::callJSResponse(QString funcId, QVariantList args) {
|
||||
std::shared_ptr<DoricAsyncResult>
|
||||
DoricViewNode::callJSResponse(QString funcId, QVariantList args) {
|
||||
QVariantList nArgs;
|
||||
QList<QString> idList = getIdList();
|
||||
nArgs.append(QVariant(idList));
|
||||
@ -219,7 +220,8 @@ void DoricViewNode::callJSResponse(QString funcId, QVariantList args) {
|
||||
return getContext()->callEntity(DoricConstant::DORIC_ENTITY_RESPONSE, nArgs);
|
||||
}
|
||||
|
||||
void DoricViewNode::pureCallJSResponse(QString funcId, QVariantList args) {
|
||||
std::shared_ptr<DoricAsyncResult>
|
||||
DoricViewNode::pureCallJSResponse(QString funcId, QVariantList args) {
|
||||
QVariantList nArgs;
|
||||
nArgs.append(getContext()->getContextId());
|
||||
nArgs.append(DoricConstant::DORIC_ENTITY_RESPONSE);
|
||||
|
@ -77,8 +77,10 @@ public:
|
||||
|
||||
void onClick();
|
||||
|
||||
void callJSResponse(QString funcId, QVariantList args);
|
||||
std::shared_ptr<DoricAsyncResult> callJSResponse(QString funcId,
|
||||
QVariantList args);
|
||||
|
||||
void pureCallJSResponse(QString funcId, QVariantList args);
|
||||
std::shared_ptr<DoricAsyncResult> pureCallJSResponse(QString funcId,
|
||||
QVariantList args);
|
||||
};
|
||||
#endif // DORICVIEWNODE_H
|
||||
|
Reference in New Issue
Block a user