RDMnet  HEAD (unstable)
Implementation of ANSI E1.33 (RDMnet)
View other versions:
common.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2020 ETC Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************
16  * This file is a part of RDMnet. For more information, go to:
17  * https://github.com/ETCLabs/RDMnet
18  *****************************************************************************/
19 
20 #ifndef RDMNET_CPP_COMMON_H_
21 #define RDMNET_CPP_COMMON_H_
22 
25 
26 #include "etcpal/cpp/error.h"
27 #include "etcpal/cpp/log.h"
28 #include "rdmnet/common.h"
29 
34 
38 
40 namespace rdmnet
41 {
43 enum class McastMode
44 {
45  kEnabledOnAllInterfaces,
46  kDisabledOnAllInterfaces
47 };
48 
61 inline etcpal::Error Init(const EtcPalLogParams* log_params = nullptr,
63 {
64  if (mcast_netints.empty())
65  {
66  return rdmnet_init(log_params, nullptr);
67  }
68  else
69  {
70  RdmnetNetintConfig config = {mcast_netints.data(), mcast_netints.size(), false};
71  return rdmnet_init(log_params, &config);
72  }
73 }
74 
86 inline etcpal::Error Init(const etcpal::Logger& logger,
88 {
89  if (mcast_netints.empty())
90  {
91  return rdmnet_init(&logger.log_params(), nullptr);
92  }
93  else
94  {
95  RdmnetNetintConfig config = {mcast_netints.data(), mcast_netints.size(), false};
96  return rdmnet_init(&logger.log_params(), &config);
97  }
98 }
99 
111 inline etcpal::Error Init(const EtcPalLogParams* log_params, McastMode mcast_mode)
112 {
113  RdmnetNetintConfig config = {nullptr, 0u, (mcast_mode == McastMode::kDisabledOnAllInterfaces)};
114  return rdmnet_init(log_params, &config);
115 }
116 
127 inline etcpal::Error Init(const etcpal::Logger& logger, McastMode mcast_mode)
128 {
129  RdmnetNetintConfig config = {nullptr, 0u, (mcast_mode == McastMode::kDisabledOnAllInterfaces)};
130  return rdmnet_init(&logger.log_params(), &config);
131 }
132 
138 inline void Deinit()
139 {
140  return rdmnet_deinit();
141 }
142 
146 {
147 public:
148  static RdmResponseAction SendAck(size_t response_data_len = 0);
149  static RdmResponseAction SendNack(rdm_nack_reason_t nack_reason);
150  static RdmResponseAction SendNack(uint16_t raw_nack_reason);
152  static RdmResponseAction RetryLater();
153 
154  constexpr const RdmnetSyncRdmResponse& get() const;
155 
156 private:
157  RdmnetSyncRdmResponse response_;
158 };
159 
163 inline RdmResponseAction RdmResponseAction::SendAck(size_t response_data_len)
164 {
165  RdmResponseAction to_return;
166  RDMNET_SYNC_SEND_RDM_ACK(&to_return.response_, response_data_len);
167  return to_return;
168 }
169 
172 inline RdmResponseAction RdmResponseAction::SendNack(rdm_nack_reason_t nack_reason)
173 {
174  RdmResponseAction to_return;
175  RDMNET_SYNC_SEND_RDM_NACK(&to_return.response_, nack_reason);
176  return to_return;
177 }
178 
182 inline RdmResponseAction RdmResponseAction::SendNack(uint16_t raw_nack_reason)
183 {
184  RdmResponseAction to_return;
185  RDMNET_SYNC_SEND_RDM_NACK(&to_return.response_, static_cast<rdm_nack_reason_t>(raw_nack_reason));
186  return to_return;
187 }
188 
192 {
193  RdmResponseAction to_return;
194  RDMNET_SYNC_DEFER_RDM_RESPONSE(&to_return.response_);
195  return to_return;
196 }
197 
200 {
201  RdmResponseAction to_return;
202  RDMNET_SYNC_RETRY_LATER(&to_return.response_);
203  return to_return;
204 }
205 
208 {
209  return response_;
210 }
211 
215 {
216 public:
217  static EptResponseAction SendData(size_t response_data_len);
218  static EptResponseAction SendStatus(ept_status_code_t status_code);
220 
221  constexpr const RdmnetSyncEptResponse& get() const;
222 
223 private:
224  RdmnetSyncEptResponse response_;
225 };
226 
230 inline EptResponseAction EptResponseAction::SendData(size_t response_data_len)
231 {
232  EptResponseAction to_return;
233  RDMNET_SYNC_SEND_EPT_DATA(&to_return.response_, response_data_len);
234  return to_return;
235 }
236 
240 {
241  EptResponseAction to_return;
242  RDMNET_SYNC_SEND_EPT_STATUS(&to_return.response_, status_code);
243  return to_return;
244 }
245 
248 {
249  EptResponseAction to_return;
250  RDMNET_SYNC_DEFER_EPT_RESPONSE(&to_return.response_);
251  return to_return;
252 }
253 
256 {
257  return response_;
258 }
259 
260 }; // namespace rdmnet
261 
262 #endif // RDMNET_CPP_COMMON_H_
const EtcPalLogParams & log_params() const noexcept
A class representing a synchronous action to take in response to a received EPT data message.
Definition: common.h:215
static EptResponseAction SendStatus(ept_status_code_t status_code)
Send an EPT status message.
Definition: common.h:239
static EptResponseAction SendData(size_t response_data_len)
Send an EPT data message in response.
Definition: common.h:230
constexpr const RdmnetSyncEptResponse & get() const
Get a const reference to the underlying C type.
Definition: common.h:255
static EptResponseAction DeferResponse()
Defer the response to the EPT message, either to be sent later or because no response is necessary.
Definition: common.h:247
A class representing a synchronous action to take in response to a received RDM command.
Definition: common.h:146
static RdmResponseAction SendNack(rdm_nack_reason_t nack_reason)
Send an RDM NACK with a reason code.
Definition: common.h:172
static RdmResponseAction SendAck(size_t response_data_len=0)
Send an RDM ACK, optionally including some response data.
Definition: common.h:163
static RdmResponseAction RetryLater()
Trigger another notification for the (non-LLRP) RDM command on the next tick.
Definition: common.h:199
static RdmResponseAction DeferResponse()
Defer the RDM response to be sent later from another context.
Definition: common.h:191
constexpr const RdmnetSyncRdmResponse & get() const
Get a const reference to the underlying C type.
Definition: common.h:207
Functions and definitions common to all RDMnet API modules.
ept_status_code_t
Definition: common.h:76
#define RDMNET_SYNC_SEND_EPT_DATA(response_ptr, response_data_len_in)
Indicate that an EPT data message should be sent when this callback returns.
Definition: common.h:335
#define RDMNET_SYNC_DEFER_EPT_RESPONSE(response_ptr)
Defer the response to the EPT message, either to be sent later or because no response is necessary.
Definition: common.h:358
#define RDMNET_SYNC_SEND_RDM_NACK(response_ptr, nack_reason_in)
Indicate that an RDM NACK should be sent when this callback returns.
Definition: common.h:255
void rdmnet_deinit(void)
Deinitialize the RDMnet library.
Definition: common.c:275
#define RDMNET_SYNC_RETRY_LATER(response_ptr)
Trigger another notification for the (non-LLRP) RDM command on the next tick.
Definition: common.h:277
etcpal_error_t rdmnet_init(const EtcPalLogParams *log_params, const RdmnetNetintConfig *netint_config)
Initialize the RDMnet library.
Definition: common.c:220
#define RDMNET_SYNC_DEFER_RDM_RESPONSE(response_ptr)
Defer the RDM response to be sent later from another context.
Definition: common.h:267
#define RDMNET_SYNC_SEND_EPT_STATUS(response_ptr, status_code_in)
Indicate that an EPT status message should be sent when this callback returns.
Definition: common.h:347
#define RDMNET_SYNC_SEND_RDM_ACK(response_ptr, response_data_len_in)
Indicate that an RDM ACK should be sent when this callback returns.
Definition: common.h:243
void Deinit()
Deinitialize the RDMnet library.
Definition: common.h:138
etcpal::Error Init(const EtcPalLogParams *log_params=nullptr, const std::vector< EtcPalMcastNetintId > &mcast_netints=std::vector< EtcPalMcastNetintId >{})
Initialize the RDMnet library.
Definition: common.h:61
A namespace which contains all C++ language definitions in the RDMnet library.
Definition: broker.h:45
McastMode
Determines whether multicast traffic is allowed through all interfaces or none.
Definition: common.h:44
Definition: common.h:383
Definition: common.h:310
Definition: common.h:217