src/simulator/scheduler.h
changeset 47 48cb60c9eeba
parent 46 627df4c75852
child 53 ae406f4957d5
equal deleted inserted replaced
46:627df4c75852 47:48cb60c9eeba
    27 
    27 
    28 namespace ns3 {
    28 namespace ns3 {
    29 
    29 
    30 class EventImpl;
    30 class EventImpl;
    31 
    31 
       
    32 /**
       
    33  * \brief Maintain the event list
       
    34  *
       
    35  * This base class specifies the interface used to maintain the 
       
    36  * event list. If you want to provide a new event list scheduler, 
       
    37  * you need to create a subclass of this base class and implement 
       
    38  * all the private pure virtual methods defined here. Namely:
       
    39  *   - ns3::Scheduler::real_insert
       
    40  *   - ns3::Scheduler::real_is_empty
       
    41  *   - ns3::Scheduler::real_peek_next
       
    42  *   - ns3::Scheduler::real_peek_next_key
       
    43  *   - ns3::Scheduler::real_remove_next
       
    44  *   - ns3::Scheduler::real_remove
       
    45  *   - ns3::Scheduler::real_is_valid
       
    46  *
       
    47  * If you need to provide a new event list scheduler without
       
    48  * editing the main simulator class, you need to also implement
       
    49  * a subclass of the ns3::SchedulerFactory base class and
       
    50  * feed it to ns3::Simulator::set_external.
       
    51  */
    32 class Scheduler {
    52 class Scheduler {
    33  public:
    53  public:
    34 	struct EventKey {
    54 	struct EventKey {
    35 		uint64_t m_ns;
    55 		uint64_t m_ns;
    36 		uint32_t m_uid;
    56 		uint32_t m_uid;
    49 	void remove_next (void);
    69 	void remove_next (void);
    50 	EventImpl *remove (EventId id, EventKey *key);
    70 	EventImpl *remove (EventId id, EventKey *key);
    51 	bool is_valid (EventId id);
    71 	bool is_valid (EventId id);
    52 
    72 
    53 private:
    73 private:
       
    74 	/**
       
    75 	 * \param event event to store in the event list
       
    76 	 * \param key timecode associated to this new event
       
    77 	 * \returns an event id which identifies the event inserted
       
    78 	 *
       
    79 	 * This method takes ownership of the event pointer.
       
    80 	 */
    54 	virtual EventId real_insert (EventImpl *event, EventKey key) = 0;
    81 	virtual EventId real_insert (EventImpl *event, EventKey key) = 0;
       
    82 	/**
       
    83 	 * \returns true if the event list is empty and false otherwise.
       
    84 	 */
    55 	virtual bool real_is_empty (void) const = 0;
    85 	virtual bool real_is_empty (void) const = 0;
       
    86 	/**
       
    87 	 * \returns a pointer to the next earliest event. The caller
       
    88 	 *          takes ownership of the returned pointer.
       
    89 	 *
       
    90 	 * This method cannot be invoked if the list is empty.
       
    91 	 */
    56 	virtual EventImpl *real_peek_next (void) const = 0;
    92 	virtual EventImpl *real_peek_next (void) const = 0;
       
    93 	/**
       
    94 	 * \returns the timecode associated with the next earliest event.
       
    95 	 *
       
    96 	 * This method cannot be invoked if the list is empty.
       
    97 	 */
    57 	virtual Scheduler::EventKey real_peek_next_key (void) const = 0;
    98 	virtual Scheduler::EventKey real_peek_next_key (void) const = 0;
       
    99 	/**
       
   100 	 * This method cannot be invoked if the list is empty.
       
   101 	 * Remove the next earliest event from the event list.
       
   102 	 */
    58 	virtual void real_remove_next (void) = 0;
   103 	virtual void real_remove_next (void) = 0;
       
   104 	/**
       
   105 	 * \param id the id of the event to remove
       
   106 	 * \param key the timecode of the event removed
       
   107 	 * \returns a pointer to the event removed. The caller
       
   108 	 *          takes ownership of the returned pointer.
       
   109 	 *
       
   110 	 * This methods cannot be invoked if the list is empty.
       
   111 	 */
    59 	virtual EventImpl *real_remove (EventId id, EventKey *key) = 0;
   112 	virtual EventImpl *real_remove (EventId id, EventKey *key) = 0;
       
   113 	/**
       
   114 	 * \param id event id to validate
       
   115 	 * \returns true if the event id identifies an existing valid
       
   116 	 *          event stored in the event list and false otherwise.
       
   117 	 */
    60 	virtual bool real_is_valid (EventId id) = 0;
   118 	virtual bool real_is_valid (EventId id) = 0;
    61 };
   119 };
    62 
   120 
    63 }; // namespace ns3
   121 }; // namespace ns3
    64 
   122