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
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 FuseImageListContent::FuseImageListContent()
00047 {
00048 __list = new DynamicBuffer(&(__imagelist_msg.image_list));
00049
00050 _payload_size = 0;
00051 _payload = NULL;
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062 FuseImageListContent::FuseImageListContent(uint32_t type, void *payload, size_t payload_size)
00063 {
00064 if ( type != FUSE_MT_IMAGE_LIST ) {
00065 throw TypeMismatchException("Type %u not equal to expected type FUSE_MT_IMAGE_LIST (%u)",
00066 type, FUSE_MT_IMAGE_LIST);
00067 }
00068 FUSE_imagelist_message_t *tmsg = (FUSE_imagelist_message_t *)payload;
00069 void *list_payload = (void *)((size_t)payload + sizeof(FUSE_imagelist_message_t));
00070 __list = new DynamicBuffer(&(tmsg->image_list), list_payload,
00071 payload_size - sizeof(FUSE_imagelist_message_t));
00072 }
00073
00074
00075
00076 FuseImageListContent::~FuseImageListContent()
00077 {
00078 delete __list;
00079 }
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 void
00091 FuseImageListContent::add_imageinfo(const char *image_id, colorspace_t colorspace,
00092 unsigned int pixel_width, unsigned int pixel_height)
00093 {
00094 FUSE_imageinfo_t imageinfo;
00095 memset(&imageinfo, 0, sizeof(imageinfo));
00096
00097 strncpy(imageinfo.image_id, image_id, IMAGE_ID_MAX_LENGTH);
00098 imageinfo.colorspace = htons(colorspace);
00099 imageinfo.width = htonl(pixel_width);
00100 imageinfo.height = htonl(pixel_height);
00101 imageinfo.buffer_size = htonl(colorspace_buffer_size(colorspace, pixel_width, pixel_height));
00102
00103 __list->append(&imageinfo, sizeof(imageinfo));
00104 }
00105
00106
00107
00108 void
00109 FuseImageListContent::reset_iterator()
00110 {
00111 __list->reset_iterator();
00112 }
00113
00114
00115
00116
00117
00118 bool
00119 FuseImageListContent::has_next()
00120 {
00121 return __list->has_next();
00122 }
00123
00124
00125
00126
00127
00128
00129
00130 FUSE_imageinfo_t *
00131 FuseImageListContent::next()
00132 {
00133 size_t size;
00134 void *tmp = __list->next(&size);
00135 if ( size != sizeof(FUSE_imageinfo_t) ) {
00136 throw TypeMismatchException("Image list content contains element that is of an "
00137 "unexpected size");
00138 }
00139
00140 return (FUSE_imageinfo_t *)tmp;
00141 }
00142
00143
00144 void
00145 FuseImageListContent::serialize()
00146 {
00147 _payload_size = sizeof(FUSE_imagelist_message_t) + __list->buffer_size();
00148 _payload = malloc(_payload_size);
00149
00150 copy_payload(0, &__imagelist_msg, sizeof(FUSE_imagelist_message_t));
00151 copy_payload(sizeof(FUSE_imagelist_message_t), __list->buffer(), __list->buffer_size());
00152 }