src/node/application.h
changeset 524 082ffdd8fbd7
parent 523 eb380b33ae24
child 525 4a6c58f0e327
equal deleted inserted replaced
523:eb380b33ae24 524:082ffdd8fbd7
     1 /* -*-  Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */
       
     2 /*
       
     3  * Copyright (c) 2006 Georgia Tech Research Corporation
       
     4  *
       
     5  * This program is free software; you can redistribute it and/or modify
       
     6  * it under the terms of the GNU General Public License version 2 as
       
     7  * published by the Free Software Foundation;
       
     8  *
       
     9  * This program is distributed in the hope that it will be useful,
       
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    12  * GNU General Public License for more details.
       
    13  *
       
    14  * You should have received a copy of the GNU General Public License
       
    15  * along with this program; if not, write to the Free Software
       
    16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
       
    17  *
       
    18  * Author: George F. Riley<riley@ece.gatech.edu>
       
    19  */
       
    20 
       
    21 #ifndef __APPLICATION_H__
       
    22 #define __APPLICATION_H__
       
    23 
       
    24 //
       
    25 // \brief The base class for all ns3 applicationes
       
    26 //
       
    27 // Class Application is the base class for all ns3 applications.
       
    28 // Applications are associated with individual nodes, and are created
       
    29 // using the AddApplication method in the ApplicationManager capability.
       
    30 // 
       
    31 // Conceptually, an application has zero or more Socket
       
    32 // objects associated with it, that are created using the Socket
       
    33 // creation API of the Kernel capability.  The Socket object
       
    34 // API is modeled after the
       
    35 // well-known BSD sockets interface, although it is somewhat 
       
    36 // simplified for use with ns3.  Further, any socket call that
       
    37 // would normally "block" in normal sockets will return immediately
       
    38 // in ns3.  A set of "upcalls" are defined that will be called when
       
    39 // the previous blocking call would normally exit.  THis is documented
       
    40 // in more detail Socket class in socket.h.
       
    41 // 
       
    42 // There is a second application class in ns3, called "ThreadedApplication"
       
    43 // that implements a true sockets interface, which should be used
       
    44 // when porting existing sockets code to ns3.  The true
       
    45 // sockets approach is significantly
       
    46 // less memory--efficient using private stacks for each defined application,
       
    47 // so that approach should be used with care.  The design and implementation
       
    48 // of the ThreadedApplication are still being discussed.
       
    49 
       
    50 #include "ns3/event-id.h"
       
    51 #include "ns3/nstime.h"
       
    52 #include "ns3/object.h"
       
    53 
       
    54 namespace ns3 {
       
    55 
       
    56 class Node;
       
    57 class RandomVariable;
       
    58   
       
    59 class Application : public Object
       
    60 {
       
    61 public:
       
    62   Application(Node *);
       
    63   Application(const Application&);  // Copy constructor
       
    64   Application& operator=(const Application&); // Assignment operator
       
    65   virtual ~Application();
       
    66   
       
    67   virtual Application* Copy() const = 0; // All applications must provide
       
    68   
       
    69   // \brief Specify application start time
       
    70   // Applications start at various times in the simulation scenario.
       
    71   // The Start method specifies when the application should be
       
    72   // started.  The application subclasses should override the
       
    73   // private "StartApplication" method defined below, which is called at the
       
    74   // time specified, to cause the application to begin.
       
    75   // \param Start time for this application, relative to the
       
    76   // current simulation time.
       
    77   void Start(const Time&);
       
    78 
       
    79   // \brief Same as above, but uses a random variable for start time
       
    80   // The random variable returns the desired start time in units of
       
    81   // Seconds.
       
    82   
       
    83 void Start(const RandomVariable&);
       
    84   
       
    85   // \brief Specify application stop time
       
    86   // Once an application has started, it is sometimes useful
       
    87   // to stop the application.  The Stop method specifies when an
       
    88   // application is to stop.  The application subclasses should override
       
    89   // the private StopApplication method defined below, to cause the application
       
    90   // to stop.
       
    91   // \param Stop time for this application, relative to the
       
    92   // current simulation time.
       
    93   void Stop(const Time&);
       
    94 
       
    95   // \brief Same as above, but uses a random variable for stop time
       
    96   // The random variable returns the desired stop time in units of
       
    97   // Seconds.
       
    98   void Stop(const RandomVariable&);
       
    99   
       
   100   // \brief Attaches an application to a specific node
       
   101   // Specifies which node object this application is associated with.
       
   102   // \param Node object to associate with this application.
       
   103   void SetNode(Node *);
       
   104 
       
   105   // \brief Returns the pointer to the attached node.
       
   106   Node* PeekNode() const;
       
   107   
       
   108   // Members
       
   109   Node          * m_node;      // All applications have an associated node
       
   110   RandomVariable* m_startVar;  // Random variable for start time
       
   111   RandomVariable* m_stopVar;   // Random variable for stop time
       
   112   EventId         m_startEvent;// Event identifier for start event
       
   113   EventId         m_stopEvent; // Event identifier for the stop event
       
   114   bool            m_start;     // True if start event scheduled
       
   115   bool            m_stop;      // True if stop event scheduled
       
   116   
       
   117 protected:
       
   118   // \brief Application specific startup code
       
   119   // The StartApplication method is called at the start time specifed by Start
       
   120   // This method should be overridden by all or most application
       
   121   // subclasses.
       
   122   virtual void StartApplication();
       
   123 
       
   124   // \brief Application specific shutdown code
       
   125   // The StopApplication method is called at the stop time specifed by Stop
       
   126   // This method should be overridden by all or most application
       
   127   // subclasses.
       
   128   virtual void StopApplication();
       
   129 
       
   130   virtual void DoDispose (void);
       
   131 private:
       
   132   // Helpers
       
   133   void ScheduleStart();
       
   134   void ScheduleStop();
       
   135 };
       
   136 
       
   137 } //namespace ns3
       
   138 #endif