21 #ifndef PLUGINS_E131_E131_DMPPDU_H_
22 #define PLUGINS_E131_E131_DMPPDU_H_
28 #include "plugins/e131/e131/DMPAddress.h"
29 #include "plugins/e131/e131/DMPHeader.h"
30 #include "plugins/e131/e131/PDU.h"
43 PDU(vector, ONE_BYTE),
44 m_header(dmp_header) {
48 unsigned int HeaderSize()
const {
return DMPHeader::DMP_HEADER_SIZE; }
49 bool PackHeader(uint8_t *data,
unsigned int *length)
const;
62 template <
typename Address>
66 const std::vector<Address> &addresses):
68 m_addresses(addresses) {}
70 unsigned int DataSize()
const {
71 return static_cast<unsigned int>(m_addresses.size() * m_header.Bytes() *
72 (m_header.Type() == NON_RANGE ? 1 : 3));
75 bool PackData(uint8_t *data,
unsigned int *length)
const {
76 typename std::vector<Address>::const_iterator iter;
77 unsigned int offset = 0;
78 for (iter = m_addresses.begin(); iter != m_addresses.end(); ++iter) {
79 unsigned int remaining = *length - offset;
80 if (!iter->Pack(data + offset, &remaining))
89 typename std::vector<Address>::const_iterator iter;
90 for (iter = m_addresses.begin(); iter != m_addresses.end(); ++iter)
95 std::vector<Address> m_addresses;
106 template <
typename type>
107 const DMPPDU *NewDMPGetProperty(
114 TypeToDMPSize<type>());
123 template <
typename type>
124 const DMPPDU *_CreateDMPGetProperty(
bool is_virtual,
126 unsigned int start) {
127 DMPAddress<type> address((type) start);
128 std::vector<DMPAddress<type> > addresses;
129 addresses.push_back(address);
130 return NewDMPGetProperty<type>(is_virtual, is_relative, addresses);
141 const DMPPDU *NewDMPGetProperty(
bool is_virtual,
154 template <
typename type>
155 const DMPPDU *NewRangeDMPGetProperty(
158 const std::vector<RangeDMPAddress<type> > &addresses) {
159 DMPHeader header(is_virtual,
162 TypeToDMPSize<type>());
163 return new DMPGetProperty<RangeDMPAddress<type> >(header, addresses);
167 template <
typename type>
168 const DMPPDU *_CreateRangeDMPGetProperty(
bool is_virtual,
171 unsigned int increment,
172 unsigned int number) {
173 std::vector<RangeDMPAddress<type> > addresses;
174 RangeDMPAddress<type> address((type) start, (type) increment, (type) number);
175 addresses.push_back(address);
176 return NewRangeDMPGetProperty<type>(is_virtual, is_relative, addresses);
189 const DMPPDU *NewRangeDMPGetProperty(
193 unsigned int increment,
194 unsigned int number);
203 template <
typename type>
206 typedef std::vector<DMPAddressData<type> > AddressDataChunks;
212 unsigned int DataSize()
const {
213 typename AddressDataChunks::const_iterator iter;
214 unsigned int length = 0;
215 for (iter = m_chunks.begin(); iter != m_chunks.end(); ++iter)
216 length += iter->Size();
220 bool PackData(uint8_t *data,
unsigned int *length)
const {
221 typename AddressDataChunks::const_iterator iter;
222 unsigned int offset = 0;
223 for (iter = m_chunks.begin(); iter != m_chunks.end(); ++iter) {
224 unsigned int remaining = *length - offset;
225 if (!iter->Pack(data + offset, &remaining))
234 typename AddressDataChunks::const_iterator iter;
235 for (iter = m_chunks.begin(); iter != m_chunks.end(); ++iter)
240 AddressDataChunks m_chunks;
247 template <
typename type>
248 const DMPPDU *NewDMPSetProperty(
256 TypeToDMPSize<type>());
268 template <
typename type>
269 const DMPPDU *NewRangeDMPSetProperty(
272 const std::vector<DMPAddressData<RangeDMPAddress<type> > > &chunks,
273 bool multiple_elements =
true,
274 bool equal_size_elements =
true) {
276 dmp_address_type address_type;
277 if (multiple_elements) {
278 if (equal_size_elements)
279 address_type = RANGE_EQUAL;
281 address_type = RANGE_MIXED;
283 address_type = RANGE_SINGLE;
286 DMPHeader header(is_virtual,
289 TypeToDMPSize<type>());
290 return new DMPSetProperty<RangeDMPAddress<type> >(header, chunks);
295 #endif // PLUGINS_E131_E131_DMPPDU_H_