first cut at george's ideas on api
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sun Sep 03 12:24:04 2006 +0200 (2006-09-03)
changeset 259b3bb088c560
parent 24 706b1d903da9
child 26 011c8d27b674
first cut at george's ideas on api
SConstruct
samples/main-event.cc
samples/main-simulator.cc
src/common/pcap-writer.cc
src/common/static-speed-position.cc
src/simulator/event-id.cc
src/simulator/event-id.h
src/simulator/event-impl.cc
src/simulator/event-impl.h
src/simulator/event-tcc-test.cc
src/simulator/event-tcc.cc
src/simulator/event.h
src/simulator/event.tcc
src/simulator/scheduler-heap.cc
src/simulator/scheduler-heap.h
src/simulator/scheduler-list.cc
src/simulator/scheduler-list.h
src/simulator/scheduler-map.cc
src/simulator/scheduler-map.h
src/simulator/scheduler.h
src/simulator/simulator.cc
src/simulator/simulator.h
src/simulator/time.cc
src/simulator/time.h
utils/bench-simulator.cc
     1.1 --- a/SConstruct	Sat Sep 02 19:50:19 2006 +0200
     1.2 +++ b/SConstruct	Sun Sep 03 12:24:04 2006 +0200
     1.3 @@ -511,13 +511,13 @@
     1.4  ns3.add (simu)
     1.5  simu.add_dep ('core')
     1.6  simu.add_sources ([
     1.7 +	'time.cc',
     1.8 +	'event-id.cc',
     1.9  	'scheduler.cc', 
    1.10  	'scheduler-list.cc',
    1.11 -        'scheduler-heap.cc',
    1.12 -        'scheduler-map.cc',
    1.13 +	'scheduler-heap.cc',
    1.14 +	'scheduler-map.cc',
    1.15          'event-impl.cc',
    1.16 -        'event-tcc.cc',
    1.17 -        'event-tcc-test.cc',
    1.18          'simulator.cc',
    1.19  	])
    1.20  simu.add_headers ([
    1.21 @@ -527,10 +527,10 @@
    1.22  	'scheduler-list.h'
    1.23  	])
    1.24  simu.add_inst_headers ([
    1.25 -	'event.h',
    1.26 +	'time.h',
    1.27 +	'event-id.h',
    1.28  	'event-impl.h',
    1.29  	'simulator.h',
    1.30 -	'event.tcc'
    1.31  	])
    1.32  
    1.33  #
    1.34 @@ -625,12 +625,6 @@
    1.35  main_callback.add_dep ('core')
    1.36  main_callback.add_source ('main-callback.cc')
    1.37  
    1.38 -main_event = Ns3Module ('main-event', 'samples')
    1.39 -main_event.set_executable ()
    1.40 -ns3.add (main_event)
    1.41 -main_event.add_dep ('simulator')
    1.42 -main_event.add_source ('main-event.cc')
    1.43 -
    1.44  main_trace = Ns3Module ('main-trace', 'samples')
    1.45  ns3.add (main_trace)
    1.46  main_trace.add_dep ('common')
     2.1 --- a/samples/main-event.cc	Sat Sep 02 19:50:19 2006 +0200
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,42 +0,0 @@
     2.4 -/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
     2.5 -#include "ns3/event.h"
     2.6 -#include "ns3/event.tcc"
     2.7 -#include <iostream>
     2.8 -
     2.9 -using namespace ns3;
    2.10 -
    2.11 -class MyModel {
    2.12 -public:
    2.13 -	void deal_with_event (double event_value);
    2.14 -};
    2.15 -
    2.16 -void
    2.17 -MyModel::deal_with_event (double value)
    2.18 -{
    2.19 -	std::cout << "Member method received event." << std::endl;
    2.20 -}
    2.21 -
    2.22 -static void 
    2.23 -random_function (void)
    2.24 -{
    2.25 -	std::cout << "Function received event." << std::endl;
    2.26 -}
    2.27 -
    2.28 -
    2.29 -int main (int argc, char *argv[])
    2.30 -{
    2.31 -	Event ev;
    2.32 -	// create event to forward to random_function
    2.33 -	ev = make_event (&random_function);
    2.34 -	// set cancel bit to on
    2.35 -	ev.cancel ();
    2.36 -	// try to invoke the random_function through the event.
    2.37 -	// This does nothing since cancel bit is on.
    2.38 -	ev ();
    2.39 -	MyModel model;
    2.40 -	// create event to forward to MyModel::deal_with_event
    2.41 -	// on the class instance "model".
    2.42 -	ev = make_event (&MyModel::deal_with_event, &model, 10.0);
    2.43 -	// invoke member method through the event.
    2.44 -	ev ();
    2.45 -}
     3.1 --- a/samples/main-simulator.cc	Sat Sep 02 19:50:19 2006 +0200
     3.2 +++ b/samples/main-simulator.cc	Sun Sep 03 12:24:04 2006 +0200
     3.3 @@ -1,7 +1,6 @@
     3.4  /* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
     3.5 -#include "ns3/event.h"
     3.6 -#include "ns3/event.tcc"
     3.7  #include "ns3/simulator.h"
     3.8 +#include "ns3/time.h"
     3.9  #include <iostream>
    3.10  
    3.11  using namespace ns3;
    3.12 @@ -10,25 +9,26 @@
    3.13  public:
    3.14  	void start (void);
    3.15  private:
    3.16 -	void deal_with_event (double event_value);
    3.17 +	void deal_with_event (void);
    3.18  };
    3.19  
    3.20  void 
    3.21  MyModel::start (void)
    3.22  {
    3.23 -	Simulator::schedule_rel_s (10.0, make_event (&MyModel::deal_with_event, 
    3.24 -						  this, Simulator::now_s ()));
    3.25 +	Simulator::schedule (RelTimeS (10.0), 
    3.26 +			     &MyModel::deal_with_event, 
    3.27 +			     this);
    3.28  }
    3.29  void
    3.30 -MyModel::deal_with_event (double value)
    3.31 +MyModel::deal_with_event (void)
    3.32  {
    3.33 -	std::cout << "Member method received event at " << Simulator::now_s () << " started at " << value << std::endl;
    3.34 +	std::cout << "Member method received event at " << Simulator::now ().s () << " started at " << std::endl;
    3.35  }
    3.36  
    3.37  static void 
    3.38  random_function (MyModel *model)
    3.39  {
    3.40 -	std::cout << "random function received event at " << Simulator::now_s () << std::endl;
    3.41 +	std::cout << "random function received event at " << Simulator::now ().s () << std::endl;
    3.42  	model->start ();
    3.43  }
    3.44  
    3.45 @@ -37,8 +37,7 @@
    3.46  {
    3.47  	MyModel model;
    3.48  
    3.49 -	Simulator::schedule_rel_s (10.0, make_event (&random_function, 
    3.50 -						     &model));
    3.51 +	Simulator::schedule (AbsTimeS (10.0), &random_function, &model);
    3.52  
    3.53  	Simulator::run ();
    3.54  
     4.1 --- a/src/common/pcap-writer.cc	Sat Sep 02 19:50:19 2006 +0200
     4.2 +++ b/src/common/pcap-writer.cc	Sun Sep 03 12:24:04 2006 +0200
     4.3 @@ -69,7 +69,7 @@
     4.4  PcapWriter::write_packet (Packet const packet)
     4.5  {
     4.6  	if (m_writer != 0) {
     4.7 -		uint64_t current = Simulator::now_us ();
     4.8 +		uint64_t current = Simulator::now ().us ();
     4.9  		uint64_t s = current / 1000000;
    4.10  		uint64_t us = current % 1000000;
    4.11  		write_32 (s & 0xffffffff);
     5.1 --- a/src/common/static-speed-position.cc	Sat Sep 02 19:50:19 2006 +0200
     5.2 +++ b/src/common/static-speed-position.cc	Sun Sep 03 12:24:04 2006 +0200
     5.3 @@ -54,7 +54,7 @@
     5.4  void 
     5.5  StaticSpeedPosition::real_get (double &x, double &y, double &z) const
     5.6  {
     5.7 -	uint64_t now_us = Simulator::now_us ();
     5.8 +	uint64_t now_us = Simulator::now ().us ();
     5.9  	uint64_t delta_us = now_us - m_prev_us;
    5.10  	m_x += m_dx * delta_us;
    5.11  	m_y += m_dy * delta_us;
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/simulator/event-id.cc	Sun Sep 03 12:24:04 2006 +0200
     6.3 @@ -0,0 +1,64 @@
     6.4 +/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
     6.5 +/*
     6.6 + * Copyright (c) 2005 INRIA
     6.7 + * All rights reserved.
     6.8 + *
     6.9 + * This program is free software; you can redistribute it and/or modify
    6.10 + * it under the terms of the GNU General Public License version 2 as
    6.11 + * published by the Free Software Foundation;
    6.12 + *
    6.13 + * This program is distributed in the hope that it will be useful,
    6.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.16 + * GNU General Public License for more details.
    6.17 + *
    6.18 + * You should have received a copy of the GNU General Public License
    6.19 + * along with this program; if not, write to the Free Software
    6.20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    6.21 + *
    6.22 + * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
    6.23 + */
    6.24 +#include "event-id.h"
    6.25 +#include "simulator.h"
    6.26 +
    6.27 +namespace ns3 {
    6.28 +
    6.29 +EventId::EventId ()
    6.30 +	: m_event_impl (0),
    6.31 +	  m_time (0),
    6.32 +	  m_uid (0)
    6.33 +{}
    6.34 +    
    6.35 +EventId::EventId (EventImpl *impl, uint64_t time, uint32_t uid)
    6.36 +	: m_event_impl (impl),
    6.37 +	  m_time (time),
    6.38 +	  m_uid (uid)
    6.39 +{}
    6.40 +void 
    6.41 +EventId::cancel (void)
    6.42 +{
    6.43 +	Simulator::cancel (*this);
    6.44 +}
    6.45 +bool 
    6.46 +EventId::is_expired (void)
    6.47 +{
    6.48 +	return Simulator::is_expired (*this);
    6.49 +}
    6.50 +EventImpl *
    6.51 +EventId::get_event_impl (void) const
    6.52 +{
    6.53 +	return m_event_impl;
    6.54 +}
    6.55 +uint64_t 
    6.56 +EventId::get_time (void) const
    6.57 +{
    6.58 +	return m_time;
    6.59 +}
    6.60 +uint32_t 
    6.61 +EventId::get_uid (void) const
    6.62 +{
    6.63 +	return m_uid;
    6.64 +}
    6.65 +
    6.66 +
    6.67 +}; // namespace ns3
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/simulator/event-id.h	Sun Sep 03 12:24:04 2006 +0200
     7.3 @@ -0,0 +1,52 @@
     7.4 +/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
     7.5 +/*
     7.6 + * Copyright (c) 2005 INRIA
     7.7 + * All rights reserved.
     7.8 + *
     7.9 + * This program is free software; you can redistribute it and/or modify
    7.10 + * it under the terms of the GNU General Public License version 2 as
    7.11 + * published by the Free Software Foundation;
    7.12 + *
    7.13 + * This program is distributed in the hope that it will be useful,
    7.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    7.16 + * GNU General Public License for more details.
    7.17 + *
    7.18 + * You should have received a copy of the GNU General Public License
    7.19 + * along with this program; if not, write to the Free Software
    7.20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    7.21 + *
    7.22 + * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
    7.23 + */
    7.24 +#ifndef EVENT_ID_H
    7.25 +#define EVENT_ID_H
    7.26 +
    7.27 +#include <stdint.h>
    7.28 +
    7.29 +namespace ns3 {
    7.30 +
    7.31 +class EventImpl;
    7.32 +
    7.33 +class EventId {
    7.34 +public:
    7.35 +        EventId ();
    7.36 +        EventId (EventImpl *impl, uint64_t time, uint32_t uid);
    7.37 +	void cancel (void);
    7.38 +	bool is_expired (void);
    7.39 +public:
    7.40 +	/* The following methods are semi-private
    7.41 +	 * they are supposed to be invoked only by
    7.42 +	 * subclasses of the Scheduler base class.
    7.43 +	 */
    7.44 +	EventImpl *get_event_impl (void) const;
    7.45 +	uint64_t get_time (void) const;
    7.46 +	uint32_t get_uid (void) const;
    7.47 +private:
    7.48 +	EventImpl *m_event_impl;
    7.49 +	uint64_t m_time;
    7.50 +	uint32_t m_uid;
    7.51 +};
    7.52 +
    7.53 +}; // namespace ns3
    7.54 +
    7.55 +#endif /* EVENT_ID_H */
     8.1 --- a/src/simulator/event-impl.cc	Sat Sep 02 19:50:19 2006 +0200
     8.2 +++ b/src/simulator/event-impl.cc	Sun Sep 03 12:24:04 2006 +0200
     8.3 @@ -29,39 +29,30 @@
     8.4  {}
     8.5  
     8.6  EventImpl::EventImpl ()
     8.7 -	: m_id (0),
     8.8 -	  m_count (1),
     8.9 -	  m_cancel (0),
    8.10 -	  m_running (1)
    8.11 +	: m_internal_iterator (0),
    8.12 +	  m_cancel (false)
    8.13  {}
    8.14  void 
    8.15  EventImpl::invoke (void)
    8.16  {
    8.17 -	if (m_cancel == 0) {
    8.18 +	if (!m_cancel) {
    8.19  		notify ();
    8.20  	}
    8.21 -	m_running = 0;
    8.22  }
    8.23  void 
    8.24 -EventImpl::set_tag (void *tag)
    8.25 +EventImpl::set_internal_iterator (void *tag)
    8.26  {
    8.27 -	m_id = tag;
    8.28 +	m_internal_iterator = tag;
    8.29  }
    8.30  void *
    8.31 -EventImpl::get_tag (void) const
    8.32 +EventImpl::get_internal_iterator (void) const
    8.33  {
    8.34 -	return m_id;
    8.35 +	return m_internal_iterator;
    8.36  }
    8.37  void 
    8.38  EventImpl::cancel (void)
    8.39  {
    8.40 -	m_cancel = 1;
    8.41 -	m_running = 0;
    8.42 -}
    8.43 -bool 
    8.44 -EventImpl::is_running (void)
    8.45 -{
    8.46 -	return (m_running == 1);
    8.47 +	m_cancel = true;
    8.48  }
    8.49  
    8.50  }; // namespace ns3
     9.1 --- a/src/simulator/event-impl.h	Sat Sep 02 19:50:19 2006 +0200
     9.2 +++ b/src/simulator/event-impl.h	Sun Sep 03 12:24:04 2006 +0200
     9.3 @@ -30,18 +30,15 @@
     9.4  	EventImpl ();
     9.5  	virtual ~EventImpl () = 0;
     9.6  	void invoke (void);
     9.7 -	void set_tag (void *tag);
     9.8 -	void *get_tag (void) const;
     9.9  	void cancel (void);
    9.10 -	bool is_running (void);
    9.11 +	void set_internal_iterator (void *iterator);
    9.12 +	void *get_internal_iterator (void) const;
    9.13  protected:
    9.14  	virtual void notify (void) = 0;
    9.15  private:
    9.16  	friend class Event;
    9.17 -	void *m_id;
    9.18 -	uint32_t m_count;
    9.19 -	uint32_t m_cancel : 1;
    9.20 -	uint32_t m_running : 1;
    9.21 +	void *m_internal_iterator;
    9.22 +	bool m_cancel;
    9.23  };
    9.24  
    9.25  }; // namespace ns3
    10.1 --- a/src/simulator/event-tcc-test.cc	Sat Sep 02 19:50:19 2006 +0200
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,110 +0,0 @@
    10.4 -/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
    10.5 -/*
    10.6 - * Copyright (c) 2006 INRIA
    10.7 - * All rights reserved.
    10.8 - *
    10.9 - * This program is free software; you can redistribute it and/or modify
   10.10 - * it under the terms of the GNU General Public License version 2 as
   10.11 - * published by the Free Software Foundation;
   10.12 - *
   10.13 - * This program is distributed in the hope that it will be useful,
   10.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   10.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10.16 - * GNU General Public License for more details.
   10.17 - *
   10.18 - * You should have received a copy of the GNU General Public License
   10.19 - * along with this program; if not, write to the Free Software
   10.20 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   10.21 - *
   10.22 - * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
   10.23 - */
   10.24 -#include "event.tcc"
   10.25 -#include "ns3/test.h"
   10.26 -
   10.27 -#ifdef RUN_SELF_TESTS
   10.28 -
   10.29 -#define ENSURE(got,expected) \
   10.30 -if (got != expected) { \
   10.31 -	g_error = true; \
   10.32 -}
   10.33 -
   10.34 -namespace {
   10.35 -bool g_error = false;
   10.36 -
   10.37 -void null_cb (void)
   10.38 -{}
   10.39 -void one_cb (int a)
   10.40 -{
   10.41 -	ENSURE (a, 1);
   10.42 -}
   10.43 -void two_cb (int a,int b)
   10.44 -{
   10.45 -	ENSURE (a, 1);
   10.46 -	ENSURE (b, 2);
   10.47 -}
   10.48 -void three_cb (int a,int b,int c)
   10.49 -{
   10.50 -	ENSURE (a, 1);
   10.51 -	ENSURE (b, 2);
   10.52 -	ENSURE (c, 3);
   10.53 -}
   10.54 -void four_cb (int a,int b,int c,int d)
   10.55 -{
   10.56 -	ENSURE (a, 1);
   10.57 -	ENSURE (b, 2);
   10.58 -	ENSURE (c, 3);
   10.59 -	ENSURE (d, 4);
   10.60 -}
   10.61 -void five_cb (int a,int b,int c,int d,int e)
   10.62 -{
   10.63 -	ENSURE (a, 1);
   10.64 -	ENSURE (b, 2);
   10.65 -	ENSURE (c, 3);
   10.66 -	ENSURE (d, 4);
   10.67 -	ENSURE (e, 5);
   10.68 -}
   10.69 -
   10.70 -};
   10.71 -
   10.72 -namespace ns3 {
   10.73 -class EventTest : public Test {
   10.74 -public:
   10.75 -	EventTest ();
   10.76 -	virtual bool run_tests (void);
   10.77 -};
   10.78 -
   10.79 -EventTest::EventTest ()
   10.80 -	: Test ("Event")
   10.81 -{}
   10.82 -
   10.83 -bool 
   10.84 -EventTest::run_tests (void)
   10.85 -{
   10.86 -	Event ev;
   10.87 -
   10.88 -	ev = ns3::make_event (&null_cb);
   10.89 -	ev ();
   10.90 -	ev = ns3::make_event (&one_cb, 1);
   10.91 -	ev ();
   10.92 -	ev = ns3::make_event (&two_cb, 1, 2);
   10.93 -	ev ();
   10.94 -	ev = ns3::make_event (&three_cb, 1, 2, 3);
   10.95 -	ev ();
   10.96 -	ev = ns3::make_event (&four_cb, 1, 2, 3, 4);
   10.97 -	ev ();
   10.98 -	ev = ns3::make_event (&five_cb, 1, 2, 3, 4, 5);
   10.99 -	ev ();
  10.100 -
  10.101 -	if (g_error) {
  10.102 -		return false;
  10.103 -	}
  10.104 -	return true;
  10.105 -}
  10.106 -
  10.107 -static EventTest g_test;
  10.108 -
  10.109 -};
  10.110 -
  10.111 -
  10.112 -
  10.113 -#endif /* RUN_SELF_TESTS */
    11.1 --- a/src/simulator/event-tcc.cc	Sat Sep 02 19:50:19 2006 +0200
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,47 +0,0 @@
    11.4 -/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
    11.5 -/*
    11.6 - * Copyright (c) 2005 INRIA
    11.7 - * All rights reserved.
    11.8 - *
    11.9 - * This program is free software; you can redistribute it and/or modify
   11.10 - * it under the terms of the GNU General Public License version 2 as
   11.11 - * published by the Free Software Foundation;
   11.12 - *
   11.13 - * This program is distributed in the hope that it will be useful,
   11.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11.16 - * GNU General Public License for more details.
   11.17 - *
   11.18 - * You should have received a copy of the GNU General Public License
   11.19 - * along with this program; if not, write to the Free Software
   11.20 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   11.21 - *
   11.22 - * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
   11.23 - */
   11.24 -#include "event-impl.h"
   11.25 -#include "event.h"
   11.26 -
   11.27 -namespace ns3 {
   11.28 -
   11.29 -class EventFunctionImpl0 : public EventImpl {
   11.30 -public:
   11.31 -	typedef void (*F)(void);
   11.32 -
   11.33 -	EventFunctionImpl0 (F function) 
   11.34 -		: m_function (function)
   11.35 -	{}
   11.36 -	virtual ~EventFunctionImpl0 () {}
   11.37 -private:
   11.38 -	virtual void notify (void) { 
   11.39 -		(*m_function) (); 
   11.40 -	}
   11.41 -private:
   11.42 -	F m_function;
   11.43 -};
   11.44 -
   11.45 -Event make_event(void (*f) (void)) 
   11.46 -{
   11.47 -	return Event (new EventFunctionImpl0 (f));
   11.48 -}
   11.49 -
   11.50 -}; // namespace ns3
    12.1 --- a/src/simulator/event.h	Sat Sep 02 19:50:19 2006 +0200
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,140 +0,0 @@
    12.4 -/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
    12.5 -/*
    12.6 - * Copyright (c) 2005 INRIA
    12.7 - * All rights reserved.
    12.8 - *
    12.9 - * This program is free software; you can redistribute it and/or modify
   12.10 - * it under the terms of the GNU General Public License version 2 as
   12.11 - * published by the Free Software Foundation;
   12.12 - *
   12.13 - * This program is distributed in the hope that it will be useful,
   12.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12.16 - * GNU General Public License for more details.
   12.17 - *
   12.18 - * You should have received a copy of the GNU General Public License
   12.19 - * along with this program; if not, write to the Free Software
   12.20 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   12.21 - *
   12.22 - * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
   12.23 - */
   12.24 -
   12.25 -#ifndef EVENT_H
   12.26 -#define EVENT_H
   12.27 -
   12.28 -#include <algorithm>
   12.29 -#include "event-impl.h"
   12.30 -
   12.31 -namespace ns3 {
   12.32 -
   12.33 -
   12.34 -class EventImpl;
   12.35 -/**
   12.36 - * \brief Simulation events.
   12.37 - *
   12.38 - * The Event class has POD semantics: it can and should
   12.39 - * be passed around by value. The Event class is a mere
   12.40 - * wrapper around the EventImpl class and performs
   12.41 - * memory management of EventImpl object instances.
   12.42 - *
   12.43 - * While users could create Events by instanciating 
   12.44 - * subclasses of the EventImpl class and storing them
   12.45 - * in an Event instance, they are advised to use the 
   12.46 - * template functions \ref make_event instead.
   12.47 - */
   12.48 -class Event {
   12.49 -public:
   12.50 -	Event ()
   12.51 -		: m_impl (0)
   12.52 -	{}
   12.53 -	Event (EventImpl *impl)
   12.54 -		: m_impl (impl)
   12.55 -	{}
   12.56 -	Event (Event const &o)
   12.57 -		: m_impl (o.m_impl)
   12.58 -	{
   12.59 -		if (m_impl != 0) {
   12.60 -			m_impl->m_count++;
   12.61 -		}
   12.62 -	}
   12.63 -	~Event ()
   12.64 -	{
   12.65 -		if (m_impl != 0) {
   12.66 -			m_impl->m_count--;
   12.67 -			if (m_impl->m_count == 0) {
   12.68 -				delete m_impl;
   12.69 -			}
   12.70 -		}
   12.71 -		m_impl = 0;
   12.72 -	}
   12.73 -	Event &operator = (Event const&o)
   12.74 -	{
   12.75 -		if (m_impl != 0) {
   12.76 -			m_impl->m_count--;
   12.77 -			if (m_impl->m_count == 0) {
   12.78 -				delete m_impl;
   12.79 -			}
   12.80 -		}
   12.81 -		m_impl = o.m_impl;
   12.82 -		if (m_impl != 0) {
   12.83 -			m_impl->m_count++;
   12.84 -		}
   12.85 -		return *this;
   12.86 -	}
   12.87 -	void operator () (void)
   12.88 -	{
   12.89 -		m_impl->invoke ();
   12.90 -	}
   12.91 -	/**
   12.92 -	 * Cancel an event. This operation has O(1) 
   12.93 -	 * complexity since it merely sets a "cancel" bit
   12.94 -	 * to on and does not remove the Event from the 
   12.95 -	 * scheduler's event list. When the event expires, 
   12.96 -	 * the scheduler checks this cancel bit and, if set,
   12.97 -	 * does not execute the event.
   12.98 -	 */
   12.99 -	void cancel (void)
  12.100 -	{
  12.101 -		if (m_impl != 0) {
  12.102 -			m_impl->cancel ();
  12.103 -		}
  12.104 -	}
  12.105 -	/**
  12.106 -	 * Return true if the event is in RUNNING state.
  12.107 -	 * Return false otherwise.
  12.108 -	 *
  12.109 -	 * An Event is created in RUNNING state and switches
  12.110 -	 * to NON_RUNNING state upon one of:
  12.111 -	 *    - cancel bit is set to on
  12.112 -	 *    - Event execution is completed.
  12.113 -	 * It is important to note that an event is in RUNNING
  12.114 -	 * state while being executed.
  12.115 -	 */
  12.116 -	bool is_running (void)
  12.117 -	{
  12.118 -		if (m_impl != 0 && m_impl->is_running ()) {
  12.119 -			return true;
  12.120 -		} else {
  12.121 -			return false;
  12.122 -		}
  12.123 -	}
  12.124 -
  12.125 -private:
  12.126 -	friend class SchedulerHeap;
  12.127 -	friend class SchedulerList;
  12.128 -	friend class SchedulerMap;
  12.129 -	void set_tag (void *tag)
  12.130 -	{
  12.131 -		return m_impl->set_tag (tag);
  12.132 -	}
  12.133 -	void *get_tag (void) const
  12.134 -	{
  12.135 -		return m_impl->get_tag ();
  12.136 -	}
  12.137 -
  12.138 -	EventImpl *m_impl;
  12.139 -};
  12.140 -
  12.141 -}; // namespace ns3
  12.142 -
  12.143 -#endif /* EVENT_H */
    13.1 --- a/src/simulator/event.tcc	Sat Sep 02 19:50:19 2006 +0200
    13.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.3 @@ -1,454 +0,0 @@
    13.4 -/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
    13.5 -/*
    13.6 - * Copyright (c) 2005 INRIA
    13.7 - * All rights reserved.
    13.8 - *
    13.9 - * This program is free software; you can redistribute it and/or modify
   13.10 - * it under the terms of the GNU General Public License version 2 as
   13.11 - * published by the Free Software Foundation;
   13.12 - *
   13.13 - * This program is distributed in the hope that it will be useful,
   13.14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13.16 - * GNU General Public License for more details.
   13.17 - *
   13.18 - * You should have received a copy of the GNU General Public License
   13.19 - * along with this program; if not, write to the Free Software
   13.20 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   13.21 - *
   13.22 - * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
   13.23 - */
   13.24 -
   13.25 -#ifndef EVENT_TCC
   13.26 -#define EVENT_TCC
   13.27 -
   13.28 -#include "event.h"
   13.29 -#include "event-impl.h"
   13.30 -
   13.31 -/**
   13.32 - * ns3 namespace
   13.33 - */
   13.34 -namespace ns3 {
   13.35 -
   13.36 -/**
   13.37 - * \defgroup make_event make_event
   13.38 - *
   13.39 - * Every make_event template function returns a newly-created Event
   13.40 - * which holds a pointer to a special subclass of the EventImpl 
   13.41 - * base class. Each of these subclasses holds information about which
   13.42 - * function or method to call and which parameters must be forwarded
   13.43 - * to this function or method.
   13.44 - *
   13.45 - * Sample code is shown below:
   13.46 - * \include samples/main-event.cc
   13.47 - */
   13.48 -
   13.49 -template<typename T>
   13.50 -class EventMemberImpl0 : public EventImpl {
   13.51 -public:
   13.52 -	typedef void (T::*F)(void);
   13.53 -
   13.54 -	EventMemberImpl0 (T *obj, F function) 
   13.55 -		: m_obj (obj), 
   13.56 -		  m_function (function)
   13.57 -	{}
   13.58 -	virtual ~EventMemberImpl0 () {}
   13.59 -private:
   13.60 -	virtual void notify (void) { 
   13.61 -		(m_obj->*m_function) (); 
   13.62 -	}
   13.63 -	T* m_obj;
   13.64 -	F m_function;
   13.65 -};
   13.66 -
   13.67 -template<typename T, typename T1>
   13.68 -class EventMemberImpl1 : public EventImpl {
   13.69 -public:
   13.70 -	typedef void (T::*F)(T1);
   13.71 -
   13.72 -	EventMemberImpl1 (T *obj, F function, T1 a1) 
   13.73 -		: m_obj (obj), 
   13.74 -		  m_function (function),
   13.75 -		  m_a1 (a1)
   13.76 -	{ }
   13.77 -	virtual ~EventMemberImpl1 () {}
   13.78 -private:
   13.79 -	virtual void notify (void) { 
   13.80 -		(m_obj->*m_function) (m_a1);
   13.81 -	}
   13.82 -	T* m_obj;
   13.83 -	F m_function;
   13.84 -	T1 m_a1;
   13.85 -};
   13.86 -
   13.87 -template<typename T, typename T1, typename T2>
   13.88 -class EventMemberImpl2 : public EventImpl {
   13.89 -public:
   13.90 -	typedef void (T::*F)(T1, T2);
   13.91 -
   13.92 -	EventMemberImpl2 (T *obj, F function, T1 a1, T2 a2) 
   13.93 -		: m_obj (obj), 
   13.94 -		  m_function (function),
   13.95 -		  m_a1 (a1),
   13.96 -		  m_a2 (a2)
   13.97 -	{ }
   13.98 -	virtual ~EventMemberImpl2 () {}
   13.99 -private:
  13.100 -	virtual void notify (void) { 
  13.101 -		(m_obj->*m_function) (m_a1, m_a2);
  13.102 -	}
  13.103 -	T* m_obj;
  13.104 -	F m_function;
  13.105 -	T1 m_a1;
  13.106 -	T2 m_a2;
  13.107 -};
  13.108 -
  13.109 -template<typename T, typename T1, typename T2, typename T3>
  13.110 -class EventMemberImpl3 : public EventImpl {
  13.111 -public:
  13.112 -	typedef void (T::*F)(T1, T2, T3);
  13.113 -
  13.114 -	EventMemberImpl3 (T *obj, F function, T1 a1, T2 a2, T3 a3) 
  13.115 -		: m_obj (obj), 
  13.116 -		  m_function (function),
  13.117 -		  m_a1 (a1),
  13.118 -		  m_a2 (a2),
  13.119 -		  m_a3 (a3)
  13.120 -	{ }
  13.121 -	virtual ~EventMemberImpl3 () {}
  13.122 -private:
  13.123 -	virtual void notify (void) { 
  13.124 -		(m_obj->*m_function) (m_a1, m_a2, m_a3);
  13.125 -	}
  13.126 -	T* m_obj;
  13.127 -	F m_function;
  13.128 -	T1 m_a1;
  13.129 -	T2 m_a2;
  13.130 -	T3 m_a3;
  13.131 -};
  13.132 -
  13.133 -template<typename T, typename T1, typename T2, typename T3, typename T4>
  13.134 -class EventMemberImpl4 : public EventImpl {
  13.135 -public:
  13.136 -	typedef void (T::*F)(T1, T2, T3, T4);
  13.137 -
  13.138 -	EventMemberImpl4 (T *obj, F function, T1 a1, T2 a2, T3 a3, T4 a4) 
  13.139 -		: m_obj (obj), 
  13.140 -		  m_function (function),
  13.141 -		  m_a1 (a1),
  13.142 -		  m_a2 (a2),
  13.143 -		  m_a3 (a3),
  13.144 -		  m_a4 (a4)
  13.145 -	{ }
  13.146 -	virtual ~EventMemberImpl4 () {}
  13.147 -private:
  13.148 -	virtual void notify (void) { 
  13.149 -		(m_obj->*m_function) (m_a1, m_a2, m_a3, m_a4);
  13.150 -	}
  13.151 -	T* m_obj;
  13.152 -	F m_function;
  13.153 -	T1 m_a1;
  13.154 -	T2 m_a2;
  13.155 -	T3 m_a3;
  13.156 -	T4 m_a4;
  13.157 -};
  13.158 -
  13.159 -template<typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
  13.160 -class EventMemberImpl5 : public EventImpl {
  13.161 -public:
  13.162 -	typedef void (T::*F)(T1, T2, T3, T4, T5);
  13.163 -
  13.164 -	EventMemberImpl5 (T *obj, F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
  13.165 -		: m_obj (obj), 
  13.166 -		  m_function (function),
  13.167 -		  m_a1 (a1),
  13.168 -		  m_a2 (a2),
  13.169 -		  m_a3 (a3),
  13.170 -		  m_a4 (a4),
  13.171 -		  m_a5 (a5)
  13.172 -	{ }
  13.173 -	virtual ~EventMemberImpl5 () {}
  13.174 -private:
  13.175 -	virtual void notify (void) { 
  13.176 -		(m_obj->*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5);
  13.177 -	}
  13.178 -	T* m_obj;
  13.179 -	F m_function;
  13.180 -	T1 m_a1;
  13.181 -	T2 m_a2;
  13.182 -	T3 m_a3;
  13.183 -	T4 m_a4;
  13.184 -	T5 m_a5;
  13.185 -};
  13.186 -
  13.187 -/**
  13.188 - * \ingroup make_event
  13.189 - * \param f class method member pointer
  13.190 - * \param t class instance
  13.191 - * \return a wrapper Event
  13.192 - * Build Events for class method members which take no arguments.
  13.193 - */
  13.194 -template<typename T>
  13.195 -Event make_event(void (T::*f) (void), T* t) {
  13.196 -	return Event (new EventMemberImpl0<T>(t, f));
  13.197 -}
  13.198 -/**
  13.199 - * \ingroup make_event
  13.200 - * \param f class method member pointer
  13.201 - * \param t class instance
  13.202 - * \param a1 first argument to pass to the target method when the event expires
  13.203 - * \return a wrapper Event
  13.204 - * Build Events for class method members which take only one argument
  13.205 - */
  13.206 -template<typename T, typename T1>
  13.207 -Event make_event(void (T::*f) (T1), T* t, T1 a1) {
  13.208 -	return Event (new EventMemberImpl1<T, T1>(t, f, a1));
  13.209 -}
  13.210 -/**
  13.211 - * \ingroup make_event
  13.212 - * \param f class method member pointer
  13.213 - * \param t class instance
  13.214 - * \param a1 first argument to pass to the target method when the event expires
  13.215 - * \param a2 second argument to pass to the target method when the event expires
  13.216 - * \return a wrapper Event
  13.217 - * Build Events for class method members which take two arguments
  13.218 - */
  13.219 -template<typename T, typename T1, typename T2>
  13.220 -Event make_event(void (T::*f) (T1, T2), T* t, T1 a1, T2 a2) {
  13.221 -	return Event (new EventMemberImpl2<T, T1, T2>(t, f, a1, a2));
  13.222 -}
  13.223 -/**
  13.224 - * \ingroup make_event
  13.225 - * \param f class method member pointer
  13.226 - * \param t class instance
  13.227 - * \param a1 first argument to pass to the target method when the event expires
  13.228 - * \param a2 second argument to pass to the target method when the event expires
  13.229 - * \param a3 third argument to pass to the target method when the event expires
  13.230 - * \return a wrapper Event
  13.231 - * Build Events for class method members which take three arguments
  13.232 - */
  13.233 -template<typename T, typename T1, typename T2, typename T3>
  13.234 -Event make_event(void (T::*f) (T1, T2, T3), T* t, T1 a1, T2 a2, T3 a3) {
  13.235 -	return Event (new EventMemberImpl3<T, T1, T2, T3>(t, f, a1, a2, a3));
  13.236 -}
  13.237 -/**
  13.238 - * \ingroup make_event
  13.239 - * \param f class method member pointer
  13.240 - * \param t class instance
  13.241 - * \param a1 first argument to pass to the target method when the event expires
  13.242 - * \param a2 second argument to pass to the target method when the event expires
  13.243 - * \param a3 third argument to pass to the target method when the event expires
  13.244 - * \param a4 fourth argument to pass to the target method when the event expires
  13.245 - * \return a wrapper Event
  13.246 - * Build Events for class method members which take four arguments
  13.247 - */
  13.248 -template<typename T, typename T1, typename T2, typename T3, typename T4>
  13.249 -Event make_event(void (T::*f) (T1, T2, T3, T4), T* t, T1 a1, T2 a2, T3 a3, T4 a4) {
  13.250 -	return Event (new EventMemberImpl4<T, T1, T2, T3, T4>(t, f, a1, a2, a3, a4));
  13.251 -}
  13.252 -/**
  13.253 - * \ingroup make_event
  13.254 - * \param f class method member pointer
  13.255 - * \param t class instance
  13.256 - * \param a1 first argument to pass to the target method when the event expires
  13.257 - * \param a2 second argument to pass to the target method when the event expires
  13.258 - * \param a3 third argument to pass to the target method when the event expires
  13.259 - * \param a4 fourth argument to pass to the target method when the event expires
  13.260 - * \param a5 fifth argument to pass to the target method when the event expires
  13.261 - * \return a wrapper Event
  13.262 - * Build Events for class method members which take five arguments.
  13.263 - */
  13.264 -template<typename T, typename T1, typename T2, typename T3, typename T4, typename T5>
  13.265 -Event make_event(void (T::*f) (T1, T2, T3, T4, T5), T* t, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) {
  13.266 -	return Event (new EventMemberImpl5<T, T1, T2, T3, T4, T5>(t, f, a1, a2, a3, a4, a5));
  13.267 -}
  13.268 -
  13.269 -template<typename T1>
  13.270 -class EventFunctionImpl1 : public EventImpl {
  13.271 -public:
  13.272 -	typedef void (*F)(T1);
  13.273 -
  13.274 -	EventFunctionImpl1 (F function, T1 a1) 
  13.275 -		: m_function (function),
  13.276 -		  m_a1 (a1)
  13.277 -	{ }
  13.278 -	virtual ~EventFunctionImpl1 () {}
  13.279 -private:
  13.280 -	virtual void notify (void) { 
  13.281 -		(*m_function) (m_a1);
  13.282 -	}
  13.283 -	F m_function;
  13.284 -	T1 m_a1;
  13.285 -};
  13.286 -
  13.287 -template<typename T1, typename T2>
  13.288 -class EventFunctionImpl2 : public EventImpl {
  13.289 -public:
  13.290 -	typedef void (*F)(T1, T2);
  13.291 -
  13.292 -	EventFunctionImpl2 (F function, T1 a1, T2 a2) 
  13.293 -		: m_function (function),
  13.294 -		  m_a1 (a1),
  13.295 -		  m_a2 (a2)
  13.296 -	{ }
  13.297 -	virtual ~EventFunctionImpl2 () {}
  13.298 -private:
  13.299 -	virtual void notify (void) { 
  13.300 -		(*m_function) (m_a1, m_a2);
  13.301 -	}
  13.302 -	F m_function;
  13.303 -	T1 m_a1;
  13.304 -	T2 m_a2;
  13.305 -};
  13.306 -
  13.307 -template<typename T1, typename T2, typename T3>
  13.308 -class EventFunctionImpl3 : public EventImpl {
  13.309 -public:
  13.310 -	typedef void (*F)(T1, T2, T3);
  13.311 -
  13.312 -	EventFunctionImpl3 (F function, T1 a1, T2 a2, T3 a3) 
  13.313 -		: m_function (function),
  13.314 -		  m_a1 (a1),
  13.315 -		  m_a2 (a2),
  13.316 -		  m_a3 (a3)
  13.317 -	{ }
  13.318 -	virtual ~EventFunctionImpl3 () {}
  13.319 -private:
  13.320 -	virtual void notify (void) { 
  13.321 -		(*m_function) (m_a1, m_a2, m_a3);
  13.322 -	}
  13.323 -	F m_function;
  13.324 -	T1 m_a1;
  13.325 -	T2 m_a2;
  13.326 -	T3 m_a3;
  13.327 -};
  13.328 -
  13.329 -template<typename T1, typename T2, typename T3, typename T4>
  13.330 -class EventFunctionImpl4 : public EventImpl {
  13.331 -public:
  13.332 -	typedef void (*F)(T1, T2, T3, T4);
  13.333 -
  13.334 -	EventFunctionImpl4 (F function, T1 a1, T2 a2, T3 a3, T4 a4) 
  13.335 -		: m_function (function),
  13.336 -		  m_a1 (a1),
  13.337 -		  m_a2 (a2),
  13.338 -		  m_a3 (a3),
  13.339 -		  m_a4 (a4)
  13.340 -	{ }
  13.341 -	virtual ~EventFunctionImpl4 () {}
  13.342 -private:
  13.343 -	virtual void notify (void) { 
  13.344 -		(*m_function) (m_a1, m_a2, m_a3, m_a4);
  13.345 -	}
  13.346 -	F m_function;
  13.347 -	T1 m_a1;
  13.348 -	T2 m_a2;
  13.349 -	T3 m_a3;
  13.350 -	T4 m_a4;
  13.351 -};
  13.352 -
  13.353 -template<typename T1, typename T2, typename T3, typename T4, typename T5>
  13.354 -class EventFunctionImpl5 : public EventImpl {
  13.355 -public:
  13.356 -	typedef void (*F)(T1, T2, T3, T4, T5);
  13.357 -
  13.358 -	EventFunctionImpl5 (F function, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) 
  13.359 -		: m_function (function),
  13.360 -		  m_a1 (a1),
  13.361 -		  m_a2 (a2),
  13.362 -		  m_a3 (a3),
  13.363 -		  m_a4 (a4),
  13.364 -		  m_a5 (a5)
  13.365 -	{ }
  13.366 -	virtual ~EventFunctionImpl5 () {}
  13.367 -private:
  13.368 -	virtual void notify (void) { 
  13.369 -		(*m_function) (m_a1, m_a2, m_a3, m_a4, m_a5);
  13.370 -	}
  13.371 -	F m_function;
  13.372 -	T1 m_a1;
  13.373 -	T2 m_a2;
  13.374 -	T3 m_a3;
  13.375 -	T4 m_a4;
  13.376 -	T5 m_a5;
  13.377 -};
  13.378 -
  13.379 -
  13.380 -/**
  13.381 - * \ingroup make_event
  13.382 - * \param f function pointer
  13.383 - * \return a wrapper Event
  13.384 - * Build Events for function pointers which take no arguments
  13.385 - */
  13.386 -Event make_event(void (*f) (void));
  13.387 -
  13.388 -/**
  13.389 - * \ingroup make_event
  13.390 - * \param f function pointer
  13.391 - * \param a1 first argument to pass to the target function when the event expires
  13.392 - * \return a wrapper Event
  13.393 - * Build Events for function pointers which take one argument
  13.394 - */
  13.395 -template<typename T1>
  13.396 -Event make_event(void (*f) (T1), T1 a1) {
  13.397 -	return Event (new EventFunctionImpl1<T1>(f, a1));
  13.398 -}
  13.399 -/**
  13.400 - * \ingroup make_event
  13.401 - * \param f function pointer
  13.402 - * \param a1 first argument to pass to the target function when the event expires
  13.403 - * \param a2 second argument to pass to the target function when the event expires
  13.404 - * \return a wrapper Event
  13.405 - * Build Events for function pointers which take two argument
  13.406 - */
  13.407 -template<typename T1, typename T2>
  13.408 -Event make_event(void (*f) (T1, T2), T1 a1, T2 a2) {
  13.409 -	return Event (new EventFunctionImpl2<T1, T2>(f, a1, a2));
  13.410 -}
  13.411 -/**
  13.412 - * \ingroup make_event
  13.413 - * \param f function pointer
  13.414 - * \param a1 first argument to pass to the target function when the event expires
  13.415 - * \param a2 second argument to pass to the target function when the event expires
  13.416 - * \param a3 third argument to pass to the target function when the event expires
  13.417 - * \return a wrapper Event
  13.418 - * Build Events for function pointers which take three argument
  13.419 - */
  13.420 -template<typename T1, typename T2, typename T3>
  13.421 -Event make_event(void (*f) (T1, T2, T3), T1 a1, T2 a2, T3 a3) {
  13.422 -	return Event (new EventFunctionImpl3<T1, T2, T3>(f, a1, a2, a3));
  13.423 -}
  13.424 -/**
  13.425 - * \ingroup make_event
  13.426 - * \param f function pointer
  13.427 - * \param a1 first argument to pass to the target function when the event expires
  13.428 - * \param a2 second argument to pass to the target function when the event expires
  13.429 - * \param a3 third argument to pass to the target function when the event expires
  13.430 - * \param a4 fourth argument to pass to the target function when the event expires
  13.431 - * \return a wrapper Event
  13.432 - * Build Events for function pointers which take four argument
  13.433 - */
  13.434 -template<typename T1, typename T2, typename T3, typename T4>
  13.435 -Event make_event(void (*f) (T1, T2, T3, T4), T1 a1, T2 a2, T3 a3, T4 a4) {
  13.436 -	return Event (new EventFunctionImpl4<T1, T2, T3, T4>(f, a1, a2, a3, a4));
  13.437 -}
  13.438 -/**
  13.439 - * \ingroup make_event
  13.440 - * \param f function pointer
  13.441 - * \param a1 first argument to pass to the target function when the event expires
  13.442 - * \param a2 second argument to pass to the target function when the event expires
  13.443 - * \param a3 third argument to pass to the target function when the event expires
  13.444 - * \param a4 fourth argument to pass to the target function when the event expires
  13.445 - * \param a5 fifth argument to pass to the target function when the event expires
  13.446 - * \return a wrapper Event
  13.447 - * Build Events for function pointers which take five argument
  13.448 - */
  13.449 -template<typename T1, typename T2, typename T3, typename T4, typename T5>
  13.450 -Event make_event(void (*f) (T1, T2, T3, T4, T5), T1 a1, T2 a2, T3 a3, T4 a4, T5 a5) {
  13.451 -	return Event (new EventFunctionImpl5<T1, T2, T3, T4, T5>(f, a1, a2, a3, a4, a5));
  13.452 -}
  13.453 -
  13.454 -
  13.455 -}; // namespace ns3
  13.456 -
  13.457 -#endif /* EVENT_TCC */
    14.1 --- a/src/simulator/scheduler-heap.cc	Sat Sep 02 19:50:19 2006 +0200
    14.2 +++ b/src/simulator/scheduler-heap.cc	Sun Sep 03 12:24:04 2006 +0200
    14.3 @@ -33,7 +33,7 @@
    14.4   */
    14.5  
    14.6  #include "scheduler-heap.h"
    14.7 -#include "event.h"
    14.8 +#include "event-impl.h"
    14.9  #include <cassert>
   14.10  
   14.11  #define noTRACE_HEAP 1
   14.12 @@ -57,25 +57,22 @@
   14.13  	// the array to make sure the indexes in the
   14.14  	// array start at one.
   14.15  	Scheduler::EventKey empty_key = {0,0};
   14.16 -	m_heap.push_back (std::make_pair ((Event )0, empty_key));
   14.17 +	m_heap.push_back (std::make_pair (static_cast<EventImpl *>(0), empty_key));
   14.18  }
   14.19  
   14.20  SchedulerHeap::~SchedulerHeap ()
   14.21  {}
   14.22  
   14.23 - 
   14.24 -void 
   14.25 -SchedulerHeap::store_in_event (Event ev, uint32_t index) const
   14.26 +void
   14.27 +SchedulerHeap::store_in_event (EventImpl *ev, uint32_t index) const
   14.28  {
   14.29 -	ev.set_tag ((void *)index);
   14.30 +	ev->set_internal_iterator ((void *)index);
   14.31  }
   14.32 -uint32_t 
   14.33 -SchedulerHeap::get_from_event (Event const ev) const
   14.34 +uint32_t
   14.35 +SchedulerHeap::get_from_event (EventImpl *ev) const
   14.36  {
   14.37 - 	return (uint32_t)ev.get_tag ();
   14.38 +       return (uint32_t)ev->get_internal_iterator ();
   14.39  }
   14.40 -
   14.41 -
   14.42  uint32_t 
   14.43  SchedulerHeap::parent (uint32_t id) const
   14.44  {
   14.45 @@ -127,14 +124,9 @@
   14.46  {
   14.47  	assert (b < m_heap.size () && a < m_heap.size ());
   14.48  	TRACE ("exch " << a << ", " << b);
   14.49 -#if 1
   14.50 -	std::swap (m_heap[a].second, m_heap[b].second);
   14.51 -	std::swap (m_heap[a].first.m_impl, m_heap[b].first.m_impl);
   14.52 -#else
   14.53 -	std::pair<Event , Scheduler::EventKey> tmp (m_heap[a]);
   14.54 +	std::pair<EventImpl*, Scheduler::EventKey> tmp (m_heap[a]);
   14.55  	m_heap[a] = m_heap[b];
   14.56  	m_heap[b] = tmp;
   14.57 -#endif
   14.58  	store_in_event (m_heap[a].first, a);
   14.59  	store_in_event (m_heap[b].first, b);
   14.60  }
   14.61 @@ -199,16 +191,16 @@
   14.62  }
   14.63  
   14.64  
   14.65 -Event  
   14.66 -SchedulerHeap::insert (Event event, Scheduler::EventKey key)
   14.67 +EventId
   14.68 +SchedulerHeap::insert (EventImpl *event, Scheduler::EventKey key)
   14.69  {
   14.70  	m_heap.push_back (std::make_pair (event, key));
   14.71 +	bottom_up ();
   14.72  	store_in_event (event, last ());
   14.73 -	bottom_up ();
   14.74 -	return event;
   14.75 +	return EventId (event, key.m_time, key.m_uid);
   14.76  }
   14.77  
   14.78 -Event
   14.79 +EventImpl *
   14.80  SchedulerHeap::peek_next (void) const
   14.81  {
   14.82  	assert (!is_empty ());
   14.83 @@ -229,15 +221,26 @@
   14.84  	top_down ();
   14.85  }
   14.86  
   14.87 -Scheduler::EventKey
   14.88 -SchedulerHeap::remove (Event const ev)
   14.89 +
   14.90 +EventImpl *
   14.91 +SchedulerHeap::remove (EventId id, Scheduler::EventKey *key)
   14.92  {
   14.93 +	EventImpl *ev = id.get_event_impl ();
   14.94  	uint32_t i = get_from_event (ev);
   14.95 -	EventKey key = m_heap[i].second;
   14.96 +	*key = m_heap[i].second;
   14.97  	exch (i, last ());
   14.98  	m_heap.pop_back ();
   14.99  	top_down ();
  14.100 -	return key;
  14.101 +	return ev;
  14.102  }
  14.103  
  14.104 +bool 
  14.105 +SchedulerHeap::is_valid (EventId id)
  14.106 +{
  14.107 +	EventImpl *ev = id.get_event_impl ();
  14.108 +	uint32_t i = get_from_event (ev);
  14.109 +	Scheduler::EventKey key = m_heap[i].second;
  14.110 +	return (key.m_time == id.get_time () &&
  14.111 +		key.m_uid == id.get_uid ());
  14.112 +}
  14.113  }; // namespace ns3
    15.1 --- a/src/simulator/scheduler-heap.h	Sat Sep 02 19:50:19 2006 +0200
    15.2 +++ b/src/simulator/scheduler-heap.h	Sun Sep 03 12:24:04 2006 +0200
    15.3 @@ -28,7 +28,6 @@
    15.4  
    15.5  namespace ns3 {
    15.6  
    15.7 -class Event;
    15.8  class EventHolder;
    15.9  
   15.10  class SchedulerHeap : public Scheduler {
   15.11 @@ -36,16 +35,17 @@
   15.12  	SchedulerHeap ();
   15.13  	virtual ~SchedulerHeap ();
   15.14  
   15.15 -	virtual Event insert (Event event, Scheduler::EventKey key);
   15.16 +	virtual EventId insert (EventImpl *event, Scheduler::EventKey key);
   15.17  	virtual bool is_empty (void) const;
   15.18 -	virtual Event peek_next (void) const;
   15.19 +	virtual EventImpl *peek_next (void) const;
   15.20  	virtual Scheduler::EventKey peek_next_key (void) const;
   15.21  	virtual void remove_next (void);
   15.22 -	virtual Scheduler::EventKey remove (Event const ev);
   15.23 +	virtual EventImpl *remove (EventId ev, Scheduler::EventKey *key);
   15.24 +	virtual bool is_valid (EventId id);
   15.25  private:
   15.26 -	typedef std::vector<std::pair<Event, Scheduler::EventKey> > BinaryHeap;
   15.27 -	inline void store_in_event (Event ev, uint32_t index) const;
   15.28 -	uint32_t get_from_event (Event const ev) const;
   15.29 +	typedef std::vector<std::pair<EventImpl *, Scheduler::EventKey> > BinaryHeap;
   15.30 +	inline void store_in_event (EventImpl *ev, uint32_t index) const;
   15.31 +	uint32_t get_from_event (EventImpl *ev) const;
   15.32  
   15.33  	inline uint32_t parent (uint32_t id) const;
   15.34  	uint32_t sibling (uint32_t id) const;
    16.1 --- a/src/simulator/scheduler-list.cc	Sat Sep 02 19:50:19 2006 +0200
    16.2 +++ b/src/simulator/scheduler-list.cc	Sun Sep 03 12:24:04 2006 +0200
    16.3 @@ -20,7 +20,7 @@
    16.4   */
    16.5  
    16.6  #include "scheduler-list.h"
    16.7 -#include "event.h"
    16.8 +#include "event-impl.h"
    16.9  #include <utility>
   16.10  #include <cassert>
   16.11  
   16.12 @@ -37,46 +37,47 @@
   16.13   * it relies on the fact that a std::list<>::iterator has a single
   16.14   * member variable, a pointer.
   16.15   */
   16.16 -void 
   16.17 -SchedulerList::store_in_event (Event ev, EventsI i)
   16.18 +EventId
   16.19 +SchedulerList::get_event_id (Scheduler::EventKey key, EventsI i)
   16.20  {
   16.21 -	assert (sizeof (i) <= sizeof (Event));
   16.22 -	void *tag;
   16.23 -	strncpy ((char *)&(tag), (char *)&i, sizeof (void *));
   16.24 -	ev.set_tag (tag);
   16.25 +	assert (sizeof (i) <= sizeof (void *));
   16.26 +	void *internal_iterator;
   16.27 +	memcpy ((char *)&(internal_iterator), (char *)&i, sizeof (void *));
   16.28 +	EventImpl *ev = i->first;
   16.29 +	ev->set_internal_iterator (internal_iterator);
   16.30 +	return EventId (ev, key.m_time, key.m_uid);
   16.31  }
   16.32  SchedulerList::EventsI 
   16.33 -SchedulerList::get_from_event (Event const ev)
   16.34 +SchedulerList::get_iterator (EventId id)
   16.35  {
   16.36  	SchedulerList::EventsI i;
   16.37 -	assert (sizeof (i) <= sizeof (Event));
   16.38 -	void *tag = ev.get_tag ();
   16.39 -	strncpy ((char *)&i, (char *)&(tag), sizeof (void *));
   16.40 +	assert (sizeof (i) <= sizeof (void *));
   16.41 +	EventImpl *ev = id.get_event_impl ();
   16.42 +	void *internal_iterator = ev->get_internal_iterator ();
   16.43 +	memcpy ((char *)&i, (char *)&(internal_iterator), sizeof (void *));
   16.44  	return i;
   16.45  }
   16.46  
   16.47  
   16.48 -Event  
   16.49 -SchedulerList::insert (Event event, Scheduler::EventKey key)
   16.50 +EventId
   16.51 +SchedulerList::insert (EventImpl *event, Scheduler::EventKey key)
   16.52  {
   16.53  	Scheduler::EventKeyCompare compare;
   16.54  	for (EventsI i = m_events.begin (); i != m_events.end (); i++) {
   16.55  		if (compare (key, i->second)) {
   16.56  			m_events.insert (i, std::make_pair (event, key));
   16.57 -			store_in_event (event, i);
   16.58 -			return event;
   16.59 +			return get_event_id (key, i);
   16.60  		}
   16.61  	}
   16.62  	m_events.push_back (std::make_pair (event, key));
   16.63 -	store_in_event (event, --(m_events.end ()));
   16.64 -	return event;
   16.65 +	return get_event_id (key, --(m_events.end ()));
   16.66  }
   16.67  bool 
   16.68  SchedulerList::is_empty (void) const
   16.69  {
   16.70  	return m_events.empty ();
   16.71  }
   16.72 -Event 
   16.73 +EventImpl *
   16.74  SchedulerList::peek_next (void) const
   16.75  {
   16.76  	assert (!is_empty ());
   16.77 @@ -95,13 +96,26 @@
   16.78  	m_events.pop_front ();
   16.79  }
   16.80  
   16.81 -Scheduler::EventKey
   16.82 -SchedulerList::remove (Event const ev)
   16.83 +EventImpl *
   16.84 +SchedulerList::remove (EventId id, Scheduler::EventKey *key)
   16.85  {
   16.86 -	EventsI i = get_from_event (ev);
   16.87 -	EventKey key = (*i).second;
   16.88 -	m_events.erase (get_from_event (ev));
   16.89 -	return key;
   16.90 +	EventsI i = get_iterator (id);
   16.91 +	*key = i->second;
   16.92 +	assert (key->m_time == id.get_time () &&
   16.93 +		key->m_uid == id.get_uid ());
   16.94 +	EventImpl *ev = i->first;
   16.95 +	m_events.erase (i);
   16.96 +	return ev;
   16.97 +}
   16.98 +
   16.99 +bool 
  16.100 +SchedulerList::is_valid (EventId id)
  16.101 +{
  16.102 +	EventsI i = get_iterator (id);
  16.103 +	Scheduler::EventKey key = i->second;
  16.104 +	return (key.m_time == id.get_time () &&
  16.105 +		key.m_uid == id.get_uid ());
  16.106 +	
  16.107  }
  16.108  
  16.109  }; // namespace ns3
    17.1 --- a/src/simulator/scheduler-list.h	Sat Sep 02 19:50:19 2006 +0200
    17.2 +++ b/src/simulator/scheduler-list.h	Sun Sep 03 12:24:04 2006 +0200
    17.3 @@ -23,31 +23,32 @@
    17.4  #define SCHEDULER_LIST_H
    17.5  
    17.6  #include "scheduler.h"
    17.7 +#include "event-id.h"
    17.8  #include <list>
    17.9  #include <utility>
   17.10  #include <stdint.h>
   17.11  
   17.12  namespace ns3 {
   17.13  
   17.14 -class Event;
   17.15 +class EventImpl;
   17.16  
   17.17  class SchedulerList : public Scheduler {
   17.18   public:
   17.19  	SchedulerList ();
   17.20  	virtual ~SchedulerList ();
   17.21  
   17.22 -	virtual Event insert (Event event, EventKey key);
   17.23 +	virtual EventId insert (EventImpl *event, EventKey key);
   17.24  	virtual bool is_empty (void) const;
   17.25 -	virtual Event peek_next (void) const;
   17.26 +	virtual EventImpl *peek_next (void) const;
   17.27  	virtual Scheduler::EventKey peek_next_key (void) const;
   17.28  	virtual void remove_next (void);
   17.29 -	virtual Scheduler::EventKey remove (Event const ev);
   17.30 -
   17.31 +	virtual EventImpl *remove (EventId ev, Scheduler::EventKey *key);
   17.32 +	virtual bool is_valid (EventId id);
   17.33   private:
   17.34 -	typedef std::list<std::pair<Event, EventKey> > Events;
   17.35 -	typedef std::list<std::pair<Event, EventKey> >::iterator EventsI;
   17.36 -	void store_in_event (Event ev, EventsI i);
   17.37 -	EventsI get_from_event (Event const ev);
   17.38 +	typedef std::list<std::pair<EventImpl*, EventKey> > Events;
   17.39 +	typedef std::list<std::pair<EventImpl*, EventKey> >::iterator EventsI;
   17.40 +	EventId get_event_id (Scheduler::EventKey key, EventsI i);
   17.41 +	EventsI get_iterator (EventId id);
   17.42  	Events m_events;
   17.43  };
   17.44  
    18.1 --- a/src/simulator/scheduler-map.cc	Sat Sep 02 19:50:19 2006 +0200
    18.2 +++ b/src/simulator/scheduler-map.cc	Sun Sep 03 12:24:04 2006 +0200
    18.3 @@ -21,7 +21,7 @@
    18.4   */
    18.5  
    18.6  #include "scheduler-map.h"
    18.7 -#include "event.h"
    18.8 +#include "event-impl.h"
    18.9  #include <cassert>
   18.10  
   18.11  #define noTRACE_MAP 1
   18.12 @@ -45,28 +45,28 @@
   18.13  
   18.14  
   18.15  void 
   18.16 -SchedulerMap::store_in_event (Event ev, EventMapI i) const
   18.17 +SchedulerMap::store_in_event (EventImpl *ev, EventMapI i) const
   18.18  {
   18.19  	void *tag;
   18.20  	memcpy (&(tag), &i, sizeof (tag));
   18.21 -	ev.set_tag (tag);
   18.22 +	ev->set_internal_iterator (tag);
   18.23  }
   18.24  SchedulerMap::EventMapI
   18.25 -SchedulerMap::get_from_event (Event const ev) const
   18.26 +SchedulerMap::get_from_event (EventImpl *ev) const
   18.27  {
   18.28  	EventMapI i;
   18.29 -	void *tag = ev.get_tag ();
   18.30 +	void *tag = ev->get_internal_iterator ();
   18.31  	memcpy (&i, &(tag), sizeof (i));
   18.32   	return i;
   18.33  }
   18.34  
   18.35 -Event  
   18.36 -SchedulerMap::insert (Event event, Scheduler::EventKey key)
   18.37 +EventId
   18.38 +SchedulerMap::insert (EventImpl *event, Scheduler::EventKey key)
   18.39  {
   18.40  	std::pair<EventMapI,bool> result = m_list.insert (std::make_pair (key, event));
   18.41  	assert (result.second);
   18.42  	store_in_event (event, result.first);
   18.43 -	return event;
   18.44 +	return EventId (event, key.m_time, key.m_uid);
   18.45  }
   18.46  
   18.47  bool
   18.48 @@ -75,7 +75,7 @@
   18.49  	return m_list.empty ();
   18.50  }
   18.51  
   18.52 -Event 
   18.53 +EventImpl *
   18.54  SchedulerMap::peek_next (void) const
   18.55  {
   18.56  	assert (!is_empty ());
   18.57 @@ -98,15 +98,24 @@
   18.58  	m_list.erase (m_list.begin ());
   18.59  }
   18.60  
   18.61 -Scheduler::EventKey
   18.62 -SchedulerMap::remove (Event const ev)
   18.63 +EventImpl *
   18.64 +SchedulerMap::remove (EventId id, Scheduler::EventKey *key)
   18.65  {
   18.66  	assert (!is_empty ());
   18.67 -	EventMapI i = get_from_event (ev);
   18.68 -	EventKey key = (*i).first;
   18.69 +	EventMapI i = get_from_event (id.get_event_impl ());
   18.70 +	*key = i->first;
   18.71  	m_list.erase (i);
   18.72 -	return key;
   18.73 +	return i->second;
   18.74  }
   18.75  
   18.76 +bool
   18.77 +SchedulerMap::is_valid (EventId id)
   18.78 +{
   18.79 +	EventMapI i = get_from_event (id.get_event_impl ());
   18.80 +	Scheduler::EventKey key = i->first;
   18.81 +	return (key.m_time == id.get_time () &&
   18.82 +		key.m_uid == id.get_uid ());
   18.83 +}
   18.84 +
   18.85  
   18.86  }; // namespace ns3
    19.1 --- a/src/simulator/scheduler-map.h	Sat Sep 02 19:50:19 2006 +0200
    19.2 +++ b/src/simulator/scheduler-map.h	Sun Sep 03 12:24:04 2006 +0200
    19.3 @@ -29,25 +29,27 @@
    19.4  
    19.5  namespace ns3 {
    19.6  
    19.7 +class EventImpl;
    19.8 +
    19.9  class SchedulerMap : public Scheduler {
   19.10  public:
   19.11  	SchedulerMap ();
   19.12  	virtual ~SchedulerMap ();
   19.13  
   19.14 -	virtual Event insert (Event event, Scheduler::EventKey key);
   19.15 +	virtual EventId insert (EventImpl *event, Scheduler::EventKey key);
   19.16  	virtual bool is_empty (void) const;
   19.17 -	virtual Event peek_next (void) const;
   19.18 +	virtual EventImpl *peek_next (void) const;
   19.19  	virtual Scheduler::EventKey peek_next_key (void) const;
   19.20  	virtual void remove_next (void);
   19.21 -	virtual Scheduler::EventKey remove (Event const ev);
   19.22 +	virtual EventImpl *remove (EventId ev, Scheduler::EventKey *key);
   19.23 +	virtual bool is_valid (EventId id);
   19.24  private:
   19.25 -	typedef std::map<Scheduler::EventKey, Event, Scheduler::EventKeyCompare> EventMap;
   19.26 -	typedef std::map<Scheduler::EventKey, Event, Scheduler::EventKeyCompare>::iterator EventMapI;
   19.27 -	typedef std::map<Scheduler::EventKey, Event, Scheduler::EventKeyCompare>::const_iterator EventMapCI;
   19.28 +	typedef std::map<Scheduler::EventKey, EventImpl*, Scheduler::EventKeyCompare> EventMap;
   19.29 +	typedef std::map<Scheduler::EventKey, EventImpl*, Scheduler::EventKeyCompare>::iterator EventMapI;
   19.30 +	typedef std::map<Scheduler::EventKey, EventImpl*, Scheduler::EventKeyCompare>::const_iterator EventMapCI;
   19.31  
   19.32 -	void store_in_event (Event ev, EventMapI i) const;
   19.33 -	EventMapI get_from_event (Event const ev) const;
   19.34 -
   19.35 +	void store_in_event (EventImpl *ev, EventMapI i) const;
   19.36 +	SchedulerMap::EventMapI get_from_event (EventImpl *ev) const;
   19.37  
   19.38  	EventMap m_list;
   19.39  	uint32_t m_uid;
    20.1 --- a/src/simulator/scheduler.h	Sat Sep 02 19:50:19 2006 +0200
    20.2 +++ b/src/simulator/scheduler.h	Sun Sep 03 12:24:04 2006 +0200
    20.3 @@ -23,10 +23,12 @@
    20.4  #define SCHEDULER_H
    20.5  
    20.6  #include <stdint.h>
    20.7 -#include "event.h"
    20.8 +#include "event-id.h"
    20.9  
   20.10  namespace ns3 {
   20.11  
   20.12 +class EventImpl;
   20.13 +
   20.14  class Scheduler {
   20.15   public:
   20.16  	struct EventKey {
   20.17 @@ -39,12 +41,13 @@
   20.18  	};
   20.19  
   20.20  	virtual ~Scheduler () = 0;
   20.21 -	virtual Event insert (Event event, EventKey key) = 0;
   20.22 +	virtual EventId insert (EventImpl *event, EventKey key) = 0;
   20.23  	virtual bool is_empty (void) const = 0;
   20.24 -	virtual Event peek_next (void) const = 0;
   20.25 +	virtual EventImpl *peek_next (void) const = 0;
   20.26  	virtual EventKey peek_next_key (void) const = 0;
   20.27  	virtual void remove_next (void) = 0;
   20.28 -	virtual EventKey remove (Event const ev) = 0;
   20.29 +	virtual EventImpl *remove (EventId id, EventKey *key) = 0;
   20.30 +	virtual bool is_valid (EventId id) = 0;
   20.31  
   20.32  };
   20.33  
    21.1 --- a/src/simulator/simulator.cc	Sat Sep 02 19:50:19 2006 +0200
    21.2 +++ b/src/simulator/simulator.cc	Sun Sep 03 12:24:04 2006 +0200
    21.3 @@ -21,9 +21,7 @@
    21.4  
    21.5  #include "simulator.h"
    21.6  #include "scheduler.h"
    21.7 -#include "event.h"
    21.8 -#include "event.tcc"
    21.9 -#include "ns3/system-semaphore.h"
   21.10 +#include "event-impl.h"
   21.11  
   21.12  #include <math.h>
   21.13  #include <cassert>
   21.14 @@ -57,24 +55,20 @@
   21.15  	void enable_log_to (char const *filename);
   21.16  
   21.17  	bool is_finished (void) const;
   21.18 -	uint64_t next_us (void) const;
   21.19 +	Time next (void) const;
   21.20  	void stop (void);
   21.21 -	void stop_at_us (uint64_t at);
   21.22 -	Event schedule_rel_us (Event event, uint64_t delta);
   21.23 -	Event schedule_rel_s (Event event, double delta);
   21.24 -	Event schedule_abs_us (Event event, uint64_t time);
   21.25 -	Event schedule_abs_s (Event event, double time);
   21.26 -	Event remove (Event const ev);
   21.27 +	void stop_at (Time time);
   21.28 +	EventId schedule (Time time, EventImpl *event);
   21.29 +	void remove (EventId ev);
   21.30 +	void cancel (EventId ev);
   21.31 +	bool is_expired (EventId ev);
   21.32  	void run (void);
   21.33 -	uint64_t now_us (void);
   21.34 -	double now_s (void);
   21.35 -	void schedule_now (Event event);
   21.36 -	void schedule_destroy (Event event);
   21.37 +	Time now (void) const;
   21.38  
   21.39  private:
   21.40  	void process_one_event (void);
   21.41  
   21.42 -	typedef std::list<std::pair<Event,uint32_t> > Events;
   21.43 +	typedef std::list<std::pair<EventImpl *,uint32_t> > Events;
   21.44  	Events m_destroy;
   21.45  	uint64_t m_stop_at;
   21.46  	bool m_stop;
   21.47 @@ -103,10 +97,11 @@
   21.48  SimulatorPrivate::~SimulatorPrivate ()
   21.49  {
   21.50  	while (!m_destroy.empty ()) {
   21.51 -		Event ev = m_destroy.front ().first;
   21.52 +		EventImpl *ev = m_destroy.front ().first;
   21.53  		m_destroy.pop_front ();
   21.54  		TRACE ("handle destroy " << ev);
   21.55 -		ev ();
   21.56 +		ev->invoke ();
   21.57 +		delete ev;
   21.58  	}
   21.59  	delete m_events;
   21.60  	m_events = (Scheduler *)0xdeadbeaf;
   21.61 @@ -123,7 +118,7 @@
   21.62  void
   21.63  SimulatorPrivate::process_one_event (void)
   21.64  {
   21.65 -	Event next_ev = m_events->peek_next ();
   21.66 +	EventImpl *next_ev = m_events->peek_next ();
   21.67  	Scheduler::EventKey next_key = m_events->peek_next_key ();
   21.68  	m_events->remove_next ();
   21.69  	TRACE ("handle " << next_ev);
   21.70 @@ -132,7 +127,8 @@
   21.71  	if (m_log_enable) {
   21.72  		m_log << "e "<<next_key.m_uid << " " << next_key.m_time << std::endl;
   21.73  	}
   21.74 -	next_ev ();
   21.75 +	next_ev->invoke ();
   21.76 +	delete next_ev;
   21.77  }
   21.78  
   21.79  bool 
   21.80 @@ -140,12 +136,12 @@
   21.81  {
   21.82  	return m_events->is_empty ();
   21.83  }
   21.84 -uint64_t 
   21.85 -SimulatorPrivate::next_us (void) const
   21.86 +Time
   21.87 +SimulatorPrivate::next (void) const
   21.88  {
   21.89  	assert (!m_events->is_empty ());
   21.90  	Scheduler::EventKey next_key = m_events->peek_next_key ();
   21.91 -	return next_key.m_time;
   21.92 +	return AbsTimeUs (next_key.m_time);
   21.93  }
   21.94  
   21.95  
   21.96 @@ -153,7 +149,7 @@
   21.97  SimulatorPrivate::run (void)
   21.98  {
   21.99  	while (!m_events->is_empty () && !m_stop && 
  21.100 -	       (m_stop_at == 0 || m_stop_at > next_us ())) {
  21.101 +	       (m_stop_at == 0 || m_stop_at > next ().us ())) {
  21.102  		process_one_event ();
  21.103  	}
  21.104  	m_log.close ();
  21.105 @@ -166,79 +162,67 @@
  21.106  	m_stop = true;
  21.107  }
  21.108  void 
  21.109 -SimulatorPrivate::stop_at_us (uint64_t at)
  21.110 +SimulatorPrivate::stop_at (Time at)
  21.111  {
  21.112 -	m_stop_at = at;
  21.113 +	m_stop_at = at.us ();
  21.114  }
  21.115 -Event   
  21.116 -SimulatorPrivate::schedule_rel_us (Event event, uint64_t delta)
  21.117 +EventId
  21.118 +SimulatorPrivate::schedule (Time time, EventImpl *event)
  21.119  {
  21.120 -	uint64_t current = now_us ();
  21.121 -	return schedule_abs_us (event, current+delta);
  21.122 -}
  21.123 -Event  
  21.124 -SimulatorPrivate::schedule_abs_us (Event event, uint64_t time)
  21.125 -{
  21.126 -	assert (time >= now_us ());
  21.127 -	Scheduler::EventKey key = {time, m_uid};
  21.128 +	if (time.is_destroy ()) {
  21.129 +		m_destroy.push_back (std::make_pair (event, m_uid));
  21.130 +		if (m_log_enable) {
  21.131 +			m_log << "id " << m_current_uid << " " << now ().us () << " "
  21.132 +			      << m_uid << std::endl;
  21.133 +		}
  21.134 +		m_uid++;
  21.135 +		//XXX
  21.136 +		return EventId ();
  21.137 +	}
  21.138 +	assert (time.us () >= now ().us ());
  21.139 +	Scheduler::EventKey key = {time.us (), m_uid};
  21.140  	if (m_log_enable) {
  21.141 -		m_log << "i "<<m_current_uid<<" "<<now_us ()<<" "
  21.142 -		      <<m_uid<<" "<<time << std::endl;
  21.143 +		m_log << "i "<<m_current_uid<<" "<<now ().us ()<<" "
  21.144 +		      <<m_uid<<" "<<time.us () << std::endl;
  21.145  	}
  21.146  	m_uid++;
  21.147  	return m_events->insert (event, key);
  21.148  }
  21.149 -uint64_t 
  21.150 -SimulatorPrivate::now_us (void)
  21.151 +Time
  21.152 +SimulatorPrivate::now (void) const
  21.153  {
  21.154 -	return m_current_us;
  21.155 -}
  21.156 -Event  
  21.157 -SimulatorPrivate::schedule_rel_s (Event event, double delta)
  21.158 -{
  21.159 -	int64_t delta_us = (int64_t)(delta * 1000000.0);
  21.160 -	uint64_t us = now_us () + delta_us;
  21.161 -	return schedule_abs_us (event, us);
  21.162 -}
  21.163 -Event  
  21.164 -SimulatorPrivate::schedule_abs_s (Event event, double time)
  21.165 -{
  21.166 -	int64_t us = (int64_t)(time * 1000000.0);
  21.167 -	assert (us >= 0);
  21.168 -	return schedule_abs_us (event, (uint64_t)us);
  21.169 -}
  21.170 -double 
  21.171 -SimulatorPrivate::now_s (void)
  21.172 -{
  21.173 -	double us = m_current_us;
  21.174 -	us /= 1000000;
  21.175 -	return us;
  21.176 -}
  21.177 -void
  21.178 -SimulatorPrivate::schedule_now (Event event)
  21.179 -{
  21.180 -	schedule_abs_us (event, now_us ());
  21.181 -}
  21.182 -void
  21.183 -SimulatorPrivate::schedule_destroy (Event event)
  21.184 -{
  21.185 -	m_destroy.push_back (std::make_pair (event, m_uid));
  21.186 -	if (m_log_enable) {
  21.187 -		m_log << "id " << m_current_uid << " " << now_us () << " "
  21.188 -		      << m_uid << std::endl;
  21.189 -	}
  21.190 -	m_uid++;
  21.191 +	return AbsTimeUs (m_current_us);
  21.192  }
  21.193  
  21.194 -Event 
  21.195 -SimulatorPrivate::remove (Event const ev)
  21.196 +void
  21.197 +SimulatorPrivate::remove (EventId ev)
  21.198  {
  21.199 -	Scheduler::EventKey key = m_events->remove (ev);
  21.200 +	Scheduler::EventKey key;
  21.201 +	EventImpl *impl = m_events->remove (ev, &key);
  21.202 +	delete impl;
  21.203  	if (m_log_enable) {
  21.204 -		m_log << "r " << m_current_uid << " " << now_us () << " "
  21.205 +		m_log << "r " << m_current_uid << " " << now ().us () << " "
  21.206  		      << key.m_uid << " " << key.m_time << std::endl;
  21.207  	}
  21.208 -	return Event (ev);
  21.209 +}
  21.210 +
  21.211 +void
  21.212 +SimulatorPrivate::cancel (EventId id)
  21.213 +{
  21.214 +	assert (m_events->is_valid (id));
  21.215 +	EventImpl *ev = id.get_event_impl ();
  21.216 +	ev->cancel ();
  21.217 +}
  21.218 +
  21.219 +bool
  21.220 +SimulatorPrivate::is_expired (EventId ev)
  21.221 +{
  21.222 +	if (ev.get_event_impl () != 0 &&
  21.223 +	    ev.get_time () <= now ().us () &&
  21.224 +	    ev.get_uid () < m_current_uid) {
  21.225 +		return false;
  21.226 +	}
  21.227 +	return true;
  21.228  }
  21.229  
  21.230  
  21.231 @@ -312,10 +296,10 @@
  21.232  {
  21.233  	return get_priv ()->is_finished ();
  21.234  }
  21.235 -uint64_t 
  21.236 -Simulator::next_us (void)
  21.237 +Time
  21.238 +Simulator::next (void)
  21.239  {
  21.240 -	return get_priv ()->next_us ();
  21.241 +	return get_priv ()->next ();
  21.242  }
  21.243  
  21.244  
  21.245 @@ -331,63 +315,39 @@
  21.246  	get_priv ()->stop ();
  21.247  }
  21.248  void 
  21.249 -Simulator::stop_at_us (uint64_t at)
  21.250 +Simulator::stop_at (Time at)
  21.251  {
  21.252 -	get_priv ()->stop_at_us (at);
  21.253 +	get_priv ()->stop_at (at);
  21.254  }
  21.255 -Event 
  21.256 -Simulator::schedule_rel_us (uint64_t delta, Event event)
  21.257 +Time
  21.258 +Simulator::now (void)
  21.259  {
  21.260 -	TRACE ("insert " << event << " in " << delta << "us");
  21.261 -	return get_priv ()->schedule_rel_us (event, delta);
  21.262 -}
  21.263 -Event 
  21.264 -Simulator::schedule_abs_us (uint64_t time, Event event)
  21.265 -{
  21.266 -	TRACE ("insert " << event << " at " << time << "us");
  21.267 -	return get_priv ()->schedule_abs_us (event, time);
  21.268 -}
  21.269 -uint64_t 
  21.270 -Simulator::now_us (void)
  21.271 -{
  21.272 -	return get_priv ()->now_us ();
  21.273 -}
  21.274 -Event  
  21.275 -Simulator::schedule_rel_s (double delta, Event event)
  21.276 -{
  21.277 -	TRACE ("insert " << event << " in " << delta << "s");
  21.278 -	return get_priv ()->schedule_rel_s (event, delta);
  21.279 -}
  21.280 -Event  
  21.281 -Simulator::schedule_abs_s (double time, Event event)
  21.282 -{
  21.283 -	TRACE ("insert " << event << " at " << time << "s");
  21.284 -	return get_priv ()->schedule_abs_s (event, time);
  21.285 -}
  21.286 -double 
  21.287 -Simulator::now_s (void)
  21.288 -{
  21.289 -	return get_priv ()->now_s ();
  21.290 -}
  21.291 -void
  21.292 -Simulator::schedule_now (Event event)
  21.293 -{
  21.294 -	TRACE ("insert later " << event);
  21.295 -	return get_priv ()->schedule_now (event);
  21.296 -}
  21.297 -void 
  21.298 -Simulator::schedule_destroy (Event event)
  21.299 -{
  21.300 -	TRACE ("insert at destroy " << event);
  21.301 -	return get_priv ()->schedule_destroy (event);
  21.302 +	return get_priv ()->now ();
  21.303  }
  21.304  
  21.305 -Event 
  21.306 -Simulator::remove (Event const ev)
  21.307 +EventId
  21.308 +Simulator::schedule (Time time, EventImpl *ev)
  21.309 +{
  21.310 +	return get_priv ()->schedule (time, ev);
  21.311 +}
  21.312 +
  21.313 +void
  21.314 +Simulator::remove (EventId ev)
  21.315  {
  21.316  	return get_priv ()->remove (ev);
  21.317  }
  21.318  
  21.319 +void
  21.320 +Simulator::cancel (EventId ev)
  21.321 +{
  21.322 +	return get_priv ()->cancel (ev);
  21.323 +}
  21.324 +bool 
  21.325 +Simulator::is_expired (EventId id)
  21.326 +{
  21.327 +	return get_priv ()->is_expired (id);
  21.328 +}
  21.329 +
  21.330  }; // namespace ns3
  21.331  
  21.332  
    22.1 --- a/src/simulator/simulator.h	Sat Sep 02 19:50:19 2006 +0200
    22.2 +++ b/src/simulator/simulator.h	Sun Sep 03 12:24:04 2006 +0200
    22.3 @@ -23,10 +23,13 @@
    22.4  #define SIMULATOR_H
    22.5  
    22.6  #include <stdint.h>
    22.7 -#include "event.h"
    22.8 +#include "event-id.h"
    22.9 +#include "event-impl.h"
   22.10 +#include "time.h"
   22.11  
   22.12  namespace ns3 {
   22.13  
   22.14 +
   22.15  class SimulatorPrivate;
   22.16  
   22.17  /**
   22.18 @@ -104,7 +107,7 @@
   22.19  	 * method is undefined. Otherwise, it returns the microsecond-based
   22.20  	 * time of the next event expected to be scheduled.
   22.21  	 */
   22.22 -	static uint64_t next_us (void);
   22.23 +	static Time next (void);
   22.24  
   22.25  	/**
   22.26  	 * Run the simulation until one of:
   22.27 @@ -127,75 +130,100 @@
   22.28  	 * is greater than or equal to the stop time.
   22.29  	 * @param at the stop time.
   22.30  	 */
   22.31 -	static void stop_at_us (uint64_t at);
   22.32 +	static void stop_at (Time time);
   22.33  
   22.34  	/**
   22.35 -	 * Schedule an event to expire at delta, relative to the
   22.36 -	 * current time.
   22.37 -	 * @param delta the expiration time relative to the current
   22.38 -	 *        time. Expressed in microsecond units.
   22.39 +	 * Schedule an event to expire at time.
   22.40 +	 *
   22.41 +	 * @param delta the expiration time of the event.
   22.42  	 * @param event the event to schedule.
   22.43 +	 * @returns an id for the scheduled event.
   22.44  	 */
   22.45 -	static Event schedule_rel_us (uint64_t delta, Event event);
   22.46 -	/**
   22.47 -	 * Schedule an event to expire at delta, relative to the
   22.48 -	 * current time.
   22.49 -	 * @param delta the expiration time, relative to the current
   22.50 -	 *        time. Expressed in second units.
   22.51 -	 * @param event the event to schedule.
   22.52 -	 */
   22.53 -	static Event schedule_rel_s (double delta, Event event);
   22.54 -	/**
   22.55 -	 * Schedule an event to expire at an absolute time.
   22.56 -	 * @param time the expiration time. Expressed in 
   22.57 -	 *             microsecond units.
   22.58 -	 * @param event the event to schedule.
   22.59 -	 */
   22.60 -	static Event schedule_abs_us (uint64_t time, Event event);
   22.61 -	/**
   22.62 -	 * Schedule an event to expire at an absolute time.
   22.63 -	 * @param time the expiration time. Expressed in 
   22.64 -	 *             second units.
   22.65 -	 * @param event the event to schedule.
   22.66 -	 */
   22.67 -	static Event schedule_abs_s (double time, Event event);
   22.68 +	template <typename T>
   22.69 +	static EventId schedule (Time time, void (T::*mem_ptr) (void), T *obj) {
   22.70 +		class EventMemberImpl0 : public EventImpl {
   22.71 +		public:
   22.72 +			typedef void (T::*F)(void);
   22.73 +			EventMemberImpl0 (T *obj, F function) 
   22.74 +				: m_obj (obj), 
   22.75 +				  m_function (function)
   22.76 +			{}
   22.77 +			virtual ~EventMemberImpl0 () {}
   22.78 +		private:
   22.79 +			virtual void notify (void) { 
   22.80 +				(m_obj->*m_function) (); 
   22.81 +			}
   22.82 +			T* m_obj;
   22.83 +			F m_function;
   22.84 +		} *ev = new EventMemberImpl0 (obj, mem_ptr);
   22.85 +		return schedule (time, ev);
   22.86 +	}
   22.87 +	static EventId schedule (Time time, void (*f) (void)) {
   22.88 +		class EventFunctionImpl0 : public EventImpl {
   22.89 +		public:
   22.90 +			typedef void (*F)(void);
   22.91 +			
   22.92 +			EventFunctionImpl0 (F function) 
   22.93 +				: m_function (function)
   22.94 +			{}
   22.95 +		protected:
   22.96 +			virtual void notify (void) { 
   22.97 +				(*m_function) (); 
   22.98 +			}
   22.99 +		private:
  22.100 +			virtual ~EventFunctionImpl0 () {}
  22.101 +			F m_function;
  22.102 +		} *ev = new EventFunctionImpl0 (f);
  22.103 +		return schedule (time, ev);
  22.104 +	}
  22.105 +	template <typename T1>
  22.106 +	static EventId schedule (Time time, void (*f) (T1), T1 a1) {
  22.107 +		class EventFunctionImpl1 : public EventImpl {
  22.108 +		public:
  22.109 +			typedef void (*F)(T1);
  22.110 +			
  22.111 +			EventFunctionImpl1 (F function, T1 a1) 
  22.112 +				: m_function (function),
  22.113 +				  m_a1 (a1)
  22.114 +				{ }
  22.115 +		protected:
  22.116 +			virtual ~EventFunctionImpl1 () {}
  22.117 +		private:
  22.118 +			virtual void notify (void) { 
  22.119 +				(*m_function) (m_a1);
  22.120 +			}
  22.121 +			F m_function;
  22.122 +			T1 m_a1;
  22.123 +		} *ev = new EventFunctionImpl1(f, a1);
  22.124 +		return schedule (time, ev);
  22.125 +	}
  22.126  	/**
  22.127  	 * Unschedule the event. i.e.: the removed event never expires.
  22.128  	 * @param id the event to remove from the list of scheduled events.
  22.129  	 */
  22.130 -	static Event remove (Event const id);
  22.131 +	static void remove (EventId id);
  22.132 +	/*
  22.133 +	  XXX
  22.134 +	 */
  22.135 +	static void cancel (EventId id);
  22.136 +	/*
  22.137 +	  XXX
  22.138 +	 */
  22.139 +	static bool is_expired (EventId id);
  22.140  	/**
  22.141 -	 * Return the "current time" in microsecond units.
  22.142 +	 * Return the "current time".
  22.143  	 */
  22.144 -	static uint64_t now_us (void);
  22.145 -	/**
  22.146 -	 * Return the "current time" in second units.
  22.147 -	 */
  22.148 -	static double now_s (void);
  22.149 -	/**
  22.150 -	 * Schedule an event to expire right now. i.e., it will
  22.151 -	 * expire after the currently-executing event is executed.
  22.152 -	 * If multiple events are scheduled with this method, 
  22.153 -	 * they are executed in FIFO order: the events scheduled first
  22.154 -	 * are executed first.
  22.155 -	 * @param event the event to schedule now.
  22.156 -	 */
  22.157 -	static void schedule_now (Event event);
  22.158 -	/**
  22.159 -	 * Schedule an event to expire when the Simulator::destroy method
  22.160 -	 * is invoked. Events are executed in FIFO order: the events
  22.161 -	 * scheduled first are executed first.
  22.162 -	 * @param event the event to schedule.
  22.163 -	 */
  22.164 -	static void schedule_destroy (Event event);
  22.165 +	static Time now (void);
  22.166  private:
  22.167  	Simulator ();
  22.168  	~Simulator ();
  22.169  	static SimulatorPrivate *get_priv (void);
  22.170 +	static EventId schedule (Time time, EventImpl *event);
  22.171  	static SimulatorPrivate *m_priv;
  22.172  	static enum ListType {
  22.173  		LINKED_LIST,
  22.174  		BINARY_HEAP,
  22.175 +
  22.176  		STD_MAP
  22.177  	} m_list_type;
  22.178  };
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/src/simulator/time.cc	Sun Sep 03 12:24:04 2006 +0200
    23.3 @@ -0,0 +1,99 @@
    23.4 +/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
    23.5 +/*
    23.6 + * Copyright (c) 2005,2006 INRIA
    23.7 + * All rights reserved.
    23.8 + *
    23.9 + * This program is free software; you can redistribute it and/or modify
   23.10 + * it under the terms of the GNU General Public License version 2 as
   23.11 + * published by the Free Software Foundation;
   23.12 + *
   23.13 + * This program is distributed in the hope that it will be useful,
   23.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   23.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   23.16 + * GNU General Public License for more details.
   23.17 + *
   23.18 + * You should have received a copy of the GNU General Public License
   23.19 + * along with this program; if not, write to the Free Software
   23.20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23.21 + *
   23.22 + * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
   23.23 + */
   23.24 +#include "time.h"
   23.25 +#include "simulator.h"
   23.26 +
   23.27 +namespace ns3 {
   23.28 +
   23.29 +Time::Time ()
   23.30 +	: m_us (0),
   23.31 +	  m_is_destroy (true)
   23.32 +{}
   23.33 +Time::Time (Time const &o)
   23.34 +	: m_us (o.m_us),
   23.35 +	  m_is_destroy (o.m_is_destroy)
   23.36 +{}
   23.37 +Time &
   23.38 +Time::operator = (Time const &o)
   23.39 +{
   23.40 +	m_us = o.m_us;
   23.41 +	m_is_destroy = o.m_is_destroy;
   23.42 +	return *this;
   23.43 +}
   23.44 +Time::Time (uint64_t us)
   23.45 +	: m_us (us),
   23.46 +	  m_is_destroy (false)
   23.47 +{}
   23.48 +
   23.49 +double 
   23.50 +Time::s (void) const
   23.51 +{
   23.52 +	double us = m_us;
   23.53 +	us /= 1000000;
   23.54 +	return us;
   23.55 +}
   23.56 +uint64_t 
   23.57 +Time::us (void) const
   23.58 +{
   23.59 +	return m_us;
   23.60 +}
   23.61 +
   23.62 +bool
   23.63 +Time::is_destroy (void) const
   23.64 +{
   23.65 +	return m_is_destroy;
   23.66 +}
   23.67 +
   23.68 +Time
   23.69 +operator + (Time const &lhs, uint64_t delta_us)
   23.70 +{
   23.71 +	return AbsTimeUs (lhs.us () + delta_us);
   23.72 +}
   23.73 +Time
   23.74 +operator + (Time const &lhs, double delta_s)
   23.75 +{
   23.76 +	uint64_t delta_us = (uint64_t)(int64_t)(delta_s * 1000000.0);
   23.77 +	return AbsTimeUs (lhs.us () + delta_us);
   23.78 +}
   23.79 +
   23.80 +
   23.81 +AbsTimeS::AbsTimeS (double s)
   23.82 +	: Time ((uint64_t)(int64_t)(s * 1000000.0))
   23.83 +{}
   23.84 +AbsTimeUs::AbsTimeUs (uint64_t us)
   23.85 +	: Time (us)
   23.86 +{}
   23.87 +RelTimeS::RelTimeS (double s)
   23.88 +	: Time (Simulator::now () + s)
   23.89 +{}
   23.90 +RelTimeUs::RelTimeUs (uint64_t us)
   23.91 +	: Time (Simulator::now () + us)
   23.92 +{}
   23.93 +
   23.94 +NowTime::NowTime ()
   23.95 +	: Time (Simulator::now ().us ())
   23.96 +{}
   23.97 +
   23.98 +DestroyTime::DestroyTime ()
   23.99 +	: Time ()
  23.100 +{}
  23.101 +
  23.102 +}; // namespace ns3
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/src/simulator/time.h	Sun Sep 03 12:24:04 2006 +0200
    24.3 @@ -0,0 +1,76 @@
    24.4 +/* -*-	Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
    24.5 +/*
    24.6 + * Copyright (c) 2005,2006 INRIA
    24.7 + * All rights reserved.
    24.8 + *
    24.9 + * This program is free software; you can redistribute it and/or modify
   24.10 + * it under the terms of the GNU General Public License version 2 as
   24.11 + * published by the Free Software Foundation;
   24.12 + *
   24.13 + * This program is distributed in the hope that it will be useful,
   24.14 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
   24.15 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   24.16 + * GNU General Public License for more details.
   24.17 + *
   24.18 + * You should have received a copy of the GNU General Public License
   24.19 + * along with this program; if not, write to the Free Software
   24.20 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   24.21 + *
   24.22 + * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
   24.23 + */
   24.24 +#ifndef TIME_H
   24.25 +#define TIME_H
   24.26 +
   24.27 +#include <stdint.h>
   24.28 +
   24.29 +namespace ns3 {
   24.30 +
   24.31 +class Time {
   24.32 +public:
   24.33 +	Time (Time const &o);
   24.34 +	Time &operator = (Time const &o);
   24.35 +	double s (void) const;
   24.36 +	uint64_t us (void) const;
   24.37 +	bool is_destroy (void) const;
   24.38 +protected:
   24.39 +	Time (uint64_t us);
   24.40 +	Time ();
   24.41 +private:
   24.42 +	uint64_t m_us;
   24.43 +	bool m_is_destroy;
   24.44 +};
   24.45 +
   24.46 +Time operator + (Time const &lhs, uint64_t delta);
   24.47 +Time operator + (Time const &lhs, double delta);
   24.48 +
   24.49 +
   24.50 +class AbsTimeS : public Time {
   24.51 +public:
   24.52 +	AbsTimeS (double s);
   24.53 +};
   24.54 +class AbsTimeUs : public Time {
   24.55 +public:
   24.56 +	AbsTimeUs (uint64_t us);
   24.57 +};
   24.58 +class RelTimeS : public Time {
   24.59 +public:
   24.60 +	RelTimeS (double s);
   24.61 +};
   24.62 +class RelTimeUs : public Time {
   24.63 +public:
   24.64 +	RelTimeUs (uint64_t us);
   24.65 +};
   24.66 +
   24.67 +class NowTime : public Time {
   24.68 +public:
   24.69 +	NowTime ();
   24.70 +};
   24.71 +
   24.72 +class DestroyTime : public Time {
   24.73 +public:
   24.74 +	DestroyTime ();
   24.75 +};
   24.76 +
   24.77 +}; // namespace ns3
   24.78 +
   24.79 +#endif /* TIME_H */
    25.1 --- a/utils/bench-simulator.cc	Sat Sep 02 19:50:19 2006 +0200
    25.2 +++ b/utils/bench-simulator.cc	Sun Sep 03 12:24:04 2006 +0200
    25.3 @@ -20,8 +20,6 @@
    25.4   */
    25.5  
    25.6  #include "ns3/simulator.h"
    25.7 -#include "ns3/event.h"
    25.8 -#include "ns3/event.tcc"
    25.9  #include "ns3/wall-clock-ms.h"
   25.10  #include <iostream>
   25.11  #include <fstream>
   25.12 @@ -75,7 +73,7 @@
   25.13  	time.start ();
   25.14  	for (std::vector<uint64_t>::const_iterator i = m_distribution.begin ();
   25.15  	     i != m_distribution.end (); i++) {
   25.16 -		Simulator::schedule_rel_us (*i, make_event (&Bench::cb, this));
   25.17 +		Simulator::schedule (AbsTimeUs (*i), &Bench::cb, this);
   25.18  	}
   25.19  	init = time.end ();
   25.20  
   25.21 @@ -105,9 +103,9 @@
   25.22  		m_current = m_distribution.begin ();
   25.23  	}
   25.24  	if (g_debug) {
   25.25 -		std::cerr << "event at " << Simulator::now_s () << std::endl;
   25.26 +		std::cerr << "event at " << Simulator::now ().s () << std::endl;
   25.27  	}
   25.28 -	Simulator::schedule_rel_us (*m_current, make_event (&Bench::cb, this));
   25.29 +	Simulator::schedule (AbsTimeUs (*m_current), &Bench::cb, this);
   25.30  	m_current++;
   25.31  	m_n++;
   25.32  }