19#include <simics/base/event.h>
20#include <simics/base/time.h>
21#include <simics/base/sim-exception.h>
47 EventInfo(
const std::string &name, event_class_flag_t flags,
55 throw std::invalid_argument {
56 "Event name cannot be empty"
60 throw std::invalid_argument {
61 "Pointer of event class pointer for event " + name + \
65 if (callback ==
nullptr) {
66 throw std::invalid_argument {
67 "Callback function for event " + name +
" is missing"
72 EventInfo(
const std::string &name, event_class_t **ev,
74 :
EventInfo(name, Sim_EC_No_Flags, ev, callback,
75 nullptr, nullptr, nullptr, nullptr) {
79 event_class_flag_t
flags_ {Sim_EC_No_Flags};
80 event_class_t **
ev_ {
nullptr};
100 throw std::invalid_argument {
101 "Device object can't be NULL"
106 throw std::invalid_argument {
107 "Event is not registered yet. Call add() from the"
116 return SIM_make_attr_nil();
125 operator event_class_t *()
const {
return ev_; }
129 return data == match_data;
134 template <
typename T>
136 static_assert(std::is_base_of<ConfObject, T>::value,
137 "T must be a descendant of ConfObject");
138 return static_cast<T *
>(
obj_);
146 event_class_t *
ev_ {
nullptr};
153template <
typename T = ConfObject>
160 bool posted(
void *match_data =
nullptr)
const override {
161 return next(match_data) >= 0.0;
164 void remove(
void *match_data =
nullptr)
const override {
171 void post(
double seconds,
void *data =
nullptr)
override {
177 "Queue not set, unable to post events");
182 if (SIM_clear_exception() != SimExc_No_Exception) {
183 SIM_LOG_ERROR(
obj_->
obj(), 0,
"%s", SIM_last_error());
187 double next(
void *match_data =
nullptr)
const override {
200template <
typename T = ConfObject>
207 bool posted(
void *match_data =
nullptr)
const override {
208 return next(match_data) >= 0;
211 void remove(
void *match_data =
nullptr)
const override {
219 void post(cycles_t cycles,
void *data =
nullptr)
override {
225 if (SIM_clear_exception() != SimExc_No_Exception) {
226 SIM_LOG_ERROR(
obj_->
obj(), 0,
"%s", SIM_last_error());
230 cycles_t
next(
void *match_data =
nullptr)
const override {
243template <
typename T = ConfObject>
250 bool posted(
void *match_data =
nullptr)
const override {
251 return next(match_data) >= 0;
254 void remove(
void *match_data =
nullptr)
const override {
261 void post(pc_step_t steps,
void *data =
nullptr)
override {
267 if (SIM_clear_exception() != SimExc_No_Exception) {
268 SIM_LOG_ERROR(
obj_->
obj(), 0,
"%s", SIM_last_error());
272 pc_step_t
next(
void *match_data =
nullptr)
const override {
struct conf_object conf_object_t
Definition: bank-issue-callbacks-interface.h:23
A class inherited by a model class to support Simics configuration.
Definition: conf-object.h:114
ConfObjectRef obj() const
Return a ConfObjectRef represents this object.
Definition: conf-object.h:134
Cycle-based event type.
Definition: event.h:202
void post(cycles_t cycles, void *data=nullptr) override
Posts the event on the associated queue of the device.
Definition: event.h:219
T * dev_
Definition: event.h:239
cycles_t next(void *match_data=nullptr) const override
Returns the cycles to the next occurrence of the event in the queue (relative to the current time)
Definition: event.h:230
bool posted(void *match_data=nullptr) const override
Returns true if the event is in the queue, and false otherwise.
Definition: event.h:207
void remove(void *match_data=nullptr) const override
Removes all events of this type with matching data from the queue.
Definition: event.h:211
T * device_ptr() const
Definition: event.h:135
const char * name() const
Definition: event.h:141
void destroy(void *data) override
Called when the event is removed from the queue without being called.
Definition: event.h:114
conf_object_t * clock_
clock_ cannot be initialized here by SIM_object_clock, since attribute queue is not set yet
Definition: event.h:149
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: event.h:115
void * set_value(attr_value_t value) override
Called to convert a configuration value into event data.
Definition: event.h:118
Event(ConfObject *obj, event_class_t *ev)
Definition: event.h:98
static int pointer_eq(void *data, void *match_data)
Definition: event.h:128
ConfObject * obj_
Definition: event.h:145
char * describe(void *data) const override
Called to generate a human-readable description of the event to be used in the print-event-queue comm...
Definition: event.h:121
event_class_t * ev_
Definition: event.h:146
Not commonly used for device model. Step-based event type.
Definition: event.h:245
void remove(void *match_data=nullptr) const override
Removes all events of this type with matching data from the queue.
Definition: event.h:254
pc_step_t next(void *match_data=nullptr) const override
Returns the steps to the next occurrence of the event in the queue (relative to the current time)
Definition: event.h:272
bool posted(void *match_data=nullptr) const override
Returns true if the event is in the queue, and false otherwise.
Definition: event.h:250
void post(pc_step_t steps, void *data=nullptr) override
Posts the event on the associated queue of the device.
Definition: event.h:261
T * dev_
Definition: event.h:281
Time-based event type.
Definition: event.h:155
void post(double seconds, void *data=nullptr) override
Posts the event on the associated queue of the device.
Definition: event.h:171
T * dev_
Definition: event.h:196
double next(void *match_data=nullptr) const override
Returns the time to the next occurrence of the event in the queue (relative to the current time)
Definition: event.h:187
bool posted(void *match_data=nullptr) const override
Returns true if the event is in the queue, and false otherwise.
Definition: event.h:160
void remove(void *match_data=nullptr) const override
Removes all events of this type with matching data from the queue.
Definition: event.h:164
Definition: event-interface.h:61
An event is required to implement the interface.
Definition: event-interface.h:29
Definition: event-interface.h:75
Definition: event-interface.h:47
Definition: attr-value.h:23
std::add_pointer_t< char *(conf_object_t *obj, void *data)> ev_describe
Definition: event.h:40
ev_callback ev_destroy
Definition: event.h:34
std::add_pointer_t< void *(conf_object_t *obj, attr_value_t value)> ev_value_setter
Definition: event.h:38
std::add_pointer_t< attr_value_t(conf_object_t *obj, void *data)> ev_value_getter
Definition: event.h:36
std::add_pointer_t< void(conf_object_t *, void *)> ev_callback
Definition: event.h:33
EventInfo(const std::string &name, event_class_flag_t flags, event_class_t **ev, ev_callback callback, ev_destroy destroy, ev_value_getter get_value, ev_value_setter set_value, ev_describe describe)
Definition: event.h:47
ev_describe describe_
Definition: event.h:85
EventInfo(const std::string &name, event_class_t **ev, ev_callback callback)
Definition: event.h:72
event_class_t ** ev_
Definition: event.h:80
ev_destroy destroy_
Definition: event.h:82
ev_value_setter set_value_
Definition: event.h:84
ev_callback callback_
Definition: event.h:81
std::string name_
Definition: event.h:78
ev_value_getter get_value_
Definition: event.h:83
event_class_flag_t flags_
Definition: event.h:79