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