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