--- libaitio/inc/aitio.h 2012/03/10 15:37:09 1.14.2.4 +++ 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.14.2.4 2012/03/10 15:37:09 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 @@ -12,7 +12,7 @@ terms: All of the documentation and software included in the ELWIX and AITNET Releases is copyrighted by ELWIX - Sofia/Bulgaria -Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 +Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 by Michael Pounov . All rights reserved. Redistribution and use in source and binary forms, with or without @@ -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,18 +110,20 @@ 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) #define AIT_LEN(_vl) (_vl)->val_len #define AIT_RAW(_vl) (_vl)->val.net +#define AIT_VOID(_vl) (_vl)->val.ptr #define AIT_BLOB_CHUNKS(_vl, _n) (assert((_vl)), AIT_LEN((_vl)) / _n + (AIT_LEN((_vl)) % _n) ? 1 : 0) #define AIT_ISEMPTY(_vl) (assert((_vl)), AIT_TYPE((_vl)) == empty) -#define AIT_GET_LIKE(_vl, _type) (assert((_vl)), (_type) (_vl)->val.net) +#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_PTR2(_vl) (assert((_vl)), (_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 { @@ -233,6 +249,9 @@ typedef union { struct sockaddr_in6 sin6; struct sockaddr_dl sdl; } io_sockaddr_t; + + +#define io_align(x, a) (((x) + (a)) & ~(a)) // io_GetErrno() Get error code of last operation