Skip to content

Commit ae0b949

Browse files
jeplerpetterreinholdtsen
authored andcommitted
halcmd: improve user feedback when loading components
Now, when a component takes a long time to load, and other components load in the meantime, a diagnostic is shown on stderr of the form: While waiting for 'wrongname', component 'example' loaded. Did you specify the correct name via 'loadusr -Wn'? Signed-off-by: Jeff Epler <jepler@unpythonic.net>
1 parent 632fcbd commit ae0b949

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

src/hal/utils/halcmd_commands.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,28 @@ is not fixed or has regressed by debian jessie)
14421442
#endif
14431443
}
14441444

1445+
#include <set>
1446+
#include <string>
1447+
1448+
static std::set<std::string> get_all_comp_names() {
1449+
std::set<std::string> result;
1450+
for(auto comp = hal_data->comp_list_ptr; comp; comp=comp->next_ptr) {
1451+
result.insert(comp->name);
1452+
}
1453+
return result;
1454+
}
1455+
1456+
static void warn_newly_loaded_comps(std::set<std::string> &names, const char *newname) {
1457+
auto new_names = get_all_comp_names();
1458+
for(const auto &name : new_names) {
1459+
if(name == newname) continue;
1460+
if(names.find(name) == names.end()) {
1461+
fprintf(stderr, "\nWhile waiting for '%s', component '%s' loaded.\nDid you specify the correct name via 'loadusr -Wn'?", newname, name.c_str());
1462+
}
1463+
}
1464+
std::swap(new_names, names);
1465+
}
1466+
14451467
int do_loadusr_cmd(const char *args[])
14461468
{
14471469
int wait_flag, wait_comp_flag, ignore_flag;
@@ -1490,6 +1512,9 @@ int do_loadusr_cmd(const char *args[])
14901512
if(!new_comp_name) {
14911513
new_comp_name = guess_comp_name(prog_name);
14921514
}
1515+
1516+
std::set<std::string> comp_names_pre = get_all_comp_names();
1517+
14931518
/* prepare to exec() the program */
14941519
argv[0] = prog_name;
14951520
/* loop thru remaining arguments */
@@ -1539,9 +1564,11 @@ int do_loadusr_cmd(const char *args[])
15391564
if(count == 200) {
15401565
fprintf(stderr, "Waiting for component '%s' to become ready.",
15411566
new_comp_name);
1567+
warn_newly_loaded_comps(comp_names_pre, new_comp_name);
15421568
fflush(stderr);
15431569
} else if(count > 200 && count % 10 == 0) {
15441570
fprintf(stderr, ".");
1571+
warn_newly_loaded_comps(comp_names_pre, new_comp_name);
15451572
fflush(stderr);
15461573
}
15471574
}

0 commit comments

Comments
 (0)