Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/blackboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,15 @@ Blackboard::Ptr Blackboard::parent()
std::shared_ptr<Blackboard::Entry> Blackboard::createEntryImpl(const std::string& key,
const TypeInfo& info)
{
// special syntax: "@" always refers to the root blackboard, the same
// redirection getEntry() applies. Without it, a key remapped to a root
// entry (port="{@foo}") is created here as a literal "@foo" entry that
// getEntry() then strips to "foo" and can never find again.
if(StartWith(key, '@'))
{
return rootBlackboard()->createEntryImpl(key.substr(1, key.size() - 1), info);
}

const std::unique_lock storage_lock(storage_mutex_);
// This function might be called recursively, when we do remapping, because we move
// to the top scope to find already existing entries
Expand Down
23 changes: 23 additions & 0 deletions tests/gtest_blackboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,29 @@ TEST(BlackboardTest, RootBlackboard)
ASSERT_EQ(4, tree.rootBlackboard()->get<int>("var5"));
}

TEST(BlackboardTest, RemapToRootBlackboard)
{
// A subtree port remapped to a root key (XML: param="{@shared}") must resolve
// to the "shared" entry in the root blackboard. createEntryImpl used to create
// it as a literal "@shared" entry instead, so getEntry("param") -- which strips
// the '@' and looks up "shared" in the root -- never found it again. That made
// ImportBlackboardFromJSON dereference a null entry, and set()/get() disagree.
auto root = Blackboard::create();
auto child = Blackboard::create(root);
child->addSubtreeRemapping("param", "@shared");

nlohmann::json js;
js["param"] = 42;
ASSERT_NO_THROW(ImportBlackboardFromJSON(js, *child));

ASSERT_EQ(42, child->get<int>("param"));
ASSERT_EQ(42, root->get<int>("shared"));

child->set("param", 7);
ASSERT_EQ(7, child->get<int>("param"));
ASSERT_EQ(7, root->get<int>("shared"));
}

TEST(BlackboardTest, TimestampedInterface)
{
auto bb = BT::Blackboard::create();
Expand Down
Loading