sACN  HEAD (unstable)
Implementation of ANSI E1.31 (Streaming ACN)
View other versions:
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright 2024 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 sACN. For more information, go to:
17 * https://github.com/ETCLabs/sACN
18 *****************************************************************************/
19
20#ifndef SACN_CPP_COMMON_H_
21#define SACN_CPP_COMMON_H_
22
28#include "etcpal/cpp/error.h"
29#include "etcpal/cpp/log.h"
30#include "etcpal/cpp/uuid.h"
31#include "sacn/common.h"
32
49namespace sacn
50{
52enum class McastMode
53{
54 kEnabledOnAllInterfaces,
55 kDisabledOnAllInterfaces
56};
57
62
67
73{
74public:
75 NotifyHandler() = default;
76 virtual ~NotifyHandler() = default;
77
82 NotifyHandler(const NotifyHandler& other) = default;
83
89 NotifyHandler& operator=(const NotifyHandler& other) = default;
90
95 NotifyHandler(NotifyHandler&& other) = default;
96
103
108 virtual void HandleUnicastSendError(const SacnSocketErrorInfo& err_info) { ETCPAL_UNUSED_ARG(err_info); }
109
114 virtual void HandleMulticastSendError(const SacnSocketErrorInfo& err_info) { ETCPAL_UNUSED_ARG(err_info); }
115};
116
132
137namespace internal
138{
139extern "C" inline void CommonCbUnicastSendError(const SacnSocketErrorInfo* err_info, void* context)
140{
141 if (err_info && context)
142 static_cast<NotifyHandler*>(context)->HandleUnicastSendError(*err_info);
143}
144
145extern "C" inline void CommonCbMulticastSendError(const SacnSocketErrorInfo* err_info, void* context)
146{
147 if (err_info && context)
148 static_cast<NotifyHandler*>(context)->HandleMulticastSendError(*err_info);
149}
150
151inline SacnCommonCallbacks GetCommonCallbacks(NotifyHandler* notify_handler)
152{
153 SacnCommonCallbacks callbacks = {internal::CommonCbUnicastSendError, internal::CommonCbMulticastSendError,
154 notify_handler};
155 return callbacks;
156}
157
158}; // namespace internal
159
184{
186 netint_config.send_socket_config = settings.send_socket_config;
187
188 auto callbacks = internal::GetCommonCallbacks(settings.notify_handler);
189 return sacn_init_features_with_cb(nullptr, &netint_config, features, settings.notify_handler ? &callbacks : nullptr);
190}
191
213inline etcpal::Error Init(const EtcPalLogParams* log_params,
215 const LibrarySettings& settings = {})
216{
218 netint_config.send_socket_config = settings.send_socket_config;
219
220 auto callbacks = internal::GetCommonCallbacks(settings.notify_handler);
221 return sacn_init_features_with_cb(log_params, &netint_config, features,
222 settings.notify_handler ? &callbacks : nullptr);
223}
224
246inline etcpal::Error Init(const EtcPalLogParams* log_params,
247 McastMode mcast_mode,
249 const LibrarySettings& settings = {})
250{
252 netint_config.send_socket_config = settings.send_socket_config;
253
254 if (mcast_mode == McastMode::kDisabledOnAllInterfaces)
255 netint_config.no_netints = true;
256
257 auto callbacks = internal::GetCommonCallbacks(settings.notify_handler);
258 return sacn_init_features_with_cb(log_params, &netint_config, features,
259 settings.notify_handler ? &callbacks : nullptr);
260}
261
281inline etcpal::Error Init(const EtcPalLogParams* log_params,
282 std::vector<SacnMcastInterface>& sys_netints,
284 const LibrarySettings& settings = {})
285{
287 netint_config.netints = sys_netints.data();
288 netint_config.num_netints = sys_netints.size();
289 netint_config.send_socket_config = settings.send_socket_config;
290
291 auto callbacks = internal::GetCommonCallbacks(settings.notify_handler);
292 return sacn_init_features_with_cb(log_params, &netint_config, features,
293 settings.notify_handler ? &callbacks : nullptr);
294}
295
315inline etcpal::Error Init(std::vector<SacnMcastInterface>& sys_netints,
317 const LibrarySettings& settings = {})
318{
320 netint_config.netints = sys_netints.data();
321 netint_config.num_netints = sys_netints.size();
322 netint_config.send_socket_config = settings.send_socket_config;
323
324 auto callbacks = internal::GetCommonCallbacks(settings.notify_handler);
325 return sacn_init_features_with_cb(nullptr, &netint_config, features, settings.notify_handler ? &callbacks : nullptr);
326}
327
348inline etcpal::Error Init(const etcpal::Logger& logger,
349 McastMode mcast_mode = McastMode::kEnabledOnAllInterfaces,
351 const LibrarySettings& settings = {})
352{
354 netint_config.send_socket_config = settings.send_socket_config;
355
356 if (mcast_mode == McastMode::kDisabledOnAllInterfaces)
357 netint_config.no_netints = true;
358
359 auto callbacks = internal::GetCommonCallbacks(settings.notify_handler);
360 return sacn_init_features_with_cb(&logger.log_params(), &netint_config, features,
361 settings.notify_handler ? &callbacks : nullptr);
362}
363
384inline etcpal::Error Init(const etcpal::Logger& logger, sacn_features_t features, const LibrarySettings& settings = {})
385{
387 netint_config.send_socket_config = settings.send_socket_config;
388
389 auto callbacks = internal::GetCommonCallbacks(settings.notify_handler);
390 return sacn_init_features_with_cb(&logger.log_params(), &netint_config, features,
391 settings.notify_handler ? &callbacks : nullptr);
392}
393
412inline etcpal::Error Init(const etcpal::Logger& logger,
413 std::vector<SacnMcastInterface>& sys_netints,
415 const LibrarySettings& settings = {})
416{
418 netint_config.netints = sys_netints.data();
419 netint_config.num_netints = sys_netints.size();
420 netint_config.send_socket_config = settings.send_socket_config;
421
422 auto callbacks = internal::GetCommonCallbacks(settings.notify_handler);
423 return sacn_init_features_with_cb(&logger.log_params(), &netint_config, features,
424 settings.notify_handler ? &callbacks : nullptr);
425}
426
439{
440 sacn_deinit_features(features);
441}
442
454{
455 return sacn_get_remote_source_handle(&source_cid.get());
456}
457
471{
472 EtcPalUuid cid;
473 etcpal_error_t error = sacn_get_remote_source_cid(source_handle, &cid);
474 etcpal::Uuid cid_to_return = cid;
475
476 if (error == kEtcPalErrOk)
477 return cid_to_return;
478
479 return error;
480}
481
482}; // namespace sacn
483
484#endif // SACN_CPP_COMMON_H_
const EtcPalLogParams & log_params() const noexcept
constexpr const EtcPalUuid & get() const noexcept
A base class for a class that receives common notification callbacks from sACN.
Definition common.h:73
NotifyHandler(const NotifyHandler &other)=default
Defaulted copy constructor.
NotifyHandler & operator=(NotifyHandler &&other)=default
Defaulted move assignment operator.
virtual void HandleMulticastSendError(const SacnSocketErrorInfo &err_info)
Notify that an error just occurred sending multicast on a socket.
Definition common.h:114
NotifyHandler & operator=(const NotifyHandler &other)=default
Defaulted copy assignment operator.
NotifyHandler(NotifyHandler &&other)=default
Defaulted move constructor.
virtual void HandleUnicastSendError(const SacnSocketErrorInfo &err_info)
Notify that an error just occurred sending unicast on a socket.
Definition common.h:108
Common definitions for sACN.
etcpal_error_t
kEtcPalErrOk
uint16_t sacn_remote_source_t
A source discovered on an sACN network that has a CID - used by Receiver and Merge Receiver.
Definition common.h:47
#define SACN_NETINT_CONFIG_DEFAULT_INIT
Initializes the members of a SacnNetintConfig to defaults.
Definition common.h:187
etcpal_error_t sacn_init_features_with_cb(const EtcPalLogParams *log_params, const SacnNetintConfig *sys_netint_config, sacn_features_t features, const SacnCommonCallbacks *callbacks)
Initialize specific features of the sACN library.
Definition common.c:153
#define SACN_SEND_SOCKET_CONFIG_DEFAULT_VALUES
Default values for initializing a SacnSendSocketConfig.
Definition common.h:177
sacn_remote_source_t sacn_get_remote_source_handle(const EtcPalUuid *source_cid)
Converts a remote source CID to the corresponding handle, or kSacnRemoteSourceInvalid if not found.
Definition common.c:580
void sacn_deinit_features(sacn_features_t features)
Deinitialize specific features of the sACN library.
Definition common.c:496
etcpal_error_t sacn_get_remote_source_cid(sacn_remote_source_t source_handle, EtcPalUuid *source_cid)
Converts a remote source handle to the corresponding source CID.
Definition common.c:605
uint32_t sacn_features_t
A mask of desired sACN features.
Definition common.h:190
#define SACN_FEATURES_ALL
Use every available module.
Definition common.h:208
static const sacn_remote_source_t kSacnRemoteSourceInvalid
An invalid remote source handle value.
Definition common.h:49
@ kSacnMinimumUniverse
The lowest sACN universe number supported.
Definition common.h:66
@ kSacnMaximumUniverse
The highest sACN universe number supported.
Definition common.h:68
etcpal::Error Init(sacn_features_t features=SACN_FEATURES_ALL, const LibrarySettings &settings={})
Initialize the sACN library.
Definition common.h:183
RemoteSourceHandle GetRemoteSourceHandle(const etcpal::Uuid &source_cid)
Converts a remote source CID to the corresponding handle, or kSacnRemoteSourceInvalid if not found.
Definition common.h:453
etcpal::Expected< etcpal::Uuid > GetRemoteSourceCid(RemoteSourceHandle source_handle)
Converts a remote source handle to the corresponding source CID.
Definition common.h:470
A namespace which contains all C++ language definitions in the sACN library.
Definition common.h:50
constexpr RemoteSourceHandle kInvalidRemoteSourceHandle
An invalid RemoteSourceHandle value.
Definition common.h:61
constexpr uint16_t kMinimumUniverse
The lowest sACN universe number supported.
Definition common.h:64
void Deinit(sacn_features_t features=SACN_FEATURES_ALL)
Deinitialize features of the sACN library.
Definition common.h:438
sacn_remote_source_t RemoteSourceHandle
A source discovered on an sACN network that has a CID - used by Receiver and Merge Receiver.
Definition common.h:59
McastMode
Determines whether multicast traffic is allowed through all interfaces or none.
Definition common.h:53
constexpr uint16_t kMaximumUniverse
The highest sACN universe number supported.
Definition common.h:66
A set of callback functions that the library uses to notify the application about sACN events.
Definition common.h:168
Network interface configuration information to give the sACN library.
Definition common.h:114
SacnMcastInterface * netints
An array of network interface IDs to which to restrict multicast traffic.
Definition common.h:117
size_t num_netints
Size of netints array.
Definition common.h:119
bool no_netints
If this is true, no network interfaces will be used for multicast.
Definition common.h:122
SacnSendSocketConfig send_socket_config
Configuration for send sockets (e.g.
Definition common.h:126
Configuration for send sockets (e.g.
Definition common.h:103
Information about a socket error that occurred.
Definition common.h:131
Settings for the sACN library beyond the sacn::Init overrides.
Definition common.h:122
NotifyHandler * notify_handler
Callback handler for common notifications from the library.
Definition common.h:124
LibrarySettings()=default
Sets default settings.
SacnSendSocketConfig send_socket_config
Configuration for send sockets (e.g.
Definition common.h:127