SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
inject_registry.h
Go to the documentation of this file.
1// -*- mode: C++; c-file-style: "virtutech-c++" -*-
2
3/*
4 © 2017 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_INJECTION_INJECT_REGISTRY_H
17#define SIMICS_SYSTEMC_INJECTION_INJECT_REGISTRY_H
18
19
20
24
25#include <tlm>
26
27#include <map>
28#include <string>
29#include <utility>
30
31namespace simics {
32namespace systemc {
33namespace injection {
34
36template <typename TPAYLOAD>
37class InjectRegistry : public tlm::tlm_mm_interface {
38 public:
39 TPAYLOAD *attrToPayload(conf_object_t *obj, attr_value_t *attr) {
40 gp_ = new TPAYLOAD(this);
41 gp_->acquire();
42 attr_value_t attrCopy = SIM_attr_copy(*attr);
43 gpAttrCopies_.insert(std::make_pair(gp_, attrCopy));
44 AttrDictParser parser(obj, &attrCopy);
45 parser_ = &parser;
46 // Reverse iterate over all objects implementing
47 // InjectInterface<TPAYLOAD> and invoke
48 // bool operator()(InjectInterface<TPAYLOAD>* iface)
50 if (parser.reportInvalidAttrs())
51 return gp_;
52
53 gp_->release();
54 return NULL;
55 }
57 iface->attrToValue(parser_, gp_);
58 return false;
59 }
60
61 private:
62 struct ReleasedInvoker {
63 bool operator()(InjectInterface<TPAYLOAD>* iface) {
64 iface->released(gp_);
65 return false;
66 }
67 TPAYLOAD *gp_;
68 };
69 virtual void free(tlm::tlm_generic_payload *gp) {
70 released_.gp_ = gp;
71 Registry<InjectInterface<TPAYLOAD> >::instance()->reverseIterate(
72 &released_);
73
74 typename std::map<TPAYLOAD *, attr_value_t>::iterator i;
75 i = gpAttrCopies_.find(gp);
76 if (i != gpAttrCopies_.end()) {
77 SIM_attr_free(&i->second);
78 gpAttrCopies_.erase(i);
79 }
80
81 delete gp;
82 }
83
84 TPAYLOAD *gp_;
85 ReleasedInvoker released_;
86 AttrDictParser *parser_;
87 std::map<TPAYLOAD *, attr_value_t> gpAttrCopies_;
88};
89
90} // namespace injection
91} // namespace systemc
92} // namespace simics
93
94#endif
Definition: registry.h:30
bool reverseIterate(F *f)
Definition: registry.h:61
Definition: attr_dict_parser.h:40
Definition: inject_interface.h:27
virtual void released(TPAYLOAD *gp)=0
virtual void attrToValue(AttrDictParser *parser, TPAYLOAD *gp)=0
Definition: inject_registry.h:37
bool operator()(InjectInterface< TPAYLOAD > *iface)
Definition: inject_registry.h:56
TPAYLOAD * attrToPayload(conf_object_t *obj, attr_value_t *attr)
Definition: inject_registry.h:39
Definition: pci_bus_interface.h:24