Open Lighting Architecture  0.9.0
 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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-2009 Simon Newton
20  */
21 
22 #ifndef PLUGINS_E131_E131_E131NODE_H_
23 #define PLUGINS_E131_E131_E131NODE_H_
24 
25 #include <map>
26 #include <string>
27 #include "ola/Callback.h"
28 #include "ola/DmxBuffer.h"
29 #include "ola/acn/ACNPort.h"
30 #include "ola/acn/CID.h"
31 #include "ola/network/Interface.h"
32 #include "ola/network/Socket.h"
33 #include "plugins/e131/e131/E131Sender.h"
34 #include "plugins/e131/e131/E131Inflator.h"
35 #include "plugins/e131/e131/RootInflator.h"
36 #include "plugins/e131/e131/RootSender.h"
37 #include "plugins/e131/e131/UDPTransport.h"
38 #include "plugins/e131/e131/DMPE131Inflator.h"
39 
40 namespace ola {
41 namespace plugin {
42 namespace e131 {
43 
44 class E131Node {
45  public:
46  E131Node(const std::string &ip_address,
48  bool use_rev2 = false,
49  bool ignore_preview = true,
50  uint8_t dscp_value = 0, // default off
51  uint16_t port = ola::acn::ACN_PORT);
52  ~E131Node();
53 
54  bool Start();
55  bool Stop();
56 
57  bool SetSourceName(unsigned int universe, const std::string &source);
58  bool SendDMX(uint16_t universe,
59  const ola::DmxBuffer &buffer,
60  uint8_t priority = DEFAULT_PRIORITY,
61  bool preview = false);
62 
63  // The following method is provided for the testing framework. Don't use
64  // it in production code!
65  bool SendDMXWithSequenceOffset(uint16_t universe,
66  const ola::DmxBuffer &buffer,
67  int8_t sequence_offset,
68  uint8_t priority = DEFAULT_PRIORITY,
69  bool preview = false);
70 
71  bool StreamTerminated(uint16_t universe,
72  const ola::DmxBuffer &buffer = DmxBuffer(),
73  uint8_t priority = DEFAULT_PRIORITY);
74 
75  bool SetHandler(unsigned int universe, ola::DmxBuffer *buffer,
76  uint8_t *priority, ola::Callback0<void> *handler);
77  bool RemoveHandler(unsigned int universe);
78 
79  const ola::network::Interface &GetInterface() const { return m_interface; }
80 
81  ola::network::UDPSocket* GetSocket() { return &m_socket; }
82 
83  private:
84  typedef struct {
85  std::string source;
86  uint8_t sequence;
87  } tx_universe;
88 
89  std::string m_preferred_ip;
90  ola::network::Interface m_interface;
91  ola::network::UDPSocket m_socket;
92  ola::acn::CID m_cid;
93  bool m_use_rev2;
94  uint8_t m_dscp;
95  uint16_t m_udp_port;
96  // senders
97  RootSender m_root_sender;
98  E131Sender m_e131_sender;
99  // inflators
100  RootInflator m_root_inflator;
101  E131Inflator m_e131_inflator;
102  E131InflatorRev2 m_e131_rev2_inflator;
103  DMPE131Inflator m_dmp_inflator;
104 
105  IncomingUDPTransport m_incoming_udp_transport;
106  std::map<unsigned int, tx_universe> m_tx_universes;
107  uint8_t *m_send_buffer;
108 
109  tx_universe *SetupOutgoingSettings(unsigned int universe);
110 
111  E131Node(const E131Node&);
112  E131Node& operator=(const E131Node&);
113 
114  static const uint16_t DEFAULT_PRIORITY = 100;
115 };
116 } // namespace e131
117 } // namespace plugin
118 } // namespace ola
119 #endif // PLUGINS_E131_E131_E131NODE_H_