Goby3  3.1.5a
2024.05.23
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 
30 #include "goby/middleware/group.h"
33 
34 namespace goby
35 {
36 namespace middleware
37 {
39 template <typename Data> class Publisher
40 {
41  public:
42  using set_group_func_type = std::function<void(Data&, const Group&)>;
43  using acked_func_type =
44  std::function<void(const Data&, const intervehicle::protobuf::AckData&)>;
45  using expired_func_type =
46  std::function<void(const Data&, const intervehicle::protobuf::ExpireData&)>;
47 
56  set_group_func_type set_group_func = set_group_func_type(),
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 
75  {
76  }
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
goby::middleware::Publisher::~Publisher
~Publisher()
Definition: publisher.h:78
goby
The global namespace for the Goby project.
Definition: acomms_constants.h:33
goby::middleware::Publisher::Publisher
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
goby::middleware::Publisher< intervehicle::protobuf::Subscription >::expired_func_type
std::function< void(const intervehicle::protobuf::Subscription &, const intervehicle::protobuf::ExpireData &)> expired_func_type
Definition: publisher.h:46
intervehicle.pb.h
group.h
goby::middleware::intervehicle::protobuf::AckData
Definition: intervehicle.pb.h:1475
group
goby::util::logger::GroupSetter group(std::string n)
Definition: logger_manipulators.h:134
goby::middleware::Publisher
Class that holds additional metadata and callback functions related to a publication (and is optional...
Definition: driver_thread.h:69
modem_message.pb.h
transporter_config.pb.h
goby::middleware::Publisher< intervehicle::protobuf::Subscription >::set_group_func_type
std::function< void(intervehicle::protobuf::Subscription &, const Group &)> set_group_func_type
Definition: publisher.h:42
detail::void
j template void())
Definition: json.hpp:4822
goby::middleware::protobuf::TransporterConfig
Definition: transporter_config.pb.h:74
goby::middleware::Publisher::acked_func
acked_func_type acked_func() const
Returns the acked data callback (or an empty function if none is set)
Definition: publisher.h:91
bool
goby::middleware::Publisher::set_group
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
goby::middleware::protobuf::TransporterConfig::intervehicle
const ::goby::middleware::intervehicle::protobuf::TransporterConfig & intervehicle() const
Definition: transporter_config.pb.h:249
goby::middleware::protobuf::TransporterConfig::mutable_intervehicle
::goby::middleware::intervehicle::protobuf::TransporterConfig * mutable_intervehicle()
Definition: transporter_config.pb.h:262
goby::middleware::Publisher< intervehicle::protobuf::Subscription >::acked_func_type
std::function< void(const intervehicle::protobuf::Subscription &, const intervehicle::protobuf::AckData &)> acked_func_type
Definition: publisher.h:44
goby::middleware::intervehicle::protobuf::ExpireData
Definition: intervehicle.pb.h:1622
goby::middleware::Publisher::cfg
const goby::middleware::protobuf::TransporterConfig & cfg() const
Returns the metadata configuration.
Definition: publisher.h:81
goby::middleware::Publisher::Publisher
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
goby::middleware::Group
Class for grouping publications in the Goby middleware. Analogous to "topics" in ROS,...
Definition: group.h:59
goby::acomms::protobuf::DynamicBufferConfig::has_ack_required
bool has_ack_required() const
Definition: buffer.pb.h:279
goby::middleware::Publisher::has_set_group_func
bool has_set_group_func() const
Definition: publisher.h:95
goby::middleware::intervehicle::protobuf::TransporterConfig::buffer
const ::goby::acomms::protobuf::DynamicBufferConfig & buffer() const
Definition: intervehicle_transporter_config.pb.h:305
goby::acomms::protobuf::DynamicBufferConfig::set_ack_required
void set_ack_required(bool value)
Definition: buffer.pb.h:296
goby::middleware::Publisher::expired_func
expired_func_type expired_func() const
Returns the expired data callback (or an empty function if none is set)
Definition: publisher.h:93
goby::middleware::intervehicle::protobuf::TransporterConfig::mutable_buffer
::goby::acomms::protobuf::DynamicBufferConfig * mutable_buffer()
Definition: intervehicle_transporter_config.pb.h:318