Open Lighting Architecture: include/olad/Port.h Source File

| 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>
27#include <ola/rdm/RDMControllerInterface.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
49 class 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
100 virtual port_priority_capability PriorityCapability() const = 0;
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
124 virtual port_priority_mode GetPriorityMode() const = 0;
125
130 virtual bool SupportsRDM() const = 0;
131};
132
133
137 class InputPort: public Port {
138 public:
139 virtual ~InputPort() {}
140
144 virtual void DmxChanged() = 0;
145
149 virtual const DmxSource &SourceData() const = 0;
150
155 virtual void HandleRDMRequest(ola::rdm::RDMRequest *request,
156 ola::rdm::RDMCallback *callback) = 0;
157};
158
159
163 class OutputPort: public Port, ola::rdm::DiscoverableRDMControllerInterface {
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
182 virtual void SendRDMRequest(ola::rdm::RDMRequest *request,
183 ola::rdm::RDMCallback *callback) = 0;
184 virtual void RunFullDiscovery(
185 ola::rdm::RDMDiscoveryCallback *on_complete) = 0;
186 virtual void RunIncrementalDiscovery(
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
199 class BasicInputPort: public InputPort {
200 public:
204 BasicInputPort(AbstractDevice *parent,
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
231 void HandleRDMRequest(ola::rdm::RDMRequest *request,
232 ola::rdm::RDMCallback *callback);
233
237 void TriggerRDMDiscovery(ola::rdm::RDMDiscoveryCallback *on_complete,
238 bool full = true);
239
240 port_priority_capability PriorityCapability() const {
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 {
250 return ola::dmx::SOURCE_PRIORITY_MIN;
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
283 class BasicOutputPort: public OutputPort {
284 public:
288 BasicOutputPort(AbstractDevice *parent,
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
307 port_priority_capability PriorityCapability() const {
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_
DmxBuffer.h
A class used to hold a single universe of DMX data.
Macro.h
Helper macros.
PluginAdaptor.h
Provides a wrapper for the DeviceManager and SelectServer objects so that the plugins can register de...
PortConstants.h
Different priority modes and priority capabilities. Please make sure to visit [Merging Algorithms] (h...
RDMCommand.h
Classes that represent RDM commands.
RDMControllerInterface.h
Definitions and Interfaces to implement an RDMController that sends a single message at a time.
ola::AbstractDevice
Definition Device.h:44
ola::BasicInputPort::SetPriorityMode
void SetPriorityMode(port_priority_mode mode)
Set the Priority Mode for this Port.
Definition Port.h:216
ola::BasicInputPort::GetPriorityMode
port_priority_mode GetPriorityMode() const
Get the Priority Mode for this Port.
Definition Port.h:217
ola::BasicInputPort::PortId
unsigned int PortId() const
Get the Port ID. This is the index within the device.
Definition Port.h:209
ola::BasicInputPort::SupportsRDM
virtual bool SupportsRDM() const
Check if this Port supports RDM or not.
Definition Port.h:258
ola::BasicInputPort::BasicInputPort
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
ola::BasicInputPort::TriggerRDMDiscovery
void TriggerRDMDiscovery(ola::rdm::RDMDiscoveryCallback *on_complete, bool full=true)
Trigger the RDM Discovery procedure for this universe.
Definition Port.cpp:109
ola::BasicInputPort::UniqueId
virtual std::string UniqueId() const
Return the globally unique id for a Port.
Definition Port.cpp:65
ola::BasicInputPort::GetUniverse
Universe * GetUniverse() const
Fetch the universe this Port is bound to.
Definition Port.h:212
ola::BasicInputPort::GetDevice
AbstractDevice * GetDevice() const
Get the device which owns this Port.
Definition Port.h:210
ola::BasicInputPort::PriorityCapability
port_priority_capability PriorityCapability() const
Get the priority capabilities for this port.
Definition Port.h:240
ola::BasicInputPort::DmxChanged
void DmxChanged()
Called when there is new data for this port.
Definition Port.cpp:83
ola::BasicInputPort::HandleRDMRequest
void HandleRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *callback)
Handle an RDM Request on this port.
Definition Port.cpp:95
ola::BasicInputPort::SetUniverse
bool SetUniverse(Universe *universe)
Bind this port to a universe.
Definition Port.cpp:52
ola::BasicInputPort::GetPriority
uint8_t GetPriority() const
Get the numeric priority for this Port.
Definition Port.h:215
ola::BasicInputPort::SourceData
const DmxSource & SourceData() const
Get the current DMX data.
Definition Port.h:223
ola::BasicInputPort::SetPriority
bool SetPriority(uint8_t priority)
Set the Priority for this Port.
Definition Port.cpp:75
ola::BasicOutputPort::PriorityCapability
port_priority_capability PriorityCapability() const
Get the priority capabilities for this port.
Definition Port.h:307
ola::BasicOutputPort::BasicOutputPort
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
ola::BasicOutputPort::GetDevice
AbstractDevice * GetDevice() const
Get the device which owns this Port.
Definition Port.h:294
ola::BasicOutputPort::GetPriority
uint8_t GetPriority() const
Get the numeric priority for this Port.
Definition Port.h:299
ola::BasicOutputPort::GetPriorityMode
port_priority_mode GetPriorityMode() const
Get the Priority Mode for this Port.
Definition Port.h:301
ola::BasicOutputPort::UniqueId
std::string UniqueId() const
Return the globally unique id for a Port.
Definition Port.cpp:150
ola::BasicOutputPort::UniverseNameChanged
virtual void UniverseNameChanged(const std::string &new_name)
Called if the universe name changes.
Definition Port.h:303
ola::BasicOutputPort::RunIncrementalDiscovery
virtual void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *on_complete)
This is a noop for ports that don't support RDM.
Definition Port.cpp:188
ola::BasicOutputPort::PortId
unsigned int PortId() const
Get the Port ID. This is the index within the device.
Definition Port.h:293
ola::BasicOutputPort::SendRDMRequest
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
ola::BasicOutputPort::SupportsRDM
virtual bool SupportsRDM() const
Check if this Port supports RDM or not.
Definition Port.h:342
ola::BasicOutputPort::GetUniverse
Universe * GetUniverse() const
Fetch the universe this Port is bound to.
Definition Port.h:296
ola::BasicOutputPort::SetPriority
bool SetPriority(uint8_t priority)
Set the Priority for this Port.
Definition Port.cpp:160
ola::BasicOutputPort::SetUniverse
bool SetUniverse(Universe *universe)
Bind this port to a universe.
Definition Port.cpp:134
ola::BasicOutputPort::UpdateUIDs
void UpdateUIDs(const ola::rdm::UIDSet &uids)
Called when the discovery triggered by patching completes.
Definition Port.cpp:194
ola::BasicOutputPort::SendTimeCode
virtual bool SendTimeCode(const ola::timecode::TimeCode &)
This is a noop for ports that don't support TimeCode.
Definition Port.h:334
ola::BasicOutputPort::RunFullDiscovery
virtual void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *on_complete)
This is a noop for ports that don't support RDM.
Definition Port.cpp:182
ola::BasicOutputPort::SetPriorityMode
void SetPriorityMode(port_priority_mode mode)
Set the Priority Mode for this Port.
Definition Port.h:300
ola::DmxBuffer
Used to hold a single universe of DMX data.
Definition DmxBuffer.h:49
ola::DmxSource
Definition DmxSource.h:36
ola::InputPort
A port that receives DMX512 data.
Definition Port.h:137
ola::InputPort::HandleRDMRequest
virtual void HandleRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *callback)=0
Handle RDMRequests, ownership of the RDMRequest object is transferred.
ola::InputPort::SourceData
virtual const DmxSource & SourceData() const =0
Get the current DMX data.
ola::InputPort::DmxChanged
virtual void DmxChanged()=0
Signal to the port that the DMX data has changed.
ola::OutputPort
A port that sends DMX512 data.
Definition Port.h:163
ola::OutputPort::UniverseNameChanged
virtual void UniverseNameChanged(const std::string &new_name)=0
Called if the universe name changes.
ola::OutputPort::SendRDMRequest
virtual void SendRDMRequest(ola::rdm::RDMRequest *request, ola::rdm::RDMCallback *callback)=0
Send a RDM command.
ola::OutputPort::WriteDMX
virtual bool WriteDMX(const DmxBuffer &buffer, uint8_t priority)=0
Write DMX data to this port.
ola::OutputPort::RunFullDiscovery
virtual void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *on_complete)=0
Start a full discovery operation.
ola::OutputPort::RunIncrementalDiscovery
virtual void RunIncrementalDiscovery(ola::rdm::RDMDiscoveryCallback *on_complete)=0
Start an incremental discovery operation.
ola::PluginAdaptor
Definition PluginAdaptor.h:41
ola::Port
The base port class.
Definition Port.h:49
ola::Port::SetUniverse
virtual bool SetUniverse(Universe *universe)=0
Bind this port to a universe.
ola::Port::SetPriority
virtual bool SetPriority(uint8_t priority)=0
Set the Priority for this Port.
ola::Port::GetDevice
virtual AbstractDevice * GetDevice() const =0
Get the device which owns this Port.
ola::Port::SupportsRDM
virtual bool SupportsRDM() const =0
Check if this Port supports RDM or not.
ola::Port::PriorityCapability
virtual port_priority_capability PriorityCapability() const =0
Get the priority capabilities for this port.
ola::Port::UniqueId
virtual std::string UniqueId() const =0
Return the globally unique id for a Port.
ola::Port::SetPriorityMode
virtual void SetPriorityMode(port_priority_mode mode)=0
Set the Priority Mode for this Port.
ola::Port::PortId
virtual unsigned int PortId() const =0
Get the Port ID. This is the index within the device.
ola::Port::GetPriority
virtual uint8_t GetPriority() const =0
Get the numeric priority for this Port.
ola::Port::GetUniverse
virtual Universe * GetUniverse() const =0
Fetch the universe this Port is bound to.
ola::Port::Description
virtual std::string Description() const =0
Fetch the string description for a Port.
ola::Port::GetPriorityMode
virtual port_priority_mode GetPriorityMode() const =0
Get the Priority Mode for this Port.
ola::Universe
Definition Universe.h:46
ola::rdm::DiscoverableRDMControllerInterface
The interface that can send RDM commands, as well as perform discovery operations.
Definition RDMControllerInterface.h:104
ola::rdm::RDMRequest
RDM Commands that represent requests (GET, SET or DISCOVER).
Definition RDMCommand.h:234
ola::rdm::UIDSet
Represents a set of RDM UIDs.
Definition UIDSet.h:48
ola::timecode::TimeCode
Definition TimeCode.h:33
ola::port_priority_capability
port_priority_capability
Defines the priority capability of a Port.
Definition PortConstants.h:58
ola::port_priority_mode
port_priority_mode
Defines the different priority modes that OLA supports.
Definition PortConstants.h:44
ola::CAPABILITY_STATIC
@ CAPABILITY_STATIC
Definition PortConstants.h:62
ola::CAPABILITY_FULL
@ CAPABILITY_FULL
Definition PortConstants.h:64
ola::CAPABILITY_NONE
@ CAPABILITY_NONE
Definition PortConstants.h:60
ola::dmx::SOURCE_PRIORITY_MIN
static const uint8_t SOURCE_PRIORITY_MIN
The minimum priority for a source.
Definition SourcePriorities.h:36
ola::rdm::RDMCallback
ola::BaseCallback1< void, RDMReply * > RDMCallback
The callback run when a RDM request completes.
Definition RDMControllerInterface.h:52
ola::rdm::RDMDiscoveryCallback
ola::BaseCallback1< void, const ola::rdm::UIDSet & > RDMDiscoveryCallback
The callback run when a discovery operation completes.
Definition RDMControllerInterface.h:68
ola::timecode
Timecode.
Definition TimeCode.cpp:30
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
ola::IsInputPort
bool IsInputPort()
This allows switching based on Port type.
Definition Port.cpp:201