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_wrapper_pool.h" 00038 00039 namespace ReChannel { 00040 namespace internals { 00041 namespace exportal { 00042 00043 wrapper_pool::~wrapper_pool() 00044 { 00045 for(if_wrapper_multimap::iterator it = p_if_wrapper_multimap.begin(); 00046 it != p_if_wrapper_multimap.end(); 00047 ++it) 00048 { 00049 delete it->second; 00050 } 00051 p_if_wrapper_multimap.clear(); 00052 } 00053 00054 wrapper_handle wrapper_pool::get( 00055 sc_interface& wrapped_if, wrapper_factory* factory) 00056 { 00057 rc_interface_wrapper_base* wrapper = NULL; 00058 00059 if_wrapper_multimap::iterator it = 00060 p_if_wrapper_multimap.find(&wrapped_if); 00061 if (it != p_if_wrapper_multimap.end()) { 00062 wrapper = it->second; 00063 p_if_wrapper_multimap.erase(it); 00064 } 00065 if (wrapper == NULL && factory != NULL) { 00066 wrapper = factory->create_interface_wrapper(wrapped_if); 00067 } 00068 if (wrapper != NULL) { 00069 ++p_num_taken; 00070 } 00071 return wrapper_handle(*this, wrapper); 00072 } 00073 00074 void wrapper_pool::add( 00075 rc_interface_wrapper_base& wrapper) 00076 { 00077 sc_interface& wrapped_if = wrapper.get_wrapped_interface(); 00078 p_if_wrapper_multimap.insert( 00079 if_wrapper_multimap::value_type(&wrapped_if, &wrapper)); 00080 } 00081 00082 void wrapper_pool::release( 00083 wrapper_handle& wrapper_handle_) 00084 { 00085 assert(wrapper_handle_.p_wrapper_pool == this); 00086 00087 rc_interface_wrapper_base* wrapper = wrapper_handle_.p_wrapper; 00088 if (wrapper != NULL) { 00089 sc_interface& wrapped_if = wrapper->get_wrapped_interface(); 00090 p_if_wrapper_multimap.insert( 00091 if_wrapper_multimap::value_type(&wrapped_if, wrapper)); 00092 if (p_num_taken > 0) { 00093 --p_num_taken; 00094 } 00095 } 00096 wrapper_handle_.p_wrapper_pool = NULL; 00097 } 00098 00099 wrapper_handle& wrapper_handle::operator=( 00100 wrapper_handle& orig) 00101 { 00102 this->release(); 00103 if (orig.p_wrapper != NULL) { 00104 p_wrapper_pool = orig.p_wrapper_pool; 00105 p_wrapper = orig.p_wrapper; 00106 orig.p_wrapper = NULL; 00107 } 00108 return *this; 00109 } 00110 00111 wrapper_handle& wrapper_handle::operator=( 00112 rc_interface_wrapper_base* wrapper) 00113 { 00114 this->release(); 00115 p_wrapper = wrapper; 00116 return *this; 00117 } 00118 00119 } // namespace exportal 00120 } // namespace internals 00121 } // namespace ReChannel 00122 00123 // 00124 // $Id: rc_wrapper_pool.cpp,v 1.1 2007/12/06 12:12:06 felke Exp $ 00125 // $Source: /var/cvs/projekte/ReChannel-v2/src/ReChannel/communication/exportals/rc_wrapper_pool.cpp,v $ 00126 //