283 lines
6.9 KiB
C++
Executable File
283 lines
6.9 KiB
C++
Executable File
|
|
#pragma once
|
|
|
|
|
|
#include <wfr/common/types/WfsTypes.h>
|
|
#include <wfr/common/types/LwdTypes.h>
|
|
#include <wfr/common/exceptions/exceptions.h>
|
|
#include <atomic>
|
|
#include <vector>
|
|
#include <memory>
|
|
|
|
namespace wfr {
|
|
|
|
// Forward declarations
|
|
namespace scheduling { class SchedulingDecision; }
|
|
namespace enactment { class WepBuilder; }
|
|
|
|
namespace wfs {
|
|
|
|
// Forward declarations
|
|
class Activity;
|
|
|
|
|
|
class ActivityInstance {
|
|
friend class enactment::WepBuilder;
|
|
|
|
// Static non-public properties
|
|
private:
|
|
/**
|
|
* Static variable holding the next free activity instanceID.
|
|
**/
|
|
static std::atomic<wfr_id_t> nextInstanceID;
|
|
|
|
/**
|
|
* Returns the next free activity instanceID.
|
|
*
|
|
* @return next free activity instanceID.
|
|
*/
|
|
static wfr_id_t getNextInstanceID();
|
|
|
|
// Mutable properties that need to be accessed via getter-/setter-functions.
|
|
protected:
|
|
/** Activity instance state. **/
|
|
ActivityInstanceStatus status;
|
|
|
|
/** Reference to the parent of this activity instance object (structure-wise). **/
|
|
ActivityInstance* parentActivity = nullptr;
|
|
|
|
/** Vector of successors. **/
|
|
std::vector<ActivityInstance*> successors;
|
|
|
|
/** Vector of predecessors. **/
|
|
std::vector<ActivityInstance*> predecessors;
|
|
|
|
/** Reference to input data struct. **/
|
|
lwd::_wfr_lwd *inputData = nullptr;
|
|
bool inputDataOwnership = false;
|
|
|
|
/** Reference to output data struct. **/
|
|
lwd::_wfr_lwd *outputData = nullptr;
|
|
bool outputDataOwnership = false;
|
|
|
|
bool allInputsAvailable = false;
|
|
|
|
bool allOutputsAvailable = false;
|
|
|
|
std::exception_ptr errorCause;
|
|
|
|
wfr::wfr_timestamp_sc_t readyTime;
|
|
|
|
wfr::wfr_timestamp_sc_t startTime;
|
|
|
|
wfr::wfr_timestamp_sc_t endTime;
|
|
|
|
uint64_t visitationCount = 0;
|
|
|
|
bool dirtyStateFlag = false;
|
|
|
|
std::shared_ptr<void> userData;
|
|
|
|
std::shared_ptr<scheduling::SchedulingDecision> schedulingDecision;
|
|
|
|
// Invariant properties that can be accessed directly.
|
|
public:
|
|
/** Unique ID of this activity instance object. **/
|
|
const wfr_id_t instanceID;
|
|
|
|
/** Activity this object is an instance of. **/
|
|
const Activity& baseActivity;
|
|
|
|
const wfr_id_t iterationID;
|
|
|
|
// Public functions
|
|
public:
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* @param parentActivity activity this object is an instance of.
|
|
*/
|
|
ActivityInstance(Activity& baseActivity, const wfr_id_t& iterationID = 0) noexcept;
|
|
|
|
/** Destructor. **/
|
|
virtual ~ActivityInstance() noexcept {
|
|
if (inputData && inputDataOwnership) {
|
|
delete inputData;
|
|
inputData = nullptr;
|
|
}
|
|
if (outputData && outputDataOwnership) {
|
|
delete outputData;
|
|
outputData = nullptr;
|
|
}
|
|
}
|
|
|
|
ActivityType activityType() const noexcept;
|
|
|
|
bool isCompositeActivity() const noexcept;
|
|
|
|
bool isLoop() const noexcept;
|
|
|
|
bool isConditional() const noexcept;
|
|
|
|
/**
|
|
* Returns the state of this activity instance.
|
|
*
|
|
* @return state of this activity instance.
|
|
**/
|
|
ActivityInstanceStatus getInstanceStatus() const noexcept { return status; }
|
|
|
|
/**
|
|
* Sets the state of this activity instance.
|
|
*
|
|
* @param status new state.
|
|
**/
|
|
void setInstanceStatus(const ActivityInstanceStatus& status);
|
|
|
|
/**
|
|
*
|
|
* Returns a reference to this activity instance input data.
|
|
*
|
|
* @return input data.
|
|
**/
|
|
lwd::_wfr_lwd* const getInputData() const noexcept { return inputData; }
|
|
|
|
/**
|
|
* Sets this instants input data.
|
|
*
|
|
* @param data input data.
|
|
*/
|
|
void setInputData(lwd::_wfr_lwd* data, bool ownership = true) noexcept {
|
|
inputData = data;
|
|
inputDataOwnership = ownership;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* Returns a reference to this activity instance output data.
|
|
*
|
|
* @return output data.
|
|
**/
|
|
lwd::_wfr_lwd* const getOutputData() const noexcept { return outputData; }
|
|
|
|
/**
|
|
* Sets this instants output data.
|
|
*
|
|
* @param data output data.
|
|
*/
|
|
void setOutputData(lwd::_wfr_lwd* data, bool ownership = true) noexcept {
|
|
outputData = data;
|
|
outputDataOwnership = ownership;
|
|
}
|
|
|
|
/**
|
|
* Returns the number of predecessors.
|
|
*
|
|
* @return number of predecessors.
|
|
**/
|
|
wfr_size_t getPredecessorCount() const noexcept { return predecessors.size(); }
|
|
|
|
const std::vector<ActivityInstance*>& getPredecessors() const noexcept { return predecessors; }
|
|
|
|
std::vector<ActivityInstance*>& getPredecessors() noexcept { return predecessors; }
|
|
|
|
ActivityInstance* const getPredecessor(wfr_size_t index) const noexcept {
|
|
return predecessors.at(index);
|
|
}
|
|
|
|
/**
|
|
* Returns the number of successors.
|
|
*
|
|
* @return number of successors.
|
|
**/
|
|
wfr_size_t getSuccessorCount() const noexcept { return successors.size(); }
|
|
|
|
const std::vector<ActivityInstance*>& getSuccessors() const noexcept { return successors; }
|
|
|
|
std::vector<ActivityInstance*>& getSuccessors() noexcept { return successors; }
|
|
|
|
ActivityInstance* const getSuccessor(int index) const noexcept {
|
|
return successors.at(index);
|
|
}
|
|
|
|
/**
|
|
* Returns the parent of this instance (structure-wise).
|
|
*
|
|
* @return parent of this instance.
|
|
**/
|
|
ActivityInstance* const getParentActivity() const noexcept { return parentActivity; }
|
|
|
|
/**
|
|
* Sets the parent of this instance (structure-wise).
|
|
*
|
|
* parent parent of this instance.
|
|
**/
|
|
void setParentActivity(ActivityInstance* parent) noexcept { this->parentActivity = parent; }
|
|
|
|
|
|
bool areAllInputsAvailable() const noexcept { return allInputsAvailable; }
|
|
|
|
void setAllInputsAvailable(const bool& areAvailable = true) noexcept { allInputsAvailable = areAvailable; }
|
|
|
|
bool areAllOutputsAvailable() const noexcept { return allOutputsAvailable; }
|
|
|
|
void setAllOutputsAvailable(const bool& areAvailable = true) noexcept { allOutputsAvailable = areAvailable; }
|
|
|
|
|
|
std::exception_ptr getErrorCause() const noexcept { return errorCause; }
|
|
|
|
void setErrorState(std::exception_ptr exception = nullptr)noexcept;
|
|
|
|
|
|
const wfr::wfr_timestamp_sc_t& getReadyTime() const noexcept { return readyTime; }
|
|
|
|
const wfr::wfr_timestamp_sc_t& getStartTime() const noexcept { return startTime; }
|
|
|
|
const wfr::wfr_timestamp_sc_t& getEndTime() const noexcept { return endTime; }
|
|
|
|
|
|
uint64_t getVisitationCount() const noexcept { return visitationCount; }
|
|
|
|
void addToVisitationCount(uint64_t val = 1) noexcept { visitationCount += val; }
|
|
|
|
|
|
void setDirtyState() { dirtyStateFlag = true; }
|
|
|
|
bool isDirtyState() const { return dirtyStateFlag; }
|
|
|
|
void resetDirtyState() { dirtyStateFlag = false; }
|
|
|
|
|
|
virtual bool executePreExecutionHooks(bool earlyEvaluation) { return false; }
|
|
|
|
virtual bool executeExecutionHook(bool earlyEvaluation) { return false; }
|
|
|
|
virtual bool executePostExecutionHooks(bool earlyEvaluation) { return false; }
|
|
|
|
std::shared_ptr<void> getUserData() { return userData; }
|
|
|
|
void setUserData(std::shared_ptr<void> data) { userData = data; }
|
|
|
|
void setSchedulingDecision(std::shared_ptr<scheduling::SchedulingDecision> sd = std::shared_ptr<scheduling::SchedulingDecision>()) noexcept {
|
|
if (sd) {
|
|
this->schedulingDecision = sd;
|
|
} else {
|
|
this->schedulingDecision.reset();
|
|
}
|
|
}
|
|
|
|
virtual void executeSimMode() noexcept;
|
|
|
|
|
|
|
|
template<class T>
|
|
T& as() noexcept { return *static_cast<T*>(this); }
|
|
|
|
template<class T>
|
|
const T& as() const noexcept { return *static_cast<const T*>(this); }
|
|
|
|
};
|
|
|
|
} /* namespace wfs */
|
|
} /* namespace wfr */
|
|
|