SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
multi_target_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_MULTI_TARGET_SPY_FACTORY_H
15#define SIMICS_SYSTEMC_AWARENESS_MULTI_TARGET_SPY_FACTORY_H
16#if INTC_EXT
17
18#include <tlm>
19#include <tlm_utils/multi_socket_bases.h>
20
24
25#include <vector>
26#include <map>
27
28namespace simics {
29namespace systemc {
30namespace awareness {
31
32template <typename IF, typename TYPES>
33class MultiTargetSpyFactoryInterface {
34 public:
35 typedef tlm::tlm_fw_transport_if<TYPES> FW_IF;
36 virtual void bind_spies(std::map<IF*, intc::sc_export_spy<IF> *>
37 *spies) = 0;
38 virtual std::map<FW_IF*, FW_IF*> *get_spies() = 0;
39 virtual MultiTargetSpyFactoryInterface<IF, TYPES> *create() = 0;
40 virtual TraverserInterface *traverser() = 0;
41 virtual ~MultiTargetSpyFactoryInterface() {}
42};
43
44template <typename IF, typename HANDLER,
45 typename TYPES = tlm::tlm_base_protocol_types>
46class MultiTargetSpyFactory : public TraverserInterface,
47 public MultiTargetSpyFactoryInterface<IF, TYPES> {
48 public:
49 using typename MultiTargetSpyFactoryInterface<IF, TYPES>::FW_IF;
50 typedef tlm::tlm_bw_transport_if<TYPES> BW_IF;
51 typedef typename tlm_utils::multi_target_base_if<TYPES> base;
52 MultiTargetSpyFactory() {}
53 MultiTargetSpyFactory(const MultiTargetSpyFactory &f) {}
54 MultiTargetSpyFactory &operator = (const MultiTargetSpyFactory &f) {}
55 virtual ~MultiTargetSpyFactory() {
56 for (auto i : handlers_)
57 delete i;
58 }
59 void applyOn(sc_core::sc_object *sc_object) override {
60 base *target = dynamic_cast<base *> (sc_object);
61 if (target) {
62 sockets_.push_back(target);
63 std::vector<tlm_utils::callback_binder_fw<TYPES>* > &binders
64 = target->get_binders();
65 for (auto i : binders) {
66 HANDLER *handler = new HANDLER(i);
67 handlers_.push_back(handler);
68 spies_[i] = handler;
69 }
70 }
71 }
72 void done() override {}
73 void bind_spies(std::map<IF*, intc::sc_export_spy<IF> *> *spies) override {
74 for (auto i : sockets_) {
75 auto &binds = i->get_multi_binds();
76 for (auto& j : binds) {
77 auto *h = TlmMultiHandlerRegistry::getHandler(j.second);
78 if (h) {
79 BW_IF *bw = dynamic_cast<BW_IF *>(h->firstHandler());
80 if (bw) {
81 j.second = bw;
82 }
83 }
84 }
85 }
86 }
87 MultiTargetSpyFactoryInterface<IF, TYPES> *create() override {
88 return new MultiTargetSpyFactory;
89 }
90 TraverserInterface *traverser() override {
91 return this;
92 }
93 std::map<FW_IF*, FW_IF*> *get_spies() override {
94 return &spies_;
95 }
96
97 private:
98 std::vector<base *> sockets_;
99 std::vector<HANDLER *> handlers_;
100 std::map<FW_IF*, FW_IF*> spies_;
101};
102
103} // namespace awareness
104} // namespace systemc
105} // namespace simics
106
107#endif // INTC_EXT
108#endif
Definition: adapter.h:79