src/simulator/event-id.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 06 Jul 2010 17:15:00 +0200
changeset 6425 c362d660e7c3
parent 5521 37c6c83d4252
permissions -rw-r--r--
Backed out changeset e27b81575ebe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2005 INRIA
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * GNU General Public License for more details.
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 *
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 */
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
#include "event-id.h"
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
#include "simulator.h"
472
41aa5fca4f49 make sure that Simulator::Cancel deals correctly with events which were already scheduled
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 209
diff changeset
    22
#include "event-impl.h"
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
namespace ns3 {
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
EventId::EventId ()
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    27
  : m_eventImpl (0),
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 472
diff changeset
    28
    m_ts (0),
5521
37c6c83d4252 Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents: 1696
diff changeset
    29
    m_context (0),
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    30
    m_uid (0)
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    31
{}
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    32
  
5521
37c6c83d4252 Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents: 1696
diff changeset
    33
EventId::EventId (const Ptr<EventImpl> &impl, uint64_t ts, uint32_t context, uint32_t uid)
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    34
  : m_eventImpl (impl),
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 472
diff changeset
    35
    m_ts (ts),
5521
37c6c83d4252 Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents: 1696
diff changeset
    36
    m_context (context),
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    37
    m_uid (uid)
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    38
{}
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    39
void 
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 110
diff changeset
    40
EventId::Cancel (void)
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    41
{
1008
6f2ea723a1db use a Ptr<> to manage EventImpl instances
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1005
diff changeset
    42
  Simulator::Cancel (*this);
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    43
}
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    44
bool 
981
eda90b17fc05 EvenId const fixes.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 962
diff changeset
    45
EventId::IsExpired (void) const
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    46
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    47
  return Simulator::IsExpired (*this);
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    48
}
209
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    49
bool 
981
eda90b17fc05 EvenId const fixes.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 962
diff changeset
    50
EventId::IsRunning (void) const
209
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    51
{
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    52
  return !IsExpired ();
8b343b9727d7 fix EventId::IsExpired and Simulator::IsExpired, add EventId::IsRunning, add relevant tests, replace Seconds, MilliSeconds, MicroSeconds, and, NanoSeconds classes by functions named similarly
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    53
}
1009
adc3ac9baea8 optimize EventImpl refcounting
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1008
diff changeset
    54
EventImpl *
adc3ac9baea8 optimize EventImpl refcounting
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1008
diff changeset
    55
EventId::PeekEventImpl (void) const
adc3ac9baea8 optimize EventImpl refcounting
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1008
diff changeset
    56
{
adc3ac9baea8 optimize EventImpl refcounting
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1008
diff changeset
    57
  return PeekPointer (m_eventImpl);
adc3ac9baea8 optimize EventImpl refcounting
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1008
diff changeset
    58
}
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    59
uint64_t 
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 472
diff changeset
    60
EventId::GetTs (void) const
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    61
{
675
a5878de7d71c The header file ns3/cairo-wideint-private.h was added since the type int32_t was used.
Emmanuelle Laprise
parents: 472
diff changeset
    62
  return m_ts;
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    63
}
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    64
uint32_t 
5521
37c6c83d4252 Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents: 1696
diff changeset
    65
EventId::GetContext (void) const
37c6c83d4252 Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents: 1696
diff changeset
    66
{
37c6c83d4252 Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents: 1696
diff changeset
    67
  return m_context;
37c6c83d4252 Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents: 1696
diff changeset
    68
}
37c6c83d4252 Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents: 1696
diff changeset
    69
uint32_t 
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 110
diff changeset
    70
EventId::GetUid (void) const
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    71
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 131
diff changeset
    72
  return m_uid;
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    73
}
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    74
962
473a781ec774 add operator == and != t o EventId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 927
diff changeset
    75
bool operator == (const EventId &a, const EventId &b)
473a781ec774 add operator == and != t o EventId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 927
diff changeset
    76
{
473a781ec774 add operator == and != t o EventId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 927
diff changeset
    77
  return 
473a781ec774 add operator == and != t o EventId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 927
diff changeset
    78
    a.m_uid == b.m_uid && 
5521
37c6c83d4252 Introduce Simulator::ScheduleWithContext* and Simulator::GetContext
Guillaume Seguin <guillaume@segu.in>
parents: 1696
diff changeset
    79
    a.m_context == b.m_context && 
962
473a781ec774 add operator == and != t o EventId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 927
diff changeset
    80
    a.m_ts == b.m_ts && 
473a781ec774 add operator == and != t o EventId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 927
diff changeset
    81
    a.m_eventImpl == b.m_eventImpl;
473a781ec774 add operator == and != t o EventId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 927
diff changeset
    82
}
473a781ec774 add operator == and != t o EventId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 927
diff changeset
    83
bool operator != (const EventId &a, const EventId &b)
473a781ec774 add operator == and != t o EventId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 927
diff changeset
    84
{
473a781ec774 add operator == and != t o EventId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 927
diff changeset
    85
  return !(a == b);
473a781ec774 add operator == and != t o EventId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 927
diff changeset
    86
}
473a781ec774 add operator == and != t o EventId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 927
diff changeset
    87
473a781ec774 add operator == and != t o EventId
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 927
diff changeset
    88
25
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
9b3bb088c560 first cut at george's ideas on api
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    90
}; // namespace ns3