Skip to content

Commit

Permalink
impl kill behavior button
Browse files Browse the repository at this point in the history
  • Loading branch information
TakashiSato committed Nov 12, 2023
1 parent 17b87cd commit c7b0bc0
Showing 1 changed file with 54 additions and 5 deletions.
59 changes: 54 additions & 5 deletions src/ui/ui_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ UI.Menu = new (function() {
["Edit Code", "page_edit", function() { UI.Menu.scEditClicked(); }, "ctrl+e"]
],
[
["Check Behavior", "check", function() { UI.Menu.checkBehaviorClicked(); }]
["Check Behavior", "check", function() { UI.Menu.checkBehaviorClicked(); }],
["Kill Behavior", "cross", function() { UI.Menu.killBehaviorClicked(); }]
]
];
var button_config_sm = [
Expand Down Expand Up @@ -61,12 +62,14 @@ UI.Menu = new (function() {
];
var button_config_rc = [
[
["Show Terminal", "title_terminal", function() { UI.Menu.terminalClicked(); }, undefined]
["Show Terminal", "title_terminal", function() { UI.Menu.terminalClicked(); }, undefined],
["Kill Behavior", "cross", function() { UI.Menu.killBehaviorClicked(); }]
]
];
var button_config_se = [
[
["Show Terminal", "title_terminal", function() { UI.Menu.terminalClicked(); }, undefined]
["Show Terminal", "title_terminal", function() { UI.Menu.terminalClicked(); }, undefined],
["Kill Behavior", "cross", function() { UI.Menu.killBehaviorClicked(); }]
],
[
["Import Configuration", "settings_import", function() { UI.Settings.importConfiguration(); }],
Expand All @@ -89,7 +92,7 @@ UI.Menu = new (function() {
td = document.createElement("td");
td.setAttribute("class", "tool_button");
td.setAttribute("id", "tool_button " + button[0]);
td.innerHTML =
td.innerHTML =
'<table cellpadding="0" cellspacing="0"><tr><td valign="middle">' +
'<img src="img/' + button[1] + '.png" />' +
'</td><td valign="middle" style="padding-left:5px">' +
Expand Down Expand Up @@ -283,6 +286,52 @@ UI.Menu = new (function() {
UI.Panels.Terminal.show();
}

this.killBehaviorClicked = function() {
try {
var rosnodeList = spawn("rosnode", ["list"]);

let nodeList = ''
rosnodeList.stdout.on('data', (data) => {
nodeList += data.toString();
});
rosnodeList.stderr.on('data', (data) => {
T.logWarn(data);
return;
});
rosnodeList.on('close', () => {
// 出力を行に分割
const lines = nodeList.split('\n');

// bahaviorで終わるノード名を抽出
const filteredLines = lines.filter(line => line.endsWith('/behavior'));
if (filteredLines.length == 0) {
T.logWarn("behavior node is not found");
return;
}
if (filteredLines.length != 1) {
T.logWarn("behavior node is not unique");
return;
}

const behaviorNodeName = filteredLines[0];
T.show();
T.logInfo(`killing behavior node: ${behaviorNodeName}`);

// behaviorノードをkill
var rosnodeKill = spawn("rosnode", ["kill", behaviorNodeName]);
rosnodeKill.stderr.on('data', (data) => {
T.logWarn(data);
});
rosnodeKill.on('close', () => {
T.logInfo(`killed behavior node: ${behaviorNodeName}`);
UI.Panels.Terminal.hide();
})
});
} catch (err) {
T.logError("failed to kill behavior node");
}
}

this.saveBehaviorClicked = function() {
var check_error_string = undefined;
if (Behavior.isReadonly()) {
Expand Down Expand Up @@ -325,7 +374,7 @@ UI.Menu = new (function() {

this.loadBehaviorClicked = function() {
if (RC.Controller.isReadonly()) return;

UI.Panels.SelectBehavior.setSelectionCallback(function(manifest) {
IO.BehaviorLoader.loadBehavior(manifest);
});
Expand Down

0 comments on commit c7b0bc0

Please sign in to comment.