21 unsigned char *src = (
unsigned char *)&value ;
22 unsigned char *dst = (
unsigned char *)&swaped ;
48#if( BYTEORDER_ENDIAN == BYTEORDER_LITTLE_ENDIAN )
65#if( BYTEORDER_ENDIAN == BYTEORDER_LITTLE_ENDIAN )
82 n_log(
LOG_ERR,
"create_msg destination is valid and should be NULL !" );
110 if( (*msg) -> tabint )
114 if( (*msg) -> tabflt )
118 if( (*msg) -> tabstr )
161 double *new_val = NULL ;
165 Malloc( new_val,
double, 1 );
168 new_val[ 0 ] = value ;
170 return list_push( msg -> tabflt, new_val, free );
183 int *new_val = NULL ;
187 Malloc( new_val,
int, 1 );
190 new_val[ 0 ] = value ;
192 return list_push( msg -> tabint, new_val, free );
266 (*value) = val[ 0 ] ;
317 n_log(
LOG_ERR,
"Previous pointer value %p overriden by pointer %p", (*value), val );
344 n_log(
LOG_ERR,
"Previous pointer value %p overriden by pointer %p", (*value), val );
347 (*value) = val -> data ;
366 N_STR *strptr = NULL,
367 *generated_str = NULL ;
369 char *charptr = NULL ;
376 str_length = 3 *
sizeof( int32_t ) + ( msg -> tabint -> nb_items *
sizeof( int32_t ) ) + ( msg -> tabflt -> nb_items *
sizeof(
double ) ) ;
379 node = msg -> tabstr -> start ;
382 strptr = (
N_STR *)node -> ptr ;
383 str_length +=
sizeof( int32_t ) +
sizeof( int32_t ) + strptr -> written ;
384 node = node -> next ;
390 Malloc( generated_str -> data,
char, str_length + 1 );
391 __n_assert( generated_str -> data,
return NULL );
393 generated_str -> length = str_length + 1 ;
394 generated_str -> written = str_length ;
398 charptr = generated_str -> data ;
401 msg -> tabint -> nb_items = htonl( msg -> tabint -> nb_items );
402 msg -> tabflt -> nb_items = htonl( msg -> tabflt -> nb_items );
403 msg -> tabstr -> nb_items = htonl( msg -> tabstr -> nb_items );
406 memcpy ( charptr, &msg -> tabint -> nb_items,
sizeof( int32_t ) );
407 charptr +=
sizeof( int32_t ) ;
409 memcpy ( charptr, &msg -> tabflt -> nb_items,
sizeof( int32_t ) );
410 charptr +=
sizeof( int32_t ) ;
412 memcpy ( charptr, &msg -> tabstr -> nb_items,
sizeof( int32_t ) );
413 charptr +=
sizeof( int32_t ) ;
416 msg -> tabint -> nb_items = ntohl( msg -> tabint -> nb_items );
417 msg -> tabflt -> nb_items = ntohl( msg -> tabflt -> nb_items );
418 msg -> tabstr -> nb_items = ntohl( msg -> tabstr -> nb_items );
421 node = msg -> tabint -> start ;
424 int32_t *nbptr = (int32_t *)node -> ptr ;
425 int32_t val = htonl( nbptr[ 0 ] );
426 memcpy( charptr, &val,
sizeof( int32_t ) );
427 charptr +=
sizeof( int32_t ) ;
428 node = node -> next ;
432 node = msg -> tabflt -> start ;
435 double *nbptr = (
double *)node -> ptr ;
436 double val =
htond( nbptr[ 0 ] );
437 memcpy( charptr, &val,
sizeof(
double ) );
438 charptr +=
sizeof( double ) ;
439 node = node -> next ;
443 if( msg -> tabstr -> nb_items > 0 )
445 node = msg -> tabstr -> start ;
448 strptr = (
N_STR *)node -> ptr ;
450 int32_t var = htonl( strptr -> length );
451 memcpy( charptr, &var,
sizeof( int32_t ) );
452 charptr +=
sizeof( int32_t );
454 var = htonl( strptr -> written );
455 memcpy( charptr, &var,
sizeof( int32_t ) );
456 charptr +=
sizeof( int32_t );
458 memcpy( charptr, strptr -> data, strptr -> written );
459 charptr += strptr -> written ;
460 node = node -> next ;
465 return generated_str;
478 N_STR *tmpstr = NULL;
480 char *charptr = NULL;
492 charptr = str -> data;
498 memcpy( &nb_int, charptr,
sizeof( int32_t ) );
499 charptr +=
sizeof( int32_t ) ;
500 nb_int = ntohl( nb_int );
502 memcpy( &nb_flt, charptr,
sizeof( int32_t ) );
503 charptr +=
sizeof( int32_t ) ;
504 nb_flt = ntohl( nb_flt );
506 memcpy( &nb_str, charptr,
sizeof( int32_t ) );
507 charptr +=
sizeof( int32_t ) ;
508 nb_str = ntohl( nb_str );
512 for( it = 0 ; it < nb_int ; it ++ )
514 memcpy( &tmpnb, charptr,
sizeof( int32_t ) ) ;
515 tmpnb = ntohl( tmpnb );
516 charptr +=
sizeof( int32_t ) ;
523 for( it = 0 ; it < nb_flt ; it ++ )
525 memcpy( &tmpflt, charptr,
sizeof(
double ) ) ;
526 tmpflt =
ntohd( tmpflt );
527 charptr +=
sizeof( double ) ;
535 for( it = 0 ; it < nb_str ; it ++ )
541 memcpy( &var, charptr,
sizeof( int32_t ) );
542 charptr +=
sizeof( int32_t ) ;
543 tmpstr -> length = ntohl( var );
545 memcpy( &var, charptr,
sizeof( int32_t ) );
546 charptr +=
sizeof( int32_t ) ;
547 tmpstr -> written = ntohl( var );
549 Malloc( tmpstr -> data,
char, tmpstr -> length );
552 memcpy( tmpstr -> data, charptr, tmpstr -> written );
553 charptr += tmpstr -> written ;
558 return generated_msg ;
577 N_STR *tmpstr = NULL ;
623 N_STR *tmpstr = NULL ;
674 N_STR *tmpstr = NULL ;
712 N_STR *tmpstr = NULL ;
745 N_STR *tmpstr = NULL ;
768 char *charptr = NULL ;
772 charptr = msg -> data ;
776 charptr += 3 *
sizeof( int32_t );
777 memcpy( &tmpnb, charptr,
sizeof( int32_t ) ) ;
778 tmpnb = ntohl( tmpnb );
837int netw_get_position(
N_STR *msg,
int *
id,
double *X,
double *Y,
double *vx,
double *vy,
double *acc_x,
double *acc_y,
int *time_stamp )
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define __n_assert(__ptr, __ret)
macro to assert things
#define Free(__ptr)
Free Handler to get errors.
#define list_shift(__LIST_, __TYPE_)
Shift macro helper for void pointer casting.
int list_empty(LIST *list)
Empty a LIST list of pointers.
int list_push(LIST *list, void *ptr, void(*destructor)(void *ptr))
Add a pointer to the end of the list.
int list_destroy(LIST **list)
Empty and Free a list container.
LIST * new_generic_list(int max_items)
Initialiaze a generic list container to max_items pointers.
Structure of a generic list node.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_ERR
error conditions
void free_nstr_ptr(void *ptr)
Free a N_STR pointer structure.
N_STR * nstrdup(N_STR *str)
Duplicate a N_STR.
N_STR * char_to_nstr(const char *src)
Convert a char into a N_STR, short version.
A box including a string and his lenght.
#define NETMSG_IDENT_REQUEST
Network Message is identification request: (int)type , (int)id , (N_STR *)name , (N_STR *)password.
double htond(double value)
If needed swap bytes for a double.
int get_str_from_msg(NETW_MSG *msg, char **value)
Get a string from a message string list.
int add_strdup_to_msg(NETW_MSG *msg, const char *str)
Add a copy of char *str to the string list in the message.
int netw_get_position(N_STR *msg, int *id, double *X, double *Y, double *vx, double *vy, double *acc_x, double *acc_y, int *time_stamp)
Retrieves position from netwmsg.
#define NETMSG_PING_REQUEST
Network Message is ping request: (int)type , (int)id_from , (int)id_to.
#define NETMSG_IDENT_REPLY_NOK
Network Message is identification reply NON OK: (int)type , (int)id , (N_STR *)name ,...
#define NETMSG_STRING
Network Message is string: (int)type , (int)id , (N_STR *)name , (N_STR *)chan , (N_STR *)text ,...
#define NETMSG_PING_REPLY
Network Message is ping reply: (int)type , (int)id_from , (int)id_to.
NETW_MSG * make_msg_from_str(N_STR *str)
Make a single message of the string.
int empty_msg(NETW_MSG **msg)
Empty a NETW_MSG *object.
double double_swap(double value)
Swap bytes endiannes for a double.
N_STR * make_str_from_msg(NETW_MSG *msg)
Make a single string of the message.
int netw_get_ping(N_STR *msg, int *type, int *from, int *to, int *time)
Retrieves a ping travel elapsed time.
int add_nstrptr_to_msg(NETW_MSG *msg, N_STR *str)
Add a string to the string list in the message.
int get_nb_from_msg(NETW_MSG *msg, double *value)
Get a number from a message number list.
#define NETMSG_QUIT
Network asking for exit.
int netw_get_quit(N_STR *msg)
get a formatted NETWMSG_QUIT message from the specified network
int create_msg(NETW_MSG **msg)
Create a NETW_MSG *object.
#define NETMSG_POSITION
Network Message position: (int)type , (int)id , (int)X , (int)Y , (int)x_shift , (int)y_shift ,...
N_STR * netmsg_make_position_msg(int id, double X, double Y, double vx, double vy, double acc_x, double acc_y, int time_stamp)
make a network NETMSG_POSITION message with given parameters
int netw_msg_get_type(N_STR *msg)
Get the type of message without killing the first number. Use with netw_get_XXX.
int get_nstr_from_msg(NETW_MSG *msg, N_STR **value)
Get a string from a message string list.
N_STR * netmsg_make_ident(int type, int id, N_STR *name, N_STR *passwd)
Add a formatted NETWMSG_IDENT message to the specified network.
int add_nstrdup_to_msg(NETW_MSG *msg, N_STR *str)
Add a copy of str to the string list in the message.
int add_int_to_msg(NETW_MSG *msg, int value)
Add an int to the int list int the message.
double ntohd(double value)
If needed swap bytes for a double.
#define NETMSG_IDENT_REPLY_OK
Network Message is identification reply OK : (int)type , (int)id , (N_STR *)name ,...
int netw_get_string(N_STR *msg, int *id, N_STR **name, N_STR **chan, N_STR **txt, int *color)
Retrieves string from netwmsg.
int delete_msg(NETW_MSG **msg)
Delete a NETW_MSG *object.
int add_nb_to_msg(NETW_MSG *msg, double value)
Add an float to the message.
N_STR * netmsg_make_quit_msg(void)
make a generic network NETMSG_QUIT message
N_STR * netmsg_make_ping(int type, int id_from, int id_to, int time)
Make a ping message to send to a network.
int netw_get_ident(N_STR *msg, int *type, int *ident, N_STR **name, N_STR **passwd)
Retrieves identification from netwmsg.
N_STR * netmsg_make_string_msg(int id_from, int id_to, N_STR *name, N_STR *chan, N_STR *txt, int color)
make a network NETMSG_STRING message with given parameters
int get_int_from_msg(NETW_MSG *msg, int *value)
Get a number from a message number list.
network message, array of char and int
Common headers and low-level hugly functions & define.
Network messages , serialization tools.