ns-3 Direct Code Execution
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dce-application.cc
Go to the documentation of this file.
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
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 
25  : m_stackSize (0),
26  m_pid (0),
27  m_uid (0),
28  m_euid (0),
29  m_gid (0),
30  m_egid (0)
31 {
32 }
34 {
35 }
36 
37 void
39 {
40  NS_LOG_FUNCTION (this);
42 }
43 void
44 DceApplication::SetBinary (std::string filename)
45 {
46  m_filename = filename;
47 }
48 void
49 DceApplication::SetStackSize (uint32_t stackSize)
50 {
51  m_stackSize = stackSize;
52 }
53 void
54 DceApplication::SetArguments (std::vector<std::string> args)
55 {
56  m_args = args;
57 }
58 
59 void
60 DceApplication::SetEnvironment (std::vector<std::pair<std::string,std::string> > envs)
61 {
62  m_envs = envs;
63 }
64 
65 void
67 {
68  NS_LOG_FUNCTION (this);
69 
70  Ptr<Node> node = GetNode ();
71  Ptr<DceManager> manager = node->GetObject<DceManager> ();
72  if (manager == 0)
73  {
74  NS_FATAL_ERROR ("You forgot to aggregate a DceManager to node=" << node->GetId ());
75  }
76  if (m_stackSize != 0)
77  {
78  m_pid = manager->Start (m_filename, m_stdinFilename, m_stackSize, m_args,
80  }
81  else
82  {
83  m_pid = manager->Start (m_filename, m_stdinFilename, m_args, m_envs,
85  }
86  if (!m_finishedCallback.IsNull ())
87  {
88  manager->SetFinishedCallback (m_pid, m_finishedCallback);
89  }
91 }
92 void
94 {
95  NS_LOG_FUNCTION (this);
96  Ptr<Node> node = GetNode ();
97  Ptr<DceManager> manager = node->GetObject<DceManager> ();
98  manager->Stop (m_pid);
99 }
100 void
101 DceApplication::SetStdinFile (std::string filename)
102 {
103  m_stdinFilename = filename;
104 }
105 void
106 DceApplication::SetFinishedCallback (Callback<void,uint16_t,int> cb)
107 {
108  m_finishedCallback = cb;
109 }
110 void
112 {
113  m_uid = i;
114 }
115 void
117 {
118  m_euid = i;
119 }
120 void
122 {
123  m_gid = i;
124 }
125 void
127 {
128  m_egid = i;
129 }
130 } // namespace ns3