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/*
2 © 2017 Intel Corporation
3
4 This software and the related documents are Intel copyrighted materials, and
5 your use of them is governed by the express license under which they were
6 provided to you ("License"). Unless the License provides otherwise, you may
7 not use, modify, copy, publish, distribute, disclose or transmit this software
8 or the related documents without Intel's prior written permission.
9
10 This software and the related documents are provided as is, with no express or
11 implied warranties, other than those that are expressly stated in the License.
12*/
13
14#ifndef SIMICS_SYSTEMC_INJECTION_INJECT_REGISTRY_H
15#define SIMICS_SYSTEMC_INJECTION_INJECT_REGISTRY_H
16
17
18
22
23#include <tlm>
24
25#include <map>
26#include <string>
27#include <utility>
28
29namespace simics {
30namespace systemc {
31namespace injection {
32
34template <typename TPAYLOAD>
35class InjectRegistry : public tlm::tlm_mm_interface {
36 public:
37 TPAYLOAD *attrToPayload(conf_object_t *obj, attr_value_t *attr) {
38 gp_ = new TPAYLOAD(this);
39 gp_->acquire();
40 attr_value_t attrCopy = SIM_attr_copy(*attr);
41 gpAttrCopies_.emplace(gp_, attrCopy);
42 AttrDictParser parser(obj, &attrCopy);
43 parser_ = &parser;
44 // Reverse iterate over all objects implementing
45 // InjectInterface<TPAYLOAD> and invoke
46 // bool operator()(InjectInterface<TPAYLOAD>* iface)
48 if (parser.reportInvalidAttrs())
49 return gp_;
50
51 gp_->release();
52 return NULL;
53 }
55 iface->attrToValue(parser_, gp_);
56 return false;
57 }
58
59 private:
60 struct ReleasedInvoker {
61 bool operator()(InjectInterface<TPAYLOAD>* iface) {
62 iface->released(gp_);
63 return false;
64 }
65 TPAYLOAD *gp_;
66 };
67 void free(tlm::tlm_generic_payload *gp) override {
68 released_.gp_ = gp;
69 Registry<InjectInterface<TPAYLOAD> >::instance()->reverseIterate(
70 &released_);
71
72 typename std::map<TPAYLOAD *, attr_value_t>::iterator i;
73 i = gpAttrCopies_.find(gp);
74 if (i != gpAttrCopies_.end()) {
75 SIM_attr_free(&i->second);
76 gpAttrCopies_.erase(i);
77 }
78
79 delete gp;
80 }
81
82 TPAYLOAD *gp_;
83 ReleasedInvoker released_;
84 AttrDictParser *parser_;
85 std::map<TPAYLOAD *, attr_value_t> gpAttrCopies_;
86};
87
88} // namespace injection
89} // namespace systemc
90} // namespace simics
91
92#endif
Definition: registry.h:30
bool reverseIterate(F *f)
Definition: registry.h:60
Definition: attr_dict_parser.h:38
Definition: inject_interface.h:25
virtual void released(TPAYLOAD *gp)=0
virtual void attrToValue(AttrDictParser *parser, TPAYLOAD *gp)=0
Definition: inject_registry.h:35
bool operator()(InjectInterface< TPAYLOAD > *iface)
Definition: inject_registry.h:54
TPAYLOAD * attrToPayload(conf_object_t *obj, attr_value_t *attr)
Definition: inject_registry.h:37
Definition: adapter.h:79