yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::editor::BackgroundCommandTask Class Reference

#include <background_command_task.h>

Classes

struct  Snapshot
 

Public Member Functions

 BackgroundCommandTask ()=default
 
 ~BackgroundCommandTask ()
 
 BackgroundCommandTask (const BackgroundCommandTask &)=delete
 
BackgroundCommandTaskoperator= (const BackgroundCommandTask &)=delete
 
absl::Status Start (const std::string &command, const std::string &directory)
 
void Cancel ()
 
Snapshot GetSnapshot () const
 
absl::Status Wait ()
 

Private Member Functions

void WorkerMain (std::string command, std::string directory)
 
void AppendOutput (const char *data, size_t size)
 
void Finalize (absl::Status status, int exit_code)
 
void JoinIfNeeded ()
 

Static Private Member Functions

static std::string ComputeOutputTail (const std::string &output)
 

Private Attributes

std::mutex mutex_
 
std::thread worker_
 
bool started_ = false
 
bool running_ = false
 
bool finished_ = false
 
bool cancel_requested_ = false
 
int exit_code_ = -1
 
int child_pid_ = -1
 
std::string command_
 
std::string directory_
 
std::string output_
 
std::string output_tail_
 
absl::Status status_ = absl::UnknownError("Task not started")
 

Detailed Description

Definition at line 12 of file background_command_task.h.

Constructor & Destructor Documentation

◆ BackgroundCommandTask() [1/2]

yaze::editor::BackgroundCommandTask::BackgroundCommandTask ( )
default

◆ ~BackgroundCommandTask()

yaze::editor::BackgroundCommandTask::~BackgroundCommandTask ( )

Definition at line 42 of file background_command_task.cc.

References Cancel(), and JoinIfNeeded().

Here is the call graph for this function:

◆ BackgroundCommandTask() [2/2]

yaze::editor::BackgroundCommandTask::BackgroundCommandTask ( const BackgroundCommandTask & )
delete

Member Function Documentation

◆ operator=()

BackgroundCommandTask & yaze::editor::BackgroundCommandTask::operator= ( const BackgroundCommandTask & )
delete

◆ Start()

absl::Status yaze::editor::BackgroundCommandTask::Start ( const std::string & command,
const std::string & directory )

◆ Cancel()

void yaze::editor::BackgroundCommandTask::Cancel ( )

Definition at line 76 of file background_command_task.cc.

References cancel_requested_, child_pid_, and mutex_.

Referenced by ~BackgroundCommandTask().

◆ GetSnapshot()

BackgroundCommandTask::Snapshot yaze::editor::BackgroundCommandTask::GetSnapshot ( ) const

◆ Wait()

absl::Status yaze::editor::BackgroundCommandTask::Wait ( )

Definition at line 108 of file background_command_task.cc.

References JoinIfNeeded(), mutex_, and status_.

Referenced by yaze::editor::EditorManager::RunProjectBuildCommand().

Here is the call graph for this function:

◆ WorkerMain()

void yaze::editor::BackgroundCommandTask::WorkerMain ( std::string command,
std::string directory )
private

Definition at line 114 of file background_command_task.cc.

References AppendOutput(), cancel_requested_, child_pid_, Finalize(), and mutex_.

Referenced by Start().

Here is the call graph for this function:

◆ AppendOutput()

void yaze::editor::BackgroundCommandTask::AppendOutput ( const char * data,
size_t size )
private

Definition at line 234 of file background_command_task.cc.

References ComputeOutputTail(), mutex_, output_, and output_tail_.

Referenced by WorkerMain().

Here is the call graph for this function:

◆ Finalize()

void yaze::editor::BackgroundCommandTask::Finalize ( absl::Status status,
int exit_code )
private

Definition at line 240 of file background_command_task.cc.

References ComputeOutputTail(), exit_code_, finished_, mutex_, output_, output_tail_, running_, and status_.

Referenced by WorkerMain().

Here is the call graph for this function:

◆ JoinIfNeeded()

void yaze::editor::BackgroundCommandTask::JoinIfNeeded ( )
private

Definition at line 249 of file background_command_task.cc.

References worker_.

Referenced by Start(), Wait(), and ~BackgroundCommandTask().

◆ ComputeOutputTail()

std::string yaze::editor::BackgroundCommandTask::ComputeOutputTail ( const std::string & output)
staticprivate

Definition at line 255 of file background_command_task.cc.

Referenced by AppendOutput(), and Finalize().

Member Data Documentation

◆ mutex_

std::mutex yaze::editor::BackgroundCommandTask::mutex_
mutableprivate

◆ worker_

std::thread yaze::editor::BackgroundCommandTask::worker_
private

Definition at line 48 of file background_command_task.h.

Referenced by JoinIfNeeded(), and Start().

◆ started_

bool yaze::editor::BackgroundCommandTask::started_ = false
private

Definition at line 49 of file background_command_task.h.

Referenced by GetSnapshot(), and Start().

◆ running_

bool yaze::editor::BackgroundCommandTask::running_ = false
private

Definition at line 50 of file background_command_task.h.

Referenced by Finalize(), GetSnapshot(), and Start().

◆ finished_

bool yaze::editor::BackgroundCommandTask::finished_ = false
private

Definition at line 51 of file background_command_task.h.

Referenced by Finalize(), GetSnapshot(), and Start().

◆ cancel_requested_

bool yaze::editor::BackgroundCommandTask::cancel_requested_ = false
private

Definition at line 52 of file background_command_task.h.

Referenced by Cancel(), GetSnapshot(), Start(), and WorkerMain().

◆ exit_code_

int yaze::editor::BackgroundCommandTask::exit_code_ = -1
private

Definition at line 53 of file background_command_task.h.

Referenced by Finalize(), GetSnapshot(), and Start().

◆ child_pid_

int yaze::editor::BackgroundCommandTask::child_pid_ = -1
private

Definition at line 54 of file background_command_task.h.

Referenced by Cancel(), Start(), and WorkerMain().

◆ command_

std::string yaze::editor::BackgroundCommandTask::command_
private

Definition at line 55 of file background_command_task.h.

Referenced by GetSnapshot(), and Start().

◆ directory_

std::string yaze::editor::BackgroundCommandTask::directory_
private

Definition at line 56 of file background_command_task.h.

Referenced by GetSnapshot(), and Start().

◆ output_

std::string yaze::editor::BackgroundCommandTask::output_
private

Definition at line 57 of file background_command_task.h.

Referenced by AppendOutput(), Finalize(), GetSnapshot(), and Start().

◆ output_tail_

std::string yaze::editor::BackgroundCommandTask::output_tail_
private

Definition at line 58 of file background_command_task.h.

Referenced by AppendOutput(), Finalize(), GetSnapshot(), and Start().

◆ status_

absl::Status yaze::editor::BackgroundCommandTask::status_ = absl::UnknownError("Task not started")
private

Definition at line 59 of file background_command_task.h.

Referenced by Finalize(), GetSnapshot(), Start(), and Wait().


The documentation for this class was generated from the following files: