event_finder.hh revision 13521:74fa3ac44057
1/*****************************************************************************
2
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements.  See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License.  You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied.  See the License for the specific language governing
16  permissions and limitations under the License.
17
18 *****************************************************************************/
19
20#ifndef __SYSTEMC_EXT_TLM_CORE_1_REQ_RSP_PORTS_EVENT_FINDER_HH__
21#define __SYSTEMC_EXT_TLM_CORE_1_REQ_RSP_PORTS_EVENT_FINDER_HH__
22
23#include "tlm_core/1/req_rsp/interfaces/tag.hh"
24
25namespace tlm
26{
27
28template <class IF, class T>
29class tlm_event_finder_t : public sc_core::sc_event_finder
30{
31  public:
32    tlm_event_finder_t(const sc_core::sc_port_base &port_,
33                       const sc_core::sc_event &(IF::*event_method_)(
34                           tlm_tag<T> *) const) :
35        sc_core::sc_event_finder(port_), m_event_method(event_method_)
36    {}
37
38    virtual ~tlm_event_finder_t() {}
39
40    virtual const sc_core::sc_event &
41        find_event(sc_core::sc_interface *if_p=nullptr) const;
42
43  private:
44    const sc_core::sc_event &(IF::*m_event_method)(tlm_tag<T> *) const;
45
46  private:
47    // disabled
48    tlm_event_finder_t();
49    tlm_event_finder_t(const tlm_event_finder_t<IF, T> &);
50    tlm_event_finder_t<IF, T> &operator = (const tlm_event_finder_t<IF, T> &);
51};
52
53template <class IF, class T>
54inline const sc_core::sc_event &
55tlm_event_finder_t<IF, T>::find_event(sc_core::sc_interface *if_p) const
56{
57    const IF *iface = if_p ? dynamic_cast<const IF *>(if_p) :
58        dynamic_cast<const IF *>(port()->_gem5Interface(0));
59    if (iface == nullptr) {
60        report_error(sc_core::SC_ID_FIND_EVENT_, "port is not bound");
61        return sc_core::sc_event::none;
62    }
63    return (const_cast<IF *>(iface)->*m_event_method)(nullptr);
64}
65
66} // namespace tlm
67
68#endif /* __SYSTEMC_EXT_TLM_CORE_1_REQ_RSP_PORTS_EVENT_FINDER_HH__ */
69