00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00037 #include "rc_transaction_counter.h"
00038
00039 namespace ReChannel {
00040
00041 rc_transaction_counter::rc_transaction_counter()
00042 : sc_object(sc_gen_unique_name("_rc_transaction_counter")), p_count(0)
00043 {
00044 p_reconf = rc_get_reconfigurable_context(this->get_parent_object());
00045 }
00046
00047 rc_transaction_counter::rc_transaction_counter(
00048 std::vector<this_type*>& children)
00049 : sc_object(sc_gen_unique_name("_rc_transaction_counter")), p_count(0)
00050 {
00051 p_reconf = rc_get_reconfigurable_context(this->get_parent_object());
00052
00053 for (std::vector<this_type*>::iterator it = children.begin();
00054 it != children.end();
00055 ++it)
00056 {
00057 rc_transaction_counter* const child = *it;
00058 if (child != NULL) {
00059 this->_rc_add_child(*child);
00060 }
00061 }
00062 }
00063
00064 void rc_transaction_counter::modify(int amount)
00065 {
00066 if (p_children.empty()) {
00067 const int prev_p_count = p_count;
00068 p_count += amount;
00069 if (prev_p_count >= 0) {
00070 if (p_count < 0) {
00071 amount -= p_count;
00072 }
00073 } else {
00074 amount = (p_count > 0 ? p_count : 0);
00075 }
00076 if (p_reconf != NULL && amount != 0) {
00077 if (p_reconf->p_transaction_count > -amount) {
00078 p_reconf->p_transaction_count += amount;
00079 } else {
00080 p_reconf->reset_transaction_count();
00081 }
00082 }
00083 } else {
00084 this->_rc_relay(amount);
00085 }
00086 }
00087
00088 void rc_transaction_counter::reset()
00089 {
00090 if (p_count != 0 && p_children.empty()) {
00091 this->modify(-p_count);
00092 }
00093 }
00094
00095 int rc_transaction_counter::get_relay_factor(int index) const
00096 {
00097 if (index >= 0 && index < (int)p_children.size()) {
00098 return p_children[index].second;
00099 } else {
00100 return 0;
00101 }
00102 }
00103
00104 void rc_transaction_counter::set_relay_factor(int index, int factor)
00105 {
00106 if (index >= 0 && index < (int)p_children.size()) {
00107 p_children[index].second = factor;
00108 }
00109 }
00110
00111 void rc_transaction_counter::set_relay_factor(
00112 rc_transaction_counter& child, int factor)
00113 {
00114 for (std::vector<std::pair<this_type*, int> >::iterator it =
00115 p_children.begin();
00116 it != p_children.end();
00117 ++it)
00118 {
00119 if (it->first == &child) {
00120 it->second = factor;
00121 }
00122 }
00123 }
00124
00125 void rc_transaction_counter::_rc_relay(int amount)
00126 {
00127 if (amount != 0) {
00128 for (std::vector<std::pair<this_type*, int> >::iterator it =
00129 p_children.begin();
00130 it != p_children.end();
00131 ++it)
00132 {
00133 const int factor = it->second;
00134 if (factor != 0) {
00135 it->first->modify(amount * factor);
00136 }
00137 }
00138 }
00139 }
00140
00141 void rc_transaction_counter::_rc_add_child(
00142 rc_transaction_counter& child, int factor)
00143 {
00144 p_children.push_back(std::pair<this_type*, int>(&child, factor));
00145 }
00146
00147
00148
00149 rc_transaction_counter::rc_transaction_counter(this_type& tc1, int factor1)
00150 : sc_object(sc_gen_unique_name("_rc_transaction_counter")), p_count(0)
00151 {
00152 p_reconf = rc_get_reconfigurable_context(this->get_parent_object());
00153 this->_rc_add_child(tc1, factor1);
00154 }
00155
00156 rc_transaction_counter::rc_transaction_counter(
00157 this_type& tc1, int factor1, this_type& tc2, int factor2)
00158 : sc_object(sc_gen_unique_name("_rc_transaction_counter")), p_count(0)
00159 {
00160 p_reconf = rc_get_reconfigurable_context(this->get_parent_object());
00161 this->_rc_add_child(tc1, factor1);
00162 this->_rc_add_child(tc2, factor2);
00163 }
00164
00165 rc_transaction_counter::rc_transaction_counter(
00166 this_type& tc1, int factor1, this_type& tc2, int factor2,
00167 this_type& tc3, int factor3)
00168 : sc_object(sc_gen_unique_name("_rc_transaction_counter")), p_count(0)
00169 {
00170 p_reconf = rc_get_reconfigurable_context(this->get_parent_object());
00171 this->_rc_add_child(tc1, factor1);
00172 this->_rc_add_child(tc2, factor2);
00173 this->_rc_add_child(tc3, factor3);
00174 }
00175
00176 rc_transaction_counter::rc_transaction_counter(
00177 this_type& tc1, int factor1, this_type& tc2, int factor2,
00178 this_type& tc3, int factor3, this_type& tc4, int factor4)
00179 : sc_object(sc_gen_unique_name("_rc_transaction_counter")), p_count(0)
00180 {
00181 p_reconf = rc_get_reconfigurable_context(this->get_parent_object());
00182 this->_rc_add_child(tc1, factor1);
00183 this->_rc_add_child(tc2, factor2);
00184 this->_rc_add_child(tc3, factor3);
00185 this->_rc_add_child(tc4, factor4);
00186 }
00187
00188 rc_transaction_counter::rc_transaction_counter(
00189 this_type& tc1, int factor1, this_type& tc2, int factor2,
00190 this_type& tc3, int factor3, this_type& tc4, int factor4,
00191 this_type& tc5, int factor5)
00192 : sc_object(sc_gen_unique_name("_rc_transaction_counter")), p_count(0)
00193 {
00194 p_reconf = rc_get_reconfigurable_context(this->get_parent_object());
00195 this->_rc_add_child(tc1, factor1);
00196 this->_rc_add_child(tc2, factor2);
00197 this->_rc_add_child(tc3, factor3);
00198 this->_rc_add_child(tc4, factor4);
00199 this->_rc_add_child(tc5, factor5);
00200 }
00201
00202 rc_transaction_counter::rc_transaction_counter(
00203 this_type& tc1, int factor1, this_type& tc2, int factor2,
00204 this_type& tc3, int factor3, this_type& tc4, int factor4,
00205 this_type& tc5, int factor5, this_type& tc6, int factor6)
00206 : sc_object(sc_gen_unique_name("_rc_transaction_counter")), p_count(0)
00207 {
00208 p_reconf = rc_get_reconfigurable_context(this->get_parent_object());
00209 this->_rc_add_child(tc1, factor1);
00210 this->_rc_add_child(tc2, factor2);
00211 this->_rc_add_child(tc3, factor3);
00212 this->_rc_add_child(tc4, factor4);
00213 this->_rc_add_child(tc5, factor5);
00214 this->_rc_add_child(tc6, factor6);
00215 }
00216
00217 rc_transaction_counter::rc_transaction_counter(
00218 this_type& tc1, int factor1, this_type& tc2, int factor2,
00219 this_type& tc3, int factor3, this_type& tc4, int factor4,
00220 this_type& tc5, int factor5, this_type& tc6, int factor6,
00221 this_type& tc7, int factor7)
00222 : sc_object(sc_gen_unique_name("_rc_transaction_counter")), p_count(0)
00223 {
00224 p_reconf = rc_get_reconfigurable_context(this->get_parent_object());
00225 this->_rc_add_child(tc1, factor1);
00226 this->_rc_add_child(tc2, factor2);
00227 this->_rc_add_child(tc3, factor3);
00228 this->_rc_add_child(tc4, factor4);
00229 this->_rc_add_child(tc5, factor5);
00230 this->_rc_add_child(tc6, factor6);
00231 this->_rc_add_child(tc7, factor7);
00232 }
00233
00234 rc_transaction_counter::rc_transaction_counter(
00235 this_type& tc1, int factor1, this_type& tc2, int factor2,
00236 this_type& tc3, int factor3, this_type& tc4, int factor4,
00237 this_type& tc5, int factor5, this_type& tc6, int factor6,
00238 this_type& tc7, int factor7, this_type& tc8, int factor8)
00239 : sc_object(sc_gen_unique_name("_rc_transaction_counter")), p_count(0)
00240 {
00241 p_reconf = rc_get_reconfigurable_context(this->get_parent_object());
00242 this->_rc_add_child(tc1, factor1);
00243 this->_rc_add_child(tc2, factor2);
00244 this->_rc_add_child(tc3, factor3);
00245 this->_rc_add_child(tc4, factor4);
00246 this->_rc_add_child(tc5, factor5);
00247 this->_rc_add_child(tc6, factor6);
00248 this->_rc_add_child(tc7, factor7);
00249 this->_rc_add_child(tc8, factor8);
00250 }
00251
00252 rc_transaction_counter::rc_transaction_counter(
00253 this_type& tc1, int factor1, this_type& tc2, int factor2,
00254 this_type& tc3, int factor3, this_type& tc4, int factor4,
00255 this_type& tc5, int factor5, this_type& tc6, int factor6,
00256 this_type& tc7, int factor7, this_type& tc8, int factor8,
00257 this_type& tc9, int factor9)
00258 : sc_object(sc_gen_unique_name("_rc_transaction_counter")), p_count(0)
00259 {
00260 p_reconf = rc_get_reconfigurable_context(this->get_parent_object());
00261 this->_rc_add_child(tc1, factor1);
00262 this->_rc_add_child(tc2, factor2);
00263 this->_rc_add_child(tc3, factor3);
00264 this->_rc_add_child(tc4, factor4);
00265 this->_rc_add_child(tc5, factor5);
00266 this->_rc_add_child(tc6, factor6);
00267 this->_rc_add_child(tc7, factor7);
00268 this->_rc_add_child(tc8, factor8);
00269 this->_rc_add_child(tc9, factor9);
00270 }
00271
00272 rc_transaction_counter::rc_transaction_counter(
00273 this_type& tc1, int factor1, this_type& tc2, int factor2,
00274 this_type& tc3, int factor3, this_type& tc4, int factor4,
00275 this_type& tc5, int factor5, this_type& tc6, int factor6,
00276 this_type& tc7, int factor7, this_type& tc8, int factor8,
00277 this_type& tc9, int factor9, this_type& tc10, int factor10)
00278 : sc_object(sc_gen_unique_name("_rc_transaction_counter")), p_count(0)
00279 {
00280 p_reconf = rc_get_reconfigurable_context(this->get_parent_object());
00281 this->_rc_add_child(tc1, factor1);
00282 this->_rc_add_child(tc2, factor2);
00283 this->_rc_add_child(tc3, factor3);
00284 this->_rc_add_child(tc4, factor4);
00285 this->_rc_add_child(tc5, factor5);
00286 this->_rc_add_child(tc6, factor6);
00287 this->_rc_add_child(tc7, factor7);
00288 this->_rc_add_child(tc8, factor8);
00289 this->_rc_add_child(tc9, factor9);
00290 this->_rc_add_child(tc10, factor10);
00291 }
00292
00293 }
00294
00295
00296
00297
00298