SMACC2
Loading...
Searching...
No Matches
cp_micro_ros_agent.hpp
Go to the documentation of this file.
1// Copyright 2025 Robosoft 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#pragma once
16
17#include <sys/types.h>
18#include <atomic>
19#include <mutex>
20#include <smacc2/smacc.hpp>
21#include <string>
22#include <thread>
23
24namespace cl_px4_mr
25{
26
28{
29public:
31 std::string command =
32 "ros2 run micro_ros_agent micro_ros_agent udp4 -p 8888 2>&1 | tee /tmp/xrce_agent.log",
33 std::string nodeName = "/px4_micro_xrce_dds");
34 ~CpMicroRosAgent() override;
35
36 void launch();
37 void shutdown();
38 bool isLaunched() const;
39 pid_t getPid() const;
40 std::string getNodeName() const;
41
42private:
43 pid_t agentPid_ = -1;
44 std::atomic<bool> launched_{false};
45 std::atomic<bool> shutdownRequested_{false};
46 std::string command_;
47 std::string nodeName_;
48 mutable std::mutex mutex_;
49 int pipeFd_ = -1;
50 // Watchdog process and the pipe end whose closing tells it this process is gone
51 pid_t watchdogPid_ = -1;
52 int lifeFd_ = -1;
53 // Drains the agent's output pipe; joined in shutdown() so it never outlives this component.
54 std::thread readerThread_;
55};
56
57} // namespace cl_px4_mr
CpMicroRosAgent(std::string command="ros2 run micro_ros_agent micro_ros_agent udp4 -p 8888 2>&1 | tee /tmp/xrce_agent.log", std::string nodeName="/px4_micro_xrce_dds")
std::atomic< bool > shutdownRequested_