Skip to content

Commit

Permalink
add enable_app_replacement param in app_manager (#26)
Browse files Browse the repository at this point in the history
This allows for both behaviors (replace currently running app or error out) and let's users choose without changing code...
  • Loading branch information
knorth55 authored Oct 15, 2020
1 parent 7ef72d3 commit 4f30de2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion scripts/app_manager
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ def main():
rospy.logerr("Failed to load exchange: {}".format(e))
sys.exit(1)

enable_app_replacement = rospy.get_param('~enable_app_replacement', True)

am = app_manager.AppManager(
robot_name, interface_master, app_list, exchange, plugins)
robot_name, interface_master, app_list, exchange, plugins,
enable_app_replacement=enable_app_replacement)

rospy.on_shutdown(am.shutdown)

Expand Down
11 changes: 9 additions & 2 deletions src/app_manager/app_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,15 @@ class AppManager(object):

def __init__(
self, robot_name, interface_master, app_list,
exchange, plugins=None
exchange, plugins=None, enable_app_replacement=True,
):
self._robot_name = robot_name
self._interface_master = interface_master
self._app_list = app_list
self._current_app = self._current_app_definition = None
self._exchange = exchange
self._plugins = plugins
self._enable_app_replacement = enable_app_replacement

rospy.loginfo("Starting app manager for %s"%self._robot_name)

Expand Down Expand Up @@ -263,9 +264,15 @@ def handle_start_app(self, req):
if self._current_app:
if self._current_app_definition.name == req.name:
return StartAppResponse(started=True, message="app [%s] already started"%(req.name), namespace=self._app_interface)
elif not self._enable_app_replacement:
return StartAppResponse(
started=False,
message="app [%s] is denied because app [%s] is already running."
% (req.name, self._current_app_definition.name),
namespace=self._app_interface,
error_code=StatusCodes.MULTIAPP_NOT_SUPPORTED)
else:
self.stop_app(self._current_app_definition.name)
#return StartAppResponse(started=False, message="Please stop the running app before starting another app.", error_code=StatusCodes.MULTIAPP_NOT_SUPPORTED)

# TODO: the app list has already loaded the App data. We should use that instead for consistency

Expand Down

0 comments on commit 4f30de2

Please sign in to comment.