SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
device.h
Go to the documentation of this file.
1// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2015 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_DEVICE_H
17#define SIMICS_SYSTEMC_DEVICE_H
18
19
20#include <systemc>
21
25
26#include <string>
27#include <utility>
28
29namespace simics {
30namespace systemc {
31
37template <typename T>
38class Device {
39 public:
43 };
44
49 Device() : simulation_(NULL), device_(NULL), is_device_owner_(false) {}
50
63 Device(Device &other)
64 : simulation_(NULL), device_(NULL), is_device_owner_(false) {
65 *this = other;
66 }
67
75 explicit Device(iface::SimulationInterface *simulation)
76 : simulation_(simulation), device_(new T), is_device_owner_(true) {
77 }
78
89 const std::string &device_name)
90 : simulation_(simulation), device_(new T(device_name.c_str())),
91 is_device_owner_(true) {
92 }
93
107 Device(iface::SimulationInterface *simulation, T *device_model,
108 ownership_t ownership = TAKE_OWNERSHIP)
109 : simulation_(simulation), device_(device_model),
110 is_device_owner_(ownership == TAKE_OWNERSHIP) {
111 }
112
113
128 Device& operator=(Device &other) { // NOLINT(runtime/references)
129 FATAL_ERROR_IF(device_, "Changing the device is not allowed");
130 FATAL_ERROR_IF(simulation_, "Changing the simulation is not allowed");
131
132 std::swap(device_, other.device_);
133 std::swap(simulation_, other.simulation_);
134 std::swap(is_device_owner_, other.is_device_owner_);
135 return *this;
136 }
137
140 return DeviceAccess<T>(simulation_, device_);
141 }
142
145 return DeviceAccess<T>(simulation_, device_);
146 }
147
149 T *pointer() {
150 return device_;
151 }
152
154 const T *pointer() const {
155 return device_;
156 }
157
158 virtual ~Device() {
159 if (is_device_owner_) {
160 simics::systemc::Context c(simulation_);
161 delete device_;
162 }
163 }
164
165 private:
166 iface::SimulationInterface *simulation_;
167 T *device_;
168 bool is_device_owner_;
169};
170
171} // namespace systemc
172} // namespace simics
173
174#endif
Utility class that handles the context switching, using RAII methodology.
Definition: context.h:31
Definition: device_access.h:28
Utility class for handling direct access to the SystemC top module (i.e.
Definition: device.h:38
const T * pointer() const
pointer to underlying device object
Definition: device.h:154
Device & operator=(Device &other)
Assume ownership of the underlying simulation and device model.
Definition: device.h:128
Device(iface::SimulationInterface *simulation, const std::string &device_name)
This constructor automatically allocates an object of type T with device_name passed as the only argu...
Definition: device.h:88
const DeviceAccess< T > operator->() const
Access the underlying device object with the proper simulation context.
Definition: device.h:144
ownership_t
Definition: device.h:40
@ TAKE_OWNERSHIP
Definition: device.h:42
@ DONT_TAKE_OWNERSHIP
Definition: device.h:41
T * pointer()
pointer to underlying device object
Definition: device.h:149
Device()
Default constructor.
Definition: device.h:49
Device(Device &other)
Assume ownership of the underlying simulation and device model.
Definition: device.h:63
Device(iface::SimulationInterface *simulation, T *device_model, ownership_t ownership=TAKE_OWNERSHIP)
Wrap an existing model in this Device.
Definition: device.h:107
virtual ~Device()
Definition: device.h:158
Device(iface::SimulationInterface *simulation)
This constructor automatically allocates an object of type T with default arguments.
Definition: device.h:75
DeviceAccess< T > operator->()
Access the underlying device object with the proper simulation context.
Definition: device.h:139
Interface to the SystemC simulation.
Definition: simulation_interface.h:27
Definition: pci_bus_interface.h:24