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