RDMnet  0.3.0
Implementation of ANSI E1.33 (RDMnet)
View other versions:
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
ept_client.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 
22 
23 #ifndef RDMNET_CPP_EPT_CLIENT_H_
24 #define RDMNET_CPP_EPT_CLIENT_H_
25 
26 #include "etcpal/common.h"
27 #include "rdmnet/cpp/client.h"
28 #include "rdmnet/cpp/common.h"
29 #include "rdmnet/cpp/message.h"
30 #include "rdmnet/ept_client.h"
31 
32 namespace rdmnet
33 {
44 
49 class EptClient
50 {
51 public:
56 
62  {
63  public:
64  virtual ~NotifyHandler() = default;
65 
70  virtual void HandleConnectedToBroker(Handle client_handle,
71  ScopeHandle scope_handle,
72  const ClientConnectedInfo& info) = 0;
73 
78  virtual void HandleBrokerConnectFailed(Handle client_handle,
79  ScopeHandle scope_handle,
80  const ClientConnectFailedInfo& info) = 0;
81 
86  virtual void HandleDisconnectedFromBroker(Handle client_handle,
87  ScopeHandle scope_handle,
88  const ClientDisconnectedInfo& info) = 0;
89 
96  virtual void HandleClientListUpdate(Handle client_handle,
97  ScopeHandle scope_handle,
98  client_list_action_t list_action,
99  const EptClientList& list) = 0;
100 
106  virtual EptResponseAction HandleEptData(Handle client_handle, ScopeHandle scope_handle, const EptData& data) = 0;
107 
112  virtual void HandleEptStatus(Handle client_handle, ScopeHandle scope_handle, const EptStatus& status) = 0;
113  };
114 
117  struct Settings
118  {
123  const uint8_t* response_buf{nullptr};
124 
126  Settings() = default;
127  Settings(const etcpal::Uuid& new_cid, const std::vector<EptSubProtocol>& new_protocols);
128 
129  bool IsValid() const;
130  };
131 
132  EptClient() = default;
133  EptClient(const EptClient& other) = delete;
134  EptClient& operator=(const EptClient& other) = delete;
135  EptClient(EptClient&& other) = default;
136  EptClient& operator=(EptClient&& other) = default;
137 
140 
142  const etcpal::SockAddr& static_broker_addr = etcpal::SockAddr{});
143  etcpal::Expected<ScopeHandle> AddScope(const Scope& scope_config);
145  etcpal::Error RemoveScope(ScopeHandle scope_handle, rdmnet_disconnect_reason_t disconnect_reason);
146 
148 
149  etcpal::Error SendData(ScopeHandle scope_handle,
150  const etcpal::Uuid& dest_cid,
151  uint16_t manufacturer_id,
152  uint16_t protocol_id,
153  const uint8_t* data,
154  size_t data_len);
155  etcpal::Error SendStatus(ScopeHandle scope_handle,
156  const etcpal::Uuid& dest_cid,
157  ept_status_code_t status_code,
158  const char* status_string = nullptr);
159 
160  Handle handle() const;
161  NotifyHandler* notify_handler() const;
162  etcpal::Expected<Scope> scope(ScopeHandle scope_handle) const;
163 
164 private:
165  Handle handle_{kInvalidHandle};
166  NotifyHandler* notify_{nullptr};
167 };
168 
170 inline EptClient::Settings::Settings(const etcpal::Uuid& new_cid, const std::vector<EptSubProtocol>& new_protocols)
171  : cid(new_cid), protocols(new_protocols)
172 {
173 }
174 
176 inline bool EptClient::Settings::IsValid() const
177 {
178  return (!cid.IsNull() && !protocols.empty());
179 }
180 
188 {
189  ETCPAL_UNUSED_ARG(notify_handler);
190  ETCPAL_UNUSED_ARG(settings);
191  return kEtcPalErrNotImpl;
192 }
193 
200 inline void EptClient::Shutdown(rdmnet_disconnect_reason_t disconnect_reason)
201 {
202  ETCPAL_UNUSED_ARG(disconnect_reason);
203 }
204 
216 inline etcpal::Expected<ScopeHandle> EptClient::AddScope(const char* id, const etcpal::SockAddr& static_broker_addr)
217 {
218  ETCPAL_UNUSED_ARG(id);
219  ETCPAL_UNUSED_ARG(static_broker_addr);
220  return kEtcPalErrNotImpl;
221 }
222 
233 {
234  ETCPAL_UNUSED_ARG(scope_config);
235  return kEtcPalErrNotImpl;
236 }
237 
248 {
249  ETCPAL_UNUSED_ARG(static_broker_addr);
250  return kEtcPalErrNotImpl;
251 }
252 
262 {
263  ETCPAL_UNUSED_ARG(scope_handle);
264  ETCPAL_UNUSED_ARG(disconnect_reason);
265  return kEtcPalErrNotImpl;
266 }
267 
276 {
277  ETCPAL_UNUSED_ARG(scope_handle);
278  return kEtcPalErrNotImpl;
279 }
280 
295  const etcpal::Uuid& dest_cid,
296  uint16_t manufacturer_id,
297  uint16_t protocol_id,
298  const uint8_t* data,
299  size_t data_len)
300 {
301  ETCPAL_UNUSED_ARG(scope_handle);
302  ETCPAL_UNUSED_ARG(dest_cid);
303  ETCPAL_UNUSED_ARG(manufacturer_id);
304  ETCPAL_UNUSED_ARG(protocol_id);
305  ETCPAL_UNUSED_ARG(data);
306  ETCPAL_UNUSED_ARG(data_len);
307  return kEtcPalErrNotImpl;
308 }
309 
323  const etcpal::Uuid& dest_cid,
324  ept_status_code_t status_code,
325  const char* status_string)
326 {
327  ETCPAL_UNUSED_ARG(scope_handle);
328  ETCPAL_UNUSED_ARG(dest_cid);
329  ETCPAL_UNUSED_ARG(status_code);
330  ETCPAL_UNUSED_ARG(status_string);
331  return kEtcPalErrNotImpl;
332 }
333 
336 {
337  return kInvalidHandle;
338 }
339 
342 {
343  return nullptr;
344 }
345 
351 {
352  ETCPAL_UNUSED_ARG(scope_handle);
353  return kEtcPalErrNotImpl;
354 }
355 
356 }; // namespace rdmnet
357 
358 #endif // RDMNET_CPP_EPT_CLIENT_H_
Information about a failed connection to a broker delivered to an RDMnet callback function.
Definition: client.h:219
Information about a successful connection to a broker delivered to an RDMnet callback function.
Definition: client.h:149
Information about a disconnect event from a broker delivered to an RDMnet callback function.
Definition: client.h:337
A base class for a class that receives notification callbacks from an EPT client.
Definition: ept_client.h:62
virtual void HandleBrokerConnectFailed(Handle client_handle, ScopeHandle scope_handle, const ClientConnectFailedInfo &info)=0
A connection attempt failed between an EPT client and a broker.
virtual EptResponseAction HandleEptData(Handle client_handle, ScopeHandle scope_handle, const EptData &data)=0
EPT data has been received addressed to an EPT client.
virtual void HandleConnectedToBroker(Handle client_handle, ScopeHandle scope_handle, const ClientConnectedInfo &info)=0
An EPT client has successfully connected to a broker.
virtual void HandleEptStatus(Handle client_handle, ScopeHandle scope_handle, const EptStatus &status)=0
An EPT status message has been received in response to a previously-sent EPT data message.
virtual void HandleClientListUpdate(Handle client_handle, ScopeHandle scope_handle, client_list_action_t list_action, const EptClientList &list)=0
A client list update has been received from a broker.
virtual void HandleDisconnectedFromBroker(Handle client_handle, ScopeHandle scope_handle, const ClientDisconnectedInfo &info)=0
An EPT client which was previously connected to a broker has disconnected.
An instance of RDMnet EPT client functionality.
Definition: ept_client.h:50
etcpal::Error RemoveScope(ScopeHandle scope_handle, rdmnet_disconnect_reason_t disconnect_reason)
Remove a previously-added scope from this EPT client instance.
Definition: ept_client.h:261
static constexpr Handle kInvalidHandle
An invalid Handle value.
Definition: ept_client.h:55
rdmnet_ept_client_t Handle
A handle type used by the RDMnet library to identify EPT client instances.
Definition: ept_client.h:53
void Shutdown(rdmnet_disconnect_reason_t disconnect_reason=kRdmnetDisconnectShutdown)
Shut down this EPT client and deallocate resources.
Definition: ept_client.h:200
etcpal::Expected< Scope > scope(ScopeHandle scope_handle) const
Retrieve the scope configuration associated with a given scope handle.
Definition: ept_client.h:350
etcpal::Expected< ScopeHandle > AddDefaultScope(const etcpal::SockAddr &static_broker_addr=etcpal::SockAddr{})
Shortcut to add the default RDMnet scope to an EPT client instance.
Definition: ept_client.h:247
etcpal::Error RequestClientList(ScopeHandle scope_handle)
Request a client list from a broker.
Definition: ept_client.h:275
EptClient & operator=(EptClient &&other)=default
Move an EPT client instance.
NotifyHandler * notify_handler() const
Retrieve the NotifyHandler reference that this EPT client was configured with.
Definition: ept_client.h:341
etcpal::Error SendData(ScopeHandle scope_handle, const etcpal::Uuid &dest_cid, uint16_t manufacturer_id, uint16_t protocol_id, const uint8_t *data, size_t data_len)
Send data from an EPT client on a scope.
Definition: ept_client.h:294
etcpal::Error SendStatus(ScopeHandle scope_handle, const etcpal::Uuid &dest_cid, ept_status_code_t status_code, const char *status_string=nullptr)
Send a status message from an EPT client on a scope.
Definition: ept_client.h:322
Handle handle() const
Retrieve the handle of an EPT client instance.
Definition: ept_client.h:335
etcpal::Error Startup(NotifyHandler &notify_handler, const Settings &settings)
Allocate resources and start up this EPT client with the given configuration.
Definition: ept_client.h:187
etcpal::Expected< ScopeHandle > AddScope(const char *id, const etcpal::SockAddr &static_broker_addr=etcpal::SockAddr{})
Add a new scope to this EPT client instance.
Definition: ept_client.h:216
EptClient(EptClient &&other)=default
Move an EPT client instance.
A list of EPT client entries.
Definition: ept_client.h:122
An EPT data message received over RDMnet and delivered to an RDMnet callback function.
Definition: ept_data.h:41
A class representing a synchronous action to take in response to a received EPT data message.
Definition: common.h:166
An EPT status message received over RDMnet and delivered to an RDMnet callback function.
Definition: ept_status.h:41
An RDMnet scope configuration.
Definition: client.h:460
C++ wrapper for RDMnet client API definitions.
C++ wrapper for the RDMnet init/deinit functions.
RDMnet C++ message type definitions.
Definitions for the RDMnet EPT Client API.
kEtcPalErrNotImpl
ept_status_code_t
EPT status code definitions.
Definition: common.h:76
rdmnet_disconnect_reason_t
Disconnect reason defines for the BrokerDisconnectMsg.
Definition: common.h:85
client_list_action_t
How to apply the client entries to the existing client list in a client_list_update_received callback...
Definition: client.h:50
@ kRdmnetDisconnectShutdown
The remote component is shutting down.
Definition: common.h:87
rdmnet_client_scope_t ScopeHandle
A handle to a scope that an RDMnet client participates in.
Definition: client.h:447
#define RDMNET_EPT_CLIENT_INVALID
An invalid RDMnet EPT Client handle value.
Definition: ept_client.h:55
int rdmnet_ept_client_t
A handle to an RDMnet EPT Client.
Definition: ept_client.h:53
A namespace which contains all C++ language definitions in the RDMnet library.
Definition: broker.h:45
A set of configuration settings that an EPT client needs to initialize.
Definition: ept_client.h:118
bool IsValid() const
Determine whether an EPT client Settings instance contains valid data for RDMnet operation.
Definition: ept_client.h:176
etcpal::Uuid cid
The EPT client's CID.
Definition: ept_client.h:119
std::string search_domain
(optional) The EPT client's search domain for discovering brokers.
Definition: ept_client.h:121
std::vector< EptSubProtocol > protocols
The list of EPT sub-protocols that this EPT client supports.
Definition: ept_client.h:120
const uint8_t * response_buf
(optional) A data buffer to be used to respond synchronously to EPT data noficiations.
Definition: ept_client.h:123
Settings()=default
Create an empty, invalid data structure by default.