Open Lighting Architecture  0.9.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
E131Node.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  * E131Node.h
17  * Header file for the E131Node class, this is the interface between OLA and
18  * the E1.31 library.
19  * Copyright (C) 2007 Simon Newton
20  */
21 
22 #ifndef PLUGINS_E131_E131_E131NODE_H_
23 #define PLUGINS_E131_E131_E131NODE_H_
24 
25 #include <map>
26 #include <set>
27 #include <string>
28 #include <vector>
29 #include "ola/Callback.h"
30 #include "ola/Constants.h"
31 #include "ola/DmxBuffer.h"
32 #include "ola/acn/ACNPort.h"
33 #include "ola/acn/CID.h"
34 #include "ola/base/Macro.h"
35 #include "ola/io/SelectServerInterface.h"
36 #include "ola/thread/SchedulerInterface.h"
37 #include "ola/network/Interface.h"
38 #include "ola/network/Socket.h"
39 #include "plugins/e131/e131/DMPE131Inflator.h"
40 #include "plugins/e131/e131/E131DiscoveryInflator.h"
41 #include "plugins/e131/e131/E131Inflator.h"
42 #include "plugins/e131/e131/E131Sender.h"
43 #include "plugins/e131/e131/RootInflator.h"
44 #include "plugins/e131/e131/RootSender.h"
45 #include "plugins/e131/e131/UDPTransport.h"
46 
47 namespace ola {
48 namespace plugin {
49 namespace e131 {
50 
51 class E131Node {
52  public:
56  struct Options {
57  public:
58  Options()
59  : use_rev2(false),
60  ignore_preview(true),
62  dscp(0),
65  }
66 
67  bool use_rev2;
70  uint8_t dscp;
71  uint16_t port;
72  std::string source_name;
73  };
74 
75  struct KnownController {
76  acn::CID cid;
77  ola::network::IPV4Address ip_address;
78  std::string source_name;
79  std::set<uint16_t> universes;
80  };
81 
90  const std::string &ip_address,
91  const Options &options,
92  const ola::acn::CID &cid = ola::acn::CID::Generate());
93  ~E131Node();
94 
98  bool Start();
99 
103  bool Stop();
104 
110  bool SetSourceName(uint16_t universe, const std::string &source);
111 
117  bool StartStream(uint16_t universe);
118 
124  bool TerminateStream(uint16_t universe,
125  uint8_t priority = DEFAULT_PRIORITY);
126 
135  bool SendDMX(uint16_t universe,
136  const ola::DmxBuffer &buffer,
137  uint8_t priority = DEFAULT_PRIORITY,
138  bool preview = false);
139 
154  bool SendDMXWithSequenceOffset(uint16_t universe,
155  const ola::DmxBuffer &buffer,
156  int8_t sequence_offset,
157  uint8_t priority = DEFAULT_PRIORITY,
158  bool preview = false);
159 
160 
171  bool SendStreamTerminated(uint16_t universe,
172  const ola::DmxBuffer &buffer = DmxBuffer(),
173  uint8_t priority = DEFAULT_PRIORITY);
174 
183  bool SetHandler(uint16_t universe, ola::DmxBuffer *buffer,
184  uint8_t *priority, ola::Callback0<void> *handler);
185 
191  bool RemoveHandler(uint16_t universe);
192 
196  const ola::network::Interface &GetInterface() const { return m_interface; }
197 
201  ola::network::UDPSocket* GetSocket() { return &m_socket; }
202 
209  void GetKnownControllers(std::vector<KnownController> *controllers);
210 
211  private:
212  struct tx_universe {
213  std::string source;
214  uint8_t sequence;
215  };
216 
217  typedef std::map<uint16_t, tx_universe> ActiveTxUniverses;
218  typedef std::map<acn::CID, class TrackedSource*> TrackedSources;
219 
221  const Options m_options;
222  const std::string m_preferred_ip;
223  const ola::acn::CID m_cid;
224 
225  ola::network::Interface m_interface;
226  ola::network::UDPSocket m_socket;
227  // senders
228  RootSender m_root_sender;
229  E131Sender m_e131_sender;
230  // inflators
231  RootInflator m_root_inflator;
232  E131Inflator m_e131_inflator;
233  E131InflatorRev2 m_e131_rev2_inflator;
234  DMPE131Inflator m_dmp_inflator;
235  E131DiscoveryInflator m_discovery_inflator;
236 
237  IncomingUDPTransport m_incoming_udp_transport;
238  ActiveTxUniverses m_tx_universes;
239  uint8_t *m_send_buffer;
240 
241  // Discovery members
242  ola::thread::timeout_id m_discovery_timeout;
243  TrackedSources m_discovered_sources;
244 
245  tx_universe *SetupOutgoingSettings(uint16_t universe);
246 
247  bool PerformDiscoveryHousekeeping();
248  void NewDiscoveryPage(const HeaderSet &headers,
249  const E131DiscoveryInflator::DiscoveryPage &page);
250  void SendDiscoveryPage(const std::vector<uint16_t> &universes, uint8_t page,
251  uint8_t last_page, uint32_t sequence_number);
252 
253  static const uint16_t DEFAULT_PRIORITY = 100;
254  static const uint16_t UNIVERSE_DISCOVERY_INTERVAL = 10000; // milliseconds
255  static const uint16_t DISCOVERY_UNIVERSE_ID = 64214;
256  static const uint16_t DISCOVERY_PAGE_SIZE = 512;
257 
258  DISALLOW_COPY_AND_ASSIGN(E131Node);
259 };
260 } // namespace e131
261 } // namespace plugin
262 } // namespace ola
263 #endif // PLUGINS_E131_E131_E131NODE_H_