|
| 1 | +// Copyright 2025 Tier IV, Inc. |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +#ifndef AUTOWARE_NODE_DEATH_MONITOR__AUTOWARE_NODE_DEATH_MONITOR_HPP_ |
| 16 | +#define AUTOWARE_NODE_DEATH_MONITOR__AUTOWARE_NODE_DEATH_MONITOR_HPP_ |
| 17 | + |
| 18 | +#include "rclcpp/rclcpp.hpp" |
| 19 | + |
| 20 | +#include <filesystem> |
| 21 | +#include <string> |
| 22 | +#include <unordered_map> |
| 23 | +#include <vector> |
| 24 | + |
| 25 | +namespace autoware::node_death_monitor |
| 26 | +{ |
| 27 | + |
| 28 | +class NodeDeathMonitor : public rclcpp::Node |
| 29 | +{ |
| 30 | +public: |
| 31 | + /** |
| 32 | + * @brief Constructor for NodeDeathMonitor |
| 33 | + * @param options Node options for configuration |
| 34 | + */ |
| 35 | + explicit NodeDeathMonitor(const rclcpp::NodeOptions & options); |
| 36 | + |
| 37 | +private: |
| 38 | + /** |
| 39 | + * @brief Read and process new content appended to launch.log |
| 40 | + */ |
| 41 | + void read_launch_log_diff(); |
| 42 | + |
| 43 | + /** |
| 44 | + * @brief Parse a single line from the log for process death information |
| 45 | + * @param line The log line to parse |
| 46 | + */ |
| 47 | + void parse_log_line(const std::string & line); |
| 48 | + |
| 49 | + /** |
| 50 | + * @brief Timer callback to report and manage dead node list |
| 51 | + */ |
| 52 | + void on_timer(); |
| 53 | + |
| 54 | + // Map to track dead nodes: [node_name-#] -> true |
| 55 | + std::unordered_map<std::string, bool> dead_nodes_; |
| 56 | + |
| 57 | + rclcpp::TimerBase::SharedPtr timer_; |
| 58 | + |
| 59 | + // Launch log file path and read position |
| 60 | + std::filesystem::path launch_log_path_; |
| 61 | + size_t last_file_pos_{static_cast<size_t>(-1)}; |
| 62 | + |
| 63 | + // Parameters |
| 64 | + std::vector<std::string> ignore_node_names_; // Node names to exclude from monitoring |
| 65 | + std::vector<int64_t> ignore_exit_codes_; // Exit codes to ignore (e.g., normal termination) |
| 66 | + double check_interval_{1.0}; // Check interval in seconds |
| 67 | + bool enable_debug_{false}; // Enable debug output |
| 68 | +}; |
| 69 | + |
| 70 | +} // namespace autoware::node_death_monitor |
| 71 | + |
| 72 | +#endif // AUTOWARE_NODE_DEATH_MONITOR__AUTOWARE_NODE_DEATH_MONITOR_HPP_ |
0 commit comments