00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2006 Georgia Tech Research Corporation 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: George F. Riley<riley@ece.gatech.edu> 00019 */ 00020 00021 // Implementation for ns3 Application base class. 00022 // George F. Riley, Georgia Tech, Fall 2006 00023 00024 #include "application.h" 00025 #include "ns3/node.h" 00026 #include "ns3/nstime.h" 00027 #include "ns3/random-variable.h" 00028 #include "ns3/simulator.h" 00029 00030 using namespace std; 00031 00032 namespace ns3 { 00033 00034 NS_OBJECT_ENSURE_REGISTERED (Application); 00035 00036 // Application Methods 00037 00038 TypeId 00039 Application::GetTypeId (void) 00040 { 00041 static TypeId tid = TypeId ("ns3::Application") 00042 .SetParent<Object> () 00043 ; 00044 return tid; 00045 } 00046 00047 // \brief Application Constructor 00048 Application::Application() 00049 {} 00050 00051 // \brief Application Destructor 00052 Application::~Application() 00053 {} 00054 00055 void 00056 Application::DoDispose (void) 00057 { 00058 m_node = 0; 00059 Simulator::Cancel(m_startEvent); 00060 Simulator::Cancel(m_stopEvent); 00061 Object::DoDispose (); 00062 } 00063 00064 void Application::Start(const Time& startTime) 00065 { 00066 ScheduleStart (startTime); 00067 } 00068 00069 void Application::Start(const RandomVariable& startVar) 00070 { 00071 RandomVariable v = startVar; 00072 ScheduleStart (Seconds (v.GetValue ())); 00073 } 00074 00075 00076 void Application::Stop(const Time& stopTime) 00077 { 00078 ScheduleStop (stopTime); 00079 } 00080 00081 void Application::Stop(const RandomVariable& stopVar) 00082 { 00083 RandomVariable v = stopVar; 00084 ScheduleStop (Seconds (v.GetValue ())); 00085 } 00086 00087 Ptr<Node> Application::GetNode() const 00088 { 00089 return m_node; 00090 } 00091 00092 void 00093 Application::SetNode (Ptr<Node> node) 00094 { 00095 m_node = node; 00096 } 00097 00098 // Protected methods 00099 // StartApp and StopApp will likely be overridden by application subclasses 00100 void Application::StartApplication() 00101 { // Provide null functionality in case subclass is not interested 00102 } 00103 00104 void Application::StopApplication() 00105 { // Provide null functionality in case subclass is not interested 00106 } 00107 00108 00109 // Private helpers 00110 void Application::ScheduleStart (const Time &startTime) 00111 { 00112 m_startEvent = Simulator::Schedule (startTime, 00113 &Application::StartApplication, this); 00114 } 00115 00116 void Application::ScheduleStop (const Time &stopTime) 00117 { 00118 m_stopEvent = Simulator::Schedule (stopTime, 00119 &Application::StopApplication, this); 00120 } 00121 00122 } //namespace ns3 00123 00124