blob: dd9100e38dbc4651e1d146feef87b05c886da290 [file] [log] [blame]
Vince Lehmanb8b18062015-07-14 13:07:22 -05001# -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2#
Ashlesh Gawandeda475f02017-03-01 17:20:58 -06003# Copyright (C) 2015-2017, The University of Memphis,
Ashlesh Gawande0cccdb82016-08-15 12:58:06 -05004# Arizona Board of Regents,
5# Regents of the University of California.
Vince Lehmanb8b18062015-07-14 13:07:22 -05006#
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):
Ashlesh Gawande532302b2018-02-15 18:58:20 -060046 if self.isRunning and self.processId != "":
47 self.node.cmd("sudo kill {}".format(self.processId))
Ashlesh Gawande792c6aa2015-07-10 12:18:36 -050048
49 self.isRunning = False