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 __TLM_EVENT_FINDER_H__
21#define __TLM_EVENT_FINDER_H__
22
23//#include <systemc>
24
25#include "tlm_core/tlm_1/tlm_req_rsp/tlm_1_interfaces/tlm_tag.h"
26
27namespace tlm {
28
29template <class IF , class T>
30class tlm_event_finder_t
31: public sc_core::sc_event_finder
32{
33public:
34
35    // constructor
36
37    tlm_event_finder_t( const sc_core::sc_port_base& port_,
38                        const sc_core::sc_event& (IF::*event_method_) ( tlm_tag<T> * ) const )
39        : sc_core::sc_event_finder( port_ ), m_event_method( event_method_ )
40        {}
41
42    // destructor (does nothing)
43
44    virtual ~tlm_event_finder_t()
45        {}
46#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
47    virtual const sc_core::sc_event& find_event( sc_core::sc_interface* if_p = 0 ) const;
48#else
49    virtual const sc_core::sc_event& find_event() const;
50#endif
51
52private:
53
54    const sc_core::sc_event& (IF::*m_event_method) ( tlm_tag<T> * ) const;
55
56private:
57
58    // disabled
59    tlm_event_finder_t();
60    tlm_event_finder_t( const tlm_event_finder_t<IF,T>& );
61    tlm_event_finder_t<IF,T>& operator = ( const tlm_event_finder_t<IF,T>& );
62};
63
64
65#if !(defined SYSTEMC_VERSION & SYSTEMC_VERSION <= 20050714)
66template <class IF , class T>
67inline
68const sc_core::sc_event&
69tlm_event_finder_t<IF,T>::find_event( sc_core::sc_interface* if_p ) const
70{
71    const IF* iface = ( if_p ) ? dynamic_cast<const IF*>( if_p ) :
72                                 dynamic_cast<const IF*>( port().get_interface() );
73    if( iface == 0 ) {
74  report_error( sc_core::SC_ID_FIND_EVENT_, "port is not bound" );
75    }
76    return (const_cast<IF*>( iface )->*m_event_method) ( 0 );
77}
78#else
79template <class IF , class T>
80inline
81const sc_core::sc_event&
82tlm_event_finder_t<IF,T>::find_event() const
83{
84    const IF* iface = dynamic_cast<const IF*>( port().get_interface() );
85    if( iface == 0 ) {
86  report_error( sc_core::SC_ID_FIND_EVENT_, "port is not bound" );
87    }
88    return (const_cast<IF*>( iface )->*m_event_method) ( 0 );
89}
90#endif
91
92} // namespace tlm
93
94#endif
95