Goby3 3.2.3
2025.05.13
Loading...
Searching...
No Matches
publisher.h
Go to the documentation of this file.
1// Copyright 2019-2021:
2// GobySoft, LLC (2013-)
3// Community contributors (see AUTHORS file)
4// File authors:
5// Toby Schneider <toby@gobysoft.org>
6//
7//
8// This file is part of the Goby Underwater Autonomy Project Libraries
9// ("The Goby Libraries").
10//
11// The Goby Libraries are free software: you can redistribute them and/or modify
12// them under the terms of the GNU Lesser General Public License as published by
13// the Free Software Foundation, either version 2.1 of the License, or
14// (at your option) any later version.
15//
16// The Goby Libraries are distributed in the hope that they will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Lesser General Public License for more details.
20//
21// You should have received a copy of the GNU Lesser General Public License
22// along with Goby. If not, see <http://www.gnu.org/licenses/>.
23
24#ifndef GOBY_MIDDLEWARE_TRANSPORT_PUBLISHER_H
25#define GOBY_MIDDLEWARE_TRANSPORT_PUBLISHER_H
26
27#include <functional>
28
33
34namespace goby
35{
36namespace middleware
37{
39template <typename Data> class Publisher
40{
41 public:
42 using set_group_func_type = std::function<void(Data&, const Group&)>;
44 std::function<void(const Data&, const intervehicle::protobuf::AckData&)>;
46 std::function<void(const Data&, const intervehicle::protobuf::ExpireData&)>;
47
59 : cfg_(cfg),
60 set_group_func_(set_group_func),
61 acked_func_(acked_func),
62 expired_func_(expired_func)
63 {
64 // if an ack function is set, we assume we require an ack
65 if (acked_func_ && !cfg_.intervehicle().buffer().has_ack_required())
66 {
68 }
69 }
70
77
79
81 const goby::middleware::protobuf::TransporterConfig& cfg() const { return cfg_; }
82
84 void set_group(Data& data, const Group& group) const
85 {
86 if (set_group_func_)
87 set_group_func_(data, group);
88 };
89
91 acked_func_type acked_func() const { return acked_func_; }
93 expired_func_type expired_func() const { return expired_func_; }
94
95 bool has_set_group_func() const { return bool(set_group_func_); }
96
97 private:
99 set_group_func_type set_group_func_;
100 acked_func_type acked_func_;
101 expired_func_type expired_func_;
102};
103
104} // namespace middleware
105} // namespace goby
106
107#endif
Class for grouping publications in the Goby middleware. Analogous to "topics" in ROS,...
Definition group.h:60
Class that holds additional metadata and callback functions related to a publication (and is optional...
Definition publisher.h:40
const goby::middleware::protobuf::TransporterConfig & cfg() const
Returns the metadata configuration.
Definition publisher.h:81
std::function< void(const Data &, const intervehicle::protobuf::AckData &)> acked_func_type
Definition publisher.h:44
acked_func_type acked_func() const
Returns the acked data callback (or an empty function if none is set)
Definition publisher.h:91
bool has_set_group_func() const
Definition publisher.h:95
void set_group(Data &data, const Group &group) const
Sets the group using the set_group_func. Only intended to be called by the various transporters.
Definition publisher.h:84
std::function< void(Data &, const Group &)> set_group_func_type
Definition publisher.h:42
Publisher(const goby::middleware::protobuf::TransporterConfig &cfg, acked_func_type acked_func, expired_func_type expired_func=expired_func_type())
Construct a Publisher but without the set_group_func callback.
Definition publisher.h:72
std::function< void(const Data &, const intervehicle::protobuf::ExpireData &)> expired_func_type
Definition publisher.h:46
Publisher(const goby::middleware::protobuf::TransporterConfig &cfg=goby::middleware::protobuf::TransporterConfig(), set_group_func_type set_group_func=set_group_func_type(), acked_func_type acked_func=acked_func_type(), expired_func_type expired_func=expired_func_type())
Construct a Publisher with all available metadata and callbacks.
Definition publisher.h:54
expired_func_type expired_func() const
Returns the expired data callback (or an empty function if none is set)
Definition publisher.h:93
const ::goby::acomms::protobuf::DynamicBufferConfig & buffer() const
const ::goby::middleware::intervehicle::protobuf::TransporterConfig & intervehicle() const
::goby::middleware::intervehicle::protobuf::TransporterConfig * mutable_intervehicle()
goby::util::logger::GroupSetter group(std::string n)
The global namespace for the Goby project.