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
 
BackgroundCommandTask & operator= (const BackgroundCommandTask &)=delete
 
absl::Status Start (const std::string &command, const std::string &directory, const std::map< std::string, std::string > &environment={})
 
void Cancel ()
 
Snapshot GetSnapshot () const
 
absl::Status Wait ()
 

Private Member Functions

void WorkerMain (std::string command, std::string directory, std::vector< std::string > environment)
 
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 14 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 187 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,
const std::map< std::string, std::string > & environment = {} )

◆ Cancel()

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

Definition at line 240 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 272 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,
std::vector< std::string > environment )
private

Definition at line 278 of file background_command_task.cc.

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

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 764 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 770 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 779 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 785 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 59 of file background_command_task.h.

Referenced by JoinIfNeeded(), and Start().

◆ started_

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

Definition at line 60 of file background_command_task.h.

Referenced by GetSnapshot(), and Start().

◆ running_

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

Definition at line 61 of file background_command_task.h.

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

◆ finished_

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

Definition at line 62 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 63 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 64 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 65 of file background_command_task.h.

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

◆ command_

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

Definition at line 66 of file background_command_task.h.

Referenced by GetSnapshot(), and Start().

◆ directory_

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

Definition at line 67 of file background_command_task.h.

Referenced by GetSnapshot(), and Start().

◆ output_

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

Definition at line 68 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 69 of file background_command_task.h.

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

◆ status_

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

Definition at line 70 of file background_command_task.h.

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


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