Fawkes API Fawkes Development Version
fuse_lutlist_content.cpp
1
2/***************************************************************************
3 * fuse_lutlist_content.cpp - FUSE LUT list content encapsulation
4 *
5 * Created: Wed Nov 21 16:33:56 2007
6 * Copyright 2005-2007 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version. A runtime exception applies to
14 * this software (see LICENSE.GPL_WRE file mentioned below for details).
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Library General Public License for more details.
20 *
21 * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22 */
23
24#include <core/exceptions/software.h>
25#include <fvutils/net/fuse_lutlist_content.h>
26#include <netcomm/utils/dynamic_buffer.h>
27#include <netinet/in.h>
28
29#include <cstdlib>
30#include <cstring>
31
32using namespace fawkes;
33
34namespace firevision {
35
36/** @class FuseLutListContent <fvutils/net/fuse_lutlist_content.h>
37 * FUSE lookup table list content.
38 * This content provides means to send an arbitrary length list of LUT
39 * information chunks.
40 * @author Tim Niemueller
41 * @ingroup FUSE
42 * @ingroup FireVision
43 */
44
45/** Constructor.
46 * Creates an empty list.
47 */
49{
50 list_ = new DynamicBuffer(&(lutlist_msg_.lut_list));
51
52 _payload_size = 0;
53 _payload = NULL;
54}
55
56/** Parsing constructor.
57 * Can be used with the FuseContent::fmsg() method to get correctly parsed output.
58 * @param type message type, must be FUSE_MT_LUT_LIST
59 * @param payload payload
60 * @param payload_size size of payload
61 * @exception TypeMismatchException thrown if the type is not FUSE_MT_LUT_LIST
62 */
63FuseLutListContent::FuseLutListContent(uint32_t type, void *payload, size_t payload_size)
64{
66 void * list_payload = (void *)((size_t)payload + sizeof(FUSE_lutlist_message_t));
67 list_ = new DynamicBuffer(&(tmsg->lut_list),
68 list_payload,
70}
71
72/** Destructor. */
74{
75 delete list_;
76}
77
78/** Add LUT info.
79 * @param lut_id LUT ID
80 * @param width width of LUT
81 * @param height height of LUT
82 * @param depth depth of LUT
83 * @param bytes_per_cell bytes per cell
84 */
85void
87 unsigned int width,
88 unsigned int height,
89 unsigned int depth,
90 unsigned int bytes_per_cell)
91{
92 FUSE_lutinfo_t lutinfo;
93 memset(&lutinfo, 0, sizeof(lutinfo));
94
95 strncpy(lutinfo.lut_id, lut_id, LUT_ID_MAX_LENGTH - 1);
96 lutinfo.width = ntohl(width);
97 lutinfo.height = ntohl(height);
98 lutinfo.depth = ntohl(depth);
99 lutinfo.bytes_per_cell = ntohl(bytes_per_cell);
100
101 list_->append(&lutinfo, sizeof(lutinfo));
102}
103
104/** Reset iterator. */
105void
107{
108 list_->reset_iterator();
109}
110
111/** Check if another LUT info is available.
112 * @return true if another LUT info is available, false otherwise
113 */
114bool
116{
117 return list_->has_next();
118}
119
120/** Get next LUT info.
121 * @return next LUT info
122 * @exception TypeMismatchException thrown if the content contained invalid data
123 * @exception OutOfBoundsException thrown if no more data is available
124 */
127{
128 size_t size;
129 void * tmp = list_->next(&size);
130 if (size != sizeof(FUSE_lutinfo_t)) {
131 throw TypeMismatchException("Lut list content contains element that is of an "
132 "unexpected size");
133 }
134
135 return (FUSE_lutinfo_t *)tmp;
136}
137
138void
140{
142 _payload = malloc(_payload_size);
143
144 copy_payload(0, &lutlist_msg_, sizeof(FUSE_lutlist_message_t));
145 copy_payload(sizeof(FUSE_lutlist_message_t), list_->buffer(), list_->buffer_size());
146}
147
148} // end namespace firevision
Dynamically growing buffer.
size_t buffer_size()
Get buffer size.
void append(const void *data, size_t data_size)
Append data.
void reset_iterator()
Reset iterator.
bool has_next()
Check if another element is available.
void * next(size_t *size)
Get next buffer.
void * buffer()
Get pointer to buffer.
bool has_next()
Check if another LUT info is available.
void add_lutinfo(const char *lut_id, unsigned int width, unsigned int height, unsigned int depth, unsigned int bytes_per_cell)
Add LUT info.
FUSE_lutinfo_t * next()
Get next LUT info.
virtual void serialize()
Serialize message content.
void copy_payload(size_t offset, void *buf, size_t len)
Copy payload into payload buffer to a specified offset.
virtual void * payload() const
Return pointer to payload.
virtual size_t payload_size() const
Return payload size.
void * _payload
Pointer to payload.
Fawkes library namespace.
LUT info message.
Definition: fuse.h:179
uint32_t height
height of LUT
Definition: fuse.h:182
uint32_t bytes_per_cell
bytes per cell
Definition: fuse.h:184
uint32_t width
width of LUT
Definition: fuse.h:181
uint32_t depth
depth of LUT
Definition: fuse.h:183
char lut_id[LUT_ID_MAX_LENGTH]
LUT ID.
Definition: fuse.h:180
fawkes::dynamic_list_t lut_list
DynamicBuffer holding a list of FUSE_lutinfo_t.
Definition: fuse.h:196