Firmware
Publication.hpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (c) 2012-2017 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
39 #pragma once
40 
41 #include <uORB/uORB.h>
42 #include <containers/List.hpp>
43 #include <systemlib/err.h>
44 
45 namespace uORB
46 {
47 
53 {
54 public:
55 
64  PublicationBase(const struct orb_metadata *meta, int priority = -1);
65 
66  virtual ~PublicationBase();
67 
68  // no copy, assignment, move, move assignment
69  PublicationBase(const PublicationBase &) = delete;
70  PublicationBase &operator=(const PublicationBase &) = delete;
71  PublicationBase(PublicationBase &&) = delete;
72  PublicationBase &operator=(PublicationBase &&) = delete;
73 
78  bool update(void *data);
79 
80 protected:
81  const struct orb_metadata *_meta;
82  const int _priority;
83 
84  orb_advert_t _handle{nullptr};
85 };
86 
92 
96 class __EXPORT PublicationNode : public PublicationBase, public ListNode<PublicationNode *>
97 {
98 public:
108  PublicationNode(const struct orb_metadata *meta, int priority = -1, List<PublicationNode *> *list = nullptr);
109  virtual ~PublicationNode() override = default;
110 
115  virtual bool update() = 0;
116 };
117 
121 template<class T>
123 {
124 public:
134  Publication(const struct orb_metadata *meta, int priority = -1, List<PublicationNode *> *list = nullptr) :
135  PublicationNode(meta, priority, list),
136  _data()
137  {
138  }
139 
140  ~Publication() override = default;
141 
142  // no copy, assignment, move, move assignment
143  Publication(const Publication &) = delete;
144  Publication &operator=(const Publication &) = delete;
145  Publication(Publication &&) = delete;
146  Publication &operator=(Publication &&) = delete;
147 
148  /*
149  * This function gets the T struct
150  * */
151  T &get() { return _data; }
152 
156  bool update() override
157  {
158  return PublicationBase::update((void *)(&_data));
159  }
160 
161  bool update(const T &data)
162  {
163  _data = data;
164  return update();
165  }
166 
167 private:
168  T _data;
169 };
170 
171 } // namespace uORB
An intrusive linked list.
Definition: List.hpp:45
__BEGIN_DECLS typedef void * orb_advert_t
ORB topic advertiser handle.
Definition: uORB.h:134
Definition: uORBFastRpcChannel.hpp:44
Publication(const struct orb_metadata *meta, int priority=-1, List< PublicationNode *> *list=nullptr)
Constructor.
Definition: Publication.hpp:134
bool update(void *data)
Update the struct.
Definition: Publication.cpp:56
Base publication wrapper class, used in list traversal of various publications.
Definition: Publication.hpp:52
Definition: List.hpp:59
Definition: I2C.hpp:51
API for the uORB lightweight object broker.
Simple error/warning functions, heavily inspired by the BSD functions of the same names...
Object metadata.
Definition: uORB.h:50
Publication wrapper class.
Definition: Publication.hpp:122
bool update() override
Create an update function that uses the embedded struct.
Definition: Publication.hpp:156
The publication base class as a list node.
Definition: Publication.hpp:96