Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 1 | # -*- Mode:python; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | # |
Ashlesh Gawande | da475f0 | 2017-03-01 17:20:58 -0600 | [diff] [blame] | 3 | # Copyright (C) 2015-2017, The University of Memphis, |
Ashlesh Gawande | 0cccdb8 | 2016-08-15 12:58:06 -0500 | [diff] [blame] | 4 | # Arizona Board of Regents, |
| 5 | # Regents of the University of California. |
Vince Lehman | b8b1806 | 2015-07-14 13:07:22 -0500 | [diff] [blame] | 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 Gawande | 792c6aa | 2015-07-10 12:18:36 -0500 | [diff] [blame] | 24 | import os |
| 25 | |
| 26 | class NdnApplication: |
| 27 | def __init__(self, node): |
| 28 | self.node = node |
| 29 | self.isRunning = False |
Ashlesh Gawande | c09c16d | 2016-08-05 14:13:12 -0500 | [diff] [blame] | 30 | self.processId = "" |
Ashlesh Gawande | 792c6aa | 2015-07-10 12:18:36 -0500 | [diff] [blame] | 31 | |
| 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 Gawande | 532302b | 2018-02-15 18:58:20 -0600 | [diff] [blame] | 46 | if self.isRunning and self.processId != "": |
| 47 | self.node.cmd("sudo kill {}".format(self.processId)) |
Ashlesh Gawande | 792c6aa | 2015-07-10 12:18:36 -0500 | [diff] [blame] | 48 | |
| 49 | self.isRunning = False |