src/simulator/synchronizer.h
author Andrey Mazo <mazo@iitp.ru>
Fri, 23 Apr 2010 15:09:31 +0400
changeset 6273 8d70de29d514
parent 3560 5aa65b1ea001
permissions -rw-r--r--
spell check, mostly in comments.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3560
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * Copyright (c) 2008 University of Washington
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * GNU General Public License for more details.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    19
#ifndef SYNCHRONIZER_H
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    20
#define SYNCHRONIZER_H
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    22
#include <stdint.h>
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    23
#include "nstime.h"
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    24
#include "ns3/object.h"
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
namespace ns3 {
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    27
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
/**
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
 * @brief Base class used for synchronizing the simulation events to some
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
 * real time "wall clock."
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
 * The simulation clock is maintained as a 64-bit integer in a unit specified
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
 * by the user through the TimeStepPrecision::Set function. This means that
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    34
 * it is not possible to specify event expiration times with anything better
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    35
 * than this user-specified accuracy.  We use this clock for the simulation
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    36
 * time.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    37
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
 * The real-time clock is maintained as a 64-bit integer count of nanoseconds.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    39
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
 * The synchronization between the simulation clock and the real-time clock
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
 * is maintained using a combination of sleep-waiting, busy-waiting and a
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
 * feedback loop.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    44
class Synchronizer : public Object 
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    45
{
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
public:
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    47
  static TypeId GetTypeId (void);
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    48
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    49
  Synchronizer ();
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    50
  virtual ~Synchronizer ();
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    51
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    52
/**
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    53
 * @brief Return true if this synchronizer is actually synchronizing to a
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    54
 * realtime clock.  The simulator sometimes needs to know this.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    55
 * @returns True if locked with realtime, false if not.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    56
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    57
  bool Realtime (void);
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    58
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    59
/**
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    60
 * @brief Retrieve the value of the origin of the underlying normalized wall
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    61
 * clock time in simulator timestep units.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    62
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    63
 * @returns The normalized wall clock time (in simulator timestep units).
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    64
 * @see TimeStepPrecision::Get
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    65
 * @see Synchronizer::SetOrigin
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    66
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    67
  uint64_t GetCurrentRealtime (void);
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    68
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    69
/**
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    70
 * @brief Establish a correspondence between a simulation time and the
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    71
 * synchronizer real time.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    72
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    73
 * This method is expected to be called at the "instant" before simulation
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    74
 * begins.  At this point, simulation time = 0, and a 
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
 * set = 0 in this method.  We then associate this time with the current
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    76
 * value of the real time clock that will be used to actually perform the
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    77
 * synchronization.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    78
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    79
 * Subclasses are expected to implement the corresponding DoSetOrigin pure
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
 * virtual method to do the actual real-time-clock-specific work of making the 
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    81
 * correspondence mentioned above.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    82
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    83
 * @param ts The simulation time we should use as the origin (in simulator
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    84
 * timestep units).
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    85
 * @see TimeStepPrecision::Get
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    86
 * @see TimeStepPrecision::DoSetOrigin
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    87
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    88
  void SetOrigin (uint64_t ts);
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    89
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    90
/**
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    91
 * @brief Retrieve the value of the origin of the simulation time in 
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    92
 * simulator timestep units.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    93
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    94
 * @returns The simulation time used as the origin (in simulator timestep
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    95
 * units).
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    96
 * @see TimeStepPrecision::Get
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    97
 * @see Synchronizer::SetOrigin
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    98
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    99
  uint64_t GetOrigin (void);
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   100
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   101
/**
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   102
 * @brief Retrieve the difference between the real time clock used to 
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   103
 * synchronize the simulation and the simulation time (in simulator timestep
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   104
 * units).
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   105
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
 * @param ts Simulation timestep from the simulator interpreted as current time
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
 * in the simulator.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   108
 * @returns Simulation timestep (in simulator timestep units) minus origin 
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   109
 * time (stored internally in nanosecond units).
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   110
 * @see TimeStepPrecision::Get
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   111
 * @see Synchronizer::SetOrigin
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   112
 * @see Synchronizer::DoGetDrift
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   113
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   114
  int64_t GetDrift (uint64_t ts);
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   115
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   116
/**
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   117
 * @brief Wait until the real time is in sync with the specified simulation
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   118
 * time or until the synchronizer is Sigalled.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   119
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   120
 * This is where the real work of synchronization is done.  The Time passed
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   121
 * in as a parameter is the simulation time.  The job of Synchronize is to
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   122
 * translate from simulation time to synchronizer time (in a perfect world
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   123
 * this is the same time) and then figure out how long in real-time it needs
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   124
 * to wait until that synchronizer / simulation time comes around.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   125
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   126
 * Subclasses are expected to implement the corresponding DoSynchronize pure
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   127
 * virtual method to do the actual real-time-clock-specific work of waiting 
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   128
 * (either busy-waiting or sleeping, or some combination thereof) until the
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   129
 * requested simulation time.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   130
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   131
 * @param tsCurrent The current simulation time (in simulator timestep units).
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   132
 * @param tsDelay The simulation time we need to wait for (in simulator
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   133
 * timestep units).
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   134
 * @returns True if the function ran to completion, false if it was interrupted
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   135
 * by a Signal.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   136
 * @see TimeStepPrecision::Get
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   137
 * @see Synchronizer::DoSynchronize
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   138
 * @see Synchronizer::Signal
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   139
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   140
  bool Synchronize (uint64_t tsCurrent, uint64_t tsDelay);
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   141
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   142
/**
6273
8d70de29d514 spell check, mostly in comments.
Andrey Mazo <mazo@iitp.ru>
parents: 3560
diff changeset
   143
 * @brief Tell a possible simulator thread waiting in the Synchronize method
3560
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   144
 * that an event has happened which demands a reevaluation of the wait time.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   145
 * This will cause the thread to wake and return to the simulator proper
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   146
 * where it can get its bearings.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   147
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   148
 * @see Synchronizer::Synchronize
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   149
 * @see Synchronizer::DoSignal
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   150
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   151
  void Signal (void);
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   152
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   153
/**
6273
8d70de29d514 spell check, mostly in comments.
Andrey Mazo <mazo@iitp.ru>
parents: 3560
diff changeset
   154
 * @brief Set the condition variable that tells a possible simulator thread 
3560
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
 * waiting in the Synchronize method that an event has happened which demands
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   156
 * a reevaluation of the wait time.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   157
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   158
 * @see Synchronizer::Signal
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   159
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   160
  void SetCondition (bool);
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   161
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   162
/**
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   163
 * @brief Ask the synchronizer to remember what time it is.  Typically used
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   164
 * with EventEnd to determine the real execution time of a simulation event.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   165
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   166
 * @see Synchronizer::EventEnd
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   167
 * @see TimeStepPrecision::Get
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   168
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   169
  void EventStart (void);
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   170
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   171
/**
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   172
 * @brief Ask the synchronizer to return the time step between the instant
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   173
 * remembered during EventStart and now.  Used in conjunction with EventStart
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   174
 * to determine the real execution time of a simulation event.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   175
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   176
 * @see Synchronizer::EventStart
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   177
 * @see TimeStepPrecision::Get
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   178
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   179
  uint64_t EventEnd (void);
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   180
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   181
protected:
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   182
/**
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   183
 * @brief Establish a correspondence between a simulation time and a 
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   184
 * wall-clock (real) time.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   185
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   186
 * @internal
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   187
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   188
 * There are three timelines involved here:  the simulation time, the 
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   189
 * (absolute) wall-clock time and the (relative) synchronizer real time.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   190
 * Calling this method makes a correspondence between the origin of the
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   191
 * synchronizer time and the current wall-clock time.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   192
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   193
 * This method is expected to be called at the "instant" before simulation
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   194
 * begins.  At this point, simulation time = 0, and synchronizer time is
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   195
 * set = 0 in this method.  We then associate this time with the current
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   196
 * value of the real time clock that will be used to actually perform the
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   197
 * synchronization.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   198
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   199
 * Subclasses are expected to implement this method to do the actual 
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   200
 * real-time-clock-specific work of making the correspondence mentioned above.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   201
 * for example, this is where the differences between Time parameters and
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   202
 * parameters to clock_nanosleep would be dealt with. 
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   203
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   204
 * @param ns The simulation time we need to use as the origin (normalized to
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   205
 * nanosecond units).
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   206
 * @see Synchronizer::SetOrigin
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   207
 * @see TimeStepPrecision::Get
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   208
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   209
  virtual void DoSetOrigin (uint64_t ns) = 0;
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   210
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   211
/**
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   212
 * @brief Return true if this synchronizer is actually synchronizing to a
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   213
 * realtime clock.  The simulator sometimes needs to know this.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   214
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   215
 * @internal
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   216
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   217
 * Subclasses are expected to implement this method to tell the outside world
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   218
 * whether or not they are synchronizing to a realtime clock.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   219
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   220
 * @returns True if locked with realtime, false if not.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   221
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   222
  virtual bool DoRealtime (void) = 0;
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   223
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   224
/**
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   225
 * @brief Retrieve the value of the origin of the underlying normalized wall
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   226
 * clock time in simulator timestep units.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   227
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   228
 * @internal
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   229
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   230
 * Subclasses are expected to implement this method to do the actual
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   231
 * real-time-clock-specific work of getting the current time.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   232
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   233
 * @returns The normalized wall clock time (in nanosecond units).
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   234
 * @see TimeStepPrecision::Get
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   235
 * @see Synchronizer::SetOrigin
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   236
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   237
  virtual uint64_t DoGetCurrentRealtime (void) = 0;
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   238
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   239
/**
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   240
 * @brief Wait until the real time is in sync with the specified simulation
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   241
 * time.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   242
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   243
 * @internal
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   244
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   245
 * This is where the real work of synchronization is done.  The Time passed
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   246
 * in as a parameter is the simulation time.  The job of Synchronize is to
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   247
 * translate from simulation time to synchronizer time (in a perfect world
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   248
 * this is the same time) and then figure out how long in real-time it needs
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   249
 * to wait until that synchronizer / simulation time comes around.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   250
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   251
 * Subclasses are expected to implement this method to do the actual
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   252
 * real-time-clock-specific work of waiting (either busy-waiting or sleeping,
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   253
 * or some combination) until the requested simulation time.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   254
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   255
 * @param nsCurrent The current simulation time (normalized to nanosecond
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   256
 * units).
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   257
 * @param nsDelay The simulation time we need to wait for (normalized to 
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   258
 * nanosecond units).
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   259
 * @returns True if the function ran to completion, false if it was interrupted
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   260
 * by a Signal.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   261
 * @see Synchronizer::Synchronize
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   262
 * @see TimeStepPrecision::Get
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   263
 * @see Synchronizer::Signal
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   264
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   265
  virtual bool DoSynchronize (uint64_t nsCurrent, uint64_t nsDelay) = 0;
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   266
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   267
/**
6273
8d70de29d514 spell check, mostly in comments.
Andrey Mazo <mazo@iitp.ru>
parents: 3560
diff changeset
   268
 * @brief Declaration of the method used to tell a possible simulator thread 
3560
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   269
 * waiting in the DoSynchronize method that an event has happened which
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   270
 * demands a reevaluation of the wait time.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   271
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   272
 * @see Synchronizer::Signal
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   273
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   274
  virtual void DoSignal (void) = 0;
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   275
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   276
/**
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   277
 * @brief Declaration of the method used to set the condition variable that 
6273
8d70de29d514 spell check, mostly in comments.
Andrey Mazo <mazo@iitp.ru>
parents: 3560
diff changeset
   278
 * tells a possible simulator thread waiting in the Synchronize method that an
3560
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   279
 * event has happened which demands a reevaluation of the wait time.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   280
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   281
 * @see Synchronizer::SetCondition
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   282
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   283
  virtual void DoSetCondition (bool) = 0;
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   284
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   285
/**
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   286
 * @brief Declaration of method used to retrieve drift between the real time
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   287
 * clock used to synchronize the simulation and the current simulation time.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   288
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   289
 * @internal
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   290
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   291
 * @param ns Simulation timestep from the simulator normalized to nanosecond 
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   292
 * steps.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   293
 * @returns Drift in nanosecond units.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   294
 * @see TimeStepPrecision::Get
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   295
 * @see Synchronizer::SetOrigin
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   296
 * @see Synchronizer::GetDrift
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   297
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   298
  virtual int64_t DoGetDrift (uint64_t ns) = 0;
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   299
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   300
  virtual void DoEventStart (void) = 0;
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   301
  virtual uint64_t DoEventEnd (void) = 0;
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   302
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   303
  uint64_t m_realtimeOriginNano;
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   304
  uint64_t m_simOriginNano;
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   305
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   306
private:
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   307
/**
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   308
 * @brief Convert a simulator time step (which can be steps of time in a 
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   309
 * user-specified unit) to a normalized time step in nanosecond units.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   310
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   311
 * @internal
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   312
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   313
 * @param ts The simulation time step to be normalized.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   314
 * @returns The simulation time step normalized to nanosecond units.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   315
 * @see TimeStepPrecision::Get
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   316
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   317
  uint64_t TimeStepToNanosecond (uint64_t ts);
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   318
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   319
/**
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   320
 * @brief Convert a normalized nanosecond count into a simulator time step
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   321
 * (which can be steps of time in a user-specified unit).
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   322
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   323
 * @internal
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   324
 *
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   325
 * @param ns The nanosecond count step to be converted
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   326
 * @returns The simulation time step to be interpreted in appropriate units.
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   327
 * @see TimeStepPrecision::Get
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   328
 */
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   329
  uint64_t NanosecondToTimeStep (uint64_t ns);
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   330
};
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   331
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   332
}; // namespace ns3
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   333
5aa65b1ea001 add realtime simulator and associated tests
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   334
#endif /* SYNCHRONIZER_H */