16#ifndef SIMICS_CONNECT_H
17#define SIMICS_CONNECT_H
19#include <simics/base/log.h>
59 return optional_ifaces_.find(iface_name) \
60 != optional_ifaces_.end();
63 template<
typename FirstIface,
typename... RestIfaces>
66 config.mark_optional<FirstIface, RestIfaces...>();
72 void mark_optional() {
73 optional_ifaces_.insert(
typename T::Info().name());
77 template<
typename FirstIface,
typename... RestIfaces>
78 typename std::enable_if<
sizeof...(RestIfaces) != 0,
void>::type
80 optional_ifaces_.insert(
typename FirstIface::Info().name());
81 mark_optional<RestIfaces...>();
84 std::set<std::string> optional_ifaces_;
97template<
typename FirstIface,
typename... RestIfaces>
100 typedef std::tuple<
typename FirstIface::ToC,
107 : device_(
device), config_(config) {}
122 set_ifaces<FirstIface, RestIfaces...>(o);
125 SIM_LOG_INFO(1, device_, 0,
"%s", e.
what());
127 SIM_LOG_INFO(1, SIM_get_object(
"sim"), 0,
"%s", e.
what());
145 typename std::enable_if<
sizeof...(RestIfaces) != 0,
146 const typename T::ToC>::type
148 return std::get<typename T::ToC>(ifaces_);
151 const typename FirstIface::ToC &
iface()
const {
152 return std::get<typename FirstIface::ToC>(ifaces_);
158 if (device_ ==
nullptr) {
159 SIM_LOG_ERROR(SIM_get_object(
"sim"), 0,
160 "Device is not set, should be set from the CTOR");
167 const typename T::ctype *interface_(
const ConfObjectRef &o)
const {
168 std::string iface_name =
typename T::Info().name();
169 auto iface =
static_cast<const typename T::ctype *
>(
173 "Interface " + iface_name +
" not found in " + o.
name()
180 void set_ifaces(
const ConfObjectRef &o) {
181 std::get<typename T::ToC>(ifaces_) = \
182 typename T::ToC(o.object(), interface_<T>(o));
186 template<
typename First,
typename... Rest>
187 typename std::enable_if<
sizeof...(Rest) != 0,
void>::type
188 set_ifaces(
const ConfObjectRef &o) {
189 std::get<typename First::ToC>(ifaces_) = \
190 typename First::ToC(o.object(), interface_<First>(o));
191 set_ifaces<Rest...>(o);
196 ConnectConfig config_;
struct conf_object conf_object_t
Definition: bank-issue-callbacks-interface.h:23
Represents Simics C type conf_object_t.
Definition: conf-object.h:37
conf_object_t * object() const
Get a pointer to the configuration object represented by this ConfObjectRef.
Definition: conf-object.h:57
const interface_t * get_interface(const std::string &name) const
Return an interface implemented by the underlying configuration object.
const std::string & name() const
Get the name of the underlying configuration object.
A virtual base class for Simics C++ interface connect class.
Definition: connect.h:34
ConfObjectRef get() const
Definition: connect.h:40
virtual ~ConnectBase()=default
ConfObjectRef obj_
Definition: connect.h:44
ConnectBase()
Definition: connect.h:36
virtual bool set(const ConfObjectRef &o)=0
By default, all interfaces in the Connect class are required.
Definition: connect.h:54
static ConnectConfig optional()
Definition: connect.h:64
bool is_optional(const std::string &iface_name) const
Definition: connect.h:58
A class for connecting with another Simics object.
Definition: connect.h:98
conf_object_t * device() const
Return the device object which can be used for logging purpose.
Definition: connect.h:157
Connect(const ConnectConfig &config)
Definition: connect.h:103
Connect(const ConfObjectRef &device, const ConnectConfig &config)
Definition: connect.h:106
std::enable_if< sizeof...(RestIfaces)!=0, consttypenameT::ToC >::type iface() const
Return the Simics C++ interface struct implemented on obj_.
Definition: connect.h:147
std::tuple< typename FirstIface::ToC, typename RestIfaces::ToC... > ifaces_type
Definition: connect.h:101
const FirstIface::ToC & iface() const
Definition: connect.h:151
bool set(const ConfObjectRef &o) override
Definition: connect.h:110
Connect(const ConfObjectRef &device)
Definition: connect.h:105
Definition: attribute-exceptions.h:25
const char * what() const noexcept override
Definition: attribute-exceptions.h:30
Definition: attr-value.h:23