Open Lighting Architecture  Latest Git
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 
36 namespace ola {
37 
38 class 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 
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:
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 
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 
276 };
277 
278 
283  public:
288  unsigned int port_id,
289  bool start_rdm_discovery_on_patch = false,
290  bool supports_rdm = false);
291 
292  unsigned int PortId() const { return m_port_id; }
293  AbstractDevice *GetDevice() const { return m_device; }
294  bool SetUniverse(Universe *universe);
295  Universe *GetUniverse() const { return m_universe; }
296  std::string UniqueId() const;
297  bool SetPriority(uint8_t priority);
298  uint8_t GetPriority() const { return m_priority; }
299  void SetPriorityMode(port_priority_mode mode) { m_priority_mode = mode; }
300  port_priority_mode GetPriorityMode() const { return m_priority_mode; }
301 
302  virtual void UniverseNameChanged(const std::string &new_name) {
303  (void) new_name;
304  }
305 
307  return SupportsPriorities() ? CAPABILITY_FULL : CAPABILITY_NONE;
308  }
309 
310  // DiscoverableRDMControllerInterface methods
314  virtual void SendRDMRequest(ola::rdm::RDMRequest *request,
315  ola::rdm::RDMCallback *callback);
319  virtual void RunFullDiscovery(ola::rdm::RDMDiscoveryCallback *on_complete);
320 
324  virtual void RunIncrementalDiscovery(
325  ola::rdm::RDMDiscoveryCallback *on_complete);
326 
327  // TimeCode
328  virtual bool SupportsTimeCode() const { return false; }
329 
333  virtual bool SendTimeCode(const ola::timecode::TimeCode &) {
334  return true;
335  }
336 
337  // Subclasses can override this to cancel the SetUniverse operation.
338  virtual bool PreSetUniverse(Universe *, Universe *) { return true; }
339  virtual void PostSetUniverse(Universe *, Universe *) { }
340 
341  virtual bool SupportsRDM() const { return m_supports_rdm; }
342 
343  protected:
344  // indicates whether this port supports priorities, default to no
345  virtual bool SupportsPriorities() const { return false; }
346 
350  void UpdateUIDs(const ola::rdm::UIDSet &uids);
351 
352  private:
353  const unsigned int m_port_id;
354  const bool m_discover_on_patch;
355  uint8_t m_priority;
356  port_priority_mode m_priority_mode;
357  mutable std::string m_port_string;
358  Universe *m_universe; // the universe this port belongs to
359  AbstractDevice *m_device;
360  bool m_supports_rdm;
361 
363 };
364 
365 
369 template<class PortClass>
370 bool IsInputPort();
371 
372 template<>
373 bool IsInputPort<OutputPort>();
374 } // namespace ola
375 #endif // INCLUDE_OLAD_PORT_H_
Represents a set of RDM UIDs.
Definition: UIDSet.h:48
Definitions and Interfaces to implement an RDMController that sends a single message at a time...
unsigned int PortId() const
Get the Port ID. This is the index within the device.
Definition: Port.h:209
AbstractDevice * GetDevice() const
Get the device which owns this Port.
Definition: Port.h:210
Definition: DmxSource.h:36
Definition: Universe.h:46
port_priority_mode GetPriorityMode() const
Get the Priority Mode for this Port.
Definition: Port.h:300
port_priority_mode GetPriorityMode() const
Get the Priority Mode for this Port.
Definition: Port.h:217
Provides a wrapper for the DeviceManager and SelectServer objects so that the plugins can register de...
A port that receives DMX512 data.
Definition: Port.h:137
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
unsigned int PortId() const
Get the Port ID. This is the index within the device.
Definition: Port.h:292
virtual uint8_t GetPriority() const =0
Get the numeric priority for this Port.
virtual bool SetPriority(uint8_t priority)=0
Set the Priority for this Port.
port_priority_capability PriorityCapability() const
Get the priority capabilities for this port.
Definition: Port.h:306
Definition: Port.h:199
virtual bool SetUniverse(Universe *universe)=0
Bind this port to a universe.
The interface that can send RDM commands, as well as perform discovery operations.
Definition: RDMControllerInterface.h:104
Definition: PortConstants.h:62
RDM Commands that represent requests (GET, SET or DISCOVER).
Definition: RDMCommand.h:234
Used to hold a single universe of DMX data.
Definition: DmxBuffer.h:49
virtual bool SupportsRDM() const
Check if this Port supports RDM or not.
Definition: Port.h:258
uint8_t GetPriority() const
Get the numeric priority for this Port.
Definition: Port.h:215
port_priority_mode
Defines the different priority modes that OLA supports.
Definition: PortConstants.h:44
void SetPriorityMode(port_priority_mode mode)
Set the Priority Mode for this Port.
Definition: Port.h:216
Universe * GetUniverse() const
Fetch the universe this Port is bound to.
Definition: Port.h:212
virtual bool SupportsRDM() const
Check if this Port supports RDM or not.
Definition: Port.h:341
A port that sends DMX512 data.
Definition: Port.h:163
port_priority_capability
Defines the priority capability of a Port.
Definition: PortConstants.h:58
AbstractDevice * GetDevice() const
Get the device which owns this Port.
Definition: Port.h:293
virtual std::string Description() const =0
Fetch the string description for a Port.
The interface for a Device.
Definition: Device.h:44
A class used to hold a single universe of DMX data.
virtual port_priority_capability PriorityCapability() const =0
Get the priority capabilities for this port.
virtual unsigned int PortId() const =0
Get the Port ID. This is the index within the device.
void SetPriorityMode(port_priority_mode mode)
Set the Priority Mode for this Port.
Definition: Port.h:299
Definition: TimeCode.h:33
virtual bool SendTimeCode(const ola::timecode::TimeCode &)
This is a noop for ports that don&#39;t support TimeCode.
Definition: Port.h:333
Definition: PluginAdaptor.h:41
bool IsInputPort()
This allows switching based on Port type.
Definition: Port.cpp:201
virtual void UniverseNameChanged(const std::string &new_name)
Called if the universe name changes.
Definition: Port.h:302
virtual Universe * GetUniverse() const =0
Fetch the universe this Port is bound to.
virtual port_priority_mode GetPriorityMode() const =0
Get the Priority Mode for this Port.
static const uint8_t SOURCE_PRIORITY_MIN
The minimum priority for a source.
Definition: SourcePriorities.h:36
Different priority modes and priority capabilities. Please make sure to visit Merging Algorithms for ...
The base class for all 1 argument callbacks.
Definition: Callback.h:982
virtual AbstractDevice * GetDevice() const =0
Get the device which owns this Port.
virtual std::string UniqueId() const =0
Return the globally unique id for a Port.
port_priority_capability PriorityCapability() const
Get the priority capabilities for this port.
Definition: Port.h:240
Helper macros.
Definition: PortConstants.h:60
const DmxSource & SourceData() const
Get the current DMX data.
Definition: Port.h:223
virtual void SetPriorityMode(port_priority_mode mode)=0
Set the Priority Mode for this Port.
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
uint8_t GetPriority() const
Get the numeric priority for this Port.
Definition: Port.h:298
The base port class.
Definition: Port.h:49
Definition: Port.h:282
virtual bool SupportsRDM() const =0
Check if this Port supports RDM or not.
Definition: PortConstants.h:64
Universe * GetUniverse() const
Fetch the universe this Port is bound to.
Definition: Port.h:295
Classes that represent RDM commands.