ns-3 Direct Code Execution
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dce-application-helper.cc
Go to the documentation of this file.
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 
11  : m_stackSize (0),
12  m_uid (0),
13  m_euid (0),
14  m_gid (0),
15  m_egid (0)
16 {
17 }
18 void
19 DceApplicationHelper::SetBinary (std::string filename)
20 {
21  m_filename = filename;
22 }
23 void
25 {
26  m_stackSize = stackSize;
27 }
28 void
29 DceApplicationHelper::SetStdinFile (std::string filename)
30 {
31  m_stdinFilename = filename;
32 }
33 void
35 {
36  NS_LOG_FUNCTION (this << arg);
37  m_args.push_back (arg);
38 }
39 void DceApplicationHelper::AddArguments (std::string a0, std::string a1)
40 {
41  AddArgument (a0);
42  AddArgument (a1);
43 }
44 void
45 DceApplicationHelper::AddArguments (std::string a0, std::string a1, std::string a2)
46 {
47  AddArgument (a0);
48  AddArgument (a1);
49  AddArgument (a2);
50 }
51 void
52 DceApplicationHelper::AddArguments (std::string a0, std::string a1, std::string a2, std::string a3)
53 {
54  AddArgument (a0);
55  AddArgument (a1);
56  AddArgument (a2);
57  AddArgument (a3);
58 }
59 void
60 DceApplicationHelper::AddArguments (std::string a0, std::string a1, std::string a2, std::string a3,
61  std::string a4)
62 {
63  AddArgument (a0);
64  AddArgument (a1);
65  AddArgument (a2);
66  AddArgument (a3);
67  AddArgument (a4);
68 }
69 void
70 DceApplicationHelper::AddArguments (std::string a0, std::string a1, std::string a2, std::string a3,
71  std::string a4, std::string a5)
72 {
73  AddArgument (a0);
74  AddArgument (a1);
75  AddArgument (a2);
76  AddArgument (a3);
77  AddArgument (a4);
78  AddArgument (a5);
79 }
80 void
81 DceApplicationHelper::AddArguments (std::string a0, std::string a1, std::string a2, std::string a3,
82  std::string a4, std::string a5, std::string a6)
83 {
84  AddArgument (a0);
85  AddArgument (a1);
86  AddArgument (a2);
87  AddArgument (a3);
88  AddArgument (a4);
89  AddArgument (a5);
90  AddArgument (a6);
91 }
92 void
93 DceApplicationHelper::AddArguments (std::string a0, std::string a1, std::string a2, std::string a3,
94  std::string a4, std::string a5, std::string a6, std::string a7)
95 {
96  AddArgument (a0);
97  AddArgument (a1);
98  AddArgument (a2);
99  AddArgument (a3);
100  AddArgument (a4);
101  AddArgument (a5);
102  AddArgument (a6);
103  AddArgument (a7);
104 }
106 {
107  std::string::size_type cur = 0, next = 0;
108  cur = args.find_first_not_of (" ", 0); // skip initial spaces
109  next = args.find (" ", cur); // next space
110  while (next != std::string::npos)
111  {
112  AddArgument (args.substr (cur, next - cur));
113  cur = args.find_first_not_of (" ", next); // skip spaces
114  next = args.find (" ", cur); // next space
115  }
116  AddArgument (args.substr (cur, args.size () - cur));
117 }
118 void
120 {
121  m_args.clear ();
122 }
123 void
124 DceApplicationHelper::AddEnvironment (std::string name, std::string value)
125 {
126  m_envs.push_back (std::make_pair (name,value));
127 }
128 void
130 {
131  m_envs.clear ();
132 }
133 
134 ApplicationContainer
136 {
137  NS_LOG_FUNCTION (this);
138  ApplicationContainer apps;
139  for (NodeContainer::Iterator j = c.Begin (); j != c.End (); ++j)
140  {
141  Ptr<DceApplication> dce = CreateObject<DceApplication> ();
142  dce->SetBinary (m_filename);
143  dce->SetStackSize (m_stackSize);
144  dce->SetArguments (m_args);
145  dce->SetEnvironment (m_envs);
146  dce->SetStdinFile (m_stdinFilename);
147  dce->SetUid (m_uid);
148  dce->SetEuid (m_euid);
149  if (!m_finishedCallback.IsNull ())
150  {
151  dce->SetFinishedCallback (m_finishedCallback);
152  }
153  (*j)->AddApplication (dce);
154  apps.Add (dce);
155  }
156  return apps;
157 }
158 
159 void
160 DceApplicationHelper::SetFinishedCallback (Callback<void,uint16_t,int> cb)
161 {
162  m_finishedCallback = cb;
163 }
164 void
166 {
167  m_uid = i;
168 }
169 void
171 {
172  m_euid = i;
173 }
174 void
176 {
177  m_gid = i;
178 }
179 void
181 {
182  m_egid = i;
183 }
184 } // namespace ns3