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"
45 PDU(vector, ONE_BYTE),
46 m_header(dmp_header) {
50 unsigned int HeaderSize()
const {
return DMPHeader::DMP_HEADER_SIZE; }
51 bool PackHeader(uint8_t *data,
unsigned int *length)
const;
64 template <
typename Address>
68 const vector<Address> &addresses):
70 m_addresses(addresses) {}
72 unsigned int DataSize()
const {
73 return static_cast<unsigned int>(m_addresses.size() * m_header.Bytes() *
74 (m_header.Type() == NON_RANGE ? 1 : 3));
77 bool PackData(uint8_t *data,
unsigned int *length)
const {
78 typename vector<Address>::const_iterator iter;
79 unsigned int offset = 0;
80 for (iter = m_addresses.begin(); iter != m_addresses.end(); ++iter) {
81 unsigned int remaining = *length - offset;
82 if (!iter->Pack(data + offset, &remaining))
91 typename vector<Address>::const_iterator iter;
92 for (iter = m_addresses.begin(); iter != m_addresses.end(); ++iter)
97 vector<Address> m_addresses;
108 template <
typename type>
109 const DMPPDU *NewDMPGetProperty(
116 TypeToDMPSize<type>());
125 template <
typename type>
126 const DMPPDU *_CreateDMPGetProperty(
bool is_virtual,
128 unsigned int start) {
129 DMPAddress<type> address((type) start);
130 vector<DMPAddress<type> > addresses;
131 addresses.push_back(address);
132 return NewDMPGetProperty<type>(is_virtual, is_relative, addresses);
143 const DMPPDU *NewDMPGetProperty(
bool is_virtual,
156 template <
typename type>
157 const DMPPDU *NewRangeDMPGetProperty(
160 const vector<RangeDMPAddress<type> > &addresses) {
161 DMPHeader header(is_virtual,
164 TypeToDMPSize<type>());
165 return new DMPGetProperty<RangeDMPAddress<type> >(header, addresses);
169 template <
typename type>
170 const DMPPDU *_CreateRangeDMPGetProperty(
bool is_virtual,
173 unsigned int increment,
174 unsigned int number) {
175 vector<RangeDMPAddress<type> > addresses;
176 RangeDMPAddress<type> address((type) start, (type) increment, (type) number);
177 addresses.push_back(address);
178 return NewRangeDMPGetProperty<type>(is_virtual, is_relative, addresses);
191 const DMPPDU *NewRangeDMPGetProperty(
195 unsigned int increment,
196 unsigned int number);
205 template <
typename type>
208 typedef vector<DMPAddressData<type> > AddressDataChunks;
214 unsigned int DataSize()
const {
215 typename AddressDataChunks::const_iterator iter;
216 unsigned int length = 0;
217 for (iter = m_chunks.begin(); iter != m_chunks.end(); ++iter)
218 length += iter->Size();
222 bool PackData(uint8_t *data,
unsigned int *length)
const {
223 typename AddressDataChunks::const_iterator iter;
224 unsigned int offset = 0;
225 for (iter = m_chunks.begin(); iter != m_chunks.end(); ++iter) {
226 unsigned int remaining = *length - offset;
227 if (!iter->Pack(data + offset, &remaining))
236 typename AddressDataChunks::const_iterator iter;
237 for (iter = m_chunks.begin(); iter != m_chunks.end(); ++iter)
242 AddressDataChunks m_chunks;
249 template <
typename type>
250 const DMPPDU *NewDMPSetProperty(
258 TypeToDMPSize<type>());
270 template <
typename type>
271 const DMPPDU *NewRangeDMPSetProperty(
274 const vector<DMPAddressData<RangeDMPAddress<type> > > &chunks,
275 bool multiple_elements =
true,
276 bool equal_size_elements =
true) {
278 dmp_address_type address_type;
279 if (multiple_elements) {
280 if (equal_size_elements)
281 address_type = RANGE_EQUAL;
283 address_type = RANGE_MIXED;
285 address_type = RANGE_SINGLE;
288 DMPHeader header(is_virtual,
291 TypeToDMPSize<type>());
292 return new DMPSetProperty<RangeDMPAddress<type> >(header, chunks);
297 #endif // PLUGINS_E131_E131_DMPPDU_H_