Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
Port.h
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 *
16 * Port.h
17 * Header file for the Port classes
18 * Copyright (C) 2005 Simon Newton
19 */
20
21#ifndef INCLUDE_OLAD_PORT_H_
22#define INCLUDE_OLAD_PORT_H_
23
24#include <ola/DmxBuffer.h>
25#include <ola/base/Macro.h>
26#include <ola/rdm/RDMCommand.h>
28#include <ola/timecode/TimeCode.h>
29#include <olad/DmxSource.h>
30#include <olad/PluginAdaptor.h>
31#include <olad/PortConstants.h>
32#include <olad/Universe.h>
33
34#include <string>
35
36namespace ola {
37
38class AbstractDevice;
39
49class Port {
50 public:
51 virtual ~Port() {}
52
57 virtual unsigned int PortId() const = 0;
58
63 virtual AbstractDevice *GetDevice() const = 0;
64
69 virtual std::string Description() const = 0;
70
79 virtual bool SetUniverse(Universe *universe) = 0;
80
86 virtual Universe *GetUniverse() const = 0;
87
94 virtual std::string UniqueId() const = 0;
95
101
106 virtual bool SetPriority(uint8_t priority) = 0;
107
112 virtual uint8_t GetPriority() const = 0;
113
118 virtual void SetPriorityMode(port_priority_mode mode) = 0;
119
125
130 virtual bool SupportsRDM() const = 0;
131};
132
133
137class InputPort: public Port {
138 public:
139 virtual ~InputPort() {}
140
144 virtual void DmxChanged() = 0;
145
149 virtual const DmxSource &SourceData() const = 0;
150
156 ola::rdm::RDMCallback *callback) = 0;
157};
158
159
164 public:
165 virtual ~OutputPort() {}
166
173 virtual bool WriteDMX(const DmxBuffer &buffer, uint8_t priority) = 0;
174
178 virtual void UniverseNameChanged(const std::string &new_name) = 0;
179
180 // Methods from DiscoverableRDMControllerInterface
181 // Ownership of the request object is transferred
183 ola::rdm::RDMCallback *callback) = 0;
184 virtual void RunFullDiscovery(
185 ola::rdm::RDMDiscoveryCallback *on_complete) = 0;
187 ola::rdm::RDMDiscoveryCallback *on_complete) = 0;
188
189 // timecode support
190 virtual bool SupportsTimeCode() const = 0;
191 virtual bool SendTimeCode(const ola::timecode::TimeCode &timecode) = 0;
192};
193
194
200 public:
205 unsigned int port_id,
206 const PluginAdaptor *plugin_adaptor,
207 bool supports_rdm = false);
208
209 unsigned int PortId() const { return m_port_id; }
210 AbstractDevice *GetDevice() const { return m_device; }
211 bool SetUniverse(Universe *universe);
212 Universe *GetUniverse() const { return m_universe; }
213 virtual std::string UniqueId() const;
214 bool SetPriority(uint8_t priority);
215 uint8_t GetPriority() const { return m_priority; }
216 void SetPriorityMode(port_priority_mode mode) { m_priority_mode = mode; }
217 port_priority_mode GetPriorityMode() const { return m_priority_mode; }
218
222 void DmxChanged();
223 const DmxSource &SourceData() const { return m_dmx_source; }
224
225 // RDM methods, the child class provides HandleRDMResponse
232 ola::rdm::RDMCallback *callback);
233
238 bool full = true);
239
241 return SupportsPriorities() ? CAPABILITY_FULL : CAPABILITY_STATIC;
242 }
243
244 // subclasses override these
245 // Read the dmx data.
246 virtual const DmxBuffer &ReadDMX() const = 0;
247
248 // Get the inherited priority
249 virtual uint8_t InheritedPriority() const {
251 }
252
253 // override this to cancel the SetUniverse operation.
254 virtual bool PreSetUniverse(Universe *, Universe *) { return true; }
255
256 virtual void PostSetUniverse(Universe *, Universe *) {}
257
258 virtual bool SupportsRDM() const { return m_supports_rdm; }
259
260 protected:
261 // indicates whether this port supports priorities, default to no
262 virtual bool SupportsPriorities() const { return false; }
263
264 private:
265 const unsigned int m_port_id;
266 uint8_t m_priority;
267 port_priority_mode m_priority_mode;
268 mutable std::string m_port_string;
269 Universe *m_universe; // the universe this port belongs to
270 AbstractDevice *m_device;
271 DmxSource m_dmx_source;
272 const PluginAdaptor *m_plugin_adaptor;
273 bool m_supports_rdm;
274
275 BasicInputPort(const BasicInputPort &) = delete;
276 const BasicInputPort &operator=(const BasicInputPort &) = delete;
277};
278
279
284 public:
289 unsigned int port_id,
290 bool start_rdm_discovery_on_patch = false,
291 bool supports_rdm = false);
292
293 unsigned int PortId() const { return m_port_id; }
294 AbstractDevice *GetDevice() const { return m_device; }
295 bool SetUniverse(Universe *universe);
296 Universe *GetUniverse() const { return m_universe; }
297 std::string UniqueId() const;
298 bool SetPriority(uint8_t priority);
299 uint8_t GetPriority() const { return m_priority; }
300 void SetPriorityMode(port_priority_mode mode) { m_priority_mode = mode; }
301 port_priority_mode GetPriorityMode() const { return m_priority_mode; }
302
303 virtual void UniverseNameChanged(const std::string &new_name) {
304 (void) new_name;
305 }
306
308 return SupportsPriorities() ? CAPABILITY_FULL : CAPABILITY_NONE;
309 }
310
311 // DiscoverableRDMControllerInterface methods
315 virtual void SendRDMRequest(ola::rdm::RDMRequest *request,
316 ola::rdm::RDMCallback *callback);
320 virtual void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *on_complete);
321
325 virtual void RunIncrementalDiscovery(
326 ola::rdm::RDMDiscoveryCallback *on_complete);
327
328 // TimeCode
329 virtual bool SupportsTimeCode() const { return false; }
330
334 virtual bool SendTimeCode(const ola::timecode::TimeCode &) {
335 return true;
336 }
337
338 // Subclasses can override this to cancel the SetUniverse operation.
339 virtual bool PreSetUniverse(Universe *, Universe *) { return true; }
340 virtual void PostSetUniverse(Universe *, Universe *) { }
341
342 virtual bool SupportsRDM() const { return m_supports_rdm; }
343
344 protected:
345 // indicates whether this port supports priorities, default to no
346 virtual bool SupportsPriorities() const { return false; }
347
351 void UpdateUIDs(const ola::rdm::UIDSet &uids);
352
353 private:
354 const unsigned int m_port_id;
355 const bool m_discover_on_patch;
356 uint8_t m_priority;
357 port_priority_mode m_priority_mode;
358 mutable std::string m_port_string;
359 Universe *m_universe; // the universe this port belongs to
360 AbstractDevice *m_device;
361 bool m_supports_rdm;
362
363 BasicOutputPort(const BasicOutputPort &) = delete;
364 const BasicOutputPort &operator=(const BasicOutputPort &) = delete;
365};
366
367
371template<class PortClass>
372bool IsInputPort();
373
374template<>
375bool IsInputPort<OutputPort>();
376} // namespace ola
377#endif // INCLUDE_OLAD_PORT_H_
A class used to hold a single universe of DMX data.
Helper macros.
Provides a wrapper for the DeviceManager and SelectServer objects so that the plugins can register de...
Different priority modes and priority capabilities. Please make sure to visit [Merging Algorithms] (h...
Classes that represent RDM commands.
Definitions and Interfaces to implement an RDMController that sends a single message at a time.
Definition Device.h:44
The base class for all 1 argument callbacks.
Definition Callback.h:982
Definition Port.h:199
void SetPriorityMode(port_priority_mode mode)
Set the Priority Mode for this Port.
Definition Port.h:216
port_priority_mode GetPriorityMode() const
Get the Priority Mode for this Port.
Definition Port.h:217
unsigned int PortId() const
Get the Port ID. This is the index within the device.
Definition Port.h:209
virtual bool SupportsRDM() const
Check if this Port supports RDM or not.
Definition Port.h:258
BasicInputPort(AbstractDevice *parent, unsigned int port_id, const PluginAdaptor *plugin_adaptor, bool supports_rdm=false)
Create a new basic input port.
Definition Port.cpp:38
void TriggerRDMDiscovery(ola::rdm::RDMDiscoveryCallback *on_complete, bool full=true)
Trigger the RDM Discovery procedure for this universe.
Definition Port.cpp:109
virtual std::string UniqueId() const
Return the globally unique id for a Port.
Definition Port.cpp:65
Universe * GetUniverse() const
Fetch the universe this Port is bound to.
Definition Port.h:212
AbstractDevice * GetDevice() const
Get the device which owns this Port.
Definition Port.h:210
port_priority_capability PriorityCapability() const
Get the priority capabilities for this port.
Definition Port.h:240
void DmxChanged()
Called when there is new data for this port.
Definition Port.cpp:83
void HandleRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *callback)
Handle an RDM Request on this port.
Definition Port.cpp:95
bool SetUniverse(Universe *universe)
Bind this port to a universe.
Definition Port.cpp:52
uint8_t GetPriority() const
Get the numeric priority for this Port.
Definition Port.h:215
const DmxSource & SourceData() const
Get the current DMX data.
Definition Port.h:223
bool SetPriority(uint8_t priority)
Set the Priority for this Port.
Definition Port.cpp:75
Definition Port.h:283
port_priority_capability PriorityCapability() const
Get the priority capabilities for this port.
Definition Port.h:307
BasicOutputPort(AbstractDevice *parent, unsigned int port_id, bool start_rdm_discovery_on_patch=false, bool supports_rdm=false)
Create a new BasicOutputPort.
Definition Port.cpp:120
AbstractDevice * GetDevice() const
Get the device which owns this Port.
Definition Port.h:294
uint8_t GetPriority() const
Get the numeric priority for this Port.
Definition Port.h:299
port_priority_mode GetPriorityMode() const
Get the Priority Mode for this Port.
Definition Port.h:301
std::string UniqueId() const
Return the globally unique id for a Port.
Definition Port.cpp:150
virtual void UniverseNameChanged(const std::string &new_name)
Called if the universe name changes.
Definition Port.h:303
virtual void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *on_complete)
This is a noop for ports that don't support RDM.
Definition Port.cpp:188
unsigned int PortId() const
Get the Port ID. This is the index within the device.
Definition Port.h:293
virtual void SendRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *callback)
Handle an RDMRequest, subclasses can implement this to support RDM.
Definition Port.cpp:168
virtual bool SupportsRDM() const
Check if this Port supports RDM or not.
Definition Port.h:342
Universe * GetUniverse() const
Fetch the universe this Port is bound to.
Definition Port.h:296
bool SetPriority(uint8_t priority)
Set the Priority for this Port.
Definition Port.cpp:160
bool SetUniverse(Universe *universe)
Bind this port to a universe.
Definition Port.cpp:134
void UpdateUIDs(const ola::rdm::UIDSet &uids)
Called when the discovery triggered by patching completes.
Definition Port.cpp:194
virtual bool SendTimeCode(const ola::timecode::TimeCode &)
This is a noop for ports that don't support TimeCode.
Definition Port.h:334
virtual void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *on_complete)
This is a noop for ports that don't support RDM.
Definition Port.cpp:182
void SetPriorityMode(port_priority_mode mode)
Set the Priority Mode for this Port.
Definition Port.h:300
Used to hold a single universe of DMX data.
Definition DmxBuffer.h:49
Definition DmxSource.h:36
A port that receives DMX512 data.
Definition Port.h:137
virtual void HandleRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *callback)=0
Handle RDMRequests, ownership of the RDMRequest object is transferred.
virtual const DmxSource & SourceData() const =0
Get the current DMX data.
virtual void DmxChanged()=0
Signal to the port that the DMX data has changed.
A port that sends DMX512 data.
Definition Port.h:163
virtual void UniverseNameChanged(const std::string &new_name)=0
Called if the universe name changes.
virtual void SendRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *callback)=0
Send a RDM command.
virtual bool WriteDMX(const DmxBuffer &buffer, uint8_t priority)=0
Write DMX data to this port.
virtual void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *on_complete)=0
Start a full discovery operation.
virtual void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *on_complete)=0
Start an incremental discovery operation.
Definition PluginAdaptor.h:41
The base port class.
Definition Port.h:49
virtual bool SetUniverse(Universe *universe)=0
Bind this port to a universe.
virtual bool SetPriority(uint8_t priority)=0
Set the Priority for this Port.
virtual AbstractDevice * GetDevice() const =0
Get the device which owns this Port.
virtual bool SupportsRDM() const =0
Check if this Port supports RDM or not.
virtual port_priority_capability PriorityCapability() const =0
Get the priority capabilities for this port.
virtual std::string UniqueId() const =0
Return the globally unique id for a Port.
virtual void SetPriorityMode(port_priority_mode mode)=0
Set the Priority Mode for this Port.
virtual unsigned int PortId() const =0
Get the Port ID. This is the index within the device.
virtual uint8_t GetPriority() const =0
Get the numeric priority for this Port.
virtual Universe * GetUniverse() const =0
Fetch the universe this Port is bound to.
virtual std::string Description() const =0
Fetch the string description for a Port.
virtual port_priority_mode GetPriorityMode() const =0
Get the Priority Mode for this Port.
Definition Universe.h:46
The interface that can send RDM commands, as well as perform discovery operations.
Definition RDMControllerInterface.h:104
RDM Commands that represent requests (GET, SET or DISCOVER).
Definition RDMCommand.h:234
Represents a set of RDM UIDs.
Definition UIDSet.h:48
Definition TimeCode.h:33
port_priority_capability
Defines the priority capability of a Port.
Definition PortConstants.h:58
port_priority_mode
Defines the different priority modes that OLA supports.
Definition PortConstants.h:44
@ CAPABILITY_STATIC
Definition PortConstants.h:62
@ CAPABILITY_FULL
Definition PortConstants.h:64
@ CAPABILITY_NONE
Definition PortConstants.h:60
static const uint8_t SOURCE_PRIORITY_MIN
The minimum priority for a source.
Definition SourcePriorities.h:36
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
bool IsInputPort()
This allows switching based on Port type.
Definition Port.cpp:201