fuse_lut_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_lut_content.h>
00025 #include <fvutils/ipc/shm_lut.h>
00026
00027 #include <core/exceptions/system.h>
00028 #include <core/exceptions/software.h>
00029
00030 #include <cstdlib>
00031 #include <netinet/in.h>
00032 #include <cstring>
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 FuseLutContent::FuseLutContent(uint32_t type,
00048 void *payload, size_t payload_size)
00049 {
00050 if ( (type != FUSE_MT_LUT) && (type != FUSE_MT_SET_LUT) ) {
00051 throw fawkes::TypeMismatchException("Type %u != FUSE_MT_LUT/FUSE_MT_SET_LUT (%u/%u)",
00052 type, FUSE_MT_LUT, FUSE_MT_SET_LUT);
00053 }
00054
00055 _payload_size = payload_size;
00056 _payload = payload;
00057
00058
00059 __header = (FUSE_lut_message_header_t *)_payload;
00060 __buffer = (unsigned char *)_payload + sizeof(FUSE_lut_message_header_t);
00061
00062 __lut_id = (char *)malloc(LUT_ID_MAX_LENGTH + 1);
00063 __lut_id[LUT_ID_MAX_LENGTH] = 0;
00064 strncpy(__lut_id, __header->lut_id, LUT_ID_MAX_LENGTH);
00065
00066 __buffer_size = ntohl(__header->width) * ntohl(__header->height) *
00067 ntohl(__header->depth) * ntohl(__header->bytes_per_cell);
00068 }
00069
00070
00071
00072
00073
00074 FuseLutContent::FuseLutContent(SharedMemoryLookupTable *b)
00075 {
00076 __buffer_size = b->width() * b->height() * b->depth() * b->bytes_per_cell();
00077 _payload_size = __buffer_size + sizeof(FUSE_lut_message_header_t);
00078
00079 _payload = malloc(_payload_size);
00080 if ( _payload == NULL ) {
00081 throw fawkes::OutOfMemoryException("Cannot allocate FuseLutContent buffer");
00082 }
00083
00084 __header = (FUSE_lut_message_header_t *)_payload;
00085 __buffer = (unsigned char *)_payload + sizeof(FUSE_lut_message_header_t);
00086
00087 strncpy(__header->lut_id, b->lut_id(), LUT_ID_MAX_LENGTH);
00088 __header->width = htonl(b->width());
00089 __header->height = htonl(b->height());
00090 __header->depth = htonl(b->depth());
00091 __header->bytes_per_cell = htonl(b->bytes_per_cell());
00092 __lut_id = strdup(b->lut_id());
00093
00094
00095 memcpy(__buffer, b->buffer(), __buffer_size);
00096
00097 }
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 FuseLutContent::FuseLutContent(const char *lut_id, void *buffer,
00110 unsigned int width, unsigned int height,
00111 unsigned int depth, unsigned int bpc)
00112 {
00113 __buffer_size = width * height * depth * bpc;
00114 _payload_size = __buffer_size + sizeof(FUSE_lut_message_header_t);
00115
00116 _payload = malloc(_payload_size);
00117 if ( _payload == NULL ) {
00118 throw fawkes::OutOfMemoryException("Cannot allocate FuseLutContent buffer");
00119 }
00120
00121 __header = (FUSE_lut_message_header_t *)_payload;
00122 __buffer = (unsigned char *)_payload + sizeof(FUSE_lut_message_header_t);
00123
00124 strncpy(__header->lut_id, lut_id, LUT_ID_MAX_LENGTH);
00125 __header->width = htonl(width);
00126 __header->height = htonl(height);
00127 __header->depth = htonl(depth);
00128 __header->bytes_per_cell = htonl(bpc);
00129 __lut_id = strdup(lut_id);
00130
00131 memcpy(__buffer, buffer, __buffer_size);
00132 }
00133
00134
00135 FuseLutContent::~FuseLutContent()
00136 {
00137 free(__lut_id);
00138 }
00139
00140
00141
00142
00143
00144 const char *
00145 FuseLutContent::lut_id() const
00146 {
00147 return __lut_id;
00148 }
00149
00150
00151
00152
00153 unsigned char *
00154 FuseLutContent::buffer() const
00155 {
00156 return __buffer;
00157 }
00158
00159
00160
00161
00162
00163 size_t
00164 FuseLutContent::buffer_size() const
00165 {
00166 return __buffer_size;
00167 }
00168
00169
00170
00171
00172
00173 unsigned int
00174 FuseLutContent::width() const
00175 {
00176 return ntohl(__header->width);
00177 }
00178
00179
00180
00181
00182
00183 unsigned int
00184 FuseLutContent::height() const
00185 {
00186 return ntohl(__header->height);
00187 }
00188
00189
00190
00191
00192 unsigned int
00193 FuseLutContent::depth() const
00194 {
00195 return ntohl(__header->depth);
00196 }
00197
00198
00199
00200
00201
00202 unsigned int
00203 FuseLutContent::bytes_per_cell() const
00204 {
00205 return ntohl(__header->bytes_per_cell);
00206 }
00207
00208
00209 void
00210 FuseLutContent::serialize()
00211 {
00212
00213 }