mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-27 10:17:45 +08:00
microRTPS: agent: simplify Subscriber code specialization
This commit is contained in:
@@ -70,9 +70,15 @@ except AttributeError:
|
|||||||
|
|
||||||
#include "@(topic)_Subscriber.h"
|
#include "@(topic)_Subscriber.h"
|
||||||
|
|
||||||
@(topic)_Subscriber::@(topic)_Subscriber() : mp_participant(nullptr), mp_subscriber(nullptr) {}
|
@(topic)_Subscriber::@(topic)_Subscriber()
|
||||||
|
: mp_participant(nullptr),
|
||||||
|
mp_subscriber(nullptr)
|
||||||
|
{ }
|
||||||
|
|
||||||
@(topic)_Subscriber::~@(topic)_Subscriber() { Domain::removeParticipant(mp_participant);}
|
@(topic)_Subscriber::~@(topic)_Subscriber()
|
||||||
|
{
|
||||||
|
Domain::removeParticipant(mp_participant);
|
||||||
|
}
|
||||||
|
|
||||||
bool @(topic)_Subscriber::init(uint8_t topic_ID, std::condition_variable* t_send_queue_cv, std::mutex* t_send_queue_mutex, std::queue<uint8_t>* t_send_queue)
|
bool @(topic)_Subscriber::init(uint8_t topic_ID, std::condition_variable* t_send_queue_cv, std::mutex* t_send_queue_mutex, std::queue<uint8_t>* t_send_queue)
|
||||||
{
|
{
|
||||||
@@ -89,7 +95,7 @@ bool @(topic)_Subscriber::init(uint8_t topic_ID, std::condition_variable* t_send
|
|||||||
@[else]@
|
@[else]@
|
||||||
PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
|
PParam.rtps.builtin.discovery_config.leaseDuration = c_TimeInfinite;
|
||||||
@[end if]@
|
@[end if]@
|
||||||
PParam.rtps.setName("@(topic)_subscriber"); //You can put the name you want
|
PParam.rtps.setName("@(topic)_subscriber");
|
||||||
mp_participant = Domain::createParticipant(PParam);
|
mp_participant = Domain::createParticipant(PParam);
|
||||||
if(mp_participant == nullptr)
|
if(mp_participant == nullptr)
|
||||||
return false;
|
return false;
|
||||||
@@ -199,19 +205,7 @@ bool @(topic)_Subscriber::hasMsg()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@[if fastrtps_version <= 1.7]@
|
@(topic)_msg_t @(topic)_Subscriber::getMsg()
|
||||||
@[ if ros2_distro]@
|
|
||||||
@(package)::msg::dds_::@(topic)_ @(topic)_Subscriber::getMsg()
|
|
||||||
@[ else]@
|
|
||||||
@(topic)_ @(topic)_Subscriber::getMsg()
|
|
||||||
@[ end if]@
|
|
||||||
@[else]@
|
|
||||||
@[ if ros2_distro]@
|
|
||||||
@(package)::msg::@(topic) @(topic)_Subscriber::getMsg()
|
|
||||||
@[ else]@
|
|
||||||
@(topic) @(topic)_Subscriber::getMsg()
|
|
||||||
@[ end if]@
|
|
||||||
@[end if]@
|
|
||||||
{
|
{
|
||||||
return m_listener.msg;
|
return m_listener.msg;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,6 +81,24 @@ except AttributeError:
|
|||||||
using namespace eprosima::fastrtps;
|
using namespace eprosima::fastrtps;
|
||||||
using namespace eprosima::fastrtps::rtps;
|
using namespace eprosima::fastrtps::rtps;
|
||||||
|
|
||||||
|
@[if fastrtps_version <= 1.7]@
|
||||||
|
@[ if ros2_distro]@
|
||||||
|
using @(topic)_msg_t = @(package)::msg::dds_::@(topic)_;
|
||||||
|
using @(topic)_msg_datatype = @(package)::msg::dds_::@(topic)_PubSubType;
|
||||||
|
@[ else]@
|
||||||
|
using @(topic)_msg_t = @(topic)_;
|
||||||
|
using @(topic)_msg_datatype = @(topic)_PubSubType;
|
||||||
|
@[ end if]@
|
||||||
|
@[else]@
|
||||||
|
@[ if ros2_distro]@
|
||||||
|
using @(topic)_msg_t = @(package)::msg::@(topic);
|
||||||
|
using @(topic)_msg_datatype = @(package)::msg::@(topic)PubSubType;
|
||||||
|
@[ else]@
|
||||||
|
using @(topic)_msg_t = @(topic);
|
||||||
|
using @(topic)_msg_datatype = @(topic)PubSubType;
|
||||||
|
@[ end if]@
|
||||||
|
@[end if]@
|
||||||
|
|
||||||
class @(topic)_Subscriber
|
class @(topic)_Subscriber
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -89,19 +107,7 @@ public:
|
|||||||
bool init(uint8_t topic_ID, std::condition_variable* t_send_queue_cv, std::mutex* t_send_queue_mutex, std::queue<uint8_t>* t_send_queue);
|
bool init(uint8_t topic_ID, std::condition_variable* t_send_queue_cv, std::mutex* t_send_queue_mutex, std::queue<uint8_t>* t_send_queue);
|
||||||
void run();
|
void run();
|
||||||
bool hasMsg();
|
bool hasMsg();
|
||||||
@[if fastrtps_version <= 1.7]@
|
@(topic)_msg_t getMsg();
|
||||||
@[ if ros2_distro]@
|
|
||||||
@(package)::msg::dds_::@(topic)_ getMsg();
|
|
||||||
@[ else]@
|
|
||||||
@(topic)_ getMsg();
|
|
||||||
@[ end if]@
|
|
||||||
@[else]@
|
|
||||||
@[ if ros2_distro]@
|
|
||||||
@(package)::msg::@(topic) getMsg();
|
|
||||||
@[ else]@
|
|
||||||
@(topic) getMsg();
|
|
||||||
@[ end if]@
|
|
||||||
@[end if]@
|
|
||||||
void unlockMsg();
|
void unlockMsg();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -118,19 +124,7 @@ private:
|
|||||||
SampleInfo_t m_info;
|
SampleInfo_t m_info;
|
||||||
int n_matched;
|
int n_matched;
|
||||||
int n_msg;
|
int n_msg;
|
||||||
@[if fastrtps_version <= 1.7]@
|
@(topic)_msg_t msg;
|
||||||
@[ if ros2_distro]@
|
|
||||||
@(package)::msg::dds_::@(topic)_ msg;
|
|
||||||
@[ else]@
|
|
||||||
@(topic)_ msg;
|
|
||||||
@[ end if]@
|
|
||||||
@[else]@
|
|
||||||
@[ if ros2_distro]@
|
|
||||||
@(package)::msg::@(topic) msg;
|
|
||||||
@[ else]@
|
|
||||||
@(topic) msg;
|
|
||||||
@[ end if]@
|
|
||||||
@[end if]@
|
|
||||||
std::atomic_bool has_msg;
|
std::atomic_bool has_msg;
|
||||||
uint8_t topic_ID;
|
uint8_t topic_ID;
|
||||||
std::condition_variable* t_send_queue_cv;
|
std::condition_variable* t_send_queue_cv;
|
||||||
@@ -140,19 +134,7 @@ private:
|
|||||||
std::mutex has_msg_mutex;
|
std::mutex has_msg_mutex;
|
||||||
|
|
||||||
} m_listener;
|
} m_listener;
|
||||||
@[if fastrtps_version <= 1.7]@
|
@(topic)_msg_datatype @(topic)DataType;
|
||||||
@[ if ros2_distro]@
|
|
||||||
@(package)::msg::dds_::@(topic)_PubSubType @(topic)DataType;
|
|
||||||
@[ else]@
|
|
||||||
@(topic)_PubSubType @(topic)DataType;
|
|
||||||
@[ end if]@
|
|
||||||
@[else]@
|
|
||||||
@[ if ros2_distro]@
|
|
||||||
@(package)::msg::@(topic)PubSubType @(topic)DataType;
|
|
||||||
@[ else]@
|
|
||||||
@(topic)PubSubType @(topic)DataType;
|
|
||||||
@[ end if]@
|
|
||||||
@[end if]@
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _@(topic)__SUBSCRIBER_H_
|
#endif // _@(topic)__SUBSCRIBER_H_
|
||||||
|
|||||||
Reference in New Issue
Block a user