AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Acore::AsyncProcessResultImplementation Class Reference
Inheritance diagram for Acore::AsyncProcessResultImplementation:
Acore::AsyncProcessResult

Public Member Functions

 AsyncProcessResultImplementation (std::string executable_, std::vector< std::string > args_, std::string logger_, std::string input_file_, bool secure)
 
 AsyncProcessResultImplementation (AsyncProcessResultImplementation const &)=delete
 
AsyncProcessResultImplementationoperator= (AsyncProcessResultImplementation const &)=delete
 
 AsyncProcessResultImplementation (AsyncProcessResultImplementation &&)=delete
 
AsyncProcessResultImplementationoperator= (AsyncProcessResultImplementation &&)=delete
 
int StartProcess ()
 
void SetFuture (std::future< int > result_)
 
std::future< int > & GetFutureResult () override
 
void Terminate () override
 Tries to terminate the process. More...
 
- Public Member Functions inherited from Acore::AsyncProcessResult
virtual ~AsyncProcessResult ()
 
virtual std::future< int > & GetFutureResult ()=0
 
virtual void Terminate ()=0
 Tries to terminate the process. More...
 

Private Attributes

std::string const executable
 
std::vector< std::string > const args
 
std::string const logger
 
std::string const input_file
 
bool const is_secure
 
std::atomic< bool > was_terminated
 
Optional< std::shared_ptr< std::future< int > > > result
 
Optional< std::reference_wrapper< child > > my_child
 

Detailed Description

Constructor & Destructor Documentation

◆ AsyncProcessResultImplementation() [1/3]

Acore::AsyncProcessResultImplementation::AsyncProcessResultImplementation ( std::string  executable_,
std::vector< std::string >  args_,
std::string  logger_,
std::string  input_file_,
bool  secure 
)
inlineexplicit
189 : executable(std::move(executable_)), args(std::move(args_)),
190 logger(std::move(logger_)), input_file(input_file_),
191 is_secure(secure), was_terminated(false) { }
std::vector< std::string > const args
Definition: StartProcess.cpp:175
std::string const input_file
Definition: StartProcess.cpp:177
bool const is_secure
Definition: StartProcess.cpp:178
std::string const logger
Definition: StartProcess.cpp:176
std::string const executable
Definition: StartProcess.cpp:174
std::atomic< bool > was_terminated
Definition: StartProcess.cpp:180

◆ AsyncProcessResultImplementation() [2/3]

Acore::AsyncProcessResultImplementation::AsyncProcessResultImplementation ( AsyncProcessResultImplementation const &  )
delete

◆ AsyncProcessResultImplementation() [3/3]

Acore::AsyncProcessResultImplementation::AsyncProcessResultImplementation ( AsyncProcessResultImplementation &&  )
delete

Member Function Documentation

◆ GetFutureResult()

std::future< int > & Acore::AsyncProcessResultImplementation::GetFutureResult ( )
inlineoverridevirtual

Returns the future which contains the result of the process as soon it is finished.

Implements Acore::AsyncProcessResult.

231 {
232 ASSERT(*result, "The process wasn't started!");
233 return **result;
234 }
#define ASSERT
Definition: Errors.h:68
Optional< std::shared_ptr< std::future< int > > > result
Definition: StartProcess.cpp:182

References ASSERT, and result.

◆ operator=() [1/2]

AsyncProcessResultImplementation & Acore::AsyncProcessResultImplementation::operator= ( AsyncProcessResultImplementation &&  )
delete

◆ operator=() [2/2]

AsyncProcessResultImplementation & Acore::AsyncProcessResultImplementation::operator= ( AsyncProcessResultImplementation const &  )
delete

◆ SetFuture()

void Acore::AsyncProcessResultImplementation::SetFuture ( std::future< int >  result_)
inline
224 {
225 result = std::make_shared<std::future<int>>(std::move(result_));
226 }

References result.

◆ StartProcess()

int Acore::AsyncProcessResultImplementation::StartProcess ( )
inline
199 {
200 ASSERT(!my_child, "Process started already!");
201
202 return CreateChildProcess([&](child& c) -> int
203 {
204 int exitCode;
205 my_child = std::reference_wrapper<child>(c);
206
207 try
208 {
209 c.wait();
210 exitCode = c.exit_code();
211 }
212 catch (...)
213 {
214 exitCode = EXIT_FAILURE;
215 }
216
217 my_child.reset();
218 return was_terminated ? EXIT_FAILURE : exitCode;
219
221 }
static int CreateChildProcess(T waiter, std::string const &executable, std::vector< std::string > const &argsVector, std::string const &logger, std::string const &input, bool secure)
Definition: StartProcess.cpp:64
Optional< std::reference_wrapper< child > > my_child
Definition: StartProcess.cpp:183

References args, ASSERT, Acore::CreateChildProcess(), executable, input_file, is_secure, logger, my_child, and was_terminated.

◆ Terminate()

void Acore::AsyncProcessResultImplementation::Terminate ( )
inlineoverridevirtual

Tries to terminate the process.

Implements Acore::AsyncProcessResult.

238 {
239 if (my_child)
240 {
241 was_terminated = true;
242 try
243 {
244 my_child->get().terminate();
245 }
246 catch (...)
247 {
248 // Do nothing
249 }
250 }
251 }

References my_child, and was_terminated.

Member Data Documentation

◆ args

std::vector<std::string> const Acore::AsyncProcessResultImplementation::args
private

Referenced by StartProcess().

◆ executable

std::string const Acore::AsyncProcessResultImplementation::executable
private

Referenced by StartProcess().

◆ input_file

std::string const Acore::AsyncProcessResultImplementation::input_file
private

Referenced by StartProcess().

◆ is_secure

bool const Acore::AsyncProcessResultImplementation::is_secure
private

Referenced by StartProcess().

◆ logger

std::string const Acore::AsyncProcessResultImplementation::logger
private

Referenced by StartProcess().

◆ my_child

Optional<std::reference_wrapper<child> > Acore::AsyncProcessResultImplementation::my_child
private

Referenced by StartProcess(), and Terminate().

◆ result

Optional<std::shared_ptr<std::future<int> > > Acore::AsyncProcessResultImplementation::result
private

Referenced by GetFutureResult(), and SetFuture().

◆ was_terminated

std::atomic<bool> Acore::AsyncProcessResultImplementation::was_terminated
private

Referenced by StartProcess(), and Terminate().