C:/ESLX/projects/TLMWG/tlm2/include/tlm/tlm_utils/peq_with_get.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2008 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 3.0 (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 #ifndef __PEQ_WITH_GET_H__
00019 #define __PEQ_WITH_GET_H__
00020 
00021 //#include "tlm.h"
00022 #include <systemc>
00023 #include <map>
00024 
00025 namespace tlm_utils {
00026 
00027 template <class PAYLOAD>
00028 class peq_with_get : public sc_core::sc_object
00029 {
00030 public:
00031   typedef PAYLOAD transaction_type;
00032   typedef std::pair<const sc_core::sc_time, transaction_type*> pair_type;
00033 
00034 public:
00035   peq_with_get(const char* name) : sc_core::sc_object(name)
00036   {
00037   }
00038 
00039   void notify(transaction_type& trans, sc_core::sc_time& t)
00040   {
00041     m_scheduled_events.insert(pair_type(t + sc_core::sc_time_stamp(), &trans));
00042     m_event.notify(t);
00043   }
00044 
00045   void notify(transaction_type& trans)
00046   {
00047     m_scheduled_events.insert(pair_type(sc_core::sc_time_stamp(), &trans));
00048     m_event.notify(); // immediate notification
00049   }
00050 
00051   // needs to be called until it returns 0
00052   transaction_type* get_next_transaction()
00053   {
00054     if (m_scheduled_events.empty()) {
00055       return 0;
00056     }
00057 
00058     sc_core::sc_time now = sc_core::sc_time_stamp();
00059     if (m_scheduled_events.begin()->first <= now) {
00060       transaction_type* trans = m_scheduled_events.begin()->second;
00061       m_scheduled_events.erase(m_scheduled_events.begin());
00062       return trans;
00063     }
00064 
00065     m_event.notify(m_scheduled_events.begin()->first - now);
00066     
00067     return 0;
00068   }
00069 
00070   sc_core::sc_event& get_event()
00071   {
00072     return m_event;
00073   }
00074 
00075 private:
00076   std::multimap<const sc_core::sc_time, transaction_type*> m_scheduled_events;
00077   sc_core::sc_event m_event;
00078 };
00079 
00080 }
00081 
00082 #endif

Generated on Thu Jun 5 17:43:04 2008 for TLM 2 by  doxygen 1.5.3