SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
interface_provider.h
Go to the documentation of this file.
1// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2013 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_SYSTEMC_INTERFACE_PROVIDER_H
17#define SIMICS_SYSTEMC_INTERFACE_PROVIDER_H
18
19#include <simics/conf-object.h>
21
22#include <set>
23
24namespace simics {
25namespace systemc {
26
33 public:
35 public:
37
38 virtual void update_target(ConfObjectRef old_target,
39 ConfObjectRef new_target) = 0;
40 };
41
42 explicit InterfaceProvider(const char *interface_name)
43 : interface_(NULL), interface_name_(interface_name), optional_(false),
45 }
49 // NOTE: The set cannot be owned by the class, it must be created and
50 // destroyed by the CTOR/DTOR; or else the DmiTransactionHandler could
51 // end up accessing an invalid set when invoking
52 // remove_target_update_listener() from its DTOR
55 }
56
57 // Interface for derived class to define how to set/use simics interface
58 virtual void set_target(const ConfObjectRef &obj) {
59 for (std::set<TargetUpdateListener*>::iterator it
60 = target_update_listeners_->begin();
61 it != target_update_listeners_->end(); ++it) {
62 (*it)->update_target(target_obj_, obj);
63 }
64 target_obj_ = simics::ConfObjectRef(obj);
65 interface_ = NULL;
66 }
67
69 if (l) {
70 target_update_listeners_->insert(l);
71 }
72 }
73
75 // NOTE: could be called from a DTOR, must check for valid set
78 }
79 }
80
81 virtual const simics::ConfObjectRef &target() const {
82 return target_obj_;
83 }
84
85 virtual bool has_interface() {
86 return get_interface() != NULL;
87 }
88
89 virtual const char *get_interface_name() const {
90 return interface_name_;
91 }
92
93 template<typename TInterface>
95 interface_t *iface = const_cast<interface_t *>(get_interface());
97 static_cast<TInterface*>(iface));
98 }
99
100 virtual void set_optional(bool optional) {
102 }
103 virtual bool optional() const {
104 return optional_;
105 }
106
107 protected:
108 virtual const interface_t *get_interface() {
109 if (interface_ == NULL) {
111 target_obj_.get_interface(interface_name_) : NULL;
112 }
113 return interface_;
114 }
115
116 simics::ConfObjectRef target_obj_;
117 const interface_t *interface_;
118 const char *interface_name_;
120 std::set<TargetUpdateListener*> *target_update_listeners_;
121};
122
125 public:
127 const char *interface_name)
128 : InterfaceProvider(interface_name), parent_(parent) {
131 }
134 }
135
136 virtual void set_target(const ConfObjectRef &obj) {
137 parent_->set_target(obj);
138 }
139
140 virtual void set_optional(bool optional) {
142 }
143 virtual bool optional() const {
144 return parent_->optional();
145 }
146
147 protected:
148 virtual void update_target(ConfObjectRef old_target,
149 ConfObjectRef new_target) {
151 }
152
154};
155
156} // namespace systemc
157} // namespace simics
158
159#endif
Definition: interface_provider.h:124
~InterfaceProviderAddOn()
Definition: interface_provider.h:132
virtual void set_target(const ConfObjectRef &obj)
Definition: interface_provider.h:136
virtual void update_target(ConfObjectRef old_target, ConfObjectRef new_target)
Definition: interface_provider.h:148
InterfaceProviderAddOn(InterfaceProvider *parent, const char *interface_name)
Definition: interface_provider.h:126
virtual bool optional() const
Definition: interface_provider.h:143
virtual void set_optional(bool optional)
Definition: interface_provider.h:140
InterfaceProvider * parent_
Definition: interface_provider.h:153
virtual ~TargetUpdateListener()
Definition: interface_provider.h:36
virtual void update_target(ConfObjectRef old_target, ConfObjectRef new_target)=0
Returns the interface provided by the associated Simics object.
Definition: interface_provider.h:32
simics::ConfObjectRef target_obj_
Definition: interface_provider.h:116
InterfaceProvider & operator=(const InterfaceProvider &)=delete
bool optional_
Definition: interface_provider.h:119
virtual bool optional() const
Definition: interface_provider.h:103
virtual void set_optional(bool optional)
Definition: interface_provider.h:100
std::set< TargetUpdateListener * > * target_update_listeners_
Definition: interface_provider.h:120
const char * interface_name_
Definition: interface_provider.h:118
virtual const char * get_interface_name() const
Definition: interface_provider.h:89
virtual ~InterfaceProvider()
Definition: interface_provider.h:48
InterfaceProvider(const InterfaceProvider &)=delete
virtual void set_target(const ConfObjectRef &obj)
Definition: interface_provider.h:58
virtual void add_target_update_listener(TargetUpdateListener *l)
Definition: interface_provider.h:68
virtual void remove_target_update_listener(TargetUpdateListener *l)
Definition: interface_provider.h:74
SimicsTargetLock< TInterface > get_interface()
Definition: interface_provider.h:94
InterfaceProvider(const char *interface_name)
Definition: interface_provider.h:42
virtual bool has_interface()
Definition: interface_provider.h:85
virtual const interface_t * get_interface()
Definition: interface_provider.h:108
virtual const simics::ConfObjectRef & target() const
Definition: interface_provider.h:81
const interface_t * interface_
Definition: interface_provider.h:117
Definition: simics_target_lock.h:27
Definition: pci_bus_interface.h:24