updated_action.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2024 Davide Faconti - All Rights Reserved
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
4 * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
5 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
10 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
11 */
12 
15 
16 namespace BT
17 {
18 
19 EntryUpdatedAction::EntryUpdatedAction(const std::string& name, const NodeConfig& config)
20  : SyncActionNode(name, config)
21 {
22  auto it = config.input_ports.find("entry");
23  if(it == config.input_ports.end() || it->second.empty())
24  {
25  throw LogicError("Missing port 'entry' in ", name);
26  }
27  const auto entry_str = it->second;
28  StringView stripped_key;
29  if(isBlackboardPointer(entry_str, &stripped_key))
30  {
31  entry_key_ = stripped_key;
32  }
33  else
34  {
35  entry_key_ = entry_str;
36  }
37 }
38 
40 {
41  if(auto entry = config().blackboard->getEntry(entry_key_))
42  {
43  std::unique_lock lk(entry->entry_mutex);
44  const uint64_t current_id = entry->sequence_id;
45  const uint64_t previous_id = sequence_id_;
46  sequence_id_ = current_id;
47  /*
48  uint64_t previous_id = 0;
49  auto& previous_id_registry = details::GlobalSequenceRegistry();
50 
51  // find the previous id in the registry.
52  auto it = previous_id_registry.find(entry.get());
53  if(it != previous_id_registry.end())
54  {
55  previous_id = it->second;
56  }
57  if(previous_id != current_id)
58  {
59  previous_id_registry[entry.get()] = current_id;
60  }*/
61  return (previous_id != current_id) ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
62  }
63  else
64  {
65  return NodeStatus::FAILURE;
66  }
67 }
68 
69 } // namespace BT
BT
Definition: ex01_wrap_legacy.cpp:29
updated_action.h
BT::TreeNode::config
const NodeConfig & config() const
Definition: tree_node.cpp:351
BT::StringView
std::string_view StringView
Definition: basic_types.h:59
BT::NodeConfig::input_ports
PortsRemapping input_ports
Definition: tree_node.h:83
BT::EntryUpdatedAction::entry_key_
std::string entry_key_
Definition: updated_action.h:40
bt_factory.h
BT::LogicError
Definition: exceptions.h:45
BT::NodeStatus::FAILURE
@ FAILURE
BT::EntryUpdatedAction::tick
NodeStatus tick() override
Method to be implemented by the user.
Definition: updated_action.cpp:39
BT::TreeNode::name
const std::string & name() const
Name of the instance, not the type.
Definition: tree_node.cpp:302
BT::NodeStatus::SUCCESS
@ SUCCESS
BT::EntryUpdatedAction::EntryUpdatedAction
EntryUpdatedAction(const std::string &name, const NodeConfig &config)
Definition: updated_action.cpp:19
BT::EntryUpdatedAction::sequence_id_
uint64_t sequence_id_
Definition: updated_action.h:39
BT::NodeConfig
Definition: tree_node.h:73
BT::TreeNode::isBlackboardPointer
static bool isBlackboardPointer(StringView str, StringView *stripped_pointer=nullptr)
Check a string and return true if it matches the pattern: {...}.
Definition: tree_node.cpp:375
BT::SyncActionNode
The SyncActionNode is an ActionNode that explicitly prevents the status RUNNING and doesn't require a...
Definition: action_node.h:52
BT::NodeStatus
NodeStatus
Definition: basic_types.h:33


behaviortree_cpp_v4
Author(s): Davide Faconti
autogenerated on Fri Dec 13 2024 03:19:17