113514Sgabeblack@google.com/*****************************************************************************
213514Sgabeblack@google.com
313514Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
413514Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
513514Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
613514Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
713514Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
813514Sgabeblack@google.com  License.  You may obtain a copy of the License at
913514Sgabeblack@google.com
1013514Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1113514Sgabeblack@google.com
1213514Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1313514Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1413514Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1513514Sgabeblack@google.com  implied.  See the License for the specific language governing
1613514Sgabeblack@google.com  permissions and limitations under the License.
1713514Sgabeblack@google.com
1813514Sgabeblack@google.com *****************************************************************************/
1913514Sgabeblack@google.com
2013514Sgabeblack@google.com#include <tlm_utils/convenience_socket_bases.h>
2113514Sgabeblack@google.com
2213514Sgabeblack@google.com#include <sstream>
2313586Sgabeblack@google.com
2413586Sgabeblack@google.com#include "systemc/ext/core/sc_object.hh"
2513586Sgabeblack@google.com#include "systemc/ext/core/sc_simcontext.hh"
2613586Sgabeblack@google.com#include "systemc/ext/utils/sc_report_handler.hh"
2713514Sgabeblack@google.com
2813514Sgabeblack@google.comnamespace tlm_utils
2913514Sgabeblack@google.com{
3013514Sgabeblack@google.com
3113514Sgabeblack@google.comvoid
3213514Sgabeblack@google.comconvenience_socket_base::display_warning(const char *text) const
3313514Sgabeblack@google.com{
3413514Sgabeblack@google.com    std::stringstream s;
3513514Sgabeblack@google.com    s << get_socket()->name() << ": " << text;
3613514Sgabeblack@google.com    SC_REPORT_WARNING(get_report_type(), s.str().c_str());
3713514Sgabeblack@google.com}
3813514Sgabeblack@google.com
3913514Sgabeblack@google.comvoid
4013514Sgabeblack@google.comconvenience_socket_base::display_error(const char *text) const
4113514Sgabeblack@google.com{
4213514Sgabeblack@google.com    std::stringstream s;
4313514Sgabeblack@google.com    s << get_socket()->name() << ": " << text;
4413514Sgabeblack@google.com    SC_REPORT_ERROR(get_report_type(), s.str().c_str());
4513514Sgabeblack@google.com}
4613514Sgabeblack@google.com
4713514Sgabeblack@google.com// Simple helpers for warnings an errors to shorten in code notation.
4813514Sgabeblack@google.com
4913514Sgabeblack@google.comvoid
5013514Sgabeblack@google.comconvenience_socket_cb_holder::display_warning(const char *msg) const
5113514Sgabeblack@google.com{
5213514Sgabeblack@google.com    m_owner->display_warning(msg);
5313514Sgabeblack@google.com}
5413514Sgabeblack@google.com
5513514Sgabeblack@google.comvoid
5613514Sgabeblack@google.comconvenience_socket_cb_holder::display_error(const char *msg) const
5713514Sgabeblack@google.com{
5813514Sgabeblack@google.com    m_owner->display_error(msg);
5913514Sgabeblack@google.com}
6013514Sgabeblack@google.com
6113514Sgabeblack@google.comconst char *
6213514Sgabeblack@google.comsimple_socket_base::get_report_type() const
6313514Sgabeblack@google.com{
6413514Sgabeblack@google.com    return "/OSCI_TLM-2/simple_socket";
6513514Sgabeblack@google.com}
6613514Sgabeblack@google.com
6713514Sgabeblack@google.comvoid
6813514Sgabeblack@google.comsimple_socket_base::elaboration_check(const char *action) const
6913514Sgabeblack@google.com{
7013514Sgabeblack@google.com    if (sc_core::sc_get_curr_simcontext()->elaboration_done()) {
7113514Sgabeblack@google.com        std::stringstream s;
7213514Sgabeblack@google.com        s << " elaboration completed, " << action << " not allowed";
7313514Sgabeblack@google.com        display_error(s.str().c_str());
7413514Sgabeblack@google.com    }
7513514Sgabeblack@google.com}
7613514Sgabeblack@google.com
7713514Sgabeblack@google.comconst char *
7813514Sgabeblack@google.compassthrough_socket_base::get_report_type() const
7913514Sgabeblack@google.com{
8013514Sgabeblack@google.com    return "/OSCI_TLM-2/passthrough_socket";
8113514Sgabeblack@google.com}
8213514Sgabeblack@google.com
8313514Sgabeblack@google.comconst char *
8413514Sgabeblack@google.commulti_socket_base::get_report_type() const
8513514Sgabeblack@google.com{
8613514Sgabeblack@google.com    return "/OSCI_TLM-2/multi_socket";
8713514Sgabeblack@google.com}
8813514Sgabeblack@google.com
8913514Sgabeblack@google.com} // namespace tlm_utils
90