mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-19 10:58:51 +00:00
Add R2Task class
This commit is contained in:
parent
e4aec07f01
commit
e0c7e625e4
@ -7,6 +7,7 @@
|
|||||||
#include "utils/TempConfig.h"
|
#include "utils/TempConfig.h"
|
||||||
#include "utils/Configuration.h"
|
#include "utils/Configuration.h"
|
||||||
#include "utils/AsyncTask.h"
|
#include "utils/AsyncTask.h"
|
||||||
|
#include "utils/R2Task.h"
|
||||||
#include "Cutter.h"
|
#include "Cutter.h"
|
||||||
#include "sdb.h"
|
#include "sdb.h"
|
||||||
|
|
||||||
@ -194,20 +195,18 @@ QJsonDocument CutterCore::cmdj(const QString &str)
|
|||||||
|
|
||||||
QString CutterCore::cmdTask(const QString &str)
|
QString CutterCore::cmdTask(const QString &str)
|
||||||
{
|
{
|
||||||
RCoreTask *task = startTask(str);
|
R2Task task(str);
|
||||||
joinTask(task);
|
task.startTask();
|
||||||
QString ret = QString::fromUtf8(task->res);
|
task.joinTask();
|
||||||
deleteTask(task);
|
return task.getResult();
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonDocument CutterCore::cmdjTask(const QString &str)
|
QJsonDocument CutterCore::cmdjTask(const QString &str)
|
||||||
{
|
{
|
||||||
RCoreTask *task = startTask(str);
|
R2Task task(str);
|
||||||
joinTask(task);
|
task.startTask();
|
||||||
QJsonDocument ret = parseJson(task->res, str);
|
task.joinTask();
|
||||||
deleteTask(task);
|
return parseJson(task.getResultRaw(), str);
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QJsonDocument CutterCore::parseJson(const char *res, const QString &cmd)
|
QJsonDocument CutterCore::parseJson(const char *res, const QString &cmd)
|
||||||
@ -1749,22 +1748,6 @@ QList<QString> CutterCore::getColorThemes()
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
RCoreTask *CutterCore::startTask(const QString &cmd)
|
|
||||||
{
|
|
||||||
RCoreTask *task = r_core_task_new (core_, true, cmd.toLocal8Bit().constData(), nullptr, nullptr);
|
|
||||||
r_core_task_enqueue(core_, task);
|
|
||||||
return task;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CutterCore::joinTask(RCoreTask *task)
|
|
||||||
{
|
|
||||||
r_core_task_join(core_, nullptr, task);
|
|
||||||
}
|
|
||||||
void CutterCore::deleteTask(RCoreTask *task)
|
|
||||||
{
|
|
||||||
r_core_task_del(core_, task->id);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CutterCore::setCutterPlugins(QList<CutterPlugin*> plugins)
|
void CutterCore::setCutterPlugins(QList<CutterPlugin*> plugins)
|
||||||
{
|
{
|
||||||
this->plugins = plugins;
|
this->plugins = plugins;
|
||||||
|
@ -524,10 +524,6 @@ public:
|
|||||||
void triggerAsmOptionsChanged();
|
void triggerAsmOptionsChanged();
|
||||||
void triggerGraphOptionsChanged();
|
void triggerGraphOptionsChanged();
|
||||||
|
|
||||||
RCoreTask *startTask(const QString &cmd);
|
|
||||||
void joinTask(RCoreTask *task);
|
|
||||||
void deleteTask(RCoreTask *task);
|
|
||||||
|
|
||||||
void setCutterPlugins(QList<CutterPlugin*> plugins);
|
void setCutterPlugins(QList<CutterPlugin*> plugins);
|
||||||
QList<CutterPlugin*> getCutterPlugins();
|
QList<CutterPlugin*> getCutterPlugins();
|
||||||
|
|
||||||
|
@ -171,7 +171,8 @@ SOURCES += \
|
|||||||
widgets/BacktraceWidget.cpp \
|
widgets/BacktraceWidget.cpp \
|
||||||
dialogs/OpenFileDialog.cpp \
|
dialogs/OpenFileDialog.cpp \
|
||||||
utils/CommandTask.cpp \
|
utils/CommandTask.cpp \
|
||||||
utils/ProgressIndicator.cpp
|
utils/ProgressIndicator.cpp \
|
||||||
|
utils/R2Task.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
Cutter.h \
|
Cutter.h \
|
||||||
@ -257,7 +258,8 @@ HEADERS += \
|
|||||||
utils/FunctionsTask.h \
|
utils/FunctionsTask.h \
|
||||||
utils/CommandTask.h \
|
utils/CommandTask.h \
|
||||||
utils/ProgressIndicator.h \
|
utils/ProgressIndicator.h \
|
||||||
plugins/CutterPlugin.h
|
plugins/CutterPlugin.h \
|
||||||
|
utils/R2Task.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
dialogs/AboutDialog.ui \
|
dialogs/AboutDialog.ui \
|
||||||
|
51
src/utils/R2Task.cpp
Normal file
51
src/utils/R2Task.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
|
||||||
|
#include "R2Task.h"
|
||||||
|
|
||||||
|
R2Task::R2Task(const QString &cmd)
|
||||||
|
{
|
||||||
|
task = r_core_task_new(Core()->core(),
|
||||||
|
true,
|
||||||
|
cmd.toLocal8Bit().constData(),
|
||||||
|
static_cast<RCoreTaskCallback>(&R2Task::taskFinishedCallback),
|
||||||
|
this);
|
||||||
|
}
|
||||||
|
|
||||||
|
R2Task::~R2Task()
|
||||||
|
{
|
||||||
|
r_core_task_del(Core()->core(), task->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void R2Task::taskFinishedCallback(void *user, char *)
|
||||||
|
{
|
||||||
|
reinterpret_cast<R2Task *>(user)->taskFinished();
|
||||||
|
}
|
||||||
|
|
||||||
|
void R2Task::taskFinished()
|
||||||
|
{
|
||||||
|
emit finished();
|
||||||
|
}
|
||||||
|
|
||||||
|
void R2Task::startTask()
|
||||||
|
{
|
||||||
|
r_core_task_enqueue(Core()->core(), task);
|
||||||
|
}
|
||||||
|
|
||||||
|
void R2Task::breakTask()
|
||||||
|
{
|
||||||
|
r_core_task_break(Core()->core(), task->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void R2Task::joinTask()
|
||||||
|
{
|
||||||
|
r_core_task_join(Core()->core(), nullptr, task);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString R2Task::getResult()
|
||||||
|
{
|
||||||
|
return QString::fromUtf8(task->res);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *R2Task::getResultRaw()
|
||||||
|
{
|
||||||
|
return task->res;
|
||||||
|
}
|
32
src/utils/R2Task.h
Normal file
32
src/utils/R2Task.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
#ifndef R2TASK_H
|
||||||
|
#define R2TASK_H
|
||||||
|
|
||||||
|
#include "Cutter.h"
|
||||||
|
|
||||||
|
class R2Task: public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
private:
|
||||||
|
RCoreTask *task;
|
||||||
|
|
||||||
|
static void taskFinishedCallback(void *user, char *);
|
||||||
|
void taskFinished();
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit R2Task(const QString &cmd);
|
||||||
|
~R2Task();
|
||||||
|
|
||||||
|
void startTask();
|
||||||
|
void breakTask();
|
||||||
|
void joinTask();
|
||||||
|
|
||||||
|
QString getResult();
|
||||||
|
const char *getResultRaw();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void finished();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // R2TASK_H
|
Loading…
Reference in New Issue
Block a user