RDMnet  0.3.0
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 {
54 inline etcpal::Error Init(const EtcPalLogParams* log_params = nullptr,
56 {
57  if (mcast_netints.empty())
58  {
59  return rdmnet_init(log_params, nullptr);
60  }
61  else
62  {
63  RdmnetNetintConfig config = {mcast_netints.data(), mcast_netints.size()};
64  return rdmnet_init(log_params, &config);
65  }
66 }
67 
79 inline etcpal::Error Init(const etcpal::Logger& logger,
81 {
82  if (mcast_netints.empty())
83  {
84  return rdmnet_init(&logger.log_params(), nullptr);
85  }
86  else
87  {
88  RdmnetNetintConfig config = {mcast_netints.data(), mcast_netints.size()};
89  return rdmnet_init(&logger.log_params(), &config);
90  }
91 }
92 
98 inline void Deinit()
99 {
100  return rdmnet_deinit();
101 }
102 
106 {
107 public:
108  static RdmResponseAction SendAck(size_t response_data_len = 0);
109  static RdmResponseAction SendNack(rdm_nack_reason_t nack_reason);
110  static RdmResponseAction SendNack(uint16_t raw_nack_reason);
112 
113  constexpr const RdmnetSyncRdmResponse& get() const;
114 
115 private:
116  RdmnetSyncRdmResponse response_;
117 };
118 
122 inline RdmResponseAction RdmResponseAction::SendAck(size_t response_data_len)
123 {
124  RdmResponseAction to_return;
125  RDMNET_SYNC_SEND_RDM_ACK(&to_return.response_, response_data_len);
126  return to_return;
127 }
128 
131 inline RdmResponseAction RdmResponseAction::SendNack(rdm_nack_reason_t nack_reason)
132 {
133  RdmResponseAction to_return;
134  RDMNET_SYNC_SEND_RDM_NACK(&to_return.response_, nack_reason);
135  return to_return;
136 }
137 
141 inline RdmResponseAction RdmResponseAction::SendNack(uint16_t raw_nack_reason)
142 {
143  RdmResponseAction to_return;
144  RDMNET_SYNC_SEND_RDM_NACK(&to_return.response_, static_cast<rdm_nack_reason_t>(raw_nack_reason));
145  return to_return;
146 }
147 
151 {
152  RdmResponseAction to_return;
153  RDMNET_SYNC_DEFER_RDM_RESPONSE(&to_return.response_);
154  return to_return;
155 }
156 
159 {
160  return response_;
161 }
162 
166 {
167 public:
168  static EptResponseAction SendData(size_t response_data_len);
169  static EptResponseAction SendStatus(ept_status_code_t status_code);
171 
172  constexpr const RdmnetSyncEptResponse& get() const;
173 
174 private:
175  RdmnetSyncEptResponse response_;
176 };
177 
181 inline EptResponseAction EptResponseAction::SendData(size_t response_data_len)
182 {
183  EptResponseAction to_return;
184  RDMNET_SYNC_SEND_EPT_DATA(&to_return.response_, response_data_len);
185  return to_return;
186 }
187 
191 {
192  EptResponseAction to_return;
193  RDMNET_SYNC_SEND_EPT_STATUS(&to_return.response_, status_code);
194  return to_return;
195 }
196 
199 {
200  EptResponseAction to_return;
201  RDMNET_SYNC_DEFER_EPT_RESPONSE(&to_return.response_);
202  return to_return;
203 }
204 
207 {
208  return response_;
209 }
210 
211 }; // namespace rdmnet
212 
213 #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:166
static EptResponseAction SendStatus(ept_status_code_t status_code)
Send an EPT status message.
Definition: common.h:190
static EptResponseAction DeferResponse()
Defer the response to the EPT message, either to be sent later or because no response is necessary.
Definition: common.h:198
constexpr const RdmnetSyncEptResponse & get() const
Get a const reference to the underlying C type.
Definition: common.h:206
static EptResponseAction SendData(size_t response_data_len)
Send an EPT data message in response.
Definition: common.h:181
A class representing a synchronous action to take in response to a received RDM command.
Definition: common.h:106
static RdmResponseAction SendNack(rdm_nack_reason_t nack_reason)
Send an RDM NACK with a reason code.
Definition: common.h:131
static RdmResponseAction SendAck(size_t response_data_len=0)
Send an RDM ACK, optionally including some response data.
Definition: common.h:122
constexpr const RdmnetSyncRdmResponse & get() const
Get a const reference to the underlying C type.
Definition: common.h:158
static RdmResponseAction DeferResponse()
Defer the RDM response to be sent later from another context.
Definition: common.h:150
Functions and definitions common to all RDMnet API modules.
ept_status_code_t
EPT status code definitions.
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:318
#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:341
#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:252
void rdmnet_deinit(void)
Deinitialize the RDMnet library.
Definition: common.c:201
etcpal_error_t rdmnet_init(const EtcPalLogParams *log_params, const RdmnetNetintConfig *netint_config)
Initialize the RDMnet library.
Definition: common.c:149
#define RDMNET_SYNC_DEFER_RDM_RESPONSE(response_ptr)
Defer the RDM response to be sent later from another context.
Definition: common.h:264
#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:330
#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:240
etcpal::Error Init(const EtcPalLogParams *log_params=nullptr, const std::vector< RdmnetMcastNetintId > &mcast_netints=std::vector< RdmnetMcastNetintId >{})
Initialize the RDMnet library.
Definition: common.h:54
void Deinit()
Deinitialize the RDMnet library.
Definition: common.h:98
A namespace which contains all C++ language definitions in the RDMnet library.
Definition: broker.h:45
Network interface configuration information to give the RDMnet library at initialization.
Definition: common.h:376
This structure should not be manipulated directly - use the macros to access it:
Definition: common.h:293
This structure should not be manipulated directly - use the macros to access it:
Definition: common.h:214