#pragma once #include #include #include #include #include #include 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 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 successors; /** Vector of predecessors. **/ std::vector 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 userData; std::shared_ptr 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& getPredecessors() const noexcept { return predecessors; } std::vector& 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& getSuccessors() const noexcept { return successors; } std::vector& 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; dirtyStateFlag = false; } 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 getUserData() { return userData; } void setUserData(std::shared_ptr data) { userData = data; } void setSchedulingDecision(std::shared_ptr sd = std::shared_ptr()) noexcept { if (sd) { this->schedulingDecision = sd; } else { this->schedulingDecision.reset(); } } virtual void executeSimMode() noexcept; template T& as() noexcept { return *static_cast(this); } template const T& as() const noexcept { return *static_cast(this); } }; } /* namespace wfs */ } /* namespace wfr */