From e17d81af21bb91eb9054fb201d95bd1db109035e Mon Sep 17 00:00:00 2001 From: Jacob Dahl <37091262+dakejahl@users.noreply.github.com> Date: Sun, 31 May 2026 00:41:49 -0400 Subject: [PATCH] refactor(uORB): hoist Publication advertise/publish to base (#27526) Signed-off-by: Jacob Dahl --- platforms/common/uORB/Publication.hpp | 37 +++++++++++++++------------ 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/platforms/common/uORB/Publication.hpp b/platforms/common/uORB/Publication.hpp index a0a7cc20cf7..d8415c43140 100644 --- a/platforms/common/uORB/Publication.hpp +++ b/platforms/common/uORB/Publication.hpp @@ -54,6 +54,15 @@ public: bool advertised() const { return _handle != nullptr; } + bool advertise() + { + if (!advertised()) { + _handle = orb_advertise(get_topic(), nullptr); + } + + return advertised(); + } + bool unadvertise() { return (Manager::orb_unadvertise(_handle) == PX4_OK); } orb_id_t get_topic() const { return get_orb_meta(_orb_id); } @@ -72,6 +81,16 @@ protected: } } + // type-independent publish; data points to a message of the topic's type + bool publish(const void *data) + { + if (!advertised()) { + advertise(); + } + + return (Manager::orb_publish(get_topic(), _handle, data) == PX4_OK); + } + orb_advert_t _handle{nullptr}; const ORB_ID _orb_id; }; @@ -92,27 +111,11 @@ public: Publication(ORB_ID id) : PublicationBase(id) {} Publication(const orb_metadata *meta) : PublicationBase(static_cast(meta->o_id)) {} - bool advertise() - { - if (!advertised()) { - _handle = orb_advertise(get_topic(), nullptr); - } - - return advertised(); - } - /** * Publish the struct * @param data The uORB message struct we are updating. */ - bool publish(const T &data) - { - if (!advertised()) { - advertise(); - } - - return (Manager::orb_publish(get_topic(), _handle, &data) == PX4_OK); - } + bool publish(const T &data) { return PublicationBase::publish(&data); } }; /**