blob: 48a6c1df09c4976b9155611d07a187fb15af9904 [file] [log] [blame]
Vince Lehmanb8b18062015-07-14 13:07:22 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
Ashlesh Gawandec09c16d2016-08-05 14:13:12 -05003# Copyright (C) 2016 The University of Memphis,
Vince Lehmanb8b18062015-07-14 13:07:22 -05004# Arizona Board of Regents,
5# Regents of the University of California.
6#
7# This file is part of Mini-NDN.
8# See AUTHORS.md for a complete list of Mini-NDN authors and contributors.
9#
10# Mini-NDN is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, either version 3 of the License, or
13# (at your option) any later version.
14#
15# Mini-NDN is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with Mini-NDN, e.g., in COPYING.md file.
22# If not, see <http://www.gnu.org/licenses/>.
23
Ashlesh Gawande792c6aa2015-07-10 12:18:36 -050024import os
25
26class NdnApplication:
27 def __init__(self, node):
28 self.node = node
29 self.isRunning = False
Ashlesh Gawandec09c16d2016-08-05 14:13:12 -050030 self.processId = ""
Ashlesh Gawande792c6aa2015-07-10 12:18:36 -050031
32 def start(self, command):
33 if self.isRunning is True:
34 try:
35 os.kill(int(self.processId), 0)
36 except OSError:
37 self.isRunning = False
38
39 if self.isRunning is False:
40 self.node.cmd(command)
41 self.processId = self.node.cmd("echo $!")[:-1]
42
43 self.isRunning = True
44
45 def stop(self):
46 if self.isRunning:
47 self.node.cmd("sudo kill %s" % self.processId)
48
49 self.isRunning = False