model/dce-application.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 19 Apr 2011 14:49:49 +0200
changeset 64 015a353a487b
parent 1 96d7044fd324
permissions -rw-r--r--
initial build of module
     1 #include "dce-application.h"
     2 #include "dce-manager.h"
     3 #include "ns3/assert.h"
     4 #include "ns3/log.h"
     5 #include "ns3/trace-source-accessor.h"
     6 
     7 namespace ns3 {
     8 
     9 NS_LOG_COMPONENT_DEFINE ("DceApplication");
    10 NS_OBJECT_ENSURE_REGISTERED (DceApplication);
    11 
    12 TypeId 
    13 DceApplication::GetTypeId (void)
    14 {
    15   static TypeId tid = TypeId ("ns3::DceApplication")
    16     .SetParent<Application> ()
    17     .AddConstructor<DceApplication> ()
    18     .AddTraceSource ("ProcessStarted", "notify when the dce is started",
    19 		     MakeTraceSourceAccessor (&DceApplication::m_dceStarted))
    20     ;
    21   return tid;
    22 }
    23 
    24 DceApplication::DceApplication ()
    25   : m_stackSize (0),
    26     m_pid (0)
    27 {}
    28 DceApplication::~DceApplication ()
    29 {}
    30 
    31 void
    32 DceApplication::DoDispose (void)
    33 {
    34   NS_LOG_FUNCTION (this);
    35   Application::DoDispose ();
    36 }
    37 void 
    38 DceApplication::SetBinary (std::string filename)
    39 {
    40   m_filename = filename;
    41 }
    42 void 
    43 DceApplication::SetStackSize (uint32_t stackSize)
    44 {
    45   m_stackSize = stackSize;
    46 }
    47 void 
    48 DceApplication::SetArguments (std::vector<std::string> args)
    49 {
    50   m_args = args;
    51 }
    52 
    53 void 
    54 DceApplication::SetEnvironment (std::vector<std::pair<std::string,std::string> > envs)
    55 {
    56   m_envs = envs;
    57 }
    58 
    59 void 
    60 DceApplication::StartApplication (void)
    61 {
    62   NS_LOG_FUNCTION (this);
    63 
    64   Ptr<Node> node = GetNode ();
    65   Ptr<DceManager> manager = node->GetObject<DceManager> ();
    66   if (manager == 0)
    67     {
    68       NS_FATAL_ERROR ("You forgot to aggregate a DceManager to node=" << node->GetId ());
    69     }
    70   if (m_stackSize != 0)
    71     {
    72       m_pid = manager->Start (m_filename, m_stackSize, m_args, m_envs);
    73     } 
    74   else
    75     {
    76       m_pid = manager->Start (m_filename, m_args, m_envs);
    77     }
    78   m_dceStarted (m_pid);
    79 }
    80 void 
    81 DceApplication::StopApplication (void)
    82 {
    83   NS_LOG_FUNCTION (this);
    84   Ptr<Node> node = GetNode ();
    85   Ptr<DceManager> manager = node->GetObject<DceManager> ();
    86   manager->Stop (m_pid);
    87 }
    88 
    89 
    90 } // namespace ns3