Open Lighting Architecture  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PreamblePacker.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  * PreamblePacker.h
17  * This class takes a block of Root Layer PDUs, prepends the ACN preamble and
18  * writes the data to a buffer.
19  * Copyright (C) 2012 Simon Newton
20  */
21 
22 #ifndef PLUGINS_E131_E131_PREAMBLEPACKER_H_
23 #define PLUGINS_E131_E131_PREAMBLEPACKER_H_
24 
25 #include "ola/io/IOStack.h"
26 #include "plugins/e131/e131/PDU.h"
27 
28 namespace ola {
29 namespace plugin {
30 namespace e131 {
31 
32 
33 /*
34  * Pack a Root PDU block and the ACN Preamble into a memory block. This class
35  * isn't reentrant so be careful where you use it.
36  */
38  public:
39  explicit PreamblePacker()
40  : m_send_buffer(NULL) {
41  }
42  ~PreamblePacker();
43 
44  const uint8_t *Pack(const PDUBlock<PDU> &pdu_block,
45  unsigned int *length);
46 
47  static void AddUDPPreamble(ola::io::IOStack *stack);
48  static void AddTCPPreamble(ola::io::IOStack *stack);
49 
50  static const uint8_t ACN_HEADER[];
51  static const unsigned int ACN_HEADER_SIZE;
52  static const unsigned int MAX_DATAGRAM_SIZE = 1472;
53 
54  private:
55  uint8_t *m_send_buffer;
56 
57  void Init();
58 
59  static const uint8_t TCP_ACN_HEADER[];
60  static const unsigned int TCP_ACN_HEADER_SIZE;
61 };
62 } // namespace e131
63 } // namespace plugin
64 } // namespace ola
65 #endif // PLUGINS_E131_E131_PREAMBLEPACKER_H_