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 <fvutils/net/fuse_lutlist_content.h>
25 #include <netcomm/utils/dynamic_buffer.h>
26 
27 #include <core/exceptions/software.h>
28 
29 #include <cstdlib>
30 #include <cstring>
31 #include <netinet/in.h>
32 
33 using namespace fawkes;
34 
35 namespace firevision {
36 #if 0 /* just to make Emacs auto-indent happy */
37 }
38 #endif
39 
40 /** @class FuseLutListContent <fvutils/net/fuse_lutlist_content.h>
41  * FUSE lookup table list content.
42  * This content provides means to send an arbitrary length list of LUT
43  * information chunks.
44  * @author Tim Niemueller
45  * @ingroup FUSE
46  * @ingroup FireVision
47  */
48 
49 /** Constructor.
50  * Creates an empty list.
51  */
52 FuseLutListContent::FuseLutListContent()
53 {
54  __list = new DynamicBuffer(&(__lutlist_msg.lut_list));
55 
56  _payload_size = 0;
57  _payload = NULL;
58 }
59 
60 
61 /** Parsing constructor.
62  * Can be used with the FuseContent::fmsg() method to get correctly parsed output.
63  * @param type message type, must be FUSE_MT_LUT_LIST
64  * @param payload payload
65  * @param payload_size size of payload
66  * @exception TypeMismatchException thrown if the type is not FUSE_MT_LUT_LIST
67  */
68 FuseLutListContent::FuseLutListContent(uint32_t type, void *payload, size_t payload_size)
69 {
71  void *list_payload = (void *)((size_t)payload + sizeof(FUSE_lutlist_message_t));
72  __list = new DynamicBuffer(&(tmsg->lut_list), list_payload,
73  payload_size - sizeof(FUSE_lutlist_message_t));
74 }
75 
76 
77 /** Destructor. */
78 FuseLutListContent::~FuseLutListContent()
79 {
80  delete __list;
81 }
82 
83 
84 /** Add LUT info.
85  * @param lut_id LUT ID
86  * @param width width of LUT
87  * @param height height of LUT
88  * @param depth depth of LUT
89  * @param bytes_per_cell bytes per cell
90  */
91 void
92 FuseLutListContent::add_lutinfo(const char *lut_id,
93  unsigned int width, unsigned int height,
94  unsigned int depth, unsigned int bytes_per_cell)
95 {
96  FUSE_lutinfo_t lutinfo;
97  memset(&lutinfo, 0, sizeof(lutinfo));
98 
99  strncpy(lutinfo.lut_id, lut_id, LUT_ID_MAX_LENGTH);
100  lutinfo.width = ntohl(width);
101  lutinfo.height = ntohl(height);
102  lutinfo.depth = ntohl(depth);
103  lutinfo.bytes_per_cell = ntohl(bytes_per_cell);
104 
105  __list->append(&lutinfo, sizeof(lutinfo));
106 }
107 
108 
109 /** Reset iterator. */
110 void
111 FuseLutListContent::reset_iterator()
112 {
113  __list->reset_iterator();
114 }
115 
116 
117 /** Check if another LUT info is available.
118  * @return true if another LUT info is available, false otherwise
119  */
120 bool
121 FuseLutListContent::has_next()
122 {
123  return __list->has_next();
124 }
125 
126 
127 /** Get next LUT info.
128  * @return next LUT info
129  * @exception TypeMismatchException thrown if the content contained invalid data
130  * @exception OutOfBoundsException thrown if no more data is available
131  */
133 FuseLutListContent::next()
134 {
135  size_t size;
136  void *tmp = __list->next(&size);
137  if ( size != sizeof(FUSE_lutinfo_t) ) {
138  throw TypeMismatchException("Lut list content contains element that is of an "
139  "unexpected size");
140  }
141 
142  return (FUSE_lutinfo_t *)tmp;
143 }
144 
145 
146 void
147 FuseLutListContent::serialize()
148 {
149  _payload_size = sizeof(FUSE_lutlist_message_t) + __list->buffer_size();
150  _payload = malloc(_payload_size);
151 
152  copy_payload(0, &__lutlist_msg, sizeof(FUSE_lutlist_message_t));
153  copy_payload(sizeof(FUSE_lutlist_message_t), __list->buffer(), __list->buffer_size());
154 }
155 
156 } // end namespace firevision
uint32_t bytes_per_cell
bytes per cell
Definition: fuse.h:180
Fawkes library namespace.
LUT list message.
Definition: fuse.h:189
uint32_t height
height of LUT
Definition: fuse.h:178
uint32_t width
width of LUT
Definition: fuse.h:177
fawkes::dynamic_list_t lut_list
DynamicBuffer holding a list of FUSE_lutinfo_t.
Definition: fuse.h:190
LUT info message.
Definition: fuse.h:175
char lut_id[LUT_ID_MAX_LENGTH]
LUT ID.
Definition: fuse.h:176
Dynamically growing buffer.
uint32_t depth
depth of LUT
Definition: fuse.h:179