00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 #if !defined(sc_process_handle_h_INCLUDED)
00038 #define sc_process_handle_h_INCLUDED
00039 
00040 #include "sysc/kernel/sc_module.h"
00041 
00042 namespace sc_core {
00043 
00044 
00045 
00046 class sc_process_handle;
00047 bool 
00048 operator == ( const sc_process_handle& left, const sc_process_handle& right );
00049 bool 
00050 operator != ( const sc_process_handle& left, const sc_process_handle& right );
00051 bool 
00052 operator < ( const sc_process_handle& left, const sc_process_handle& right );
00053 
00054 
00055 
00056 
00063 class sc_simcontext;
00064 class sc_process_handle {
00065     typedef sc_process_handle this_type;
00066 
00067     friend bool operator == ( const this_type& left, const this_type& right );
00068     friend bool operator != ( const this_type& left, const this_type& right );
00069     friend bool operator < ( const this_type& left, const this_type& right );
00070     friend class sc_object;
00071     friend class sc_join;
00072     friend class sc_module;
00073 
00074     
00075     friend class sc_channel;
00076 
00077     friend class sc_reset;
00078     friend class sc_sensitive;
00079     friend class sc_sensitive_pos;
00080     friend class sc_sensitive_neg;
00081     friend class sc_thread_process;
00082 
00083   public:
00084     inline sc_process_handle();
00085     inline explicit sc_process_handle( sc_object* object_p );
00086     inline explicit sc_process_handle( sc_process_b* process_p );
00087     inline sc_process_handle( const sc_process_handle& orig );
00088     inline ~sc_process_handle();
00089     inline sc_process_handle& operator = ( sc_process_handle src );
00090     inline void swap( sc_process_handle& other );
00091 
00092   public:
00093     inline void disable(
00094         sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS );
00095     inline bool dynamic() const;
00096     inline void enable(
00097         sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS );
00098     inline const std::vector<sc_event*>& get_child_events() const;
00099     inline const std::vector<sc_object*>& get_child_objects() const;
00100     inline sc_object* get_parent_object() const;
00101     inline sc_object* get_process_object() const;
00102     inline bool is_unwinding() const;
00103     inline void kill( 
00104         sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS );
00105     inline const char* name() const;
00106     inline sc_curr_proc_kind proc_kind() const;
00107     inline void reset( 
00108         sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS );
00109     inline sc_event& reset_event() const;
00110     inline void resume(
00111         sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS );
00112     inline void suspend(
00113         sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS );
00114     inline void sync_reset_off( 
00115         sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS );
00116     inline void sync_reset_on( 
00117         sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS );
00118     inline sc_event& terminated_event();
00119     inline bool terminated() const;
00120     template<typename EXCEPT>
00121     inline void throw_it( const EXCEPT& exception,
00122         sc_descendant_inclusion_info descendants=SC_NO_DESCENDANTS );
00123     inline bool valid() const;
00124 
00125   public: 
00126     inline std::string dump_state() const;
00127 
00128   protected:
00129     inline bool dont_initialize() const 
00130         { return m_target_p ? m_target_p->dont_initialize() : false; }
00131     inline void dont_initialize( bool dont );
00132 
00133   public:
00134     operator sc_process_b* () 
00135         { return m_target_p; }
00136     operator sc_cthread_handle ();
00137     operator sc_method_handle ();
00138     operator sc_thread_handle ();  
00139 
00140   protected:
00141     sc_process_b* m_target_p;   
00142 
00143   protected:
00144     static std::vector<sc_event*>  empty_event_vector;  
00145     static std::vector<sc_object*> empty_object_vector; 
00146     static sc_event                non_event;           
00147 };
00148 
00149 inline bool operator == ( 
00150     const sc_process_handle& left, const sc_process_handle& right )
00151 {
00152     return (left.m_target_p != 0) && (right.m_target_p != 0) &&
00153         (left.m_target_p == right.m_target_p);
00154 }
00155 
00156 inline bool operator != ( 
00157     const sc_process_handle& left, const sc_process_handle& right )
00158 {
00159     return (left.m_target_p == 0) || (right.m_target_p == 0) ||
00160         (left.m_target_p != right.m_target_p);
00161 }
00162 
00163 inline bool operator < (
00164     const sc_process_handle& left, const sc_process_handle& right )
00165 {
00166     return left.m_target_p < right.m_target_p;
00167 }
00168 
00169 
00170 
00171 
00172 
00173 
00174 
00175 inline sc_process_handle::sc_process_handle() : m_target_p(0)
00176 {
00177 }
00178 
00179 
00180 
00181 
00182 
00183 
00184 
00185 
00186 
00187 inline sc_process_handle::sc_process_handle( sc_object* object_p ) :
00188     m_target_p(DCAST<sc_process_b*>(object_p))
00189 {
00190     if ( m_target_p ) m_target_p->reference_increment();
00191 }
00192 
00193 
00194 
00195 
00196 
00197 
00198 
00199 
00200 
00201 inline sc_process_handle::sc_process_handle( sc_process_b* process_p ) :
00202   m_target_p(process_p)
00203 {
00204   if ( m_target_p ) m_target_p->reference_increment();
00205 }
00206 
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00215 inline sc_process_handle::sc_process_handle( const sc_process_handle& orig ) :
00216     m_target_p(orig.m_target_p)
00217 {
00218     if ( m_target_p ) m_target_p->reference_increment();
00219 }
00220 
00221 
00222 
00223 
00224 
00225 
00226 
00227 
00228 
00229 
00230 
00231 
00232 
00233 
00234 
00235 
00236 inline sc_process_handle& 
00237 sc_process_handle::operator = ( sc_process_handle orig )
00238 {
00239     swap( orig );
00240     return *this;
00241 }
00242 
00243 
00244 
00245 
00246 
00247 
00248 
00249 
00250 inline sc_process_handle::~sc_process_handle()
00251 {
00252     if ( m_target_p ) m_target_p->reference_decrement();
00253 }
00254 
00255 
00256 
00257 
00258 
00259 
00260 
00261 
00262 
00263 inline void sc_process_handle::disable(sc_descendant_inclusion_info descendants)
00264 {
00265     if ( m_target_p ) 
00266         m_target_p->disable_process(descendants);
00267     else
00268         SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "disable()");
00269 }
00270 
00271 
00272 
00273 inline void sc_process_handle::dont_initialize( bool dont )
00274 {
00275     if ( m_target_p ) 
00276         m_target_p->dont_initialize( dont );
00277     else
00278         SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "dont_initialize()");
00279 }
00280 
00281 
00282 
00283 inline std::string sc_process_handle::dump_state() const
00284 {
00285     return m_target_p ? m_target_p->dump_state() : std::string("NO TARGET");
00286 }
00287 
00288 
00289 
00290 inline bool sc_process_handle::dynamic() const
00291 {
00292     return  m_target_p ?  m_target_p->dynamic() : false;
00293 }
00294 
00295 
00296 
00297 inline void sc_process_handle::enable(sc_descendant_inclusion_info descendants)
00298 {
00299     if ( m_target_p ) 
00300         m_target_p->enable_process(descendants);
00301     else
00302         SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "enable()");
00303 }
00304 
00305 
00306 
00307 inline 
00308 const std::vector<sc_event*>& sc_process_handle::get_child_events() const
00309 {
00310     return m_target_p ?  m_target_p->get_child_events() : empty_event_vector;
00311 }
00312 
00313 
00314 
00315 inline 
00316 const std::vector<sc_object*>& sc_process_handle::get_child_objects() const
00317 {
00318     return m_target_p ?  m_target_p->get_child_objects() : empty_object_vector;
00319 }
00320 
00321 
00322 
00323 inline sc_object* sc_process_handle::get_parent_object() const
00324 {
00325     return m_target_p ?  m_target_p->get_parent_object() : NULL;
00326 }
00327 
00328 
00329 
00330 inline sc_object* sc_process_handle::get_process_object() const
00331 {
00332     return m_target_p;
00333 }
00334 
00335 
00336 
00337 inline bool sc_process_handle::is_unwinding() const
00338 {
00339     if ( m_target_p )
00340         return m_target_p->is_unwinding();
00341     else {
00342         SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "is_unwinding()");
00343         return false;
00344     }
00345 }
00346 
00347 
00348 
00349 inline void sc_process_handle::kill( sc_descendant_inclusion_info descendants )
00350 {
00351     if ( m_target_p ) 
00352         m_target_p->kill_process( descendants );
00353     else
00354         SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "kill()");
00355 }
00356 
00357 
00358 
00359 inline const char* sc_process_handle::name() const
00360 {
00361     return  m_target_p ? m_target_p->name() : ""; 
00362 }
00363 
00364 
00365 
00366 inline sc_curr_proc_kind sc_process_handle::proc_kind() const
00367 {
00368     return m_target_p ?  m_target_p->proc_kind() : SC_NO_PROC_;
00369 }
00370 
00371 
00372 
00373 inline void sc_process_handle::reset( sc_descendant_inclusion_info descendants )
00374 {
00375     if ( m_target_p ) 
00376         m_target_p->reset_process( sc_process_b::reset_asynchronous,
00377                                    descendants );
00378     else
00379         SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "reset()");
00380 }
00381 
00382 
00383 
00384 inline sc_event& sc_process_handle::reset_event() const
00385 {
00386     if ( m_target_p ) 
00387         return m_target_p->reset_event();
00388     else
00389     {
00390         SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "reset()");
00391         return sc_process_handle::non_event;
00392     }
00393 }
00394 
00395 
00396 
00397 inline void sc_process_handle::resume(sc_descendant_inclusion_info descendants)
00398 {
00399     if ( m_target_p ) 
00400         m_target_p->resume_process(descendants);
00401     else
00402         SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "resume()");
00403 }
00404 
00405 
00406 
00407 inline void sc_process_handle::suspend(sc_descendant_inclusion_info descendants)
00408 {
00409     if ( m_target_p ) 
00410         m_target_p->suspend_process(descendants);
00411     else
00412         SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "suspend()");
00413 }
00414 
00415 
00416 
00417 inline void sc_process_handle::swap( sc_process_handle& other )
00418 {
00419     sc_process_b* tmp = m_target_p;
00420     m_target_p = other.m_target_p;
00421     other.m_target_p = tmp;
00422 }
00423 
00424 
00425 
00426 inline void sc_process_handle::sync_reset_off(
00427     sc_descendant_inclusion_info descendants)
00428 {
00429     if ( m_target_p ) 
00430         m_target_p->reset_process( sc_process_b::reset_synchronous_off, 
00431                                    descendants);
00432     else
00433         SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "sync_reset_off()");
00434 }
00435 
00436 
00437 
00438 inline void sc_process_handle::sync_reset_on(
00439     sc_descendant_inclusion_info descendants)
00440 {
00441     if ( m_target_p ) 
00442     {
00443         m_target_p->reset_process(sc_process_b::reset_synchronous_on, 
00444             descendants);
00445     }
00446     else
00447     {
00448         SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "sync_reset_on()");
00449     }
00450 }
00451 
00452 
00453 
00454 inline bool sc_process_handle::terminated() const
00455 {
00456     return m_target_p ?  m_target_p->terminated() : false;
00457 }
00458 
00459 
00460 
00461 inline sc_event& sc_process_handle::terminated_event()
00462 {
00463     if ( m_target_p )
00464         return m_target_p->terminated_event();
00465     else
00466     {
00467         SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "terminated_event()");
00468         return sc_process_handle::non_event;
00469     }
00470 }
00471 
00472 
00473 
00474 inline bool sc_process_handle::valid() const
00475 {
00476     return m_target_p ? true : false;
00477 }
00478 
00479 
00480 
00481 
00482 
00483 
00484 
00485 
00486 
00487 
00488 
00489 
00490 
00491 
00492 
00493 
00494 
00495 
00496 
00497 template<typename EXCEPT>
00498 inline void sc_process_handle::throw_it( const EXCEPT& exception,
00499     sc_descendant_inclusion_info descendants)
00500 {
00501     sc_throw_it<EXCEPT> helper(exception);  
00502 
00503     if ( !m_target_p ) 
00504     {
00505         SC_REPORT_WARNING( SC_ID_EMPTY_PROCESS_HANDLE_, "throw_it()");
00506         return;
00507     }
00508     m_target_p->throw_user(helper, descendants);
00509 }
00510 
00511 
00512 
00513 
00514 
00515 
00516 
00517 inline sc_process_handle sc_process_b::last_created_process_handle()
00518 {
00519     return sc_process_handle(m_last_created_process_p);
00520 }
00521 
00522 inline sc_process_handle sc_get_last_created_process_handle()
00523 {
00524     return sc_process_b::last_created_process_handle();
00525 }
00526 
00527 } 
00528 
00529 
00530 
00531 
00532 
00533 
00534 
00535 
00536 
00537 
00538 
00539 
00540 
00541 
00542 
00543 
00544 
00545 
00546 
00547 
00548 
00549 
00550 
00551 
00552 
00553 
00554 
00555 
00556 
00557 
00558 
00559 
00560 
00561 
00562 
00563 
00564 
00565 
00566 
00567 
00568 
00569 
00570 
00571 
00572 
00573 
00574 
00575 
00576 
00577 
00578 
00579 
00580 
00581 
00582 
00583 
00584 
00585 
00586 
00587 
00588 
00589 
00590 
00591 
00592 
00593 
00594 
00595 
00596 
00597 
00598 
00599 
00600 
00601 
00602 
00603 
00604 
00605 
00606 
00607 
00608 
00609 
00610 #endif // !defined(sc_spawn_h_INCLUDED)