Nilorea Library
C utilities for networking, threading, graphics
n_network_msg.h
Go to the documentation of this file.
1
7#ifndef N_NETWORK_MESSAGES
8#define N_NETWORK_MESSAGES
9
10#ifdef __cplusplus
11extern "C"
12{
13#endif
14
20#include <sys/param.h>
21
22#include "n_str.h"
23#include "n_list.h"
24#include "n_3d.h"
25
27#define NETMSG_IDENT_REQUEST 0
29#define NETMSG_IDENT_REPLY_OK 1
31#define NETMSG_IDENT_REPLY_NOK 2
33#define NETMSG_STRING 3
35#define NETMSG_POSITION 4
37#define NETMSG_PING_REQUEST 5
39#define NETMSG_PING_REPLY 6
41#define NETMSG_GET_BOX 7
43#define NETMSG_BOX 8
45#define NETMSG_QUIT 9
46
48typedef struct NETW_MSG
49{
56} NETW_MSG ;
57
58/* swap bytes */
59double double_swap( double value );
60/* host to network double */
61double htond( double value );
62/* network to host double */
63double ntohd( double value );
64
65/* Create a NETW_MSG *object */
66int create_msg( NETW_MSG **msg );
67/* Delete a NETW_MSG *object */
68int delete_msg( NETW_MSG **msg );
69/* Empty a NETW_MSG *object */
70int empty_msg( NETW_MSG **msg );
71/* Add an float to the the message */
72int add_nb_to_msg( NETW_MSG *msg, double value );
73/* Add an int to the the message */
74int add_int_to_msg( NETW_MSG *msg, int value );
75/* Add a string to the the message */
76int add_nstrptr_to_msg( NETW_MSG *msg, N_STR *str );
77/* Add a string to the the message */
78int add_nstrdup_to_msg( NETW_MSG *msg, N_STR *str );
79/* Add a char *string to the the message */
80int add_strdup_to_msg( NETW_MSG *msg, const char *str );
81/* Get an int from the message */
82int get_int_from_msg( NETW_MSG *msg, int *value );
83/* Get a float value from the message */
84int get_nb_from_msg( NETW_MSG *msg, double *value );
85/* Get a N_STR *string from the message */
86int get_nstr_from_msg( NETW_MSG *msg, N_STR **str );
87/* Get a char *string from the message */
88int get_str_from_msg( NETW_MSG *msg, char **str );
89/* Make a single string of the message */
91/* Make a message from a single string */
93
94N_STR *netmsg_make_ping( int type, int id_from, int id_to, int time );
95N_STR *netmsg_make_ident( int type, int id, N_STR *name, N_STR *passwd );
96N_STR *netmsg_make_position_msg( int id, double X, double Y, double vx, double vy, double acc_x, double acc_y, int time_stamp );
97N_STR *netmsg_make_string_msg( int id_from, int id_to, N_STR *name, N_STR *chan, N_STR *txt, int color );
99
100int netw_msg_get_type( N_STR *msg );
101
102int netw_get_ident( N_STR *msg, int *type, int *ident, N_STR **name, N_STR **passwd );
103int 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 );
104int netw_get_string( N_STR *msg, int *id, N_STR **name, N_STR **chan, N_STR **txt, int *color );
105int netw_get_ping( N_STR *msg, int *type, int *from, int *to, int *time );
106int netw_get_quit( N_STR *msg );
107
112#ifdef __cplusplus
113}
114#endif
115
116#endif /*#ifndef N_NETWORK*/
117
118
119
120
121
Structure of a generic LIST container.
Definition: n_list.h:45
A box including a string and his lenght.
Definition: n_str.h:173
LIST * tabflt
array of casted double value
Definition: n_network_msg.h:55
LIST * tabstr
array of N_STR
Definition: n_network_msg.h:53
LIST * tabint
array of int
Definition: n_network_msg.h:51
double htond(double value)
If needed swap bytes for a double.
Definition: n_network_msg.c:44
int get_str_from_msg(NETW_MSG *msg, char **str)
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.
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.
Definition: n_network_msg.c:18
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.
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.
Definition: n_network_msg.c:78
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 **str)
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.
Definition: n_network_msg.c:61
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
Definition: n_network_msg.h:49
Simple 3D movement simulation.
List structures and definitions.
N_STR and string function declaration.