Open Lighting Architecture  0.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
46  /*
47  * Return the id for this inflator
48  */
49  virtual uint32_t Id() const = 0;
50 
51  /*
52  * Parse a block of PDU data
53  */
54  virtual unsigned int InflatePDUBlock(HeaderSet *headers,
55  const uint8_t *data,
56  unsigned int len) = 0;
57 };
58 
59 
60 /*
61  * An abstract PDU inflator
62  */
64  friend class BaseInflatorTest;
65 
66  public:
67  explicit BaseInflator(PDU::vector_size v_size = PDU::FOUR_BYTES);
68  virtual ~BaseInflator() {}
69 
70  /*
71  * Add another inflator as a handler. Ownership is not transferred.
72  */
73  bool AddInflator(InflatorInterface *inflator);
74 
75  /*
76  * Return the inflator used for a particular vector.
77  */
78  class InflatorInterface *GetInflator(uint32_t vector) const;
79 
80  /*
81  * Parse a block of PDU data
82  */
83  virtual unsigned int InflatePDUBlock(HeaderSet *headers,
84  const uint8_t *data,
85  unsigned int len);
86 
87  // masks for the flag fields
88  // This indicates a 20 bit length field (default is 12 bits)
89  static const uint8_t LFLAG_MASK = 0x80;
90  // This masks the first 4 bits of the length field
91  static const uint8_t LENGTH_MASK = 0x0F;
92 
93  protected:
94  uint32_t m_last_vector;
95  bool m_vector_set;
96  PDU::vector_size m_vector_size; // size of the vector field
97  // map protos to inflators
98  std::map<uint32_t, InflatorInterface*> m_proto_map;
99 
100  // Reset repeated pdu fields
101  virtual void ResetPDUFields();
102  virtual void ResetHeaderField() = 0;
103 
104  // determine the length of a pdu
105  bool DecodeLength(const uint8_t *data,
106  unsigned int data_length,
107  unsigned int *pdu_length,
108  unsigned int *bytes_used) const;
109 
110  // determine the vector of a pdu
111  bool DecodeVector(uint8_t flags,
112  const uint8_t *data,
113  unsigned int length,
114  uint32_t *vector,
115  unsigned int *bytes_used);
116 
117  // Decode a header block and adds any PduHeaders to the HeaderSet object
118  virtual bool DecodeHeader(HeaderSet *headers,
119  const uint8_t *data,
120  unsigned int len,
121  unsigned int *bytes_used) = 0;
122 
123  // parse the body of a pdu
124  bool InflatePDU(HeaderSet *headers,
125  uint8_t flags,
126  const uint8_t *data,
127  unsigned int pdu_len);
128 
129  // called after the header is parsed
130  virtual bool PostHeader(uint32_t vector, const HeaderSet &headers);
131 
132  // called in the absence of an inflator to handle the pdu data
133  virtual bool HandlePDUData(uint32_t vector,
134  const HeaderSet &headers,
135  const uint8_t *data,
136  unsigned int pdu_len);
137 };
138 } // namespace acn
139 } // namespace ola
140 #endif // LIBS_ACN_BASEINFLATOR_H_
Definition: HeaderSet.h:35
Definition: BaseInflator.h:42
Definition: BaseInflator.h:63
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44