blob: 66f0b1ba1fad5b8800b630aba82734f4ca434f1e [file] [log] [blame]
Vince Lehmanb8b18062015-07-14 13:07:22 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
3# Copyright (C) 2015 The University of Memphis,
4# 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
30
31 def start(self, command):
32 if self.isRunning is True:
33 try:
34 os.kill(int(self.processId), 0)
35 except OSError:
36 self.isRunning = False
37
38 if self.isRunning is False:
39 self.node.cmd(command)
40 self.processId = self.node.cmd("echo $!")[:-1]
41
42 self.isRunning = True
43
44 def stop(self):
45 if self.isRunning:
46 self.node.cmd("sudo kill %s" % self.processId)
47
48 self.isRunning = False