SMACC2
Loading...
Searching...
No Matches
smacc2_client_library
cl_px4_mr
include
cl_px4_mr
components
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
24
namespace
cl_px4_mr
25
{
26
27
class
CpMicroRosAgent
:
public
smacc2::ISmaccComponent
28
{
29
public
:
30
CpMicroRosAgent
(
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
42
private
:
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
cl_px4_mr::CpMicroRosAgent
Definition
cp_micro_ros_agent.hpp:28
cl_px4_mr::CpMicroRosAgent::CpMicroRosAgent
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")
Definition
cp_micro_ros_agent.cpp:80
cl_px4_mr::CpMicroRosAgent::watchdogPid_
pid_t watchdogPid_
Definition
cp_micro_ros_agent.hpp:51
cl_px4_mr::CpMicroRosAgent::command_
std::string command_
Definition
cp_micro_ros_agent.hpp:46
cl_px4_mr::CpMicroRosAgent::nodeName_
std::string nodeName_
Definition
cp_micro_ros_agent.hpp:47
cl_px4_mr::CpMicroRosAgent::readerThread_
std::thread readerThread_
Definition
cp_micro_ros_agent.hpp:54
cl_px4_mr::CpMicroRosAgent::launch
void launch()
Definition
cp_micro_ros_agent.cpp:87
cl_px4_mr::CpMicroRosAgent::mutex_
std::mutex mutex_
Definition
cp_micro_ros_agent.hpp:48
cl_px4_mr::CpMicroRosAgent::getNodeName
std::string getNodeName() const
Definition
cp_micro_ros_agent.cpp:267
cl_px4_mr::CpMicroRosAgent::shutdownRequested_
std::atomic< bool > shutdownRequested_
Definition
cp_micro_ros_agent.hpp:45
cl_px4_mr::CpMicroRosAgent::isLaunched
bool isLaunched() const
Definition
cp_micro_ros_agent.cpp:259
cl_px4_mr::CpMicroRosAgent::getPid
pid_t getPid() const
Definition
cp_micro_ros_agent.cpp:261
cl_px4_mr::CpMicroRosAgent::pipeFd_
int pipeFd_
Definition
cp_micro_ros_agent.hpp:49
cl_px4_mr::CpMicroRosAgent::shutdown
void shutdown()
Definition
cp_micro_ros_agent.cpp:200
cl_px4_mr::CpMicroRosAgent::~CpMicroRosAgent
~CpMicroRosAgent() override
Definition
cp_micro_ros_agent.cpp:85
cl_px4_mr::CpMicroRosAgent::launched_
std::atomic< bool > launched_
Definition
cp_micro_ros_agent.hpp:44
cl_px4_mr::CpMicroRosAgent::agentPid_
pid_t agentPid_
Definition
cp_micro_ros_agent.hpp:43
cl_px4_mr::CpMicroRosAgent::lifeFd_
int lifeFd_
Definition
cp_micro_ros_agent.hpp:52
smacc2::ISmaccComponent
Definition
component.hpp:30
cl_px4_mr
Definition
cl_px4_mr.hpp:31
smacc.hpp
Generated by
1.12.0