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
23namespace cl_px4_mr
24{
25
27{
28public:
30 std::string command =
31 "ros2 run micro_ros_agent micro_ros_agent udp4 -p 8888 2>&1 | tee /tmp/xrce_agent.log",
32 std::string nodeName = "/px4_micro_xrce_dds");
33 virtual ~CpMicroRosAgent();
34
35 void launch();
36 void shutdown();
37 bool isLaunched() const;
38 pid_t getPid() const;
39 std::string getNodeName() const;
40
41private:
42 static void killProcessesRecursive(pid_t pid);
43
44 pid_t agentPid_ = -1;
45 std::atomic<bool> launched_{false};
46 std::atomic<bool> shutdownRequested_{false};
47 std::string command_;
48 std::string nodeName_;
49 mutable std::mutex mutex_;
50 int pipeFd_ = -1;
51};
52
53} // 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_
static void killProcessesRecursive(pid_t pid)