rc_transaction_counter.cpp

Go to the documentation of this file.
00001 // vim:set et sts=4 ts=4 tw=75 sw=4 ai ci cin cino=g0,t0:
00002 /*
00003  * Copyright (C) 2007, Technical Computer Science Group,
00004  *                     University of Bonn
00005  *
00006  * This file is part of the ReChannel library.
00007  *
00008  * The ReChannel library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License as
00010  * published by the Free Software Foundation; either version 2 of the
00011  * License, or (at your option) any later version.
00012  *
00013  * This library is distributed in the hope that it will be
00014  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this library; see the file COPYING. If not, write to the
00020  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
00021  * Boston, MA 02110-1301, USA.
00022  *
00023  * Authors: Andreas Raabe and Armin Felke. Implementation by Armin Felke.
00024  *          {raabe, felke}@cs.uni-bonn.de
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 { //(prev_p_count < 0)
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 /* convenience constructors */
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 } // namespace ReChannel
00294 
00295 //
00296 // $Id: rc_transaction_counter.cpp,v 1.6 2007/12/20 20:42:13 felke Exp $
00297 // $Source: /var/cvs/projekte/ReChannel-v2/src/ReChannel/core/rc_transaction_counter.cpp,v $
00298 //

Generated on Tue Jan 1 23:14:06 2008 for ReChannel by  doxygen 1.5.3