Add NdnApplication class to handle start and stop
refs: #2909
Change-Id: Ibe5760b155e0edf2227d2d7146f8b6552149a63b
diff --git a/ndn/ndn_application.py b/ndn/ndn_application.py
new file mode 100644
index 0000000..665a0ba
--- /dev/null
+++ b/ndn/ndn_application.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+import os
+
+class NdnApplication:
+ def __init__(self, node):
+ self.node = node
+ self.isRunning = False
+
+ def start(self, command):
+ if self.isRunning is True:
+ try:
+ os.kill(int(self.processId), 0)
+ except OSError:
+ self.isRunning = False
+
+ if self.isRunning is False:
+ self.node.cmd(command)
+ self.processId = self.node.cmd("echo $!")[:-1]
+
+ self.isRunning = True
+
+ def stop(self):
+ if self.isRunning:
+ self.node.cmd("sudo kill %s" % self.processId)
+
+ self.isRunning = False