code format & class prefix

This commit is contained in:
王劲鹏
2021-02-04 16:59:58 +08:00
committed by osborn
parent 99afe83b19
commit be37a71699
90 changed files with 1196 additions and 1274 deletions

View File

@@ -0,0 +1,16 @@
#ifndef ASYNC_CALL_H
#define ASYNC_CALL_H
#include <QThreadPool>
#include <QtConcurrent/QtConcurrent>
class DoricAsyncCall {
public:
static void ensureRunInThreadPool(QThreadPool *threadPool,
std::function<void()> lambda) {
QtConcurrent::run(threadPool, lambda);
}
};
#endif // ASYNC_CALL_H

View File

@@ -0,0 +1,38 @@
#include "DoricAsyncResult.h"
DoricAsyncResult::DoricAsyncResult() {}
DoricAsyncResult::DoricAsyncResult(QJSValue result) { this->result = result; }
void DoricAsyncResult::setResult(QJSValue result) {
this->result = result;
if (this->callback != NULL) {
this->callback->onResult(result);
this->callback->onFinish();
}
}
void DoricAsyncResult::setError(QJSValue exception) {
this->result = exception;
if (this->callback != NULL) {
this->callback->onResult(result);
this->callback->onFinish();
}
}
bool DoricAsyncResult::hasResult() { return !result.equals(EMPTY); }
QJSValue DoricAsyncResult::getResult() { return this->result; }
void DoricAsyncResult::setCallback(DoricCallback *callback) {
this->callback = callback;
if (this->result.isError()) {
this->callback->onError(result);
this->callback->onFinish();
} else if (!result.equals(EMPTY)) {
this->callback->onResult(result);
this->callback->onFinish();
}
}
DoricSettableFuture *DoricAsyncResult::synchronous() { return NULL; }

View File

@@ -0,0 +1,34 @@
#ifndef ASYNCRESULT_H
#define ASYNCRESULT_H
#include <QJSValue>
#include "DoricCallback.h"
#include "DoricSettableFuture.h"
static QJSValue EMPTY(QJSValue::NullValue);
class DoricAsyncResult {
private:
QJSValue result = EMPTY;
DoricCallback *callback;
public:
DoricAsyncResult();
DoricAsyncResult(QJSValue result);
void setResult(QJSValue result);
void setError(QJSValue exception);
bool hasResult();
QJSValue getResult();
void setCallback(DoricCallback *callback);
DoricSettableFuture *synchronous();
};
#endif // ASYNCRESULT_H

View File

@@ -0,0 +1,15 @@
#ifndef CALLBACK_H
#define CALLBACK_H
#include <QJSValue>
class DoricCallback {
public:
virtual void onResult(QJSValue result) = 0;
virtual void onError(QJSValue error) = 0;
virtual void onFinish() = 0;
};
#endif // CALLBACK_H

View File

@@ -0,0 +1,17 @@
#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;
}

View File

@@ -0,0 +1,19 @@
#ifndef SETTABLE_FUTURE_H
#define SETTABLE_FUTURE_H
#include <QJSValue>
#include "utils/DoricCountDownLatch.h"
class DoricSettableFuture {
private:
QJSValue mResult;
DoricCountDownLatch *mReadyLatch = new DoricCountDownLatch();
public:
void set(QJSValue result);
QJSValue get();
};
#endif // SETTABLE_FUTURE_H

View File

@@ -1,16 +0,0 @@
#ifndef ASYNC_CALL_H
#define ASYNC_CALL_H
#include <QThreadPool>
#include <QtConcurrent/QtConcurrent>
class AsyncCall {
public:
static void ensureRunInThreadPool(QThreadPool *threadPool, std::function<void()> lambda)
{
QtConcurrent::run(threadPool, lambda);
}
};
#endif // ASYNC_CALL_H

View File

@@ -1,56 +0,0 @@
#include "async_result.h"
AsyncResult::AsyncResult()
{
}
AsyncResult::AsyncResult(QJSValue result)
{
this->result = result;
}
void AsyncResult::setResult(QJSValue result)
{
this->result = result;
if (this->callback != NULL) {
this->callback->onResult(result);
this->callback->onFinish();
}
}
void AsyncResult::setError(QJSValue exception)
{
this->result = exception;
if (this->callback != NULL) {
this->callback->onResult(result);
this->callback->onFinish();
}
}
bool AsyncResult::hasResult()
{
return !result.equals(EMPTY);
}
QJSValue AsyncResult::getResult()
{
return this->result;
}
void AsyncResult::setCallback(Callback *callback)
{
this->callback = callback;
if (this->result.isError()) {
this->callback->onError(result);
this->callback->onFinish();
} else if (!result.equals(EMPTY)) {
this->callback->onResult(result);
this->callback->onFinish();
}
}
SettableFuture* AsyncResult::synchronous()
{
return NULL;
}

View File

@@ -1,35 +0,0 @@
#ifndef ASYNCRESULT_H
#define ASYNCRESULT_H
#include <QJSValue>
#include "callback.h"
#include "settable_future.h"
static QJSValue EMPTY(QJSValue::NullValue);
class AsyncResult
{
private:
QJSValue result = EMPTY;
Callback *callback;
public:
AsyncResult();
AsyncResult(QJSValue result);
void setResult(QJSValue result);
void setError(QJSValue exception);
bool hasResult();
QJSValue getResult();
void setCallback(Callback *callback);
SettableFuture *synchronous();
};
#endif // ASYNCRESULT_H

View File

@@ -1,15 +0,0 @@
#ifndef CALLBACK_H
#define CALLBACK_H
#include <QJSValue>
class Callback {
public:
virtual void onResult(QJSValue result) = 0;
virtual void onError(QJSValue error) = 0;
virtual void onFinish() = 0;
};
#endif // CALLBACK_H

View File

@@ -1,20 +0,0 @@
#include <QDebug>
#include "settable_future.h"
void SettableFuture::set(QJSValue result)
{
if (mReadyLatch == NULL)
{
qDebug() << "Result has already been set!";
return;
}
mResult = result;
delete mReadyLatch;
}
QJSValue SettableFuture::get()
{
mReadyLatch->lock();
return mResult;
}

View File

@@ -1,18 +0,0 @@
#ifndef SETTABLE_FUTURE_H
#define SETTABLE_FUTURE_H
#include <QJSValue>
#include "utils/count_down_latch.h"
class SettableFuture {
private:
QJSValue mResult;
CountDownLatch *mReadyLatch = new CountDownLatch();
public:
void set(QJSValue result);
QJSValue get();
};
#endif // SETTABLE_FUTURE_H