helper/dce-application-helper.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 19 Apr 2011 14:49:49 +0200
changeset 64 015a353a487b
parent 0 0a55bed4c895
permissions -rw-r--r--
initial build of module
mathieu@0
     1
#include "dce-application-helper.h"
mathieu@64
     2
#include "dce-application.h"
mathieu@0
     3
#include "ns3/log.h"
mathieu@0
     4
#include <stdarg.h>
mathieu@0
     5
mathieu@0
     6
NS_LOG_COMPONENT_DEFINE ("DceApplicationHelper");
mathieu@0
     7
mathieu@0
     8
namespace ns3 {
mathieu@0
     9
mathieu@0
    10
DceApplicationHelper::DceApplicationHelper ()
mathieu@0
    11
  : m_stackSize (0)
mathieu@0
    12
{}
mathieu@0
    13
void 
mathieu@0
    14
DceApplicationHelper::SetBinary (std::string filename)
mathieu@0
    15
{
mathieu@0
    16
  m_filename = filename;
mathieu@0
    17
}
mathieu@0
    18
void 
mathieu@0
    19
DceApplicationHelper::SetStackSize (uint32_t stackSize)
mathieu@0
    20
{
mathieu@0
    21
  m_stackSize = stackSize;
mathieu@0
    22
}
mathieu@0
    23
void 
mathieu@0
    24
DceApplicationHelper::AddArgument (std::string arg)
mathieu@0
    25
{
mathieu@0
    26
  NS_LOG_FUNCTION (this << arg);
mathieu@0
    27
  m_args.push_back (arg);
mathieu@0
    28
}
mathieu@0
    29
void DceApplicationHelper::AddArguments (std::string a0, std::string a1)
mathieu@0
    30
{
mathieu@0
    31
  AddArgument (a0);
mathieu@0
    32
  AddArgument (a1);
mathieu@0
    33
}
mathieu@0
    34
void 
mathieu@0
    35
DceApplicationHelper::AddArguments (std::string a0, std::string a1, std::string a2)
mathieu@0
    36
{
mathieu@0
    37
  AddArgument (a0);
mathieu@0
    38
  AddArgument (a1);
mathieu@0
    39
  AddArgument (a2);
mathieu@0
    40
}
mathieu@0
    41
void 
mathieu@0
    42
DceApplicationHelper::AddArguments (std::string a0, std::string a1, std::string a2, std::string a3)
mathieu@0
    43
{
mathieu@0
    44
  AddArgument (a0);
mathieu@0
    45
  AddArgument (a1);
mathieu@0
    46
  AddArgument (a2);
mathieu@0
    47
  AddArgument (a3);
mathieu@0
    48
}
mathieu@0
    49
void 
mathieu@0
    50
DceApplicationHelper::AddArguments (std::string a0, std::string a1, std::string a2, std::string a3,
mathieu@0
    51
			     std::string a4)
mathieu@0
    52
{
mathieu@0
    53
  AddArgument (a0);
mathieu@0
    54
  AddArgument (a1);
mathieu@0
    55
  AddArgument (a2);
mathieu@0
    56
  AddArgument (a3);
mathieu@0
    57
  AddArgument (a4);
mathieu@0
    58
}
mathieu@0
    59
void 
mathieu@0
    60
DceApplicationHelper::AddArguments (std::string a0, std::string a1, std::string a2, std::string a3,
mathieu@0
    61
			     std::string a4, std::string a5)
mathieu@0
    62
{
mathieu@0
    63
  AddArgument (a0);
mathieu@0
    64
  AddArgument (a1);
mathieu@0
    65
  AddArgument (a2);
mathieu@0
    66
  AddArgument (a3);
mathieu@0
    67
  AddArgument (a4);
mathieu@0
    68
  AddArgument (a5);
mathieu@0
    69
}
mathieu@0
    70
void 
mathieu@0
    71
DceApplicationHelper::AddArguments (std::string a0, std::string a1, std::string a2, std::string a3,
mathieu@0
    72
		     std::string a4, std::string a5, std::string a6)
mathieu@0
    73
{
mathieu@0
    74
  AddArgument (a0);
mathieu@0
    75
  AddArgument (a1);
mathieu@0
    76
  AddArgument (a2);
mathieu@0
    77
  AddArgument (a3);
mathieu@0
    78
  AddArgument (a4);
mathieu@0
    79
  AddArgument (a5);
mathieu@0
    80
  AddArgument (a6);
mathieu@0
    81
}
mathieu@0
    82
void 
mathieu@0
    83
DceApplicationHelper::AddArguments (std::string a0, std::string a1, std::string a2, std::string a3,
mathieu@0
    84
			     std::string a4, std::string a5, std::string a6, std::string a7)
mathieu@0
    85
{
mathieu@0
    86
  AddArgument (a0);
mathieu@0
    87
  AddArgument (a1);
mathieu@0
    88
  AddArgument (a2);
mathieu@0
    89
  AddArgument (a3);
mathieu@0
    90
  AddArgument (a4);
mathieu@0
    91
  AddArgument (a5);
mathieu@0
    92
  AddArgument (a6);
mathieu@0
    93
  AddArgument (a7);
mathieu@0
    94
}
mathieu@0
    95
void DceApplicationHelper::ParseArguments (std::string args)
mathieu@0
    96
{
mathieu@0
    97
  std::string::size_type cur = 0, next = 0;
mathieu@0
    98
  cur = args.find_first_not_of (" ", 0); // skip initial spaces
mathieu@0
    99
  next = args.find (" ", cur); // next space
mathieu@0
   100
  while (next != std::string::npos)
mathieu@0
   101
    {
mathieu@0
   102
      AddArgument (args.substr (cur, next - cur));
mathieu@0
   103
      cur = args.find_first_not_of (" ", next); // skip spaces
mathieu@0
   104
      next = args.find (" ", cur); // next space
mathieu@0
   105
    }
mathieu@0
   106
  AddArgument (args.substr (cur, args.size () - cur));
mathieu@0
   107
}
mathieu@0
   108
void
mathieu@0
   109
DceApplicationHelper::ResetArguments (void)
mathieu@0
   110
{
mathieu@0
   111
  m_args.clear ();
mathieu@0
   112
}
mathieu@0
   113
void 
mathieu@0
   114
DceApplicationHelper::AddEnvironment (std::string name, std::string value)
mathieu@0
   115
{
mathieu@0
   116
  m_envs.push_back (std::make_pair (name,value));
mathieu@0
   117
}
mathieu@0
   118
void 
mathieu@0
   119
DceApplicationHelper::ResetEnvironment (void)
mathieu@0
   120
{
mathieu@0
   121
  m_envs.clear ();
mathieu@0
   122
}
mathieu@0
   123
mathieu@0
   124
ApplicationContainer
mathieu@0
   125
DceApplicationHelper::Install (NodeContainer c)
mathieu@0
   126
{
mathieu@0
   127
  NS_LOG_FUNCTION (this);
mathieu@0
   128
  ApplicationContainer apps;
mathieu@0
   129
  for (NodeContainer::Iterator j = c.Begin (); j != c.End (); ++j)
mathieu@0
   130
    {
mathieu@0
   131
      Ptr<DceApplication> dce = CreateObject<DceApplication> ();
mathieu@0
   132
      dce->SetBinary (m_filename);
mathieu@0
   133
      dce->SetStackSize (m_stackSize);
mathieu@0
   134
      dce->SetArguments (m_args);
mathieu@0
   135
      dce->SetEnvironment (m_envs);
mathieu@0
   136
      (*j)->AddApplication (dce);
mathieu@0
   137
      apps.Add (dce);
mathieu@0
   138
    }
mathieu@0
   139
  return apps;
mathieu@0
   140
}
mathieu@0
   141
mathieu@0
   142
mathieu@0
   143
} // namespace ns3