Open Lighting Architecture  0.9.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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(const 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(const 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(const ola::rdm::RDMRequest *request,
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  DISALLOW_COPY_AND_ASSIGN(BasicInputPort);
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 
306  port_priority_capability PriorityCapability() const {
307  return SupportsPriorities() ? CAPABILITY_FULL : CAPABILITY_NONE;
308  }
309 
310  // DiscoverableRDMControllerInterface methods
314  virtual void SendRDMRequest(const 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 
362  DISALLOW_COPY_AND_ASSIGN(BasicOutputPort);
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_