17#include "cci_broker.h"
20#include <util/ities.h>
26cci_originator cci_broker::get_preset_value_origin(
const std::string& parname)
const {
27 const_cast<cci_broker*
>(
this)->insert_matching_preset_value(parname);
28 return consuming_broker::get_preset_value_origin(parname);
34bool cci_broker::sendToParent(
const std::string& parname)
const {
35 return ((expose.find(parname) != expose.end()) && (!is_global_broker()));
41cci_broker::cci_broker(
const std::string& name)
42: consuming_broker(name)
43, m_parent(get_parent_broker())
45 sc_assert(name.length() > 0 &&
"Name must not be empty");
48cci_broker::~cci_broker() {}
50cci_originator cci_broker::get_value_origin(
const std::string& parname)
const {
51 if(sendToParent(parname)) {
52 return m_parent.get_value_origin(parname);
54 return consuming_broker::get_value_origin(parname);
58void cci_broker::insert_matching_preset_value(
const std::string& parname) {
60 for(
auto const& e : wildcard_presets) {
61 if(std::regex_match(parname, e.second.rr)) {
62 consuming_broker::set_preset_cci_value(parname, e.second.value, e.second.originator);
68 for(
auto const& e : wildcard_locks) {
69 if(std::regex_match(parname, e.second)) {
70 consuming_broker::lock_preset_value(parname);
75bool cci_broker::has_preset_value(
const std::string& parname)
const {
76 if(sendToParent(parname)) {
77 return m_parent.has_preset_value(parname);
78 }
else if(consuming_broker::has_preset_value(parname)) {
81 const_cast<cci_broker*
>(
this)->insert_matching_preset_value(parname);
82 return consuming_broker::has_preset_value(parname);
86cci_value cci_broker::get_preset_cci_value(
const std::string& parname)
const {
87 if(sendToParent(parname)) {
88 return m_parent.get_preset_cci_value(parname);
89 }
else if(consuming_broker::has_preset_value(parname)) {
90 return consuming_broker::get_preset_cci_value(parname);
92 const_cast<cci_broker*
>(
this)->insert_matching_preset_value(parname);
93 return consuming_broker::get_preset_cci_value(parname);
97cci_value cci_broker::get_cci_value(
const std::string& parname,
const cci::cci_originator& originator)
const {
98 if(sendToParent(parname)) {
99 return m_parent.get_cci_value(parname);
101 return consuming_broker::get_cci_value(parname);
105void cci_broker::add_param(cci_param_if* par) {
106 if(sendToParent(par->name())) {
107 return m_parent.add_param(par);
109 return consuming_broker::add_param(par);
113void cci_broker::remove_param(cci_param_if* par) {
114 if(sendToParent(par->name())) {
115 return m_parent.remove_param(par);
117 return consuming_broker::remove_param(par);
121cci_param_untyped_handle cci_broker::get_param_handle(
const std::string& parname,
const cci_originator& originator)
const {
122 if(sendToParent(parname)) {
123 return m_parent.get_param_handle(parname, originator);
125 cci_param_if* orig_param = get_orig_param(parname);
127 return cci_param_untyped_handle(*orig_param, originator);
130 return m_parent.get_param_handle(parname, originator);
132 return cci_param_untyped_handle(originator);
135std::vector<cci_param_untyped_handle> cci_broker::get_param_handles(
const cci_originator& originator)
const {
137 std::vector<cci_param_untyped_handle> p_param_handles = m_parent.get_param_handles();
138 std::vector<cci_param_untyped_handle> param_handles = consuming_broker::get_param_handles(originator);
139 param_handles.insert(param_handles.end(), p_param_handles.begin(), p_param_handles.end());
140 return param_handles;
142 return consuming_broker::get_param_handles(originator);
146bool cci_broker::is_global_broker()
const {
return (!has_parent); }
149 if(sendToParent(parname)) {
150 return m_parent.set_preset_cci_value(parname, value, originator);
153 if(parname.find_first_of(
"*?[") != std::string::npos) {
154 wildcard_presets.insert(std::pair<std::string, wildcard_entry>(
156 }
else if(parname[0] ==
'^') {
157 wildcard_presets.insert(
158 std::pair<std::string, wildcard_entry>(parname, wildcard_entry{std::regex(parname), value, originator}));
160 consuming_broker::set_preset_cci_value(parname, value, originator);
161 }
catch(std::regex_error& e) {
162 SCCERR() <<
"Invalid preset parameter name '" << parname <<
"', " << e.what();
168 if(sendToParent(parname)) {
169 m_parent.lock_preset_value(parname);
172 if(parname.find_first_of(
"*?[") != std::string::npos) {
173 wildcard_locks.insert(std::pair<std::string, std::regex>(parname, std::regex(
util::glob_to_regex(parname))));
174 }
else if(parname[0] ==
'^') {
175 wildcard_locks.insert(std::pair<std::string, std::regex>(parname, std::regex(parname)));
177 consuming_broker::lock_preset_value(parname);
178 }
catch(std::regex_error& e) {
179 SCCERR() <<
"Invalid preset parameter name '" << parname <<
"', " << e.what();
184#if defined(CWR_SYSTEMC) || defined(MTI_SYSTEMC)
188bool init_cci(std::string name) {
192 thread_local bool registered{
false};
194 cci::cci_register_broker(broker);
void lock_preset_value(const std::string &parname) override
Lock a parameter's preset value.
void set_preset_cci_value(const std::string &parname, const cci::cci_value &cci_value, const cci::cci_originator &originator) override
Set a parameter's preset value.
std::string glob_to_regex(std::string val)