27 ulist -> highter = -1;
28 for(
int it = 0; it < max ; it ++ )
30 ulist -> list[ it ] . state = 0 ;
31 ulist -> list[ it ] . nb_rec_pos = 10 ;
32 ulist -> list[ it ] . only_last_pos = 1 ;
33 ulist -> list[ it ] .
id = -1 ;
36 memset( ulist -> list[ it ] . position, 0, 3 *
sizeof(
double ) );
37 ulist -> list[ it ] . netw = NULL ;
38 memset( ulist -> list[ it ] . name, 0, 1024 );
39 ulist -> list[ it ] . netw = NULL ;
61 __n_assert( only_last_pos < 0 || only_last_pos > 1,
return FALSE );
64 __n_assert( ulist -> list[
id ] . state == 0,
return FALSE );
65 unlock( ulist -> user_rwbolt );
68 ulist -> list[ id ] . nb_rec_pos = nb_rec_pos ;
69 ulist -> list[ id ] . only_last_pos = only_last_pos ;
73 if( ! ulist -> list[
id ] . last_positions )
75 n_log(
LOG_ERR,
"could not resize to only_last_pos VECTOR3D" );
81 if( ! ulist -> list[
id ] . last_positions )
83 n_log(
LOG_ERR,
"could not resize to %d VECTOR3D", nb_rec_pos );
85 ulist -> list[ id ] . nb_rec_pos = 1 ;
87 __n_assert( ulist -> list[
id ] . last_positions,
unlock( ulist -> user_rwbolt );
return FALSE );
88 unlock( ulist -> user_rwbolt );
112 while( it < ulist -> max && ulist -> list[ it ] . state != 0);
113 if( it < ulist -> max )
115 ulist -> list[ it ] . state = 1;
116 ulist -> list[ it ] . netw = netw ;
117 if( it > ulist -> highter )
118 ulist -> highter = it;
119 unlock( ulist -> user_rwbolt );
122 unlock( ulist -> user_rwbolt );
140 if(
id > ulist -> max )
142 unlock( ulist -> user_rwbolt );
145 if( ulist -> list[
id ] . state == 0 )
147 unlock( ulist -> user_rwbolt );
150 ulist -> list[ id ] . state = 0 ;
151 ulist -> list[ id ] . nb_rec_pos = 1 ;
152 ulist -> list[ id ] . only_last_pos = 1 ;
153 ulist -> list[ id ] .
id = -1 ;
155 if( ! ulist -> list[
id ] . last_positions )
159 list_empty( ulist -> list[
id ] . netw_waitlist );
160 memset( ulist -> list[
id ] . position, 0, 3 *
sizeof(
double ) );
161 ulist -> list[ id ] . netw = NULL ;
162 memset( ulist -> list[
id ] . name, 0, 1024 );
164 if(
id >= ulist -> highter )
169 if( ulist -> list[ it ] . state == 1 )
171 ulist -> highter = it ;
177 unlock( ulist -> user_rwbolt );
200 for(
int it = 0 ; it <= ulist -> highter ; it ++ )
202 if( ulist -> list[ it ] . state == 1 )
205 unlock( ulist -> user_rwbolt );
210 for(
int it = 0 ; it <= ulist -> highter ; it ++ )
214 if( ulist -> list[ it ] . state == 1 )
217 unlock( ulist -> user_rwbolt );
225 unlock( ulist -> user_rwbolt );
283 for(
int it = 0 ; it < (*ulist) -> max ; it ++ )
285 Free( (*ulist) -> list[it ] . last_positions );
288 Free( (*ulist) -> list );
289 unlock( (*ulist) -> user_rwbolt );
291 pthread_rwlock_destroy( &(*ulist) -> user_rwbolt );
315 if( id <= ulist -> highter )
317 if( ulist -> list[
id ] . state == 1 )
319 ret =
list_push( ulist -> list[
id ] . netw_waitlist, netmsg, NULL );
322 unlock( ulist -> user_rwbolt );
340 if( id <= ulist -> highter )
342 if( ulist -> list[
id ] . state == 1 )
344 list_foreach( node, ulist -> list[
id ] . netw_waitlist )
349 list_empty( ulist -> list[
id ] . netw_waitlist );
352 unlock( ulist -> user_rwbolt );
367 for(
int id = 0 ;
id <= ulist -> highter ;
id ++ )
369 if( ulist -> list[
id ] . state == 1 )
371 list_foreach( node, ulist -> list[
id ] . netw_waitlist )
376 list_empty( ulist -> list[
id ] . netw_waitlist );
379 unlock( ulist -> user_rwbolt );
#define init_lock(__rwlock_mutex)
Macro for initializing a rwlock.
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define __n_assert(__ptr, __ret)
macro to assert things
#define unlock(__rwlock_mutex)
Macro for releasing read/write lock a rwlock mutex.
#define write_lock(__rwlock_mutex)
Macro for acquiring a write lock on a rwlock mutex.
#define Realloc(__ptr, __struct, __size)
Realloc Handler to get errors.
#define Free(__ptr)
Free Handler to get errors.
#define read_lock(__rwlock_mutex)
Macro for acquiring a read lock on a rwlock mutex.
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.
#define list_foreach(__ITEM_, __LIST_)
ForEach macro helper.
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.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_ERR
error conditions
N_STR * nstrdup(N_STR *str)
Duplicate a N_STR.
A box including a string and his lenght.
int userlist_del_user(N_USERLIST *ulist, int id)
delete an user from the list
int userlist_add_msg_to(N_USERLIST *ulist, N_STR *msg, int id)
add a N_STR *message to user list (USERLIST_ONE)
int userlist_add_msg_to_ex(N_USERLIST *ulist, N_STR *msg, int mode, int id)
add a N_STR *message to user list
#define USERLIST_ONE
flag to target one user in the list
int userlist_user_send_waiting_msgs(N_USERLIST *ulist, int id)
send all waiting messages in user 'id' waiting list
#define USERLIST_ALL_EXCEPT
flag to target all users in the list except one
N_USERLIST * userlist_new(int max)
create a new N_USERLIST user list with 'max' users
#define USERLIST_ALL
flag to target all users in the list
int userlist_add_msg_to_all(N_USERLIST *ulist, N_STR *msg)
add a N_STR *message to user list (USERLIST_ALL)
int userlist_send_waiting_msgs(N_USERLIST *ulist)
send all waiting messages ofr each user of the lsit
int userlist_set_position_behavior(N_USERLIST *ulist, int id, int nb_rec_pos, int only_last_pos)
set the position parameters for trajectory processing for user 'id'
int userlist_add_user(N_USERLIST *ulist, NETWORK *netw)
add an user to the list
int userlist_add_msg_to_all_except(N_USERLIST *ulist, N_STR *msg, int id)
add a N_STR *message to user list except user 'id' (USERLIST_ALL_EXCEPT)
int userlist_destroy(N_USERLIST **ulist)
destroy and free a N_USERLIST *userlist
int userlist_user_add_waiting_msg(N_USERLIST *ulist, int id, N_STR *netmsg)
add a newtork message to specified user 'id'
int netw_add_msg(NETWORK *netw, N_STR *msg)
Add a message to send in aimed NETWORK.
double VECTOR3D[3]
struct of a point
USERS handling for tiny game apps.