SystemC Library API Reference Manual
Reference documentation for the Simics SystemC Library.
 
Loading...
Searching...
No Matches
multi_initiator_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_INITIATOR_SPY_FACTORY_H
17#define SIMICS_SYSTEMC_AWARENESS_MULTI_INITIATOR_SPY_FACTORY_H
18#if INTC_EXT
19
23
24#include <tlm_utils/multi_socket_bases.h>
25#include <sysc/intc/communication/sc_export_spy.h>
26#include <tlm>
27
28#include <map>
29#include <vector>
30
31namespace simics {
32namespace systemc {
33namespace awareness {
34
35template <typename TYPES, typename IF>
36class MultiInitiatorSpyFactoryInterface {
37 public:
38 typedef tlm::tlm_bw_transport_if<TYPES> BW_IF;
39 virtual void bind_spies(std::map<IF*, intc::sc_export_spy<IF> *>
40 *spies) = 0;
41 virtual std::map<BW_IF*, BW_IF*> *get_spies() = 0;
42 virtual MultiInitiatorSpyFactoryInterface<TYPES, IF> *create() = 0;
43 virtual TraverserInterface *traverser() = 0;
44 virtual ~MultiInitiatorSpyFactoryInterface() {}
45};
46
47template <typename IF, typename HANDLER,
48 typename TYPES = tlm::tlm_base_protocol_types>
49class MultiInitiatorSpyFactory
50 : public TraverserInterface,
51 public MultiInitiatorSpyFactoryInterface<TYPES, IF> {
52 public:
53 using typename MultiInitiatorSpyFactoryInterface<TYPES, IF>::BW_IF;
54 typedef tlm::tlm_fw_transport_if<TYPES> FW_IF;
55 typedef typename tlm_utils::multi_init_base_if<TYPES> base;
56 MultiInitiatorSpyFactory() {}
57 MultiInitiatorSpyFactory(const MultiInitiatorSpyFactory &f) {}
58 MultiInitiatorSpyFactory &operator = (const MultiInitiatorSpyFactory &f) {}
59 virtual void applyOn(sc_core::sc_object *sc_object) {
60 base *initiator = dynamic_cast<base *>(sc_object);
61 if (initiator) {
62 sockets_.push_back(initiator);
63 std::vector<tlm_utils::callback_binder_bw<TYPES>* > &binders
64 = initiator->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 virtual void done() {}
73 virtual MultiInitiatorSpyFactoryInterface<TYPES, IF> *create() {
74 return new MultiInitiatorSpyFactory;
75 }
76 virtual TraverserInterface *traverser() {
77 return this;
78 }
79 void bind_spies(std::map<IF*, intc::sc_export_spy<IF> *> *spies) {
80 for (auto i : sockets_) {
81 std::vector<FW_IF *> &targets = i->get_sockets();
82 for (auto& j : targets) {
83 intc::sc_export_spy<IF> *spy = (*spies)[j];
84 if (spy) {
85 j = spy->get_current_interface();
86 } else {
87 auto* fw = dynamic_cast<
88 tlm_utils::callback_binder_fw<TYPES> *>(j);
89 TlmMultiHandlerInterface *h =
90 TlmMultiHandlerRegistry::getHandler(fw);
91 if (h) {
92 j = dynamic_cast<FW_IF *>(h->firstHandler());
93 }
94 }
95 }
96 }
97 }
98 virtual std::map<BW_IF*, BW_IF*> *get_spies() {
99 return &spies_;
100 }
101 virtual ~MultiInitiatorSpyFactory() {
102 for (auto i : handlers_)
103 delete i;
104 }
105 private:
106 std::vector<base *> sockets_;
107 std::vector<HANDLER *> handlers_;
108 std::map<BW_IF*, BW_IF*> spies_;
109};
110
111} // namespace awareness
112} // namespace systemc
113} // namespace simics
114
115#endif // INTC_EXT
116#endif
Definition: pci_bus_interface.h:24