clouseau: bmp_info_st info now encoded with eet.

Signed-off-by: Aharon Hillel <a.hillel@samsung.com>

SVN revision: 72343
This commit is contained in:
Aharon Hillel 2012-06-18 07:22:39 +00:00 committed by Tom Hacohen
parent e7f43b2bea
commit 77963edfcb
1 changed files with 41 additions and 36 deletions

View File

@ -394,18 +394,6 @@ data_descriptors_shutdown(void)
} }
} }
enum _bmp_field_idx
{ /* Index for bmp_info_st fields to be stored in BLOB */
gui = 0,
app,
object,
ctr,
w,
h,
top_idx /* Used for allocation */
};
typedef enum _bmp_field_idx bmp_field_idx;
void * void *
packet_compose(message_type t, void *data, packet_compose(message_type t, void *data,
int data_size, int *size, int data_size, int *size,
@ -415,38 +403,50 @@ packet_compose(message_type t, void *data,
void *p = NULL; void *p = NULL;
void *pb = NULL; void *pb = NULL;
unsigned char p_type = VARIANT_PACKET; unsigned char p_type = VARIANT_PACKET;
data_desc *d = data_descriptors_init();
switch (t) switch (t)
{ {
case BMP_DATA: case BMP_DATA:
{ /* Builed raw data without encoding */ { /* Builed Bitmap data as follows:
/* Do NOT forget to update *size, allocate using p */ First we have encoding size of bmp_info_st
bmp_info_st *b = data; (Done Network Byte Order)
*size = (top_idx * sizeof(unsigned long long)) + blob_size; The next to come will be the encoded bmp_info_st itself
unsigned long long *longs = malloc(*size); folloed by the Bitmap raw data. */
longs[gui] = b->gui; /* First, we like to encode bmp_info_st from data */
longs[app] = b->app; int e_size;
longs[object] = b->object; Variant_st *v = variant_alloc(t, data_size, data);
longs[ctr] = b->ctr; p = eet_data_descriptor_encode(
longs[w] = b->w; d->_variant_descriptor , v, &e_size);
longs[h] = b->h; variant_free(v);
if (blob) /* Save encoded size in network format */
memcpy(&longs[top_idx], blob, blob_size); /* Copy BMP info */ uint32_t enc_size = htonl((uint32_t) e_size);
/* Update size to the buffer size we about to return */
*size = (e_size + blob_size + sizeof(enc_size));
char *b = malloc(*size);
/* Copy encoded-size first, followd by encoded data */
memcpy(b, &enc_size, sizeof(enc_size));
memcpy(b + sizeof(enc_size), p, e_size);
free(p);
if (blob) /* Copy BMP info */
memcpy(b + sizeof(enc_size) + e_size, blob, blob_size);
p_type = BMP_RAW_DATA; p_type = BMP_RAW_DATA;
p = longs; p = b;
} }
break; break;
default: default:
{ /* All others are variant packets with EET encoding */ { /* All others are variant packets with EET encoding */
/* Variant is composed of message type + ptr to data */ /* Variant is composed of message type + ptr to data */
data_desc *d = data_descriptors_init();
Variant_st *v = variant_alloc(t, data_size, data); Variant_st *v = variant_alloc(t, data_size, data);
p = eet_data_descriptor_encode( p = eet_data_descriptor_encode(
d->_variant_descriptor , v, size); d->_variant_descriptor ,v, size);
variant_free(v); variant_free(v);
} }
} }
@ -464,31 +464,36 @@ Variant_st *
packet_info_get(void *data, int size) packet_info_get(void *data, int size)
{ /* user has to use variant_free() to free return struct */ { /* user has to use variant_free() to free return struct */
char *ch = data; char *ch = data;
data_desc *d = data_descriptors_init();
switch (*ch) switch (*ch)
{ {
case BMP_RAW_DATA: case BMP_RAW_DATA:
{ {
void *bmp = NULL; void *bmp = NULL;
unsigned long long *longs = (unsigned long long *) (ch + 1); char *b = (char *) (ch + 1);
/* Allocate size minus longs array and ch size for bmp */ uint32_t enc_size = ntohl(*(uint32_t *) b);
int blob_size = size - (((char *) (&longs[top_idx])) - ch); /* blob_size is total size minus 1st byte and enc_size size */
int blob_size = size - (enc_size + 1 + sizeof(enc_size));
if (blob_size) if (blob_size)
{ /* Allocate BMP only if was included in packet */ { /* Allocate BMP only if was included in packet */
bmp = malloc(blob_size); bmp = malloc(blob_size);
memcpy(bmp, &longs[top_idx], blob_size); memcpy(bmp, b + sizeof(enc_size) + enc_size, blob_size);
} }
bmp_info_st t = { longs[gui], longs[app], longs[object],
longs[ctr], longs[w], longs[h], NULL, NULL, bmp };
/* User have to free both: variant_free(rt), free(t->bmp) */ /* User have to free both: variant_free(rt), free(t->bmp) */
return variant_alloc(BMP_DATA, sizeof(t), &t); Variant_st *v = eet_data_descriptor_decode(d->_variant_descriptor,
b + sizeof(enc_size), enc_size);
bmp_info_st *st = v->data;
st->bmp = bmp;
return v;
} }
break; break;
default: default:
{ {
data_desc *d = data_descriptors_init();
return eet_data_descriptor_decode(d->_variant_descriptor, return eet_data_descriptor_decode(d->_variant_descriptor,
ch + 1, size - 1); ch + 1, size - 1);
} }