rc_interface_wrapper.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_INTERFACE_WRAPPER_H_
00038 #define RC_INTERFACE_WRAPPER_H_
00039 
00040 #include "ReChannel/core/rc_interface_filter.h"
00041 #include "ReChannel/core/rc_process.h"
00042 #include "ReChannel/util/rc_driver_object.h"
00043 #include "ReChannel/util/rc_member_func.h"
00044 #include "ReChannel/util/rc_port_handle.h"
00045 
00046 #include "ReChannel/communication/rc_event_forwarder.h"
00047 
00048 namespace ReChannel {
00049 
00053 class rc_interface_wrapper_base
00054 {
00055 public:
00056     class accessor_base;
00057 
00058 protected:
00059     class access_base;
00060 
00061 public:
00062     virtual std::string get_interface_wrapper_name() const = 0;
00063 
00064     virtual void register_port(
00065         sc_port_base& port_, const char* if_typename) = 0;
00066 
00067     virtual sc_interface& get_wrapped_interface() const = 0;
00068 
00069     virtual rc_event_forwarder_host* get_event_forwarder_host() = 0;
00070 
00071     virtual ~rc_interface_wrapper_base() {}
00072 
00073 protected:
00074     virtual bool set_wrapped_interface(sc_interface& if_) = 0;
00075 
00076     virtual rc_process_behavior_change begin_access_callback() = 0;
00077 
00078     virtual void end_access_callback() = 0;
00079 };
00080 
00084 class rc_interface_wrapper_base::access_base
00085 {
00086 public:
00087     access_base() { }
00088 
00089 protected:
00090     inline rc_process_behavior_change
00091         begin_access(rc_interface_wrapper_base& wrapper) const
00092         { return wrapper.begin_access_callback(); }
00093 
00094     inline void end_access(rc_interface_wrapper_base& wrapper) const
00095         { wrapper.end_access_callback(); }
00096 };
00097 
00101 class rc_interface_wrapper_base::accessor_base
00102     : virtual public rc_interface_filter,
00103       virtual protected rc_event_filter
00104 {
00105 public:
00106     virtual rc_interface_wrapper_base*
00107         rc_get_target_wrapper_base() const = 0;
00108 
00109     virtual bool rc_set_target(rc_interface_wrapper_base& target) = 0;
00110 
00111     virtual sc_interface* rc_get_target_interface() const = 0;
00112 
00113     virtual bool rc_set_target(sc_interface& target) = 0;
00114 
00115     virtual bool rc_set_target(
00116         sc_interface& target, const rc_process_control& pctrl) = 0;
00117 
00118     virtual void rc_clear_target() = 0;
00119 
00120     virtual int rc_get_bound_port_count() const = 0;
00121 
00122     virtual sc_port_base* rc_get_bound_port(int index) const = 0;
00123 
00124     virtual rc_event_filter* rc_get_event_filter() = 0;
00125 
00126 protected:
00127     virtual bool rc_on_event(const sc_event& e) = 0;
00128 
00129     virtual void rc_set_event_trigger(
00130         const sc_event& e, rc_event_trigger& t) = 0;
00131 
00132     virtual void rc_clear_event_trigger(const sc_event& e) = 0;
00133 };
00134 
00138 template<class IF>
00139 class rc_interface_wrapper
00140     : virtual public rc_interface_wrapper_base
00141 {
00142     RC_STATIC_ASSERT_VALID_INTERFACE(IF);
00143 
00144 public:
00145     class accessor;
00146 
00147 protected:
00148     class nb_interface_access;
00149     class interface_access;
00150     class nb_driver_access;
00151     class driver_access;
00152 
00153 public:
00154     virtual interface_access get_interface_access() = 0;
00155 
00156     virtual nb_interface_access get_nb_interface_access() = 0;
00157 
00158     virtual driver_access get_driver_access(int driver_index) = 0;
00159 
00160     virtual nb_driver_access get_nb_driver_access(int driver_index) = 0;
00161 
00162     virtual accessor* create_accessor() const = 0;
00163 
00164     virtual int get_driver_count() const = 0;
00165 
00166     virtual int get_nb_driver_count() const = 0;
00167 
00168 protected:
00169     virtual bool set_wrapped_interface(IF& if_) = 0;
00170 
00171     virtual IF* nb_interface_access_callback() = 0;
00172 
00173     virtual IF* interface_access_callback() = 0;
00174 
00175     virtual typename rc_nb_driver_object<IF>::driver_access*
00176         nb_driver_access_callback(int driver_index) = 0;
00177 
00178     virtual typename rc_driver_object<IF>::driver_access*
00179         driver_access_callback(int driver_index) = 0;
00180 };
00181 
00185 template<class IF>
00186 class rc_interface_wrapper<IF>::accessor
00187     : virtual public rc_interface_wrapper_base::accessor_base,
00188       virtual public IF
00189 {
00190     RC_STATIC_ASSERT_VALID_INTERFACE(IF);
00191 
00192 protected:
00193     typedef typename rc_interface_wrapper<IF>::interface_access
00194         interface_access;
00195     typedef typename rc_interface_wrapper<IF>::nb_interface_access
00196         nb_interface_access;
00197     typedef typename rc_interface_wrapper<IF>::driver_access
00198         driver_access;
00199     typedef typename rc_interface_wrapper<IF>::nb_driver_access
00200         nb_driver_access;
00201 
00202 public:
00203     typedef rc_interface_wrapper<IF> interface_wrapper;
00204 
00205 public:
00206     virtual interface_wrapper* rc_get_target_wrapper() const = 0;
00207 
00208     virtual bool rc_set_target(interface_wrapper& target) = 0;
00209 
00210     virtual bool rc_set_target(IF& target) = 0;
00211 
00212     virtual bool rc_set_target(
00213         IF& target, const rc_process_control& pctrl) = 0;
00214 };
00215 
00219 template<class IF>
00220 class rc_interface_wrapper<IF>::nb_interface_access
00221     : public rc_interface_wrapper_base::access_base
00222 {
00223 public:
00224     inline explicit nb_interface_access(rc_interface_wrapper<IF>& wrapper)
00225         : p_wrapper(wrapper)
00226     { }
00227 
00228     inline IF* operator->() const
00229         { return p_wrapper.nb_interface_access_callback(); }
00230 
00231     template<class METHOD_PTR>
00232     inline rc_member_func<METHOD_PTR> operator->*(METHOD_PTR mp) const
00233     {
00234         return rc_member_func<METHOD_PTR>(
00235             *p_wrapper.nb_interface_access_callback(), mp);
00236     }
00237 
00238 private:
00239     rc_interface_wrapper<IF>& p_wrapper;
00240 };
00241 
00245 template<class IF>
00246 class rc_interface_wrapper<IF>::interface_access
00247     : public rc_interface_wrapper_base::access_base
00248 {
00249 public:
00250     inline explicit interface_access(rc_interface_wrapper<IF>& wrapper)
00251         : p_wrapper(wrapper),
00252           p_process_behavior_change(begin_access(wrapper))
00253     { }
00254 
00255     inline IF* operator->() const
00256         { return p_wrapper.interface_access_callback(); }
00257 
00258     template<class METHOD_PTR>
00259     inline
00260     rc_member_func<METHOD_PTR> operator->*(METHOD_PTR mp) const
00261     {
00262         return rc_member_func<METHOD_PTR>(
00263             *p_wrapper.interface_access_callback(), mp);
00264     }
00265 
00266     inline ~interface_access()
00267         { end_access(p_wrapper); }
00268 
00269 private:
00270     rc_interface_wrapper<IF>&        p_wrapper;
00271     const rc_process_behavior_change p_process_behavior_change;
00272 };
00273 
00277 template<class IF>
00278 class rc_interface_wrapper<IF>::nb_driver_access
00279     : public rc_interface_wrapper_base::access_base
00280 {
00281 public:
00282     inline nb_driver_access(
00283         rc_interface_wrapper<IF>& wrapper, int driver_index)
00284         : p_wrapper(wrapper), p_driver_index(driver_index)
00285     { }
00286 
00287     inline
00288     typename rc_nb_driver_object<IF>::driver_access* operator->() const
00289         { return p_wrapper.nb_driver_access_callback(p_driver_index); }
00290 
00291 private:
00292     rc_interface_wrapper<IF>& p_wrapper;
00293     const int                 p_driver_index;
00294 };
00295 
00299 template<class IF>
00300 class rc_interface_wrapper<IF>::driver_access
00301     : public rc_interface_wrapper_base::access_base
00302 {
00303 public:
00304     inline driver_access(
00305         rc_interface_wrapper<IF>& wrapper, int driver_index)
00306         : p_wrapper(wrapper), p_driver_index(driver_index),
00307           p_process_behavior_change(begin_access(wrapper))
00308     { }
00309 
00310     inline
00311     typename rc_driver_object<IF>::driver_access* operator->() const
00312         { return p_wrapper.driver_access_callback(p_driver_index); }
00313 
00314     inline ~driver_access()
00315         { end_access(p_wrapper); }
00316 
00317 private:
00318     rc_interface_wrapper<IF>&        p_wrapper;
00319     const int                        p_driver_index;
00320     const rc_process_behavior_change p_process_behavior_change;
00321 };
00322 
00323 } // namespace ReChannel
00324 
00325 #endif //RC_INTERFACE_WRAPPER_H_
00326 
00327 //
00328 // $Id: rc_interface_wrapper.h,v 1.13 2008/01/01 13:48:36 felke Exp $
00329 // $Source: /var/cvs/projekte/ReChannel-v2/src/ReChannel/communication/rc_interface_wrapper.h,v $
00330 //
00331 

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