16#ifndef SIMICS_CONNECT_H
17#define SIMICS_CONNECT_H
19#include <simics/base/log.h>
61 operator conf_object_t*()
const {
return obj_.
object(); }
79 return optional_ifaces_.find(iface_name) \
80 != optional_ifaces_.end();
83 template<
typename FirstIface,
typename... RestIfaces>
86 config.mark_optional<FirstIface, RestIfaces...>();
92 void mark_optional() {
93 optional_ifaces_.insert(
typename T::Info().name());
97 template<
typename FirstIface,
typename... RestIfaces>
98 typename std::enable_if<
sizeof...(RestIfaces) != 0,
void>::type
100 optional_ifaces_.insert(
typename FirstIface::Info().name());
101 mark_optional<RestIfaces...>();
104 std::set<std::string> optional_ifaces_;
117template<
typename FirstIface,
typename... RestIfaces>
121 typename RestIfaces::ToC...>;
127 : device_(
device), config_(config) {}
142 set_ifaces<FirstIface, RestIfaces...>(o);
145 SIM_LOG_INFO(1, device_, 0,
"%s", e.
what());
147 SIM_LOG_INFO(1, SIM_get_object(
"sim"), 0,
"%s", e.
what());
165 typename std::enable_if<
sizeof...(RestIfaces) != 0,
166 const typename T::ToC>::type
168 return std::get<typename T::ToC>(ifaces_);
171 const typename FirstIface::ToC &
iface()
const {
172 return std::get<typename FirstIface::ToC>(ifaces_);
178 if (device_ ==
nullptr) {
179 SIM_LOG_ERROR(SIM_get_object(
"sim"), 0,
180 "Device is not set, should be set from the CTOR");
187 conf_object_t *
dev()
const {
193 const typename T::ctype *interface_(
const ConfObjectRef &o)
const {
194 std::string iface_name =
typename T::Info().name();
195 auto iface =
static_cast<const typename T::ctype *
>(
199 "Interface " + iface_name +
" not found in " + o.
name()
206 void set_ifaces(
const ConfObjectRef &o) {
207 std::get<typename T::ToC>(ifaces_) = \
208 typename T::ToC(o.object(), interface_<T>(o));
212 template<
typename First,
typename... Rest>
213 typename std::enable_if<
sizeof...(Rest) != 0,
void>::type
214 set_ifaces(
const ConfObjectRef &o) {
215 std::get<typename First::ToC>(ifaces_) = \
216 typename First::ToC(o.object(), interface_<First>(o));
217 set_ifaces<Rest...>(o);
221 conf_object_t *device_ {
nullptr};
222 ConnectConfig config_;
Represents Simics C type conf_object_t.
Definition: conf-object.h:38
conf_object_t * object() const
Get a pointer to the configuration object represented by this ConfObjectRef.
Definition: conf-object.h:54
std::string name() const
Get the name of the underlying configuration object.
const interface_t * get_interface(const std::string &name) const
Return an interface implemented by the underlying configuration object.
A base class for Simics C++ interface connect class.
Definition: connect.h:36
ConfObjectRef get() const
Get the connected configuration object.
Definition: connect.h:54
virtual ~ConnectBase()=default
ConfObjectRef obj_
Definition: connect.h:64
ConnectBase()
Definition: connect.h:38
virtual bool set(const ConfObjectRef &o)=0
Set the connected configuration object.
By default, all interfaces in the Connect class are required.
Definition: connect.h:74
static ConnectConfig optional()
Definition: connect.h:84
bool is_optional(const std::string &iface_name) const
Definition: connect.h:78
A class for connecting with another Simics object.
Definition: connect.h:118
conf_object_t * dev() const
Return the device object which can be used for logging purpose This is an alias for device() and foll...
Definition: connect.h:187
std::tuple< typename FirstIface::ToC, typename RestIfaces::ToC... > ifaces_type
Definition: connect.h:121
conf_object_t * device() const
Return the device object which can be used for logging purpose.
Definition: connect.h:177
Connect(const ConnectConfig &config)
Definition: connect.h:123
Connect(const ConfObjectRef &device, const ConnectConfig &config)
Definition: connect.h:126
std::enable_if< sizeof...(RestIfaces)!=0, consttypenameT::ToC >::type iface() const
Return the Simics C++ interface struct implemented on obj_.
Definition: connect.h:167
const FirstIface::ToC & iface() const
Definition: connect.h:171
bool set(const ConfObjectRef &o) override
Set the connected configuration object.
Definition: connect.h:130
Connect(const ConfObjectRef &device)
Definition: connect.h:125
Definition: attribute-exceptions.h:25
const char * what() const noexcept override
Definition: attribute-exceptions.h:30
Definition: after-bank.h:33