diff options
| author | Rusty Wagner <rusty@vector35.com> | 2016-09-15 01:55:28 -0400 |
|---|---|---|
| committer | Rusty Wagner <rusty@vector35.com> | 2016-09-15 01:55:28 -0400 |
| commit | 124cf1bc4f465a915621b7ac81af94b9a69a937a (patch) | |
| tree | 2e9319c6ac28141a26a83197a210923ef161e58c /backgroundtask.cpp | |
| parent | fb0d896cd5cc3197a8dd259a9ca53f2788ef5fdb (diff) | |
Add APIs to display busy indicator for long running plugin tasks
Diffstat (limited to 'backgroundtask.cpp')
| -rw-r--r-- | backgroundtask.cpp | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/backgroundtask.cpp b/backgroundtask.cpp new file mode 100644 index 00000000..aebf980c --- /dev/null +++ b/backgroundtask.cpp @@ -0,0 +1,75 @@ +#include "binaryninjaapi.h" + +using namespace std; +using namespace BinaryNinja; + + +BackgroundTask::BackgroundTask(BNBackgroundTask* task) +{ + m_object = task; +} + + +BackgroundTask::BackgroundTask(const string& initialText, bool canCancel) +{ + m_object = BNBeginBackgroundTask(initialText.c_str(), canCancel); +} + + +bool BackgroundTask::CanCancel() const +{ + return BNCanCancelBackgroundTask(m_object); +} + + +bool BackgroundTask::IsCancelled() const +{ + return BNIsBackgroundTaskCancelled(m_object); +} + + +bool BackgroundTask::IsFinished() const +{ + return BNIsBackgroundTaskFinished(m_object); +} + + +string BackgroundTask::GetProgressText() const +{ + char* text = BNGetBackgroundTaskProgressText(m_object); + string result = text; + BNFreeString(text); + return result; +} + + +void BackgroundTask::Cancel() +{ + BNCancelBackgroundTask(m_object); +} + + +void BackgroundTask::Finish() +{ + BNFinishBackgroundTask(m_object); +} + + +void BackgroundTask::SetProgressText(const string& text) +{ + BNSetBackgroundTaskProgressText(m_object, text.c_str()); +} + + +vector<Ref<BackgroundTask>> BackgroundTask::GetRunningTasks() +{ + size_t count; + BNBackgroundTask** tasks = BNGetRunningBackgroundTasks(&count); + + vector<Ref<BackgroundTask>> result; + for (size_t i = 0; i < count; i++) + result.push_back(new BackgroundTask(BNNewBackgroundTaskReference(tasks[i]))); + + BNFreeBackgroundTaskList(tasks, count); + return result; +} |
