Open Lighting Architecture  Latest Git
BaseInflator.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  * BaseInflator.h
17  * Provides the base class for inflating PDU blocks.
18  * Copyright (C) 2007 Simon Newton
19  *
20  * The BaseInflator takes care of most of the heavy lifting when inflating PDU
21  * blocks. To create a specific Inflator, subclass BaseInflator and implement
22  * the Id() and DecodeHeader() methods.
23  */
24 
25 #ifndef LIBS_ACN_BASEINFLATOR_H_
26 #define LIBS_ACN_BASEINFLATOR_H_
27 
28 #include <stdint.h>
29 #include <map>
30 #include "libs/acn/HeaderSet.h"
31 #include "libs/acn/PDU.h"
32 
33 namespace ola {
34 namespace acn {
35 
36 class BaseInflatorTest;
37 
38 
43  public:
44  virtual ~InflatorInterface() {}
45 
50  virtual uint32_t Id() const = 0;
51 
55  virtual unsigned int InflatePDUBlock(HeaderSet *headers,
56  const uint8_t *data,
57  unsigned int len) = 0;
58 };
59 
60 
65  friend class BaseInflatorTest;
66 
67  public:
68  explicit BaseInflator(PDU::vector_size v_size = PDU::FOUR_BYTES);
69  virtual ~BaseInflator() {}
70 
74  bool AddInflator(InflatorInterface *inflator);
75 
80  class InflatorInterface *GetInflator(uint32_t vector) const;
81 
85  virtual unsigned int InflatePDUBlock(HeaderSet *headers,
86  const uint8_t *data,
87  unsigned int len);
88 
89  // masks for the flag fields
90  // This indicates a 20 bit length field (default is 12 bits)
91  static const uint8_t LFLAG_MASK = 0x80;
92  // This masks the first 4 bits of the length field
93  static const uint8_t LENGTH_MASK = 0x0F;
94 
95  protected:
96  uint32_t m_last_vector;
97  bool m_vector_set;
98  PDU::vector_size m_vector_size; // size of the vector field
99  // map protos to inflators
100  std::map<uint32_t, InflatorInterface*> m_proto_map;
101 
102  // Reset repeated pdu fields
103  virtual void ResetPDUFields();
104  virtual void ResetHeaderField() = 0;
105 
106  // determine the length of a pdu
107  bool DecodeLength(const uint8_t *data,
108  unsigned int data_length,
109  unsigned int *pdu_length,
110  unsigned int *bytes_used) const;
111 
112  // determine the vector of a pdu
113  bool DecodeVector(uint8_t flags,
114  const uint8_t *data,
115  unsigned int length,
116  uint32_t *vector,
117  unsigned int *bytes_used);
118 
119  // Decode a header block and adds any PduHeaders to the HeaderSet object
120  virtual bool DecodeHeader(HeaderSet *headers,
121  const uint8_t *data,
122  unsigned int len,
123  unsigned int *bytes_used) = 0;
124 
125  // parse the body of a pdu
126  bool InflatePDU(HeaderSet *headers,
127  uint8_t flags,
128  const uint8_t *data,
129  unsigned int pdu_len);
130 
131  // called after the header is parsed
132  virtual bool PostHeader(uint32_t vector, const HeaderSet &headers);
133 
134  // called in the absence of an inflator to handle the pdu data
135  virtual bool HandlePDUData(uint32_t vector,
136  const HeaderSet &headers,
137  const uint8_t *data,
138  unsigned int pdu_len);
139 };
140 } // namespace acn
141 } // namespace ola
142 #endif // LIBS_ACN_BASEINFLATOR_H_
Definition: HeaderSet.h:35
The inflator interface.
Definition: BaseInflator.h:42
An abstract PDU inflator.
Definition: BaseInflator.h:64
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
virtual unsigned int InflatePDUBlock(HeaderSet *headers, const uint8_t *data, unsigned int len)=0
Parse a block of PDU data.
virtual uint32_t Id() const =0