Sane C++ Libraries
C++ Platform Abstraction Libraries
SC::AsyncProcessExit Struct Reference

Starts monitoring a process, notifying about its termination. More...

#include <Async.h>

Inheritance diagram for SC::AsyncProcessExit:
SC::AsyncRequest

Classes

struct  CompletionData
 Completion data for AsyncProcessExit. More...
 
struct  Result
 Callback result for AsyncProcessExit. More...
 

Public Member Functions

SC::Result start (AsyncEventLoop &eventLoop, ProcessDescriptor::Handle process)
 Starts monitoring a process, notifying about its termination. More...
 
- Public Member Functions inherited from SC::AsyncRequest
void setDebugName (const char *newDebugName)
 
AsyncEventLoopgetEventLoop () const
 Get the event loop associated with this AsyncRequest. More...
 
void cacheInternalEventLoop (AsyncEventLoop &loop)
 Caches the event loop associated with this AsyncRequest. More...
 
 AsyncRequest (Type type)
 Constructs a free async request of given type. More...
 
Result stop ()
 Stops the async operation. More...
 
bool isFree () const
 

Public Attributes

Function< void(Result &)> callback
 Called when process has exited. More...
 
- Public Attributes inherited from SC::AsyncRequest
AsyncRequestnext = nullptr
 
AsyncRequestprev = nullptr
 

Friends

struct AsyncEventLoop
 

Additional Inherited Members

- Public Types inherited from SC::AsyncRequest
enum class  Type : uint8_t {
  LoopTimeout ,
  LoopWakeUp ,
  LoopWork ,
  ProcessExit ,
  SocketAccept ,
  SocketConnect ,
  SocketSend ,
  SocketReceive ,
  SocketClose ,
  FileRead ,
  FileWrite ,
  FileClose ,
  FilePoll
}
 Type of async request. More...
 
- Protected Member Functions inherited from SC::AsyncRequest
Result validateAsync ()
 
Result queueSubmission (AsyncEventLoop &eventLoop)
 
Result queueSubmission (AsyncEventLoop &eventLoop, ThreadPool &threadPool, AsyncTask &task)
 
- Protected Attributes inherited from SC::AsyncRequest
AsyncEventLoopeventLoop = nullptr
 
AsyncTaskasyncTask = nullptr
 

Detailed Description

Starts monitoring a process, notifying about its termination.

Process library can be used to start a process and obtain the native process handle.

// Assuming an already created (and running) AsyncEventLoop named eventLoop
// ...
Process process;
SC_TRY(process.launch({"executable", "--parameter"}));
ProcessDescriptor::Handle processHandle;
SC_TRY(process.handle.get(processHandle, Result::Error("Invalid Handle")));
AsyncProcessExit processExit; // Memory lifetime must be valid until callback is called
processExit.callback = [&](AsyncProcessExit::Result& res)
{
ProcessDescriptor::ExitStatus exitStatus;
if(res.get(exitStatus))
{
console.print("Process Exit status = {}", exitStatus.status);
}
};
SC_TRY(processExit.start(eventLoop, processHandle));
#define SC_TRY(expression)
Checks the value of the given expression and if failed, returns this value to caller.
Definition: Result.h:47
static constexpr Result Error(const char(&msg)[numChars])
Constructs an Error from a pointer to an ASCII string literal.
Definition: Result.h:23

Member Function Documentation

◆ start()

SC::Result SC::AsyncProcessExit::start ( AsyncEventLoop eventLoop,
ProcessDescriptor::Handle  process 
)

Starts monitoring a process, notifying about its termination.

Parameters
eventLoopThe event loop where queuing this async request
processNative handle of the process that is being monitored
Returns
Valid Result if the request has been successfully queued

Member Data Documentation

◆ callback

Function<void(Result&)> SC::AsyncProcessExit::callback

Called when process has exited.


The documentation for this struct was generated from the following file: