SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
port_spy_factory.h
Go to the documentation of this file.
1/*
2 © 2015 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_AWARENESS_PORT_SPY_FACTORY_H
15#define SIMICS_SYSTEMC_AWARENESS_PORT_SPY_FACTORY_H
16
17#if INTC_EXT
18
20
21#include <sysc/intc/communication/sc_port_spy.h>
22#include <systemc>
23
24#include <map>
25#include <vector>
26
27namespace simics {
28namespace systemc {
29namespace awareness {
30
31template <typename IF, typename HANDLER>
32class PortSpyFactory : public simics::systemc::TraverserInterface {
33 public:
34 typedef typename std::vector<HANDLER *>::iterator iterator;
35 typedef typename std::map<IF*, intc::sc_port_spy<IF> *>::iterator
36 spy_iterator;
37 PortSpyFactory() {}
38 PortSpyFactory(const PortSpyFactory &f) {}
39 PortSpyFactory &operator = (const PortSpyFactory &f) {}
40 virtual ~PortSpyFactory() {
41 for (auto *handler : handlers_)
42 delete handler;
43 for (auto &spy : spies_)
44 delete spy.second;
45 }
46 void applyOn(sc_core::sc_object *sc_object) override {
47 if (sc_core::sc_port<IF> *if_
48 = dynamic_cast<sc_core::sc_port<IF> *>(sc_object)) {
49 if (if_->size() <= 0)
50 return;
51 intc::sc_port_spy<IF> *spy = new intc::sc_port_spy<IF>(if_);
52 HANDLER *handler = new HANDLER(spy);
53 spy->set_spy_interface(handler);
54 handlers_.push_back(handler);
55 spies_[spy->get_interface()] = spy;
56 }
57 if (sc_core::sc_port<IF, 0> *if_
58 = dynamic_cast<sc_core::sc_port<IF, 0> *>(sc_object)) {
59 if (if_->size() <= 0)
60 return;
61 for (int i = 0; i < if_->size(); ++i) {
62 intc::sc_port_spy<IF> *spy = new intc::sc_port_spy<IF>(if_, i);
63 HANDLER *handler = new HANDLER(spy);
64 handlers_.push_back(handler);
65 spy->set_spy_interface(handler);
66 spies_[spy->get_interface()] = spy;
67 }
68 }
69 }
70 void done() override {}
71 void bindSpies(std::map<IF*, intc::sc_export_spy<IF> *> *exports) {
72 for (auto &entry : spies_) {
73 if (intc::sc_export_spy<IF> *spy = (*exports)[entry.first]) {
74 entry.second->set_interface(spy->get_current_interface());
75 }
76 }
77 }
78 void bindSpies(std::map<IF*, IF *> *exports) {
79 for (auto &entry : spies_) {
80 if (IF *spy = (*exports)[entry.first]) {
81 entry.second->set_interface(spy);
82 }
83 }
84 }
85
86 private:
87 std::vector<HANDLER *> handlers_;
88 std::map<IF*, intc::sc_port_spy<IF> *> spies_;
89};
90
91} // namespace awareness
92} // namespace systemc
93} // namespace simics
94
95#endif // INTC_EXT
96#endif
Definition: traverser_interface.h:24
Definition: adapter.h:79