sim: Make SignalSinkPort::set virtual (#1679)

We are implementing derived classes of SignalSinkPort that does some
additional logic after it's triggered (set() invoked by SignalSourcePort
peer), and before executing the callback that a device provides (in
onChange_). The logic is like additional logging, or providing debugging
features. However, set() itself directly calls the onChange_ callback.

Making the set() virtual could provide the flexibility to achieve this
feature.
This commit is contained in:
handsomeliu-google
2024-10-18 20:41:05 +08:00
committed by GitHub
parent ae0cee66ed
commit 3fc6cc7763

View File

@@ -51,12 +51,11 @@ class SignalSinkPort : public Port
SignalSourcePort<State> *_source = nullptr;
State _state = {};
OnChangeFunc _onChange;
protected:
// if bypass_on_change is specified true, it will not call the _onChange
// function. Only _state will be updated if needed.
void
virtual void
set(const State &new_state, const bool bypass_on_change = false)
{
if (new_state == _state)
@@ -67,6 +66,8 @@ class SignalSinkPort : public Port
_onChange(_state);
}
OnChangeFunc _onChange;
public:
SignalSinkPort(const std::string &_name, PortID _id=InvalidPortID) :
Port(_name, _id)