23#include <unordered_set>
45 static std::unordered_set<AfterCallInterface*> &getIfaces();
50template<
typename... Args>
59 std::string
name()
const override {
63 void set_args(
const attr_value_t &value)
override {
78 void invoke()
override {
79 invoke_impl(std::index_sequence_for<Args...>{});
83 template<std::size_t... I>
84 void invoke_impl(std::index_sequence<I...>) {
85 func_(std::get<I>(args_)...);
90 std::tuple<Args...> args_;
96template<
typename Class,
typename... Args>
102 : func_(func), name_(
name + typeid(func).
name()),
105 std::string
name()
const override {
113 void set_args(
const attr_value_t &value)
override {
115 obj_ = std::get<0>(t);
116 set_args_impl(t, std::index_sequence_for<Args...>{});
125 auto rest = std::tuple_cat(std::make_tuple(obj_), args_);
130 void invoke()
override {
132 throw std::invalid_argument {
133 "Cannot call class member function without class instance"
136 invoke_impl(std::index_sequence_for<Args...>{});
140 template<std::size_t... I>
141 void invoke_impl(std::index_sequence<I...>) {
142 (from_obj<Class>(obj_)->*func_)(std::get<I>(args_)...);
146 template <std::size_t... Is>
147 void set_args_impl(
const std::tuple<ConfObjectRef, Args...> &input_tuple,
148 std::index_sequence<Is...>) {
149 args_ = std::make_tuple(std::get<Is + 1>(input_tuple)...);
155 std::tuple<Args...> args_;
158template<
typename... Args>
162class RegisterInterface;
164template<
typename Class,
typename... Args>
166 static_assert(std::is_base_of<ConfObject, Class>::value
167 || std::is_base_of<BankInterface, Class>::value
168 || std::is_base_of<RegisterInterface, Class>::value
169 || std::is_base_of<FieldInterface, Class>::value,
170 "Only class derived of ConfObject/BankInterface/"
171 "RegisterInterface/FieldInterface supports the after call");
175template<
typename... Args>
177 const std::string &name) {
182template<
typename Class,
typename... Args>
184 const std::string &name) {
198 void post(
double seconds,
void *data =
nullptr);
199 void post(cycles_t cycles,
void *data =
nullptr);
202 void checkSetValueFormat(
const attr_value_t &value);
224 void schedule(
double seconds,
const std::string &name,
225 const attr_value_t &args)
override {
226 auto *iface = get_iface(name);
228 iface->set_args(args);
232 void schedule(cycles_t cycles,
const std::string &name,
233 const attr_value_t &args)
override {
234 auto *iface = get_iface(name);
236 iface->set_args(args);
254 if (iface ==
nullptr) {
257 std::string(
"After call (" + name +
") needs to be "
258 "registered by REGISTER_AFTER_CALL or "
259 "REGISTER_REG_BANK_AFTER_CALL first"));
262 return iface->make_copy();
271#define FUNC_AND_NAME(f) f, #f
273#define REGISTER_AFTER_CALL(f) \
274 simics::AfterCall::addIface(simics::make_function_call(FUNC_AND_NAME(f)));
276#define AFTER_CALL(dev, t, f, ...) { \
277 simics::check_function_call(f); \
278 auto *iface = dynamic_cast<simics::AfterInterface *>(dev); \
279 if (iface == nullptr) { \
280 std::cerr << "The first argument to the AFTER_CALL does " \
281 << "not implement AfterInterface*" \
284 iface->schedule(t, std::string(#f) + typeid(f).name(), \
285 simics::AttrValue(simics::std_to_attr( \
286 std::forward_as_tuple(__VA_ARGS__)))); \
Definition: after-interface.h:27
static void removeIface(AfterCallInterface *iface)
static void addIface(AfterCallInterface *iface)
static AfterCallInterface * findIface(const std::string &name)
void callback(void *data) override
Called when the event expires.
void remove(void *=nullptr) const
void post(double seconds, void *data=nullptr)
void post(cycles_t cycles, void *data=nullptr)
void * set_value(attr_value_t value) override
Called to convert a configuration value into event data.
attr_value_t get_value(void *data) override
Called to convert the event data into a value that can be saved in a configuration.
Definition: after-interface.h:44
Represents Simics C type conf_object_t.
Definition: conf-object.h:38
Base class for all Simics configuration objects.
Definition: conf-object.h:126
ConfObjectRef obj() const
Return a ConfObjectRef represents this object.
Definition: conf-object.h:137
void schedule(cycles_t cycles, const std::string &name, const attr_value_t &args) override
Definition: after.h:232
ConfObject * obj_
Definition: after.h:247
AfterEvent after_event
Definition: after.h:248
static event_class_t * event_cls
Definition: after.h:244
void cancel_all() override
Definition: after.h:240
void schedule(double seconds, const std::string &name, const attr_value_t &args) override
Definition: after.h:224
static EventInfo afterEventInfo(const std::string &name="after_event")
Definition: after.h:212
EnableAfterCall(ConfObject *obj)
Definition: after.h:208
The Event class allows users to define callbacks that will be executed after a specified delay.
Definition: event.h:79
Event(ConfObject *obj, event_class_t *ev)
FunctionCall(FunctionType func, const std::string &name)
Definition: after.h:55
void(*)(Args...) FunctionType
Definition: after.h:53
std::string name() const override
Definition: after.h:59
AfterCallInterface * make_copy() override
Definition: after.h:67
attr_value_t get_value() override
Definition: after.h:72
void set_args(const attr_value_t &value) override
Definition: after.h:63
void(Class::*)(Args...) MemberFunctionType
Definition: after.h:99
AfterCallInterface * make_copy() override
Definition: after.h:119
attr_value_t get_value() override
Definition: after.h:124
std::string name() const override
Definition: after.h:105
MemberFunctionCall(MemberFunctionType func, const std::string &name)
Definition: after.h:101
void set_args(const attr_value_t &value) override
Definition: after.h:113
#define EVENT_HELPER(cls, m, f)
Definition: event-helper.h:28
#define SIM_LOG_ERROR_STR(obj, group, str)
Definition: log.h:39
Definition: after-bank.h:33
std::enable_if< std::is_enum< T >::value, attr_value_t >::type std_to_attr(const T &src)
Function transforms C++ enum type T to Simics attr_value_t.
Definition: attribute-traits.h:163
std::enable_if< std::is_enum< T >::value, T >::type attr_to_std(attr_value_t src)
Function transforms Simics attr_value_t to C++ enum type.
Definition: attribute-traits.h:207
constexpr auto make_function_call(void(*func)(Args...), const std::string &name)
Definition: after.h:176
constexpr void check_function_call(void(*func)(Args...))
Definition: after.h:159