src/node/application.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 04 Jun 2007 16:17:01 +0200
changeset 728 95c426b1cb60
parent 607 1b7abeccfcda
child 729 b5e744285e92
permissions -rw-r--r--
rename INode to Node
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     1
/* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     2
/*
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     3
 * Copyright (c) 2006 Georgia Tech Research Corporation
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     4
 *
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     8
 *
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    12
 * GNU General Public License for more details.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    13
 *
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    17
 *
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    18
 * Author: George F. Riley<riley@ece.gatech.edu>
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    19
 */
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    20
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    21
// Implementation for ns3 Application base class.
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    22
// George F. Riley, Georgia Tech, Fall 2006
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    23
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    24
#include "application.h"
604
0b6bef4e99bc rename node.h to i-node.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 588
diff changeset
    25
#include "ns3/i-node.h"
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    26
#include "ns3/nstime.h"
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    27
#include "ns3/random-variable.h"
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    28
#include "ns3/simulator.h"
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    29
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    30
using namespace std;
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    31
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    32
namespace ns3 {
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    33
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    34
// Application Methods
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    35
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    36
// \brief Application Constructor
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
    37
Application::Application(Ptr<Node> n) 
588
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
    38
    : m_node (n)
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    39
{
585
a009b03b720a remove ApplicationList. Move functionality to Node class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 563
diff changeset
    40
  m_node->AddApplication (this);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    41
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    42
  
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    43
// \brief Application Destructor
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    44
Application::~Application()
517
702e96b8960f finish Dispose -> DoDispose rework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 497
diff changeset
    45
{}
497
34d6f349478f implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 493
diff changeset
    46
34d6f349478f implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 493
diff changeset
    47
void
517
702e96b8960f finish Dispose -> DoDispose rework
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 497
diff changeset
    48
Application::DoDispose (void)
497
34d6f349478f implement Dispose properly throughout the network stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 493
diff changeset
    49
{
563
fc4833e1a9b0 implement properly Application::DoDispose and rename Application::PeekNOde to Application::GetNode
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 545
diff changeset
    50
  m_node = 0;
588
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
    51
  Simulator::Cancel(m_startEvent);
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
    52
  Simulator::Cancel(m_stopEvent);
587
8d2fd4c1bb7a remove Application::Copy
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 585
diff changeset
    53
}  
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    54
   
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    55
void Application::Start(const Time& startTime)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    56
{
588
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
    57
  ScheduleStart (startTime);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    58
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    59
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    60
void Application::Start(const RandomVariable& startVar)
588
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
    61
{
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
    62
  RandomVariable *v = startVar.Copy ();
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
    63
  ScheduleStart (Seconds (v->GetValue ()));
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
    64
  delete v;
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    65
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    66
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    67
   
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    68
void Application::Stop(const Time& stopTime)
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    69
{
588
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
    70
  ScheduleStop (stopTime);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    71
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    72
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    73
void Application::Stop(const RandomVariable& stopVar)
588
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
    74
{
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
    75
  RandomVariable *v = stopVar.Copy ();
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
    76
  ScheduleStop (Seconds (v->GetValue ()));
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
    77
  delete v;
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    78
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    79
  
728
95c426b1cb60 rename INode to Node
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 607
diff changeset
    80
Ptr<Node> Application::GetNode() const
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    81
{
493
68542941fc8a use ref/unref for Node in more cases
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 488
diff changeset
    82
  return m_node;
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    83
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    84
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    85
// Protected methods
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    86
// StartApp and StopApp will likely be overridden by application subclasses
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    87
void Application::StartApplication()
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    88
{ // Provide null functionality in case subclass is not interested
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    89
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    90
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    91
void Application::StopApplication()
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    92
{ // Provide null functionality in case subclass is not interested
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    93
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    94
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    95
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    96
// Private helpers
588
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
    97
void Application::ScheduleStart (const Time &startTime)
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
    98
{
588
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
    99
  m_startEvent = Simulator::Schedule(startTime -
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   100
                                     Simulator::Now(),
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   101
                                     &Application::StartApplication, this);
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   102
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   103
588
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
   104
void Application::ScheduleStop (const Time &stopTime)
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   105
{
588
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
   106
  m_stopEvent = Simulator::Schedule(stopTime -
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
   107
                                    Simulator::Now(),
639ee55495ec fix the doxygen comments and simplify the implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 587
diff changeset
   108
                                    &Application::StopApplication, this);
346
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   109
}
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   110
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   111
} //namespace ns3
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   112
      
4a76f247e7dc Add random number files, base class Application
Tom Henderson <tomh@tomh.org>
parents:
diff changeset
   113