rc_abstract_prim_filter.h

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 #ifndef RC_ABSTRACT_PRIM_FILTER_H_
00038 #define RC_ABSTRACT_PRIM_FILTER_H_
00039 
00040 #include "ReChannel/communication/filters/rc_abstract_filter.h"
00041 
00042 namespace ReChannel {
00043 
00047 template<class IF>
00048 class rc_abstract_prim_filter
00049     : public rc_abstract_filter<IF>
00050 {
00051     RC_STATIC_ASSERT_VALID_INTERFACE(IF);
00052 
00053 private:
00054     typedef rc_abstract_prim_filter<IF> this_type;
00055 
00056 protected:
00057     typedef rc_accessor<IF> accessor_type;
00058     typedef typename boost::template function<void (bool)> sync_callback;
00059 
00060     enum rc_predefined_sync_callback_id {
00061         RC_DO_NOTHING_ = 0,
00062         RC_POSSIBLE_DEACTIVATION_,
00063         RC_MODIFY_TRANSACTION_
00064     };
00065 
00066 public:
00067     typedef IF if_type;
00068 
00069 protected:
00070     rc_abstract_prim_filter();
00071 
00072     explicit rc_abstract_prim_filter(
00073         const sync_callback& func_before, const sync_callback& func_after);
00074 
00075     rc_abstract_prim_filter(
00076         rc_predefined_sync_callback_id func_before,
00077         rc_predefined_sync_callback_id func_after,
00078         rc_transaction_counter& tc, int tc_modify);
00079 
00080 protected:
00081 
00082     inline void rc_sync_callback_before()
00083         { this->_rc_sync_callback_before(false); }
00084 
00085     inline void rc_sync_callback_after()
00086         { this->_rc_sync_callback_after(false); }
00087 
00088     inline void rc_nb_sync_callback_before()
00089         { this->_rc_sync_callback_before(true); }
00090 
00091     inline void rc_nb_sync_callback_after()
00092         { this->_rc_sync_callback_after(true); }
00093 
00094     sync_callback rc_predefined_sync_callback(
00095         rc_predefined_sync_callback_id func);
00096 
00097     sync_callback rc_predefined_sync_callback(
00098         rc_predefined_sync_callback_id func,
00099         rc_transaction_counter& tc, int tc_modify);
00100 
00101 private:
00102 
00103     inline void _rc_sync_callback_before(bool nb);
00104 
00105     inline void _rc_sync_callback_after(bool nb);
00106 
00107 private:
00108 
00109     static void _rc_modify_transaction_callback(
00110         bool nb, rc_transaction_counter& tc, int count);
00111 
00112     static void _rc_possible_deactivation_callback(
00113         bool nb, rc_reconfigurable* reconf);
00114 
00115 protected:
00116 
00117     sync_callback m_sync_callback_before;
00118     sync_callback m_sync_callback_after;
00119 
00120 private:
00121     // disabled
00122     rc_abstract_prim_filter(const this_type& other_);
00123     this_type& operator=(const this_type& other_);
00124 };
00125 
00126 /* inline code */
00127 
00128 template<class IF>
00129 inline
00130 void rc_abstract_prim_filter<IF>::_rc_sync_callback_before(bool nb)
00131 {
00132     if (!m_sync_callback_before.empty()) {
00133         this->m_sync_callback_before(nb);
00134     }
00135 }
00136 
00137 template<class IF>
00138 inline
00139 void rc_abstract_prim_filter<IF>::_rc_sync_callback_after(bool nb)
00140 {
00141     if (!m_sync_callback_after.empty()) {
00142         this->m_sync_callback_after(nb);
00143     }
00144 }
00145 
00146 /* template code */
00147 
00148 template<class IF>
00149 rc_abstract_prim_filter<IF>::rc_abstract_prim_filter()
00150 { }
00151 
00152 template<class IF>
00153 rc_abstract_prim_filter<IF>::rc_abstract_prim_filter(
00154     const sync_callback& func_before, const sync_callback& func_after)
00155     : m_sync_callback_before(func_before),
00156       m_sync_callback_after(func_after)
00157 { }
00158 
00159 template<class IF>
00160 typename rc_abstract_prim_filter<IF>::sync_callback
00161 rc_abstract_prim_filter<IF>::rc_predefined_sync_callback(
00162     rc_predefined_sync_callback_id func_type,
00163     rc_transaction_counter& tc, int tc_modify)
00164 {
00165     switch(func_type) {
00166         case RC_POSSIBLE_DEACTIVATION_:
00167             return boost::bind(
00168                 &this_type::_rc_possible_deactivation_callback,
00169                 _1, this->rc_get_reconfigurable());
00170         case RC_MODIFY_TRANSACTION_:
00171             return boost::bind(
00172                 &this_type::_rc_modify_transaction_callback,
00173                 _1, boost::ref(tc), tc_modify);
00174         case RC_DO_NOTHING_:
00175         default:
00176             return sync_callback();
00177     }
00178 }
00179 
00180 template<class IF>
00181 typename rc_abstract_prim_filter<IF>::sync_callback
00182 rc_abstract_prim_filter<IF>::rc_predefined_sync_callback(
00183     rc_predefined_sync_callback_id func_type)
00184 {
00185     switch(func_type) {
00186         case RC_POSSIBLE_DEACTIVATION_:
00187             return boost::bind(
00188                 &this_type::_rc_possible_deactivation_callback,
00189                 _1, this->rc_get_reconfigurable());
00190         case RC_MODIFY_TRANSACTION_:
00191         case RC_DO_NOTHING_:
00192         default:
00193             return sync_callback();
00194     }
00195 }
00196 
00197 template<class IF>
00198 void rc_abstract_prim_filter<IF>::_rc_modify_transaction_callback(
00199     bool nb, rc_transaction_counter& tc, int count)
00200 {
00201     tc.modify(count);
00202 }
00203 
00204 template<class IF>
00205 void rc_abstract_prim_filter<IF>::_rc_possible_deactivation_callback(
00206     bool nb, rc_reconfigurable* reconf)
00207 {
00208     if (nb == false && reconf != NULL) {
00209         reconf->rc_possible_deactivation();
00210     }
00211 }
00212 
00213 } // namespace ReChannel
00214 
00215 #define RC_NO_SYNC_CALLBACK() NULL
00216 
00217 #define RC_SYNC_CALLBACK(func) \
00218     rc_bind(&RC_CURRENT_USER_MODULE::func, this, _1)
00219 
00220 #define RC_SYNC_CALLBACK0(func) \
00221     rc_bind(&RC_CURRENT_USER_MODULE::func, this, _1)
00222 
00223 #define RC_SYNC_CALLBACK1(func, p1) \
00224     rc_bind(&RC_CURRENT_USER_MODULE::func, this, _1, p1)
00225 
00226 #define RC_SYNC_CALLBACK2(func, p1, p2) \
00227     rc_bind(&RC_CURRENT_USER_MODULE::func, this, _1, p1, p2)
00228 
00229 #define RC_SYNC_CALLBACK3(func, p1, p2, p3) \
00230     rc_bind(&RC_CURRENT_USER_MODULE::func, this, _1, p1, p2, p3)
00231 
00232 #define RC_SYNC_CALLBACK4(func, p1, p2, p3, p4) \
00233     rc_bind(&RC_CURRENT_USER_MODULE::func, this, _1, p1, p2, p3, p4)
00234 
00235 #define RC_SYNC_CALLBACK5(func, p1, p2, p3, p4, p5) \
00236     rc_bind(&RC_CURRENT_USER_MODULE::func, this, _1, p1, p2, p3, p4, p5)
00237 
00238 #define RC_SYNC_CALLBACK6(func, p1, p2, p3, p4, p5, p6) \
00239     rc_bind(&RC_CURRENT_USER_MODULE::func, this, \
00240         _1, p1, p2, p3, p4, p5, p6)
00241 
00242 #define RC_SYNC_CALLBACK7(func, p1, p2, p3, p4, p5, p6, p7) \
00243     rc_bind( \
00244         &RC_CURRENT_USER_MODULE::func, this, \
00245         _1, p1, p2, p3, p4, p5, p6, p7)
00246 
00247 #define RC_SYNC_CALLBACK8(func, p1, p2, p3, p4, p5, p6, p7, p8) \
00248     rc_bind( \
00249         &RC_CURRENT_USER_MODULE::func, this, \
00250         _1, p1, p2, p3, p4, p5, p6, p7, p8)
00251 
00252 #define RC_SYNC_CALLBACK9(func, p1, p2, p3, p4, p5, p6, p7, p8, p9) \
00253     rc_bind( \
00254         &RC_CURRENT_USER_MODULE::func, this, \
00255         _1, p1, p2, p3, p4, p5, p6, p7, p8, p9)
00256 
00257 #define RC_SYNC_CALLBACK10(func, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) \
00258     rc_bind( \
00259         &RC_CURRENT_USER_MODULE::func, this, \
00260         _1, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)
00261 
00262 #endif // RC_ABSTRACT_PRIM_FILTER_H_
00263 
00264 //
00265 // $Id: rc_abstract_prim_filter.h,v 1.6 2008/01/01 13:50:07 felke Exp $
00266 // $Source: /var/cvs/projekte/ReChannel-v2/src/ReChannel/communication/filters/rc_abstract_prim_filter.h,v $
00267 //

Generated on Tue Jan 1 23:13:31 2008 for ReChannel by  doxygen 1.5.3