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