fuse_imagelist_content.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <fvutils/net/fuse_imagelist_content.h>
00025 #include <netcomm/utils/dynamic_buffer.h>
00026 #include <core/exceptions/software.h>
00027
00028 #include <cstdlib>
00029 #include <cstring>
00030 #include <netinet/in.h>
00031
00032 using namespace fawkes;
00033
00034 namespace firevision {
00035 #if 0
00036 }
00037 #endif
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 FuseImageListContent::FuseImageListContent()
00052 {
00053 __list = new DynamicBuffer(&(__imagelist_msg.image_list));
00054
00055 _payload_size = 0;
00056 _payload = NULL;
00057 }
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 FuseImageListContent::FuseImageListContent(uint32_t type, void *payload, size_t payload_size)
00068 {
00069 if ( type != FUSE_MT_IMAGE_LIST ) {
00070 throw TypeMismatchException("Type %u not equal to expected type FUSE_MT_IMAGE_LIST (%u)",
00071 type, FUSE_MT_IMAGE_LIST);
00072 }
00073 FUSE_imagelist_message_t *tmsg = (FUSE_imagelist_message_t *)payload;
00074 void *list_payload = (void *)((size_t)payload + sizeof(FUSE_imagelist_message_t));
00075 __list = new DynamicBuffer(&(tmsg->image_list), list_payload,
00076 payload_size - sizeof(FUSE_imagelist_message_t));
00077 }
00078
00079
00080
00081 FuseImageListContent::~FuseImageListContent()
00082 {
00083 delete __list;
00084 }
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 void
00096 FuseImageListContent::add_imageinfo(const char *image_id, colorspace_t colorspace,
00097 unsigned int pixel_width, unsigned int pixel_height)
00098 {
00099 FUSE_imageinfo_t imageinfo;
00100 memset(&imageinfo, 0, sizeof(imageinfo));
00101
00102 strncpy(imageinfo.image_id, image_id, IMAGE_ID_MAX_LENGTH);
00103 imageinfo.colorspace = htons(colorspace);
00104 imageinfo.width = htonl(pixel_width);
00105 imageinfo.height = htonl(pixel_height);
00106 imageinfo.buffer_size = htonl(colorspace_buffer_size(colorspace, pixel_width, pixel_height));
00107
00108 __list->append(&imageinfo, sizeof(imageinfo));
00109 }
00110
00111
00112
00113 void
00114 FuseImageListContent::reset_iterator()
00115 {
00116 __list->reset_iterator();
00117 }
00118
00119
00120
00121
00122
00123 bool
00124 FuseImageListContent::has_next()
00125 {
00126 return __list->has_next();
00127 }
00128
00129
00130
00131
00132
00133
00134
00135 FUSE_imageinfo_t *
00136 FuseImageListContent::next()
00137 {
00138 size_t size;
00139 void *tmp = __list->next(&size);
00140 if ( size != sizeof(FUSE_imageinfo_t) ) {
00141 throw TypeMismatchException("Image list content contains element that is of an "
00142 "unexpected size");
00143 }
00144
00145 return (FUSE_imageinfo_t *)tmp;
00146 }
00147
00148
00149 void
00150 FuseImageListContent::serialize()
00151 {
00152 _payload_size = sizeof(FUSE_imagelist_message_t) + __list->buffer_size();
00153 _payload = malloc(_payload_size);
00154
00155 copy_payload(0, &__imagelist_msg, sizeof(FUSE_imagelist_message_t));
00156 copy_payload(sizeof(FUSE_imagelist_message_t), __list->buffer(), __list->buffer_size());
00157 }
00158
00159 }