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 
32 using namespace fawkes;
33 
34 namespace 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  */
48 FuseLutListContent::FuseLutListContent()
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  */
63 FuseLutListContent::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,
69  payload_size - sizeof(FUSE_lutlist_message_t));
70 }
71 
72 /** Destructor. */
73 FuseLutListContent::~FuseLutListContent()
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  */
85 void
86 FuseLutListContent::add_lutinfo(const char * lut_id,
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. */
105 void
106 FuseLutListContent::reset_iterator()
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  */
114 bool
115 FuseLutListContent::has_next()
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  */
126 FuseLutListContent::next()
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 
138 void
139 FuseLutListContent::serialize()
140 {
141  _payload_size = sizeof(FUSE_lutlist_message_t) + list_->buffer_size();
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
firevision::FUSE_lutinfo_t::width
uint32_t width
width of LUT
Definition: fuse.h:187
firevision::FUSE_lutlist_message_t
LUT list message.
Definition: fuse.h:200
firevision::FUSE_lutinfo_t
LUT info message.
Definition: fuse.h:184
fawkes::DynamicBuffer
Definition: dynamic_buffer.h:55
fawkes::TypeMismatchException
Definition: software.h:49
firevision::FUSE_lutlist_message_t::lut_list
fawkes::dynamic_list_t lut_list
DynamicBuffer holding a list of FUSE_lutinfo_t.
Definition: fuse.h:202
firevision::FUSE_lutinfo_t::depth
uint32_t depth
depth of LUT
Definition: fuse.h:189
fawkes
firevision::FUSE_lutinfo_t::bytes_per_cell
uint32_t bytes_per_cell
bytes per cell
Definition: fuse.h:190
firevision::FUSE_lutinfo_t::height
uint32_t height
height of LUT
Definition: fuse.h:188
firevision::FUSE_lutinfo_t::lut_id
char lut_id[LUT_ID_MAX_LENGTH]
LUT ID.
Definition: fuse.h:186