Pakman
AbstractWorkerHandler Class Referenceabstract

#include <AbstractWorkerHandler.h>

Inheritance diagram for AbstractWorkerHandler:
Collaboration diagram for AbstractWorkerHandler:

Public Member Functions

 AbstractWorkerHandler (const Command &simulator, const std::string &input_string)
 
virtual ~AbstractWorkerHandler ()=default
 
virtual bool isDone ()=0
 
std::string getOutput ()
 
int getErrorCode ()
 

Protected Attributes

const Command m_simulator
 
const std::string m_input_string
 
std::string m_output_buffer
 
int m_error_code = -1
 

Detailed Description

An abstract class for representing Workers.

Workers are instantiations of the simulator user executable. Since they can be implemented as forked processes or MPI processes, this abstract class was made to provide an interface to both types.

When an AbstractWorkerHandler is constructed, the simulation is initiated immediately. Hence, there are no member functions to start the simulation, only functions to check whether the simulation has finished (isDone()) and to obtain the results (getOutput() and getErrorCode()).

The destructor of a WorkerHandler ensures that the simulation is terminated, but the Worker process may persist, as in the case of MPIWorkerHandler.

Definition at line 23 of file AbstractWorkerHandler.h.

Constructor & Destructor Documentation

◆ AbstractWorkerHandler()

AbstractWorkerHandler::AbstractWorkerHandler ( const Command simulator,
const std::string &  input_string 
)

Construct from simulator string and input string.

Parameters
simulatorcommand to run simulation.
input_stringinput string to simulator.

Definition at line 7 of file AbstractWorkerHandler.cc.

◆ ~AbstractWorkerHandler()

virtual AbstractWorkerHandler::~AbstractWorkerHandler ( )
virtualdefault

Default destructor does nothing.

Member Function Documentation

◆ getErrorCode()

int AbstractWorkerHandler::getErrorCode ( )
Returns
error code of finished Worker.
Warning
Calling this function before Worker is finished will result in an error, so always check with isDone() first.

Definition at line 22 of file AbstractWorkerHandler.cc.

◆ getOutput()

std::string AbstractWorkerHandler::getOutput ( )
Returns
output of finished Worker.
Warning
Calling this function before Worker is finished will result in an error, so always check with isDone() first.

Definition at line 15 of file AbstractWorkerHandler.cc.

◆ isDone()

virtual bool AbstractWorkerHandler::isDone ( )
pure virtual
Returns
whether Worker has finished.

Implemented in MPIWorkerHandler, and ForkedWorkerHandler.

Member Data Documentation

◆ m_error_code

int AbstractWorkerHandler::m_error_code = -1
protected

Error code received from simulator.

Definition at line 68 of file AbstractWorkerHandler.h.

◆ m_input_string

const std::string AbstractWorkerHandler::m_input_string
protected

Input string to simulator.

Definition at line 62 of file AbstractWorkerHandler.h.

◆ m_output_buffer

std::string AbstractWorkerHandler::m_output_buffer
protected

Buffer to contain simulator output.

Definition at line 65 of file AbstractWorkerHandler.h.

◆ m_simulator

const Command AbstractWorkerHandler::m_simulator
protected

Command to run simulation.

Definition at line 59 of file AbstractWorkerHandler.h.


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