rc_wrapper_pool.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_WRAPPER_POOL_H_
00038 #define RC_WRAPPER_POOL_H_
00039 
00040 #include "ReChannel/core/rc_reconfigurable.h"
00041 #include "ReChannel/communication/rc_interface_wrapper.h"
00042 
00043 namespace ReChannel {
00044 namespace internals {
00045 namespace exportal {
00046 
00050 class wrapper_factory
00051 {
00052 public:
00053     virtual rc_interface_wrapper_base* create_interface_wrapper(
00054         sc_interface& wrapped_if) = 0;
00055 
00056 protected:
00057     virtual ~wrapper_factory() {}
00058 };
00059 
00060 class wrapper_handle;
00061 
00065 class wrapper_pool
00066 {
00067     friend class wrapper_handle;
00068 
00069 private:
00070     typedef std::set<wrapper_handle*> wrapper_handle_set; 
00071     typedef std::multimap<
00072                 sc_interface*,
00073                 rc_interface_wrapper_base*
00074             > if_wrapper_multimap;
00075     typedef std::pair<
00076                 if_wrapper_multimap::iterator,
00077                 if_wrapper_multimap::iterator
00078             > multimap_range;
00079 public:
00080 
00081     wrapper_handle get(
00082         sc_interface& wrapped_if, wrapper_factory* factory=NULL);
00083 
00084     void add(rc_interface_wrapper_base& wrapper);
00085 
00086     unsigned int size() const
00087     { return p_if_wrapper_multimap.size() + p_num_taken; }
00088 
00089     unsigned int available() const
00090         { return p_if_wrapper_multimap.size(); }
00091 
00092     unsigned int available(sc_interface& wrapped_if) const
00093         { return p_if_wrapper_multimap.count(&wrapped_if); }
00094 
00095     ~wrapper_pool();
00096 
00097 private:
00098     void release(wrapper_handle& wrapper_handle_);
00099 
00100 private:
00101 
00103     if_wrapper_multimap p_if_wrapper_multimap;
00104 
00106     unsigned int p_num_taken;
00107 };
00108 
00113 class wrapper_handle
00114 {
00115     friend class wrapper_pool;
00116 
00117 public:
00118     wrapper_handle(const wrapper_handle& orig)
00119         : p_wrapper_pool(orig.p_wrapper_pool), p_wrapper(orig.p_wrapper)
00120         { orig.p_wrapper = NULL; }
00121 
00122     wrapper_handle(rc_interface_wrapper_base* wrapper=NULL)
00123         : p_wrapper_pool(NULL), p_wrapper(wrapper)
00124         { }
00125 
00126     inline bool valid() const
00127         { return (p_wrapper != NULL); }
00128 
00129     inline rc_interface_wrapper_base* get_object() const
00130         { return p_wrapper; }
00131 
00132     inline rc_interface_wrapper_base& operator*()
00133         { return *p_wrapper; }
00134 
00135     inline rc_interface_wrapper_base* operator->()
00136         { return p_wrapper; }
00137 
00138     inline rc_interface_wrapper_base* operator->() const
00139         { return p_wrapper; }
00140 
00141     inline void release();
00142 
00143     wrapper_handle& operator=(wrapper_handle& orig);
00144 
00145     wrapper_handle& operator=(rc_interface_wrapper_base* wrapper);
00146 
00147     inline ~wrapper_handle()
00148         { this->release(); }
00149 
00150 private:
00151     wrapper_handle(
00152         wrapper_pool& wrapper_pool_, rc_interface_wrapper_base* wrapper_)
00153         : p_wrapper_pool(&wrapper_pool_), p_wrapper(wrapper_)
00154         { }
00155 
00156 private:
00157     mutable wrapper_pool*              p_wrapper_pool;
00158     mutable rc_interface_wrapper_base* p_wrapper;
00159 };
00160 
00161 inline void wrapper_handle::release()
00162 {
00163     if (p_wrapper_pool != NULL) {
00164         p_wrapper_pool->release(*this);
00165     }
00166     p_wrapper = NULL;
00167 }
00168 
00169 } // namespace exportal
00170 } // namespace internals
00171 } // namespace ReChannel
00172 
00173 #endif // RC_WRAPPER_POOL_H_
00174 //
00175 // $Id: rc_wrapper_pool.h,v 1.2 2008/01/01 13:46:06 felke Exp $
00176 // $Source: /var/cvs/projekte/ReChannel-v2/src/ReChannel/communication/exportals/rc_wrapper_pool.h,v $
00177 //

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