--- libaitio/inc/aitio.h 2012/03/15 01:52:22 1.15 +++ libaitio/inc/aitio.h 2012/03/27 20:53:37 1.15.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: aitio.h,v 1.15 2012/03/15 01:52:22 misho Exp $ +* $Id: aitio.h,v 1.15.2.1 2012/03/27 20:53:37 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -81,7 +81,7 @@ typedef struct _tagArray { /* AIT RPC variables and managment */ typedef enum { - empty, ptr, /* empty -> variable is not set; ptr -> void* */ + empty, ptr, data, /* empty -> variable is not set; ptr -> void*; data -> data after struct */ buffer, string, blob, /* buffer -> uint8_t*; string -> int8_t*; blob -> uint32_t blobID(+socket); */ f32, f64, /* float -> f32; double -> f64 */ u8, u16, u32, u64, /* unsigned integers ... */ @@ -110,6 +110,7 @@ typedef struct { int32_t i32; int64_t i64; } val; + uint8_t val_data[0]; } __packed ait_val_t; #define AIT_TYPE(_vl) ((ait_type_t) (_vl)->val_type) @@ -122,6 +123,7 @@ typedef struct { #define AIT_GET_LIKE(_vl, _type) (assert((_vl)), (_type) (_vl)->val.ptr) #define AIT_GET_PTR(_vl) (assert((_vl)), assert(AIT_TYPE((_vl)) == ptr), (_vl)->val.ptr) +#define AIT_GET_DATA(_vl) (assert((_vl)), assert(AIT_TYPE((_vl)) == data), (_vl)->val_data) #define AIT_GET_BUF(_vl) (assert((_vl)), assert(AIT_TYPE((_vl)) == buffer), (_vl)->val.buffer) #define AIT_GET_STR(_vl) (assert((_vl)), assert(AIT_TYPE((_vl)) == string), (_vl)->val.string) #define AIT_GET_BLOB(_vl) (assert((_vl)), assert(AIT_TYPE((_vl)) == blob), (_vl)->val.blob) @@ -136,6 +138,15 @@ typedef struct { #define AIT_GET_F32(_vl) (assert((_vl)), assert(AIT_TYPE((_vl)) == f32), (_vl)->val.f32) #define AIT_GET_F64(_vl) (assert((_vl)), assert(AIT_TYPE((_vl)) == f64), (_vl)->val.f64) +#define AIT_SET_DATA(_vl, _p, _len) do { ait_val_t *__val = (_vl); assert(__val); \ + __val = realloc(__val, sizeof(ait_val_t) + _len); \ + if (__val) { \ + __val->val_type = data; AIT_LEN(__val) = _len; \ + if ((_p)) \ + memcpy(__val->val_data, (_p), _len); \ + } \ + (_vl) = __val; \ + } while (0); #define AIT_SET_PTR(_vl, _p, _len) do { ait_val_t *__val = (_vl); assert(__val); \ __val->val_type = ptr; AIT_LEN(__val) = _len; \ __val->val.ptr = _p; } while (0) @@ -199,8 +210,8 @@ typedef struct { AIT_LEN(__val) = sizeof(double); } while (0) /* if attribute zeroCopy is set not execute free() */ -#define AIT_FREE_VAL(_vl) do { ait_val_t *__val = (ait_val_t*) (_vl); assert(__val); \ - switch (__val->val_type) { \ +#define AIT_FREE_VAL(_vl) do { ait_val_t *__val = (_vl); assert(__val); \ + switch (AIT_TYPE(__val)) { \ case buffer: \ if (__val->val.buffer) { \ free(__val->val.buffer); \ @@ -213,11 +224,16 @@ typedef struct { __val->val.string = NULL; \ } \ break; \ + case data: \ + __val = realloc(__val, sizeof(ait_val_t)); \ + break; \ default: \ break; \ } \ - __val->val_type = empty; \ - AIT_LEN(__val) = 0; \ + if (__val) { \ + __val->val_type = empty; \ + AIT_LEN(__val) = 0; \ + } \ } while (0) struct io_ether_addr {