Coverage Report

Created: 2026-06-15 06:51

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/behaviortreecpp/src/actions/updated_action.cpp
Line
Count
Source
1
/* Copyright (C) 2024-2025 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
13
#include "behaviortree_cpp/actions/updated_action.h"
14
15
#include "behaviortree_cpp/bt_factory.h"
16
17
namespace BT
18
{
19
20
EntryUpdatedAction::EntryUpdatedAction(const std::string& name, const NodeConfig& config)
21
0
  : SyncActionNode(name, config)
22
0
{
23
0
  auto it = config.input_ports.find("entry");
24
0
  if(it == config.input_ports.end() || it->second.empty())
25
0
  {
26
0
    throw LogicError("Missing port 'entry' in ", name);
27
0
  }
28
0
  const auto entry_str = it->second;
29
0
  StringView stripped_key;
30
0
  if(isBlackboardPointer(entry_str, &stripped_key))
31
0
  {
32
0
    entry_key_ = stripped_key;
33
0
  }
34
0
  else
35
0
  {
36
0
    entry_key_ = entry_str;
37
0
  }
38
0
}
39
40
NodeStatus EntryUpdatedAction::tick()
41
0
{
42
0
  if(auto entry = config().blackboard->getEntry(entry_key_))
43
0
  {
44
0
    const std::unique_lock lk(entry->entry_mutex);
45
0
    const uint64_t current_id = entry->sequence_id;
46
0
    const uint64_t previous_id = sequence_id_;
47
0
    sequence_id_ = current_id;
48
    /*
49
    uint64_t previous_id = 0;
50
    auto& previous_id_registry = details::GlobalSequenceRegistry();
51
52
    // find the previous id in the registry.
53
    auto it = previous_id_registry.find(entry.get());
54
    if(it != previous_id_registry.end())
55
    {
56
      previous_id = it->second;
57
    }
58
    if(previous_id != current_id)
59
    {
60
      previous_id_registry[entry.get()] = current_id;
61
    }*/
62
0
    return (previous_id != current_id) ? NodeStatus::SUCCESS : NodeStatus::FAILURE;
63
0
  }
64
0
  else
65
0
  {
66
0
    return NodeStatus::FAILURE;
67
0
  }
68
0
}
69
70
}  // namespace BT