Open Lighting Architecture
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RootPDU.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  * RootPDU.h
17  * Interface for the RootPDU class
18  * Copyright (C) 2007-2009 Simon Newton
19  */
20 
21 #ifndef PLUGINS_E131_E131_ROOTPDU_H_
22 #define PLUGINS_E131_E131_ROOTPDU_H_
23 
24 #include <stdint.h>
25 
26 #include "ola/acn/CID.h"
27 #include "ola/io/IOStack.h"
28 
29 #include "plugins/e131/e131/PDU.h"
30 
31 namespace ola {
32 namespace plugin {
33 namespace e131 {
34 
35 using ola::acn::CID;
36 
37 class RootPDU: public PDU {
38  public:
39  explicit RootPDU(unsigned int vector):
40  PDU(vector),
41  m_block(NULL),
42  m_block_size(0) {}
43  RootPDU(unsigned int vector, const CID &cid, const PDUBlock<PDU> *block):
44  PDU(vector),
45  m_cid(cid),
46  m_block(block) {
47  m_block_size = block ? block->Size() : 0;
48  }
49  ~RootPDU() {}
50 
51  unsigned int HeaderSize() const { return CID::CID_LENGTH; }
52  unsigned int DataSize() const { return m_block_size; }
53  bool PackHeader(uint8_t *data, unsigned int *length) const;
54  bool PackData(uint8_t *data, unsigned int *length) const;
55 
56  void PackHeader(OutputStream *stream) const;
57  void PackData(OutputStream *stream) const;
58 
59  const CID &Cid() const { return m_cid; }
60  const CID &Cid(const CID &cid) { return m_cid = cid; }
61  void SetBlock(const PDUBlock<PDU> *block);
62 
63  static void PrependPDU(ola::io::IOStack *stack, uint32_t vector,
64  const CID &cid);
65 
66  private:
67  CID m_cid;
68  const PDUBlock<PDU> *m_block;
69  unsigned int m_block_size;
70 };
71 } // namespace e131
72 } // namespace plugin
73 } // namespace ola
74 #endif // PLUGINS_E131_E131_ROOTPDU_H_