113521Sgabeblack@google.com/*****************************************************************************
213521Sgabeblack@google.com
313521Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
413521Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
513521Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
613521Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
713521Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
813521Sgabeblack@google.com  License.  You may obtain a copy of the License at
913521Sgabeblack@google.com
1013521Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1113521Sgabeblack@google.com
1213521Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1313521Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1413521Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1513521Sgabeblack@google.com  implied.  See the License for the specific language governing
1613521Sgabeblack@google.com  permissions and limitations under the License.
1713521Sgabeblack@google.com
1813521Sgabeblack@google.com *****************************************************************************/
1913521Sgabeblack@google.com
2013521Sgabeblack@google.com#ifndef __SYSTEMC_EXT_TLM_CORE_1_ANALYSIS_ANALYSIS_PORT_HH__
2113521Sgabeblack@google.com#define __SYSTEMC_EXT_TLM_CORE_1_ANALYSIS_ANALYSIS_PORT_HH__
2213521Sgabeblack@google.com
2313521Sgabeblack@google.com#include <algorithm>
2413521Sgabeblack@google.com#include <deque>
2513521Sgabeblack@google.com
2613586Sgabeblack@google.com#include "analysis_if.hh"
2713521Sgabeblack@google.com
2813521Sgabeblack@google.comnamespace tlm
2913521Sgabeblack@google.com{
3013521Sgabeblack@google.com
3113521Sgabeblack@google.comtemplate <typename T>
3213521Sgabeblack@google.comclass tlm_analysis_port : public sc_core::sc_object,
3313521Sgabeblack@google.com    public virtual tlm_analysis_if<T>
3413521Sgabeblack@google.com{
3513521Sgabeblack@google.com  public:
3613521Sgabeblack@google.com    tlm_analysis_port() : sc_core::sc_object() {}
3713521Sgabeblack@google.com    tlm_analysis_port(const char *nm) : sc_core::sc_object(nm) {}
3813521Sgabeblack@google.com
3913521Sgabeblack@google.com    // bind and () work for both interfaces and analysis ports, since
4013521Sgabeblack@google.com    // analysis ports implement the analysis interface.
4113521Sgabeblack@google.com
4213521Sgabeblack@google.com    virtual void
4313521Sgabeblack@google.com    bind(tlm_analysis_if<T> &_if)
4413521Sgabeblack@google.com    {
4513521Sgabeblack@google.com        m_interfaces.push_back(&_if);
4613521Sgabeblack@google.com    }
4713521Sgabeblack@google.com
4813521Sgabeblack@google.com    void operator() (tlm_analysis_if<T> &_if) { bind(_if); }
4913521Sgabeblack@google.com    virtual bool
5013521Sgabeblack@google.com    unbind(tlm_analysis_if<T> &_if)
5113521Sgabeblack@google.com    {
5213521Sgabeblack@google.com        typename std::deque<tlm_analysis_if<T> *>::iterator i =
5313521Sgabeblack@google.com            std::remove(m_interfaces.begin(), m_interfaces.end(), &_if);
5413521Sgabeblack@google.com
5513521Sgabeblack@google.com        if (i != m_interfaces.end()) {
5613521Sgabeblack@google.com            m_interfaces.erase(i, m_interfaces.end());
5713521Sgabeblack@google.com            return 1;
5813521Sgabeblack@google.com        }
5913521Sgabeblack@google.com        return 0;
6013521Sgabeblack@google.com    }
6113521Sgabeblack@google.com
6213521Sgabeblack@google.com    void
6313521Sgabeblack@google.com    write(const T &t)
6413521Sgabeblack@google.com    {
6513521Sgabeblack@google.com        typename std::deque<tlm_analysis_if<T> *>::iterator i;
6613521Sgabeblack@google.com
6713521Sgabeblack@google.com        for (i = m_interfaces.begin(); i != m_interfaces.end(); i++) {
6813521Sgabeblack@google.com            (*i)->write(t);
6913521Sgabeblack@google.com        }
7013521Sgabeblack@google.com    }
7113521Sgabeblack@google.com
7213521Sgabeblack@google.com  private:
7313521Sgabeblack@google.com    std::deque<tlm_analysis_if<T> *> m_interfaces;
7413521Sgabeblack@google.com};
7513521Sgabeblack@google.com
7613521Sgabeblack@google.com} // namespace tlm
7713521Sgabeblack@google.com
7813521Sgabeblack@google.com#endif /* __SYSTEMC_EXT_TLM_CORE_1_ANALYSIS_ANALYSIS_PORT_HH__ */
79