Open Lighting Architecture
 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 using ola::acn::CID;
45 using std::string;
46 
47 class E131Node {
48  public:
49  E131Node(const string &ip_address,
50  const CID &cid = CID::Generate(),
51  bool use_rev2 = false,
52  bool ignore_preview = true,
53  uint8_t dscp_value = 0, // default off
54  uint16_t port = ola::acn::ACN_PORT);
55  ~E131Node();
56 
57  bool Start();
58  bool Stop();
59 
60  bool SetSourceName(unsigned int universe, const string &source);
61  bool SendDMX(uint16_t universe,
62  const ola::DmxBuffer &buffer,
63  uint8_t priority = DEFAULT_PRIORITY,
64  bool preview = false);
65 
66  // The following method is provided for the testing framework. Don't use
67  // it in production code!
68  bool SendDMXWithSequenceOffset(uint16_t universe,
69  const ola::DmxBuffer &buffer,
70  int8_t sequence_offset,
71  uint8_t priority = DEFAULT_PRIORITY,
72  bool preview = false);
73 
74  bool StreamTerminated(uint16_t universe,
75  const ola::DmxBuffer &buffer = DmxBuffer(),
76  uint8_t priority = DEFAULT_PRIORITY);
77 
78  bool SetHandler(unsigned int universe, ola::DmxBuffer *buffer,
79  uint8_t *priority, ola::Callback0<void> *handler);
80  bool RemoveHandler(unsigned int universe);
81 
82  const ola::network::Interface &GetInterface() const { return m_interface; }
83 
84  ola::network::UDPSocket* GetSocket() { return &m_socket; }
85 
86  private:
87  typedef struct {
88  string source;
89  uint8_t sequence;
90  } tx_universe;
91 
92  string m_preferred_ip;
93  ola::network::Interface m_interface;
94  ola::network::UDPSocket m_socket;
95  CID m_cid;
96  bool m_use_rev2;
97  uint8_t m_dscp;
98  uint16_t m_udp_port;
99  // senders
100  RootSender m_root_sender;
101  E131Sender m_e131_sender;
102  // inflators
103  RootInflator m_root_inflator;
104  E131Inflator m_e131_inflator;
105  E131InflatorRev2 m_e131_rev2_inflator;
106  DMPE131Inflator m_dmp_inflator;
107 
108  IncomingUDPTransport m_incoming_udp_transport;
109  std::map<unsigned int, tx_universe> m_tx_universes;
110  uint8_t *m_send_buffer;
111 
112  tx_universe *SetupOutgoingSettings(unsigned int universe);
113 
114  E131Node(const E131Node&);
115  E131Node& operator=(const E131Node&);
116 
117  static const uint16_t DEFAULT_PRIORITY = 100;
118 };
119 } // namespace e131
120 } // namespace plugin
121 } // namespace ola
122 #endif // PLUGINS_E131_E131_E131NODE_H_