00001 /***************************************************************************** 00002 00003 The following code is derived, directly or indirectly, from the SystemC 00004 source code Copyright (c) 1996-2006 by all Contributors. 00005 All Rights reserved. 00006 00007 The contents of this file are subject to the restrictions and limitations 00008 set forth in the SystemC Open Source License Version 2.4 (the "License"); 00009 You may not use this file except in compliance with such restrictions and 00010 limitations. You may obtain instructions on how to receive a copy of the 00011 License at http://www.systemc.org/. Software distributed by Contributors 00012 under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF 00013 ANY KIND, either express or implied. See the License for the specific 00014 language governing rights and limitations under the License. 00015 00016 *****************************************************************************/ 00017 00018 /***************************************************************************** 00019 00020 sc_export.h -- Base classes of all export classes. 00021 00022 Original Author: Andy Goodrich, Forte Design Systems 00023 Bishnupriya Bhattacharya, Cadence Design Systems 00024 00025 *****************************************************************************/ 00026 00027 /***************************************************************************** 00028 00029 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 00030 changes you are making here. 00031 00032 Name, Affiliation, Date: 00033 Description of Modification: 00034 00035 *****************************************************************************/ 00036 00037 // $Log: sc_export.h,v $ 00038 // Revision 1.1.1.1 2006/12/15 20:31:35 acg 00039 // SystemC 2.2 00040 // 00041 // Revision 1.3 2006/01/13 18:47:42 acg 00042 // Added $Log command so that CVS comments are reproduced in the source. 00043 // 00044 00045 #ifndef SC_EXPORT_H 00046 #define SC_EXPORT_H 00047 #include <typeinfo> 00048 00049 #include "sysc/communication/sc_communication_ids.h" 00050 #include "sysc/communication/sc_interface.h" 00051 #include "sysc/kernel/sc_object.h" 00052 00053 namespace sc_core { 00054 00055 //============================================================================= 00056 // CLASS : sc_export_base 00057 // 00058 // Abstract base class for class sc_export<IF>. 00059 //============================================================================= 00060 00061 class sc_export_base : public sc_object 00062 { 00063 friend class sc_export_registry; 00064 public: 00065 00066 // typedefs 00067 00068 typedef sc_export_base this_type; 00069 00070 public: 00071 00072 virtual sc_interface* get_interface() = 0; 00073 virtual const sc_interface* get_interface() const = 0; 00074 00075 protected: 00076 00077 // constructors 00078 00079 sc_export_base(); 00080 sc_export_base(const char* name); 00081 00082 // destructor 00083 00084 virtual ~sc_export_base(); 00085 00086 protected: 00087 00088 // called when construction is done 00089 virtual void before_end_of_elaboration(); 00090 00091 // called when elaboration is done (does nothing by default) 00092 virtual void end_of_elaboration(); 00093 00094 // called before simulation starts (does nothing by default) 00095 virtual void start_of_simulation(); 00096 00097 // called after simulation ends (does nothing) 00098 virtual void end_of_simulation(); 00099 00100 virtual const char* if_typename() const = 0; 00101 00102 private: 00103 00104 // disabled 00105 sc_export_base(const this_type&); 00106 this_type& operator = (const this_type& ); 00107 00108 }; 00109 00110 //============================================================================= 00111 // CLASS : sc_export 00112 // 00113 // Generic export class for other export classes. This 00114 // class provides a binding point for access to an interface. 00115 //============================================================================= 00116 template<class IF> 00117 class sc_export : public sc_export_base 00118 { 00119 typedef sc_export<IF> this_type; 00120 00121 public: // constructors: 00122 sc_export() : sc_export_base() 00123 { 00124 m_interface_p = 0; 00125 } 00126 00127 explicit sc_export( const char* name_ ) : sc_export_base(name_) 00128 { 00129 m_interface_p = 0; 00130 } 00131 00132 public: // destructor: 00133 virtual ~sc_export() 00134 { 00135 } 00136 00137 public: // interface access: 00138 00139 virtual sc_interface* get_interface() 00140 { 00141 return m_interface_p; 00142 } 00143 00144 virtual const sc_interface* get_interface() const 00145 { 00146 return m_interface_p; 00147 } 00148 00149 const IF* operator -> () const { 00150 if ( m_interface_p == 0 ) 00151 { 00152 SC_REPORT_ERROR(SC_ID_SC_EXPORT_HAS_NO_INTERFACE_,name()); 00153 } 00154 return m_interface_p; 00155 } 00156 00157 IF* operator -> () { 00158 if ( m_interface_p == 0 ) 00159 { 00160 SC_REPORT_ERROR(SC_ID_SC_EXPORT_HAS_NO_INTERFACE_,name()); 00161 } 00162 return m_interface_p; 00163 } 00164 00165 operator IF& () 00166 { 00167 if ( m_interface_p == 0 ) 00168 { 00169 SC_REPORT_ERROR(SC_ID_SC_EXPORT_HAS_NO_INTERFACE_,name()); 00170 } 00171 return *m_interface_p; 00172 } 00173 00174 public: // binding: 00175 void bind( IF& interface_ ) 00176 { 00177 if ( m_interface_p ) 00178 { 00179 SC_REPORT_ERROR(SC_ID_SC_EXPORT_ALREADY_BOUND_,name()); 00180 } 00181 else 00182 { 00183 m_interface_p = &interface_; 00184 } 00185 } 00186 00187 void operator () ( IF& interface_ ) 00188 { 00189 if ( m_interface_p ) 00190 { 00191 SC_REPORT_ERROR(SC_ID_SC_EXPORT_ALREADY_BOUND_,name()); 00192 } 00193 else 00194 { 00195 m_interface_p = &interface_; 00196 } 00197 } 00198 00199 public: // identification: 00200 virtual const char* kind() const { return "sc_export"; } 00201 00202 protected: 00203 const char* if_typename() const { 00204 return typeid( IF ).name(); 00205 } 00206 00207 private: // disabled 00208 sc_export( const this_type& ); 00209 this_type& operator = ( const this_type& ); 00210 00211 protected: // data fields: 00212 IF* m_interface_p; // Interface this port provides. 00213 }; 00214 00215 // ---------------------------------------------------------------------------- 00216 // CLASS : sc_export_registry 00217 // 00218 // Registry for all exports. 00219 // FOR INTERNAL USE ONLY! 00220 // ---------------------------------------------------------------------------- 00221 00222 class sc_export_registry 00223 { 00224 friend class sc_simcontext; 00225 00226 public: 00227 00228 void insert( sc_export_base* ); 00229 void remove( sc_export_base* ); 00230 00231 int size() const 00232 { return m_export_vec.size(); } 00233 00234 private: 00235 00236 // constructor 00237 explicit sc_export_registry( sc_simcontext& simc_ ); 00238 00239 // destructor 00240 ~sc_export_registry(); 00241 00242 // called when construction is done 00243 void construction_done(); 00244 00245 // called when elaboration is done 00246 void elaboration_done(); 00247 00248 // called before simulation starts 00249 void start_simulation(); 00250 00251 // called after simulation ends 00252 void simulation_done(); 00253 00254 private: 00255 00256 sc_simcontext* m_simc; 00257 std::vector<sc_export_base*> m_export_vec; 00258 00259 private: 00260 00261 // disabled 00262 sc_export_registry(); 00263 sc_export_registry( const sc_export_registry& ); 00264 sc_export_registry& operator = ( const sc_export_registry& ); 00265 }; 00266 00267 } // namespace sc_core 00268 00269 #endif 00270 00271 // Taf!