RDMnet  HEAD (unstable)
Implementation of ANSI E1.33 (RDMnet)
View other versions:
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 "etcpal/cpp/opaque_id.h"
28 #include "rdmnet/cpp/client.h"
29 #include "rdmnet/cpp/common.h"
30 #include "rdmnet/cpp/message.h"
31 #include "rdmnet/ept_client.h"
32 
33 namespace rdmnet
34 {
45 
46 namespace detail
47 {
49 {
50 };
51 }; // namespace detail
52 
57 class EptClient
58 {
59 public:
62 
68  {
69  public:
70  virtual ~NotifyHandler() = default;
71 
76  virtual void HandleConnectedToBroker(Handle client_handle,
77  ScopeHandle scope_handle,
78  const ClientConnectedInfo& info) = 0;
79 
84  virtual void HandleBrokerConnectFailed(Handle client_handle,
85  ScopeHandle scope_handle,
86  const ClientConnectFailedInfo& info) = 0;
87 
92  virtual void HandleDisconnectedFromBroker(Handle client_handle,
93  ScopeHandle scope_handle,
94  const ClientDisconnectedInfo& info) = 0;
95 
102  virtual void HandleClientListUpdate(Handle client_handle,
103  ScopeHandle scope_handle,
104  client_list_action_t list_action,
105  const EptClientList& list) = 0;
106 
112  virtual EptResponseAction HandleEptData(Handle client_handle, ScopeHandle scope_handle, const EptData& data) = 0;
113 
118  virtual void HandleEptStatus(Handle client_handle, ScopeHandle scope_handle, const EptStatus& status) = 0;
119  };
120 
123  struct Settings
124  {
129  const uint8_t* response_buf{nullptr};
130 
132  Settings() = default;
133  Settings(const etcpal::Uuid& new_cid, const std::vector<EptSubProtocol>& new_protocols);
134 
135  bool IsValid() const;
136  };
137 
138  EptClient() = default;
139  EptClient(const EptClient& other) = delete;
140  EptClient& operator=(const EptClient& other) = delete;
141  EptClient(EptClient&& other) = default;
142  EptClient& operator=(EptClient&& other) = default;
143 
146 
148  const etcpal::SockAddr& static_broker_addr = etcpal::SockAddr{});
149  etcpal::Expected<ScopeHandle> AddScope(const Scope& scope_config);
151  etcpal::Error RemoveScope(ScopeHandle scope_handle, rdmnet_disconnect_reason_t disconnect_reason);
152 
154 
155  etcpal::Error SendData(ScopeHandle scope_handle,
156  const etcpal::Uuid& dest_cid,
157  uint16_t manufacturer_id,
158  uint16_t protocol_id,
159  const uint8_t* data,
160  size_t data_len);
161  etcpal::Error SendStatus(ScopeHandle scope_handle,
162  const etcpal::Uuid& dest_cid,
163  ept_status_code_t status_code,
164  const char* status_string = nullptr);
165 
166  Handle handle() const;
167  NotifyHandler* notify_handler() const;
168  etcpal::Expected<Scope> scope(ScopeHandle scope_handle) const;
169 
170 private:
171  Handle handle_;
172  NotifyHandler* notify_{nullptr};
173 };
174 
176 inline EptClient::Settings::Settings(const etcpal::Uuid& new_cid, const std::vector<EptSubProtocol>& new_protocols)
177  : cid(new_cid), protocols(new_protocols)
178 {
179 }
180 
182 inline bool EptClient::Settings::IsValid() const
183 {
184  return (!cid.IsNull() && !protocols.empty());
185 }
186 
194 {
195  ETCPAL_UNUSED_ARG(notify_handler);
196  ETCPAL_UNUSED_ARG(settings);
197  return kEtcPalErrNotImpl;
198 }
199 
206 inline void EptClient::Shutdown(rdmnet_disconnect_reason_t disconnect_reason)
207 {
208  ETCPAL_UNUSED_ARG(disconnect_reason);
209 }
210 
222 inline etcpal::Expected<ScopeHandle> EptClient::AddScope(const char* id, const etcpal::SockAddr& static_broker_addr)
223 {
224  ETCPAL_UNUSED_ARG(id);
225  ETCPAL_UNUSED_ARG(static_broker_addr);
226  return kEtcPalErrNotImpl;
227 }
228 
239 {
240  ETCPAL_UNUSED_ARG(scope_config);
241  return kEtcPalErrNotImpl;
242 }
243 
254 {
255  ETCPAL_UNUSED_ARG(static_broker_addr);
256  return kEtcPalErrNotImpl;
257 }
258 
268 {
269  ETCPAL_UNUSED_ARG(scope_handle);
270  ETCPAL_UNUSED_ARG(disconnect_reason);
271  return kEtcPalErrNotImpl;
272 }
273 
282 {
283  ETCPAL_UNUSED_ARG(scope_handle);
284  return kEtcPalErrNotImpl;
285 }
286 
301  const etcpal::Uuid& dest_cid,
302  uint16_t manufacturer_id,
303  uint16_t protocol_id,
304  const uint8_t* data,
305  size_t data_len)
306 {
307  ETCPAL_UNUSED_ARG(scope_handle);
308  ETCPAL_UNUSED_ARG(dest_cid);
309  ETCPAL_UNUSED_ARG(manufacturer_id);
310  ETCPAL_UNUSED_ARG(protocol_id);
311  ETCPAL_UNUSED_ARG(data);
312  ETCPAL_UNUSED_ARG(data_len);
313  return kEtcPalErrNotImpl;
314 }
315 
329  const etcpal::Uuid& dest_cid,
330  ept_status_code_t status_code,
331  const char* status_string)
332 {
333  ETCPAL_UNUSED_ARG(scope_handle);
334  ETCPAL_UNUSED_ARG(dest_cid);
335  ETCPAL_UNUSED_ARG(status_code);
336  ETCPAL_UNUSED_ARG(status_string);
337  return kEtcPalErrNotImpl;
338 }
339 
342 {
343  return EptClient::Handle();
344 }
345 
348 {
349  return nullptr;
350 }
351 
357 {
358  ETCPAL_UNUSED_ARG(scope_handle);
359  return kEtcPalErrNotImpl;
360 }
361 
362 }; // namespace rdmnet
363 
364 #endif // RDMNET_CPP_EPT_CLIENT_H_
Information about a failed connection to a broker delivered to an RDMnet callback function.
Definition: client.h:228
Information about a successful connection to a broker delivered to an RDMnet callback function.
Definition: client.h:158
Information about a disconnect event from a broker delivered to an RDMnet callback function.
Definition: client.h:346
A base class for a class that receives notification callbacks from an EPT client.
Definition: ept_client.h:68
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 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.
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 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.
An instance of RDMnet EPT client functionality.
Definition: ept_client.h:58
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:193
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:253
EptClient & operator=(EptClient &&other)=default
Move an EPT client instance.
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:328
Handle handle() const
Retrieve the handle of an EPT client instance.
Definition: ept_client.h:341
EptClient(EptClient &&other)=default
Move an EPT client instance.
etcpal::Error RequestClientList(ScopeHandle scope_handle)
Request a client list from a broker.
Definition: ept_client.h:281
NotifyHandler * notify_handler() const
Retrieve the NotifyHandler reference that this EPT client was configured with.
Definition: ept_client.h:347
void Shutdown(rdmnet_disconnect_reason_t disconnect_reason=kRdmnetDisconnectShutdown)
Shut down this EPT client and deallocate resources.
Definition: ept_client.h:206
etcpal::Expected< Scope > scope(ScopeHandle scope_handle) const
Retrieve the scope configuration associated with a given scope handle.
Definition: ept_client.h:356
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:267
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:300
etcpal::OpaqueId< detail::EptClientHandleType, rdmnet_ept_client_t, RDMNET_EPT_CLIENT_INVALID > Handle
A handle type used by the RDMnet library to identify EPT client instances.
Definition: ept_client.h:61
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:222
A list of EPT client entries.
Definition: ept_client.h:123
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:215
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:469
Definition: ept_client.h:49
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
Definition: common.h:76
rdmnet_disconnect_reason_t
Definition: common.h:85
client_list_action_t
Definition: client.h:50
@ kRdmnetDisconnectShutdown
Definition: common.h:87
etcpal::OpaqueId< detail::ScopeHandleType, rdmnet_client_scope_t, RDMNET_CLIENT_SCOPE_INVALID > ScopeHandle
Definition: client.h:456
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:124
Settings()=default
Create an empty, invalid data structure by default.
const uint8_t * response_buf
(optional) A data buffer to be used to respond synchronously to EPT data noficiations.
Definition: ept_client.h:129
std::vector< EptSubProtocol > protocols
The list of EPT sub-protocols that this EPT client supports.
Definition: ept_client.h:126
std::string search_domain
Definition: ept_client.h:127
etcpal::Uuid cid
The EPT client's CID.
Definition: ept_client.h:125
bool IsValid() const
Determine whether an EPT client Settings instance contains valid data for RDMnet operation.
Definition: ept_client.h:182