Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * fuse_lutlist_content.cpp - FUSE LUT list content encapsulation 00004 * 00005 * Created: Wed Nov 21 16:33:56 2007 00006 * Copyright 2005-2007 Tim Niemueller [www.niemueller.de] 00007 * 00008 ****************************************************************************/ 00009 00010 /* This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. A runtime exception applies to 00014 * this software (see LICENSE.GPL_WRE file mentioned below for details). 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Library General Public License for more details. 00020 * 00021 * Read the full text in the LICENSE.GPL_WRE file in the doc directory. 00022 */ 00023 00024 #include <fvutils/net/fuse_lutlist_content.h> 00025 #include <netcomm/utils/dynamic_buffer.h> 00026 00027 #include <core/exceptions/software.h> 00028 00029 #include <cstdlib> 00030 #include <cstring> 00031 #include <netinet/in.h> 00032 00033 using namespace fawkes; 00034 00035 namespace firevision { 00036 #if 0 /* just to make Emacs auto-indent happy */ 00037 } 00038 #endif 00039 00040 /** @class FuseLutListContent <fvutils/net/fuse_lutlist_content.h> 00041 * FUSE lookup table list content. 00042 * This content provides means to send an arbitrary length list of LUT 00043 * information chunks. 00044 * @author Tim Niemueller 00045 * @ingroup FUSE 00046 * @ingroup FireVision 00047 */ 00048 00049 /** Constructor. 00050 * Creates an empty list. 00051 */ 00052 FuseLutListContent::FuseLutListContent() 00053 { 00054 __list = new DynamicBuffer(&(__lutlist_msg.lut_list)); 00055 00056 _payload_size = 0; 00057 _payload = NULL; 00058 } 00059 00060 00061 /** Parsing constructor. 00062 * Can be used with the FuseContent::fmsg() method to get correctly parsed output. 00063 * @param type message type, must be FUSE_MT_LUT_LIST 00064 * @param payload payload 00065 * @param payload_size size of payload 00066 * @exception TypeMismatchException thrown if the type is not FUSE_MT_LUT_LIST 00067 */ 00068 FuseLutListContent::FuseLutListContent(uint32_t type, void *payload, size_t payload_size) 00069 { 00070 FUSE_lutlist_message_t *tmsg = (FUSE_lutlist_message_t *)payload; 00071 void *list_payload = (void *)((size_t)payload + sizeof(FUSE_lutlist_message_t)); 00072 __list = new DynamicBuffer(&(tmsg->lut_list), list_payload, 00073 payload_size - sizeof(FUSE_lutlist_message_t)); 00074 } 00075 00076 00077 /** Destructor. */ 00078 FuseLutListContent::~FuseLutListContent() 00079 { 00080 delete __list; 00081 } 00082 00083 00084 /** Add LUT info. 00085 * @param lut_id LUT ID 00086 * @param width width of LUT 00087 * @param height height of LUT 00088 * @param depth depth of LUT 00089 * @param bytes_per_cell bytes per cell 00090 */ 00091 void 00092 FuseLutListContent::add_lutinfo(const char *lut_id, 00093 unsigned int width, unsigned int height, 00094 unsigned int depth, unsigned int bytes_per_cell) 00095 { 00096 FUSE_lutinfo_t lutinfo; 00097 memset(&lutinfo, 0, sizeof(lutinfo)); 00098 00099 strncpy(lutinfo.lut_id, lut_id, LUT_ID_MAX_LENGTH); 00100 lutinfo.width = ntohl(width); 00101 lutinfo.height = ntohl(height); 00102 lutinfo.depth = ntohl(depth); 00103 lutinfo.bytes_per_cell = ntohl(bytes_per_cell); 00104 00105 __list->append(&lutinfo, sizeof(lutinfo)); 00106 } 00107 00108 00109 /** Reset iterator. */ 00110 void 00111 FuseLutListContent::reset_iterator() 00112 { 00113 __list->reset_iterator(); 00114 } 00115 00116 00117 /** Check if another LUT info is available. 00118 * @return true if another LUT info is available, false otherwise 00119 */ 00120 bool 00121 FuseLutListContent::has_next() 00122 { 00123 return __list->has_next(); 00124 } 00125 00126 00127 /** Get next LUT info. 00128 * @return next LUT info 00129 * @exception TypeMismatchException thrown if the content contained invalid data 00130 * @exception OutOfBoundsException thrown if no more data is available 00131 */ 00132 FUSE_lutinfo_t * 00133 FuseLutListContent::next() 00134 { 00135 size_t size; 00136 void *tmp = __list->next(&size); 00137 if ( size != sizeof(FUSE_lutinfo_t) ) { 00138 throw TypeMismatchException("Lut list content contains element that is of an " 00139 "unexpected size"); 00140 } 00141 00142 return (FUSE_lutinfo_t *)tmp; 00143 } 00144 00145 00146 void 00147 FuseLutListContent::serialize() 00148 { 00149 _payload_size = sizeof(FUSE_lutlist_message_t) + __list->buffer_size(); 00150 _payload = malloc(_payload_size); 00151 00152 copy_payload(0, &__lutlist_msg, sizeof(FUSE_lutlist_message_t)); 00153 copy_payload(sizeof(FUSE_lutlist_message_t), __list->buffer(), __list->buffer_size()); 00154 } 00155 00156 } // end namespace firevision