Open Lighting Architecture  0.9.4
 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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  PreamblePacker() : m_send_buffer(NULL) {}
40  ~PreamblePacker();
41 
42  const uint8_t *Pack(const PDUBlock<PDU> &pdu_block,
43  unsigned int *length);
44 
45  static void AddUDPPreamble(ola::io::IOStack *stack);
46  static void AddTCPPreamble(ola::io::IOStack *stack);
47 
48  static const uint8_t ACN_HEADER[];
49  static const unsigned int ACN_HEADER_SIZE;
50  static const unsigned int MAX_DATAGRAM_SIZE = 1472;
51 
52  private:
53  uint8_t *m_send_buffer;
54 
55  void Init();
56 
57  static const uint8_t TCP_ACN_HEADER[];
58  static const unsigned int TCP_ACN_HEADER_SIZE;
59 };
60 } // namespace e131
61 } // namespace plugin
62 } // namespace ola
63 #endif // PLUGINS_E131_E131_PREAMBLEPACKER_H_