C++ Device API Reference Manual
Reference documentation for the Simics C++ Device API.
 
Loading...
Searching...
No Matches
event-helper.h
Go to the documentation of this file.
1// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2023 Intel Corporation
5
6 This software and the related documents are Intel copyrighted materials, and
7 your use of them is governed by the express license under which they were
8 provided to you ("License"). Unless the License provides otherwise, you may
9 not use, modify, copy, publish, distribute, disclose or transmit this software
10 or the related documents without Intel's prior written permission.
11
12 This software and the related documents are provided as is, with no express or
13 implied warranties, other than those that are expressly stated in the License.
14*/
15
16#ifndef SIMICS_DETAIL_EVENT_HELPER_H
17#define SIMICS_DETAIL_EVENT_HELPER_H
18
19#include <simics/base/event.h> // event_class_t
20
21#include "simics/conf-object.h" // from_obj
22
23namespace simics {
24namespace detail {
25
26template <typename T, typename O> struct event_helper;
27
28#define EVENT_HELPER(cls, m, f) \
29 simics::detail::event_helper<decltype(&cls::m), cls>::template f<&cls::m>
30
31#define EVENT_CALLBACK(cls, m) \
32 simics::detail::event_helper<decltype(&cls::m), cls>::event_class_ptr(), \
33 EVENT_HELPER(cls, m, callback)
34
35#define EVENT_CLS_VAR(cls, m) \
36 EVENT_CALLBACK(cls, m), EVENT_HELPER(cls, m, destroy), \
37 EVENT_HELPER(cls, m, get_value), EVENT_HELPER(cls, m, set_value), \
38 EVENT_HELPER(cls, m, describe)
39
40template <typename T, typename O, typename C>
41struct event_helper<T O::*, C> {
42 template <T O::*R>
43 static void callback(conf_object_t *obj, void *data) {
44 (simics::from_obj<C>(obj)->*R).callback(data);
45 }
46
47 template <T O::*R>
48 static void destroy(conf_object_t *obj, void *data) {
49 (simics::from_obj<C>(obj)->*R).destroy(data);
50 }
51
52 template <T O::*R>
53 static attr_value_t get_value(conf_object_t *obj, void *data) {
54 return (simics::from_obj<C>(obj)->*R).get_value(data);
55 }
56
57 template <T O::*R>
58 static void *set_value(conf_object_t *obj, attr_value_t value) {
59 return (simics::from_obj<C>(obj)->*R).set_value(value);
60 }
61
62 template <T O::*R>
63 static char *describe(conf_object_t *obj, void *data) {
64 return (simics::from_obj<C>(obj)->*R).describe(data);
65 }
66
67 // SFINAE: return &T::event_cls if available, otherwise nullptr
68 template <typename U>
69 static auto event_class_ptr_impl(int) -> decltype(&U::event_cls) {
70 return &U::event_cls;
71 }
72 template <typename U>
73 static event_class_t **event_class_ptr_impl(...) {
74 return nullptr;
75 }
76 static event_class_t **event_class_ptr() {
77 return event_class_ptr_impl<T>(0);
78 }
79};
80
81} // namespace detail
82} // namespace simics
83
84#endif
Definition: after-bank.h:33
static attr_value_t get_value(conf_object_t *obj, void *data)
Definition: event-helper.h:53
static void * set_value(conf_object_t *obj, attr_value_t value)
Definition: event-helper.h:58
static event_class_t ** event_class_ptr()
Definition: event-helper.h:76
static char * describe(conf_object_t *obj, void *data)
Definition: event-helper.h:63
static void callback(conf_object_t *obj, void *data)
Definition: event-helper.h:43
static event_class_t ** event_class_ptr_impl(...)
Definition: event-helper.h:73
static auto event_class_ptr_impl(int) -> decltype(&U::event_cls)
Definition: event-helper.h:69
static void destroy(conf_object_t *obj, void *data)
Definition: event-helper.h:48
Definition: event-helper.h:26