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 #ifndef __APPLICATION_H__ 00022 #define __APPLICATION_H__ 00023 00024 #include "ns3/event-id.h" 00025 #include "ns3/nstime.h" 00026 #include "ns3/object.h" 00027 #include "ns3/ptr.h" 00028 #include "ns3/node.h" 00029 00030 namespace ns3 { 00031 00032 class Node; 00033 class RandomVariable; 00034 00035 /** 00036 * \addtogroup applications Applications 00037 * 00038 * Class ns3::Application can be used as a base class for ns3 applications. 00039 * Applications are associated with individual nodes. Each node 00040 * holds a list of references (smart pointers) to its applications. 00041 * 00042 * Conceptually, an application has zero or more ns3::Socket 00043 * objects associated with it, that are created using the Socket 00044 * creation API of the Kernel capability. The Socket object 00045 * API is modeled after the 00046 * well-known BSD sockets interface, although it is somewhat 00047 * simplified for use with ns3. Further, any socket call that 00048 * would normally "block" in normal sockets will return immediately 00049 * in ns3. A set of "upcalls" are defined that will be called when 00050 * the previous blocking call would normally exit. THis is documented 00051 * in more detail Socket class in socket.h. 00052 * 00053 * The main purpose of the base class application public API is to 00054 * provide a uniform way to start and stop applications. 00055 */ 00056 00057 /** 00058 * \brief The base class for all ns3 applications 00059 * 00060 */ 00061 class Application : public Object 00062 { 00063 public: 00064 static TypeId GetTypeId (void); 00065 Application (); 00066 virtual ~Application (); 00067 00068 /** 00069 * \brief Specify application start time 00070 * \param startTime Start time for this application, 00071 * relative to the current simulation time. 00072 * 00073 * Applications start at various times in the simulation scenario. 00074 * The Start method specifies when the application should be 00075 * started. The application subclasses should override the 00076 * private "StartApplication" method defined below, which is called at the 00077 * time specified, to cause the application to begin. 00078 */ 00079 void Start (const Time& startTime); 00080 00081 /** 00082 * \brief Specify application start time. 00083 * \param startVariable the random variable to use to pick 00084 * the real start time as a relative time, in units of 00085 * seconds, relative to the current simulation time. 00086 */ 00087 void Start (const RandomVariable& startVariable); 00088 00089 /** 00090 * \brief Specify application stop time 00091 * \param stopTime Stop time for this application, relative to the 00092 * current simulation time. 00093 * 00094 * Once an application has started, it is sometimes useful 00095 * to stop the application. The Stop method specifies when an 00096 * application is to stop. The application subclasses should override 00097 * the private StopApplication method, to be notified when that 00098 * time has come. 00099 */ 00100 void Stop (const Time& stopTime); 00101 00102 /** 00103 * \brief Specify application stop time 00104 * \param stopVariable the random variable to use to pick 00105 * the real stop time, in units of seconds, 00106 * relative to the current simulation time. 00107 */ 00108 void Stop (const RandomVariable& stopVariable); 00109 00110 /** 00111 * \returns the Node to which this Application object is attached. 00112 */ 00113 Ptr<Node> GetNode () const; 00114 00115 /** 00116 * \param node the node to which this Application object is attached. 00117 */ 00118 void SetNode (Ptr<Node> node); 00119 00120 private: 00121 /** 00122 * \brief Application specific startup code 00123 * 00124 * The StartApplication method is called at the start time specifed by Start 00125 * This method should be overridden by all or most application 00126 * subclasses. 00127 */ 00128 virtual void StartApplication (void); 00129 00130 /** 00131 * \brief Application specific shutdown code 00132 * 00133 * The StopApplication method is called at the stop time specifed by Stop 00134 * This method should be overridden by all or most application 00135 * subclasses. 00136 */ 00137 virtual void StopApplication (void); 00138 protected: 00139 virtual void DoDispose (void); 00140 private: 00141 void ScheduleStart (const Time &time); 00142 void ScheduleStop (const Time &time); 00143 00144 EventId m_startEvent; 00145 EventId m_stopEvent; 00146 Ptr<Node> m_node; 00147 }; 00148 00149 } //namespace ns3 00150 #endif