From b1acf7fe2f1886e9adcb4313f53548c9995a906c Mon Sep 17 00:00:00 2001 From: mquinson Date: Mon, 26 Apr 2004 10:11:28 +0000 Subject: [PATCH] [Messaging] - Porting to new standards. [Data description] - interface cleanup. There is no bag anymore, no need to take extra provision to mask the pointers behind "ID". Better splitup of functions between files create/exchange/convert. This is still a bit artificial since convert and receive are so interleaved, but anyway. [Virtu(process)] - add a queued message list to procdata (the ones not matching criteria in msg_wait) - factorize some more code between SG and RL wrt procdata [Tests] - use gras_exit in example to track memleaks - get rid of gs_example now that GS is properly integrated into gras - update run_test to integrate the lastest tests (datadesc) [Logging] - rename WARNINGn macros to WARNn since it prooved error-prone git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@83 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- include/datadesc.h | 188 +++----- include/gras.h | 3 +- include/log.h | 32 +- include/messages.h | 222 ++------- include/module.h | 4 +- include/modules/base.h | 2 +- include/transport.h | 4 + src/gras/Common/gras.c | 111 ----- src/gras/Common/gras_datadesc.c | 82 ---- src/gras/DataDesc/datadesc.c | 204 ++++---- src/gras/DataDesc/datadesc_interface.h | 22 +- src/gras/DataDesc/datadesc_private.h | 67 +-- .../DataDesc/{ddt_remote.c => ddt_convert.c} | 46 -- src/gras/DataDesc/ddt_create.c | 282 ++++++----- src/gras/DataDesc/ddt_declare.c | 181 -------- .../DataDesc/{ddt_use.c => ddt_exchange.c} | 23 +- src/gras/Makefile.am | 14 +- src/gras/Msg/msg.c | 438 ++++++++++++++++++ src/gras/Msg/msg_interface.h | 35 ++ src/gras/Msg/msg_private.h | 56 +++ src/gras/Transport/rl_transport.c | 4 +- src/gras/Transport/transport.c | 12 +- src/gras/Transport/transport_plugin_file.c | 2 +- src/gras/Transport/transport_plugin_tcp.c | 4 +- src/gras/Virtu/process.c | 39 ++ src/gras/Virtu/rl_process.c | 25 +- src/gras/Virtu/sg_process.c | 40 +- src/gras/Virtu/virtu_interface.h | 9 +- src/gras/gras_private.h | 4 +- src/xbt/config.c | 10 +- src/xbt/module.c | 18 +- testsuite/Makefile.am | 6 +- testsuite/gras/datadesc_usage.c | 77 ++- testsuite/gras/gs_example.in | 4 - testsuite/gras/gs_example_receive.c | 168 ------- testsuite/gras/gs_example_send.c | 201 -------- testsuite/gras/trp_file_client.c | 4 +- testsuite/gras/trp_file_server.c | 3 +- testsuite/gras/trp_tcp_client.c | 4 +- testsuite/gras/trp_tcp_server.c | 3 +- testsuite/xbt/config_usage.c | 3 +- testsuite/xbt/dict_crash.c | 4 +- testsuite/xbt/dict_usage.c | 2 +- testsuite/xbt/dynar_double.c | 2 +- testsuite/xbt/dynar_int.c | 3 +- testsuite/xbt/dynar_string.c | 3 +- testsuite/xbt/log_usage.c | 4 +- testsuite/xbt/multidict_crash.c | 14 +- testsuite/xbt/set_usage.c | 3 +- 49 files changed, 1111 insertions(+), 1580 deletions(-) delete mode 100644 src/gras/Common/gras.c delete mode 100644 src/gras/Common/gras_datadesc.c rename src/gras/DataDesc/{ddt_remote.c => ddt_convert.c} (54%) delete mode 100644 src/gras/DataDesc/ddt_declare.c rename src/gras/DataDesc/{ddt_use.c => ddt_exchange.c} (97%) create mode 100644 src/gras/Msg/msg.c create mode 100644 src/gras/Msg/msg_interface.h create mode 100644 src/gras/Msg/msg_private.h create mode 100644 src/gras/Virtu/process.c delete mode 100644 testsuite/gras/gs_example.in delete mode 100644 testsuite/gras/gs_example_receive.c delete mode 100644 testsuite/gras/gs_example_send.c diff --git a/include/datadesc.h b/include/datadesc.h index f50c9c4ae3..3a904bee1d 100644 --- a/include/datadesc.h +++ b/include/datadesc.h @@ -38,23 +38,82 @@ BEGIN_DECL +/* datadesc */ typedef struct s_gras_datadesc_type gras_datadesc_type_t; +/* callbacks prototypes */ +typedef void (*gras_datadesc_type_cb_void_t)(void *vars, + gras_datadesc_type_t *p_type, + void *data); +typedef int (*gras_datadesc_type_cb_int_t)(void *vars, + gras_datadesc_type_t *p_type, + void *data); + /*********************************************** **** Search and retrieve declared datatype **** ***********************************************/ -long int gras_datadesc_get_id_from_name(const char *name); - gras_error_t gras_datadesc_by_name(const char *name, gras_datadesc_type_t **type); -gras_error_t gras_datadesc_by_id (long int code, - gras_datadesc_type_t **type); -#define gras_datadesc_by_code(a,b) gras_datadesc_by_id(a,b) -/********************************************* - **** DataDesc callback persistent states **** - *********************************************/ +/****************************************** + **** Declare datadescription yourself **** + ******************************************/ + +gras_error_t +gras_datadesc_declare_struct(const char *name, + gras_datadesc_type_t **dst); +gras_error_t +gras_datadesc_declare_struct_append(gras_datadesc_type_t *struct_type, + const char *name, + gras_datadesc_type_t *field_type); +gras_error_t +gras_datadesc_declare_struct_append_name(gras_datadesc_type_t *struct_type, + const char *name, + const char *field_type_name); +gras_error_t +gras_datadesc_declare_union(const char *name, + gras_datadesc_type_cb_int_t selector, + gras_datadesc_type_t **dst); +gras_error_t +gras_datadesc_declare_union_append(gras_datadesc_type_t *union_type, + const char *name, + gras_datadesc_type_t *field_type); +gras_error_t +gras_datadesc_declare_union_append_name(gras_datadesc_type_t *union_type, + const char *name, + const char *field_type_name); +gras_error_t +gras_datadesc_declare_ref(const char *name, + gras_datadesc_type_t *referenced_type, + gras_datadesc_type_t **dst); +gras_error_t +gras_datadesc_declare_ref_generic(const char *name, + gras_datadesc_type_cb_int_t discriminant, + gras_datadesc_type_t **dst); +gras_error_t +gras_datadesc_declare_array_fixed(const char *name, + gras_datadesc_type_t *element_type, + long int fixed_size, + gras_datadesc_type_t **dst); +gras_error_t +gras_datadesc_declare_array_dyn(const char *name, + gras_datadesc_type_t *element_type, + gras_datadesc_type_cb_int_t dynamic_size, + gras_datadesc_type_t **dst); + +/********************************* + * Change stuff within datadescs * + *********************************/ + typedef struct s_gras_dd_cbps gras_dd_cbps_t; +void gras_datadesc_cb_set_pre (gras_datadesc_type_t *type, + gras_datadesc_type_cb_void_t pre); +void gras_datadesc_cb_set_post(gras_datadesc_type_t *type, + gras_datadesc_type_cb_void_t post); + +/******************************************************** + * Advanced data describing: callback persistent states * + ********************************************************/ void * gras_dd_cbps_pop (gras_dd_cbps_t *ps, @@ -82,100 +141,8 @@ void gras_dd_cbps_block_end(gras_dd_cbps_t *ps); -/****************************************** - **** Declare datadescription manually **** - ******************************************/ - -typedef void (*gras_datadesc_type_cb_void_t)(void *vars, - gras_datadesc_type_t *p_type, - void *data); -typedef int (*gras_datadesc_type_cb_int_t)(void *vars, - gras_datadesc_type_t *p_type, - void *data); - -/* Create a new type and register it on the local machine */ -#define gras_datadesc_declare_struct( name, code) \ - gras_datadesc_declare_struct_cb(name, NULL, NULL, code) - -#define gras_datadesc_declare_struct_add_name( struct_code,field_name,field_type_name) \ - gras_datadesc_declare_struct_add_name_cb(struct_code,field_name,field_type_name, NULL, NULL) - -#define gras_datadesc_declare_struct_add_code( struct_code,field_name,field_type_code) \ - gras_datadesc_declare_struct_add_code_cb(struct_code,field_name,field_type_code, NULL, NULL) - -gras_error_t -gras_datadesc_declare_struct_cb(const char *name, - gras_datadesc_type_cb_void_t pre_cb, - gras_datadesc_type_cb_void_t post_cb, - long int *code); -gras_error_t -gras_datadesc_declare_struct_add_name_cb(long int struct_code, - const char *field_name, - const char *field_type_name, - gras_datadesc_type_cb_void_t pre_cb, - gras_datadesc_type_cb_void_t post_cb); - -gras_error_t -gras_datadesc_declare_struct_add_code_cb(long int struct_code, - const char *field_name, - long int field_code, - gras_datadesc_type_cb_void_t pre_cb, - gras_datadesc_type_cb_void_t post_cb); -/* union */ -#define gras_datadesc_declare_union( name, code) \ - gras_datadesc_declare_union_cb(name, NULL, NULL, code) - -#define gras_datadesc_declare_union_add_name( union_code,field_name,field_type_name) \ - gras_datadesc_declare_union_add_name_cb(union_code,field_name,field_type_name, NULL, NULL) - -#define gras_datadesc_declare_union_add_code( union_code,field_name,field_type_code) \ - gras_datadesc_declare_union_add_code_cb(union_code,field_name,field_type_code, NULL, NULL) - -gras_error_t -gras_datadesc_declare_union_cb(const char *name, - gras_datadesc_type_cb_int_t field_count, - gras_datadesc_type_cb_void_t post, - long int *code); -gras_error_t -gras_datadesc_declare_union_add_name_cb(long int union_code, - const char *field_name, - const char *field_type_name, - gras_datadesc_type_cb_void_t pre_cb, - gras_datadesc_type_cb_void_t post_cb); -gras_error_t -gras_datadesc_declare_union_add_code_cb(long int union_code, - const char *field_name, - long int field_code, - gras_datadesc_type_cb_void_t pre_cb, - gras_datadesc_type_cb_void_t post_cb); -/* ref */ -#define gras_datadesc_declare_ref(name,ref_type, code) \ - gras_datadesc_declare_ref_cb(name, ref_type, NULL, NULL, code) -#define gras_datadesc_declare_ref_disc(name,discriminant, code) \ - gras_datadesc_declare_ref_cb(name, NULL, discriminant, NULL, code) - -gras_error_t -gras_datadesc_declare_ref_cb(const char *name, - gras_datadesc_type_t *referenced_type, - gras_datadesc_type_cb_int_t discriminant, - gras_datadesc_type_cb_void_t post, - long int *code); -/* array */ -#define gras_datadesc_declare_array(name,elm_type, size, code) \ - gras_datadesc_declare_array_cb(name, elm_type, size, NULL, NULL, code) -#define gras_datadesc_declare_array_dyn(name,elm_type, dynamic_size, code) \ - gras_datadesc_declare_array_cb(name, elm_type, -1, dynamic_size, NULL, code) - -gras_error_t -gras_datadesc_declare_array_cb(const char *name, - gras_datadesc_type_t *element_type, - long int fixed_size, - gras_datadesc_type_cb_int_t dynamic_size, - gras_datadesc_type_cb_void_t post, - long int *code); - /******************************* **** About data convertion **** *******************************/ @@ -187,17 +154,17 @@ int gras_arch_selfid(void); /* ID of this arch */ gras_error_t gras_datadesc_parse(const char *name, const char *Cdefinition, - long int *code); + gras_datadesc_type_t **dst); #define GRAS_DEFINE_TYPE(name,def) \ static const char * _gras_this_type_symbol_does_not_exist__##name=#def; def -#define gras_type_symbol_parse(bag,name) \ - _gs_type_parse(bag, _gs_this_type_symbol_does_not_exist__##name) - -#define gs_type_get_by_symbol(bag,name) \ +/*#define gras_type_symbol_parse(name) \ + _gras_datadesc_parse(_gras_this_datadesc_type_symbol_does_not_exist__##name) +*/ +#define gras_datadesc_by_symbol(name) \ (bag->bag_ops->get_type_by_name(bag, NULL, #name) ? \ bag->bag_ops->get_type_by_name(bag, NULL, #name) : \ - gras_type_symbol_parse(bag, name) \ + gras_datadesc_parse(name) \ ) /***************************** @@ -245,11 +212,10 @@ typedef struct DataDescriptorStruct { sizeof(memberType) * repetitions gras_error_t -gras_datadesc_from_nws(const char *name, - const DataDescriptor *desc, - size_t howmany, - long int *code); - +gras_datadesc_import_nws(const char *name, + const DataDescriptor *desc, + size_t howmany, + gras_datadesc_type_t **dst); END_DECL diff --git a/include/gras.h b/include/gras.h index 1b0d8433cd..ce3f387be9 100644 --- a/include/gras.h +++ b/include/gras.h @@ -17,6 +17,8 @@ #define TRUE 1 #define FALSE 0 +#define GRAS_MAX_CHANNEL 10 /* FIXME: killme */ + #include #include @@ -33,7 +35,6 @@ #include #include - #include #include #include diff --git a/include/log.h b/include/log.h index bcd6a0a8b8..716e10ce2c 100644 --- a/include/log.h +++ b/include/log.h @@ -310,13 +310,13 @@ extern gras_log_appender_t *gras_log_default_appender; #define CINFO5(c, f,a1,a2,a3,a4,a5) CLOG5(c, gras_log_priority_info, f,a1,a2,a3,a4,a5) #define CINFO6(c, f,a1,a2,a3,a4,a5,a6) CLOG6(c, gras_log_priority_info, f,a1,a2,a3,a4,a5,a6) -#define CWARNING0(c, f) CLOG0(c, gras_log_priority_warning, f) -#define CWARNING1(c, f,a1) CLOG1(c, gras_log_priority_warning, f,a1) -#define CWARNING2(c, f,a1,a2) CLOG2(c, gras_log_priority_warning, f,a1,a2) -#define CWARNING3(c, f,a1,a2,a3) CLOG3(c, gras_log_priority_warning, f,a1,a2,a3) -#define CWARNING4(c, f,a1,a2,a3,a4) CLOG4(c, gras_log_priority_warning, f,a1,a2,a3,a4) -#define CWARNING5(c, f,a1,a2,a3,a4,a5) CLOG5(c, gras_log_priority_warning, f,a1,a2,a3,a4,a5) -#define CWARNING6(c, f,a1,a2,a3,a4,a5,a6) CLOG6(c, gras_log_priority_warning, f,a1,a2,a3,a4,a5,a6) +#define CWARN0(c, f) CLOG0(c, gras_log_priority_warning, f) +#define CWARN1(c, f,a1) CLOG1(c, gras_log_priority_warning, f,a1) +#define CWARN2(c, f,a1,a2) CLOG2(c, gras_log_priority_warning, f,a1,a2) +#define CWARN3(c, f,a1,a2,a3) CLOG3(c, gras_log_priority_warning, f,a1,a2,a3) +#define CWARN4(c, f,a1,a2,a3,a4) CLOG4(c, gras_log_priority_warning, f,a1,a2,a3,a4) +#define CWARN5(c, f,a1,a2,a3,a4,a5) CLOG5(c, gras_log_priority_warning, f,a1,a2,a3,a4,a5) +#define CWARN6(c, f,a1,a2,a3,a4,a5,a6) CLOG6(c, gras_log_priority_warning, f,a1,a2,a3,a4,a5,a6) #define CERROR0(c, f) CLOG0(c, gras_log_priority_error, f) #define CERROR1(c, f,a1) CLOG1(c, gras_log_priority_error, f,a1) @@ -446,7 +446,7 @@ extern gras_log_appender_t *gras_log_default_appender; #define INFO6(f,a1,a2,a3,a4,a5,a6) LOG6(gras_log_priority_info, f,a1,a2,a3,a4,a5,a6) /** - * WARNING6: + * WARN6: * @f: the format string * @a1: first argument of the format * @a2: second argument of the format @@ -457,18 +457,18 @@ extern gras_log_appender_t *gras_log_default_appender; * * Log something to the current default category under the warning priority. * - * The macros WARNING0 ... WARNING5 naturally also exist, but are not listed here + * The macros WARN0 ... WARN5 naturally also exist, but are not listed here * for sake of clarity. They just differ in the number of arguments passed * along with the format string. */ -#define WARNING0(f) LOG0(gras_log_priority_warning, f) -#define WARNING1(f,a1) LOG1(gras_log_priority_warning, f,a1) -#define WARNING2(f,a1,a2) LOG2(gras_log_priority_warning, f,a1,a2) -#define WARNING3(f,a1,a2,a3) LOG3(gras_log_priority_warning, f,a1,a2,a3) -#define WARNING4(f,a1,a2,a3,a4) LOG4(gras_log_priority_warning, f,a1,a2,a3,a4) -#define WARNING5(f,a1,a2,a3,a4,a5) LOG5(gras_log_priority_warning, f,a1,a2,a3,a4,a5) -#define WARNING6(f,a1,a2,a3,a4,a5,a6) LOG6(gras_log_priority_warning, f,a1,a2,a3,a4,a5,a6) +#define WARN0(f) LOG0(gras_log_priority_warning, f) +#define WARN1(f,a1) LOG1(gras_log_priority_warning, f,a1) +#define WARN2(f,a1,a2) LOG2(gras_log_priority_warning, f,a1,a2) +#define WARN3(f,a1,a2,a3) LOG3(gras_log_priority_warning, f,a1,a2,a3) +#define WARN4(f,a1,a2,a3,a4) LOG4(gras_log_priority_warning, f,a1,a2,a3,a4) +#define WARN5(f,a1,a2,a3,a4,a5) LOG5(gras_log_priority_warning, f,a1,a2,a3,a4,a5) +#define WARN6(f,a1,a2,a3,a4,a5,a6) LOG6(gras_log_priority_warning, f,a1,a2,a3,a4,a5,a6) /** * ERROR6: diff --git a/include/messages.h b/include/messages.h index 598886da40..9f62356c6d 100644 --- a/include/messages.h +++ b/include/messages.h @@ -1,21 +1,18 @@ /* $Id$ */ -/* gras/messages.h - Public interface to GRAS messages */ +/* messaging - high level communication (send/receive messages) */ + +/* module's public interface exported to end user. */ /* Authors: Martin Quinson */ -/* Copyright (C) 2003,2004 Martin Quinson. */ +/* Copyright (C) 2003, 2004 Martin Quinson. */ /* This program is free software; you can redistribute it and/or modify it under the terms of the license (GNU LGPL) which comes with this package. */ -#ifndef GRAS_MSG_H -#define GRAS_MSG_H - -#include /* offsetof() */ -#include /* size_t */ -#include - +#ifndef GRAS_MESSAGES_H +#define GRAS_MESSAGES_H /*! C++ users need love */ #ifndef BEGIN_DECL @@ -38,128 +35,28 @@ BEGIN_DECL -typedef unsigned int gras_msgid_t; -typedef struct gras_msgheader_s gras_msgheader_t; -typedef struct gras_msgentry_s gras_msgentry_t; - -/** - * A message sent or received to/from the network - * - * Do not mess with the content of this structure. Only access it through the following functions: - * @gras_msg_new() or @gras_msg_copy() to create such struct. - * @gras_msg_free() to get ride of it. - * @gras_msg_ctn() to read its content. - * - */ -typedef struct { - /* public */ - gras_socket_t *sock; /** the socket on which the message was received (to answer) */ - - /* private */ - gras_msgheader_t *header; - gras_msgentry_t *entry; - unsigned int *dataCount; - void **data; - e_gras_free_directive_t freeDirective; -} gras_msg_t; - -/** - * gras_msgtype_register: - * @msgId: identificator of such messages - * @name: name as it should be used for logging messages - * @sequence_count: number of groups in variadics - * @Varargs: List of (const DataDescriptor *, int DDcount), describing the - * elements in each sequence (DDlength is the length of the corresponding - * DataDescriptor). - * @Returns: the error code (or no_error). - * - * Registers a message to the GRAS mecanism. - */ -gras_error_t -gras_msgtype_register(gras_msgid_t msgId, - const char *name, - int sequence_count, - ...); - -/** - * gras_msg_new_and_send: - * @sd: Socket on which the message should be sent - * @msgId: identificator this messages - * @Varargs: List of (void **data, int seqLen) forming the payload of the message. - * The number of sequences is given by the registration of ht - * @Returns: the error code (or no_error). - * - * Create a new message, and send it on the network through the given socket. - */ -gras_error_t -gras_msg_new_and_send(gras_socket_t *sd, - gras_msgid_t msgId, - int seqCount, - ...); - - -/** - * gras_msg_new: - * @msgId: identificator this messages - * @free_data_on_free: boolean indicating wheater the data must be freed when the msg get freed. - * @seqCount: number of sequences in this message (must be the same than the value - * registered using gras_msgtype_register() for that msgId) - * @Varargs: List of (void **data, int seqLen) forming the payload of the message. - * The number of sequences is given by the registration of ht - * @Returns: the message built or NULL on error - * - * Build a message to be sent - */ - -gras_msg_t *gras_msg_new(gras_msgid_t msgId, - e_gras_free_directive_t free_data_on_free, - int seqCount, - ...); - -/** - * gras_msg_new_va: - * - * Build a new message in the exact same way than gras_msg_new(), but taking its arguments as - * variadic ones. - */ -gras_msg_t *gras_msg_new_va(gras_msgid_t msgId, - e_gras_free_directive_t free_data, - int seqCount, - va_list ap); - -/** - * gras_msg_copy: - * @msg: original to copy. - * - * Copy a message. - */ +/* msgtype declaration and retrival */ +typedef struct s_gras_msgtype gras_msgtype_t; -gras_msg_t *gras_msg_copy(gras_msg_t *msg); +gras_error_t gras_msgtype_declare (const char *name, + gras_datadesc_type_t *payload, + gras_msgtype_t **dst); +gras_error_t gras_msgtype_declare_v(const char *name, + short int version, + gras_datadesc_type_t *payload, + gras_msgtype_t **dst); -/** - * gras_msg_free: - * @msg: poor guy going to diediedie. - * - * Free a msg built with gras_msg_new(). - */ -void gras_msg_free(gras_msg_t *msg); +gras_error_t gras_msgtype_by_name (const char *name, + gras_msgtype_t **dst); +gras_error_t gras_msgtype_by_namev(const char *name, + short int version, + gras_msgtype_t **dst); -/** - * gras_msg_ctn: - * @msg: the carrier of the data - * @sequence: Sequence in which you want to see the data. - * @num: Number in this sequence of the element to access. - * @type: type of the element to access. - * - * Access to the content of a message. - */ -#define gras_msg_ctn(msg,sequence,num,type) \ - ((type *)msg->data[sequence])[num] /** * gras_cb_t: * @msg: The message itself - * @Returns: true if the message was accepted by the callback and false if it should be passed to the next one. + * @Returns: true if the message was consumed by the callback. * * Type of message callback functions. Once a such a function is registered to * handle messages of a given type with RegisterCallback(), it will be called @@ -167,71 +64,24 @@ void gras_msg_free(gras_msg_t *msg); * * If the callback accepts the message, it should free it after use. */ - -typedef int (*gras_cb_t)(gras_msg_t *msg); - -/** - * gras_cb_register: - * @message: id of the concerned messages - * @TTL: How many time should this callback be used - * @cb: The callback. - * @Returns: the error code (or no_error). - * - * Indicates a desire that the function #cb# be called whenever a - * #message# message comes in. - * #TTL# is how many time this callback should be used. After that, this - * callback will be unregistred. If <0, the callback will never be unregistered. - * (ie, it will be permanent) - */ -gras_error_t -gras_cb_register(gras_msgid_t message, - int TTL, - gras_cb_t cb); - -/** - * gras_msg_handle: - * @timeOut: How long to wait for incoming messages - * @Returns: the error code (or no_error). - * - * Waits up to #timeOut# seconds to see if a message comes in; if so, calls the - * registered listener for that message (see RegisterCallback()). - */ +typedef int (*gras_cb_t)(gras_socket_t *expeditor, + gras_datadesc_type_t *payload_type, + void *payload_data); +gras_error_t gras_cb_register (gras_msgtype_t *msgtype, + gras_cb_t cb); +void gras_cb_unregister(gras_msgtype_t *msgtype, + gras_cb_t cb); + +gras_error_t gras_msg_send(gras_socket_t *sock, + gras_msgtype_t *msgtype, + void *payload); +gras_error_t gras_msg_wait(double timeout, + gras_msgtype_t *msgt_want, + gras_socket_t **expeditor, + void **payload); gras_error_t gras_msg_handle(double timeOut); -/** - * gras_msg_send: - * @sd: Socket to write on - * @msg: to send (build it with @gras_msg_new()) - * @freeDirective: if the msg passed as argument should be gras_msg_free'ed after sending. - * @Returns: the error code (or no_error). - * - * Sends the message on the socket sd using an automatic and adaptative timeout. - */ - -gras_error_t -gras_msg_send(gras_socket_t *sd, - gras_msg_t *msg, - e_gras_free_directive_t freeDirective); - -/** - * gras_msg_wait: - * @timeout: How long should we wait for this message. - * @id: id of awaited msg - * @message: where to store the message when it comes. - * @Returns: the error code (or no_error). - * - * Waits for a message to come in over a given socket. - * - * Every message of another type received before the one waited will be queued - * and used by subsequent call to this function or MsgHandle(). - */ -gras_error_t -gras_msg_wait(double timeout, - gras_msgid_t id, - gras_msg_t **message); - - END_DECL #endif /* GRAS_MSG_H */ diff --git a/include/module.h b/include/module.h index d97da11e3b..0dfb6faea0 100644 --- a/include/module.h +++ b/include/module.h @@ -16,7 +16,7 @@ typedef struct gras_module_ gras_module_t; typedef gras_module_t (*gras_module_new_fct_t)(int argc, char **argv); typedef int (*gras_module_finalize_fct_t)(void); -void gras_init(int argc,char **argv); -void gras_init_defaultlog(int argc,char **argv, const char *defaultlog); +void gras_init(int *argc,char **argv); +void gras_init_defaultlog(int *argc,char **argv, const char *defaultlog); void gras_exit(void); #endif /* _GRAS_MODULE_H */ diff --git a/include/modules/base.h b/include/modules/base.h index 856cd0f14a..0f300f590a 100644 --- a/include/modules/base.h +++ b/include/modules/base.h @@ -83,7 +83,7 @@ static const DataDescriptor msgResultDesc[] = * on localhost's stderr. */ void -grasRepportError (gras_socket_t *sock, gras_msgid_t id, int SeqCount, +grasRepportError (gras_socket_t *sock, int id, int SeqCount, const char *severeError, gras_error_t errcode, const char* format,...); diff --git a/include/transport.h b/include/transport.h index ad0a1bd70c..0a67d63652 100644 --- a/include/transport.h +++ b/include/transport.h @@ -22,6 +22,10 @@ gras_error_t gras_socket_server(unsigned short port, /* OUT */ gras_socket_t **dst); void gras_socket_close(gras_socket_t **sd); +/* get information about socket */ +int gras_socket_my_port (gras_socket_t *sock); +int gras_socket_peer_port(gras_socket_t *sock); +char *gras_socket_peer_name(gras_socket_t *sock); /* debuging functions */ gras_error_t gras_socket_client_from_file(const char*path, diff --git a/src/gras/Common/gras.c b/src/gras/Common/gras.c deleted file mode 100644 index cfa9d34ecd..0000000000 --- a/src/gras/Common/gras.c +++ /dev/null @@ -1,111 +0,0 @@ -/* $Id$ */ - -/* gras.c - common parts for the Grid Reality And Simulation */ - -/* Authors: Martin Quinson */ -/* Copyright (C) 2003 the OURAGAN project. */ - -/* This program is free software; you can redistribute it and/or modify it - under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "gras_private.h" - -/**************************************************************************/ -/**************************************************************************/ -/* Lock handling */ -/**************************************************************************/ -/**************************************************************************/ - -#ifdef HAVE_LIBPTHREAD -#include - -/* this is the lock for this module. Every other module will use a void * - * as a variable as mutex. */ -pthread_mutex_t gras_thelock = PTHREAD_MUTEX_INITIALIZER; -#endif - -int -gras_lock() { - //fprintf(stderr,"Get Lock... "); -#ifdef HAVE_LIBPTHREAD - int ret; - - ret = pthread_mutex_lock((pthread_mutex_t *)(&gras_thelock)); - if (ret != 0) { - fprintf(stderr, "gras_lock: Unable to lock (errno = %d)!\n", ret); - return 0; - } -#endif - //fprintf(stderr,"ok\n"); - return 1; -} - -int -gras_unlock() { - - // fprintf(stderr,"Release Lock... "); -#ifdef HAVE_LIBPTHREAD - int ret; - - ret = pthread_mutex_unlock((pthread_mutex_t *)&gras_thelock); - if (ret != 0) { - fprintf(stderr, "grasReleaseLock: Unable to release lock (errno = %d)!\n", ret); - return 0; - } -#endif - //fprintf(stderr,"ok\n"); - return 1; -} - -/* ************************************************************************** - * Manipulating Callback list - * **************************************************************************/ -gras_cblist_t *gras_cb_get(gras_msgid_t id) { - grasProcessData_t *pd=grasProcessDataGet(); - int i; - - for (i=0 ; igrasCblListLen && pd->grasCblList[i].id != id ; i++); - return i==pd->grasCblListLen ? NULL : &(pd->grasCblList[i]); -} - -gras_error_t gras_cb_create(gras_msgid_t message) { - grasProcessData_t *pd=grasProcessDataGet(); - - if (pd->grasCblListLen++) { - pd->grasCblList = (gras_cblist_t *)realloc(pd->grasCblList, - sizeof(gras_cblist_t)*pd->grasCblListLen); - } else { - pd->grasCblList = (gras_cblist_t *)malloc(sizeof(gras_cblist_t)* - pd->grasCblListLen); - } - if (!pd->grasCblList) { - fprintf(stderr,"PANIC: Malloc error (All callbacks for all hosts are lost)\n"); - pd->grasCblListLen=0; - return malloc_error; - } - - pd->grasCblList[pd->grasCblListLen-1].id=message; - - pd->grasCblList[pd->grasCblListLen-1].cbCount=0; - pd->grasCblList[pd->grasCblListLen-1].cb=NULL; - pd->grasCblList[pd->grasCblListLen-1].cbTTL=NULL; - - return no_error; -} - -/* ************************************************************************** - * Manipulating User Data - * **************************************************************************/ -void *gras_userdata_get(void) { - grasProcessData_t *pd=grasProcessDataGet(); - - return pd ? pd->userdata : NULL; -} - -void *gras_userdata_set(void *ud) { - grasProcessData_t *pd=grasProcessDataGet(); - - ASSERT(pd,"ProcessData==NULL => This process did not run grasInit()\n"); - return pd->userdata=ud; -} - diff --git a/src/gras/Common/gras_datadesc.c b/src/gras/Common/gras_datadesc.c deleted file mode 100644 index 18e13a8627..0000000000 --- a/src/gras/Common/gras_datadesc.c +++ /dev/null @@ -1,82 +0,0 @@ -/* $Id$ */ - -/* gras_datadesc.c - manipulating datadescriptors */ - -/* Authors: Martin Quinson */ -/* Copyright (C) 2003 the OURAGAN project. */ - -/* This program is free software; you can redistribute it and/or modify it - under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "gras_private.h" - -void *gras_datadesc_copy_data(const DataDescriptor *dd, unsigned int c, - void *data) { - size_t s=DataSize(dd,c,HOST_FORMAT); - void *res=malloc(s); - - if (!res) { - fprintf(stderr,"grasDataDescCpyData: malloc of %d bytes failed.\n",s); - return NULL; - } - - memcpy(res,data,s); - - return data; -} - -int gras_datadesc_cmp(const DataDescriptor *dd1, unsigned int c1, - const DataDescriptor *dd2, unsigned int c2) { - unsigned int i; - int subcmp; - - if (c1 != c2) - return c1 < c2; - - if (!dd1 && !dd2) return 0; - if (!dd1 || !dd2) return 1; - - for (i=0;iname = strdup(name); res->name_len = strlen(name); - res->pre = NULL; - res->post = NULL; + TRY(gras_set_add(gras_datadesc_set_local, + (gras_set_elm_t*)res,&gras_ddt_freev)); + *dst=res; return no_error; } /** - * gras_ddt_new_scalar: + * gras_datadesc_by_name: + * + * Retrieve a type from its name + */ +gras_error_t gras_datadesc_by_name(const char *name, + gras_datadesc_type_t **type) { + return gras_set_get_by_name(gras_datadesc_set_local, + name,(gras_set_elm_t**)type); +} + +/** + * gras_datadesc_by_id: + * + * Retrieve a type from its code + */ +gras_error_t gras_datadesc_by_id(long int code, + gras_datadesc_type_t **type) { + return gras_set_get_by_id(gras_datadesc_set_local, + code,(gras_set_elm_t**)type); +} + +/** + * gras_datadesc_declare_scalar: * * Create a new scalar and give a pointer to it */ gras_error_t -gras_ddt_new_scalar(const char *name, - gras_ddt_scalar_type_t type, - enum e_gras_dd_scalar_encoding encoding, - gras_datadesc_type_cb_void_t cb, - gras_datadesc_type_t **dst) { +gras_datadesc_declare_scalar(const char *name, + gras_ddt_scalar_type_t type, + enum e_gras_dd_scalar_encoding encoding, + gras_datadesc_type_cb_void_t cb, + gras_datadesc_type_t **dst) { gras_error_t errcode; gras_datadesc_type_t *res; @@ -114,15 +151,13 @@ void gras_dd_cat_field_free(void *f) { } /** - * gras_ddt_new_struct: + * gras_datadesc_declare_struct: * * Create a new struct and give a pointer to it */ gras_error_t -gras_ddt_new_struct(const char *name, - gras_datadesc_type_cb_void_t pre, - gras_datadesc_type_cb_void_t post, - gras_datadesc_type_t **dst) { +gras_datadesc_declare_struct(const char *name, + gras_datadesc_type_t **dst) { gras_error_t errcode; gras_datadesc_type_t *res; @@ -140,23 +175,34 @@ gras_ddt_new_struct(const char *name, TRY(gras_dynar_new(&(res->category.struct_data.fields), sizeof(gras_dd_cat_field_t*), &gras_dd_cat_field_free)); - res->pre = pre; - res->post = post; return no_error; } +gras_error_t +gras_datadesc_declare_struct_append_name(gras_datadesc_type_t *struct_type, + const char *name, + const char *field_type_name){ + gras_error_t errcode; + gras_datadesc_type_t *field_type; + + errcode = gras_datadesc_by_name(field_type_name, &field_type); + if (errcode != no_error) { + WARN2("Got error '%s' while looking for '%s'", + gras_error_name(errcode), field_type_name); + return errcode; + } + return gras_datadesc_declare_struct_append(struct_type,name,field_type); +} /** - * gras_ddt_new_struct_append: + * gras_datadesc_declare_struct_append: * * Append a field to the struct */ gras_error_t -gras_ddt_new_struct_append(gras_datadesc_type_t *struct_type, - const char *name, - gras_datadesc_type_t *field_type, - gras_datadesc_type_cb_void_t pre, - gras_datadesc_type_cb_void_t post) { +gras_datadesc_declare_struct_append(gras_datadesc_type_t *struct_type, + const char *name, + gras_datadesc_type_t *field_type) { gras_error_t errcode; gras_dd_cat_field_t *field; @@ -175,8 +221,8 @@ gras_ddt_new_struct_append(gras_datadesc_type_t *struct_type, field->offset[arch] = aligned(struct_type->size[arch], field_type->alignment[arch]); } field->code = field_type->code; - field->pre = pre; - field->post = post; + field->pre = NULL; + field->post = NULL; TRY(gras_dynar_push(struct_type->category.struct_data.fields, &field)); @@ -190,14 +236,13 @@ gras_ddt_new_struct_append(gras_datadesc_type_t *struct_type, } /** - * gras_ddt_new_union: + * gras_datadesc_declare_union: * * Create a new union and give a pointer to it */ gras_error_t -gras_ddt_new_union(const char *name, +gras_datadesc_declare_union(const char *name, gras_datadesc_type_cb_int_t selector, - gras_datadesc_type_cb_void_t post, gras_datadesc_type_t **dst) { gras_error_t errcode; @@ -220,23 +265,19 @@ gras_ddt_new_union(const char *name, sizeof(gras_dd_cat_field_t*), &gras_dd_cat_field_free)); res->category.union_data.selector = selector; - res->pre = NULL; - res->post = post; return no_error; } /** - * gras_ddt_new_union_append: + * gras_datadesc_declare_union_append: * * Append a field to the union */ gras_error_t -gras_ddt_new_union_append(gras_datadesc_type_t *union_type, +gras_datadesc_declare_union_append(gras_datadesc_type_t *union_type, const char *name, - gras_datadesc_type_t *field_type, - gras_datadesc_type_cb_void_t pre, - gras_datadesc_type_cb_void_t post) { + gras_datadesc_type_t *field_type) { gras_error_t errcode; gras_dd_cat_field_t *field; @@ -254,8 +295,8 @@ gras_ddt_new_union_append(gras_datadesc_type_t *union_type, field->offset[arch] = 0; /* that's the purpose of union ;) */ } field->code = field_type->code; - field->pre = pre; - field->post = post; + field->pre = NULL; + field->post = NULL; TRY(gras_dynar_push(union_type->category.union_data.fields, &field)); @@ -269,24 +310,52 @@ gras_ddt_new_union_append(gras_datadesc_type_t *union_type, } /** - * gras_ddt_new_ref: + * gras_datadesc_declare_ref: * - * Create a new ref and give a pointer to it + * Create a new ref to a fixed type and give a pointer to it */ gras_error_t -gras_ddt_new_ref(const char *name, - gras_datadesc_type_t *referenced_type, - gras_datadesc_type_cb_int_t selector, - gras_datadesc_type_cb_void_t post, - gras_datadesc_type_t **dst) { +gras_datadesc_declare_ref(const char *name, + gras_datadesc_type_t *referenced_type, + gras_datadesc_type_t **dst) { gras_error_t errcode; gras_datadesc_type_t *res; gras_datadesc_type_t *pointer_type; int arch; - gras_assert0(selector || referenced_type, - "Attempt to create a generic reference without selector"); + TRY(gras_ddt_new(name,dst)); + res=*dst; + + TRY(gras_datadesc_by_name("data pointer", &pointer_type)); + + for (arch=0; archsize[arch] = pointer_type->size[arch]; + res->alignment[arch] = pointer_type->alignment[arch]; + res->aligned_size[arch] = pointer_type->aligned_size[arch]; + } + + res->category_code = e_gras_datadesc_type_cat_ref; + + res->category.ref_data.code = referenced_type->code; + res->category.ref_data.selector = NULL; + + return no_error; +} +/** + * gras_datadesc_declare_ref_generic: + * + * Create a new ref to a type given at use time, and give a pointer to it + */ +gras_error_t +gras_datadesc_declare_ref_generic(const char *name, + gras_datadesc_type_cb_int_t selector, + gras_datadesc_type_t **dst) { + + gras_error_t errcode; + gras_datadesc_type_t *res; + gras_datadesc_type_t *pointer_type; + int arch; TRY(gras_ddt_new(name,dst)); res=*dst; @@ -301,43 +370,33 @@ gras_ddt_new_ref(const char *name, res->category_code = e_gras_datadesc_type_cat_ref; - res->category.ref_data.code = referenced_type ? referenced_type->code : -1; + res->category.ref_data.code = -1; res->category.ref_data.selector = selector; - res->pre = NULL; - res->post = post; return no_error; } /** - * gras_ddt_new_array: + * gras_datadesc_declare_array_fixed: * * Create a new array and give a pointer to it */ gras_error_t -gras_ddt_new_array(const char *name, - gras_datadesc_type_t *element_type, - long int fixed_size, - gras_datadesc_type_cb_int_t dynamic_size, - gras_datadesc_type_cb_void_t post, - gras_datadesc_type_t **dst) { +gras_datadesc_declare_array_fixed(const char *name, + gras_datadesc_type_t *element_type, + long int fixed_size, + gras_datadesc_type_t **dst) { gras_error_t errcode; gras_datadesc_type_t *res; int arch; - gras_assert0(dynamic_size || fixed_size>0, - "Attempt to create a dynamic array without size discriminant"); - TRY(gras_ddt_new(name,dst)); res=*dst; + gras_assert1(fixed_size > 0, "'%s' is a array of negative fixed size",name); for (arch=0; archsize[arch] = fixed_size; /* make sure it indicates "dynamic" */ - } else { - res->size[arch] = fixed_size * element_type->aligned_size[arch]; - } + res->size[arch] = fixed_size * element_type->aligned_size[arch]; res->alignment[arch] = element_type->alignment[arch]; res->aligned_size[arch] = fixed_size; /*FIXME: That was so in GS, but looks stupid*/ } @@ -345,84 +404,64 @@ gras_ddt_new_array(const char *name, res->category.array_data.code = element_type->code; res->category.array_data.fixed_size = fixed_size; - res->category.array_data.dynamic_size = dynamic_size; - - res->pre = NULL; - res->post = post; + res->category.array_data.dynamic_size = NULL; return no_error; } - /** - * gras_ddt_new_ignored: - * - * Create a new ignored field and give a pointer to it. + * gras_datadesc_declare_array_dyn: * - * If you give a default value, it will be copied away so that you can free your copy. + * Create a new array and give a pointer to it */ gras_error_t -gras_ddt_new_ignored(const char *name, - void *default_value, - void_f_pvoid_t *free_func, - long int size, - long int alignment, - gras_datadesc_type_cb_void_t post, - gras_datadesc_type_t **dst) { - RAISE_UNIMPLEMENTED; - /* +gras_datadesc_declare_array_dyn(const char *name, + gras_datadesc_type_t *element_type, + gras_datadesc_type_cb_int_t dynamic_size, + gras_datadesc_type_t **dst) { + gras_error_t errcode; gras_datadesc_type_t *res; + int arch; + + gras_assert1(dynamic_size, + "'%s' is a dynamic array without size discriminant", + name); TRY(gras_ddt_new(name,dst)); res=*dst; - res->size = size > 0?size:0; - res->alignment = alignment; - - if (size > 0) { - res->aligned_size = aligned(size, alignment); - } else { - res->aligned_size = 0; - } - - if (default_value && res->size) { - res->category.ignored_data.default_value = malloc((size_t)size); - if (! (res->category.ignored_data.default_value) ) - RAISE_MALLOC; - memcpy(res->category.ignored_data.default_value, - default_value, (size_t)size); + for (arch=0; archsize[arch] = -1; /* make sure it indicates "dynamic" */ + res->alignment[arch] = element_type->alignment[arch]; + res->aligned_size[arch] = -1; /*FIXME: That was so in GS, but looks stupid*/ } + res->category_code = e_gras_datadesc_type_cat_array; - res->category_code = e_gras_datadesc_type_cat_ignored; - res->category.ignored_data.free_func = free_func; - - res->post = post; - - - res->size = size; + res->category.array_data.code = element_type->code; + res->category.array_data.fixed_size = -1; + res->category.array_data.dynamic_size = dynamic_size; return no_error; - */ } /** - * gras_ddt_new_parse: + * gras_datadesc_declare_parse: * * Create a datadescription from the result of parsing the C type description */ gras_error_t -gras_ddt_new_parse(const char *name, - const char *C_statement, - gras_datadesc_type_t **dst) { +gras_datadesc_parse(const char *name, + const char *C_statement, + gras_datadesc_type_t **dst) { RAISE_UNIMPLEMENTED; } gras_error_t -gras_ddt_new_from_nws(const char *name, - const DataDescriptor *desc, - size_t howmany, - gras_datadesc_type_t **dst) { +gras_datadesc_import_nws(const char *name, + const DataDescriptor *desc, + size_t howmany, + gras_datadesc_type_t **dst) { RAISE_UNIMPLEMENTED; } @@ -465,3 +504,22 @@ void gras_ddt_free(gras_datadesc_type_t **type) { } } } + +/** + * gras_datadesc_cb_set_pre: + * + * Add a pre-send callback to this datadexc + */ +void gras_datadesc_cb_set_pre (gras_datadesc_type_t *type, + gras_datadesc_type_cb_void_t pre) { + type->pre = pre; +} +/** + * gras_datadesc_cb_set_post: + * + * Add a post-send callback to this datadexc + */ +void gras_datadesc_cb_set_post(gras_datadesc_type_t *type, + gras_datadesc_type_cb_void_t post) { + type->post = post; +} diff --git a/src/gras/DataDesc/ddt_declare.c b/src/gras/DataDesc/ddt_declare.c deleted file mode 100644 index 4001167c33..0000000000 --- a/src/gras/DataDesc/ddt_declare.c +++ /dev/null @@ -1,181 +0,0 @@ -/* $Id$ */ - -/* ddt_declare - user functions to create datatypes on locale machine */ - -/* Authors: Olivier Aumage, Martin Quinson */ -/* Copyright (C) 2003, 2004 the GRAS posse. */ - -/* This program is free software; you can redistribute it and/or modify it - under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "DataDesc/datadesc_private.h" - -gras_error_t -gras_datadesc_declare_struct_cb(const char *name, - gras_datadesc_type_cb_void_t pre, - gras_datadesc_type_cb_void_t post, - long int *code) { - gras_error_t errcode; - gras_datadesc_type_t *type; - TRY(gras_ddt_new_struct(name, pre, post, &type)); - TRY(gras_ddt_register(type)); - *code = type->code; - return no_error; -} - -gras_error_t -gras_datadesc_declare_struct_add_name_cb(long int struct_code, - const char *field_name, - const char *field_type_name, - gras_datadesc_type_cb_void_t pre_cb, - gras_datadesc_type_cb_void_t post_cb) { - - gras_error_t errcode; - gras_datadesc_type_t *struct_type; - gras_datadesc_type_t *field_type; - - TRY(gras_datadesc_by_id(struct_code,&struct_type)); - TRY(gras_datadesc_by_name(field_type_name,&field_type)); - - TRY(gras_ddt_new_struct_append(struct_type, - field_name, field_type, - pre_cb, post_cb)); - - return no_error; -} -gras_error_t -gras_datadesc_declare_struct_add_code_cb(long int struct_code, - const char *field_name, - long int field_code, - gras_datadesc_type_cb_void_t pre_cb, - gras_datadesc_type_cb_void_t post_cb) { - gras_error_t errcode; - gras_datadesc_type_t *struct_type; - gras_datadesc_type_t *field_type; - - TRY(gras_datadesc_by_id(struct_code,&struct_type)); - TRY(gras_datadesc_by_id(field_code, &field_type)); - - TRY(gras_ddt_new_struct_append(struct_type, - field_name, field_type, - pre_cb, post_cb)); - - return no_error; -} - -gras_error_t -gras_datadesc_declare_union_cb(const char *name, - gras_datadesc_type_cb_int_t field_count, - gras_datadesc_type_cb_void_t post, - long int *code) { - gras_error_t errcode; - gras_datadesc_type_t *type; - TRY(gras_ddt_new_union(name, field_count, post, &type)); - TRY(gras_ddt_register(type)); - *code = type->code; - return no_error; -} - -gras_error_t -gras_datadesc_declare_union_add_name_cb(long int union_code, - const char *field_name, - const char *field_type_name, - gras_datadesc_type_cb_void_t pre_cb, - gras_datadesc_type_cb_void_t post_cb) { - gras_error_t errcode; - gras_datadesc_type_t *union_type; - gras_datadesc_type_t *field_type; - - TRY(gras_datadesc_by_id (union_code, &union_type)); - TRY(gras_datadesc_by_name(field_type_name, &field_type)); - - TRY(gras_ddt_new_union_append(union_type, - field_name, field_type, - pre_cb, post_cb)); - - return no_error; -} -gras_error_t -gras_datadesc_declare_union_add_code_cb(long int union_code, - const char *field_name, - long int field_code, - gras_datadesc_type_cb_void_t pre_cb, - gras_datadesc_type_cb_void_t post_cb) { - gras_error_t errcode; - gras_datadesc_type_t *union_type; - gras_datadesc_type_t *field_type; - - TRY(gras_datadesc_by_id(union_code, &union_type)); - TRY(gras_datadesc_by_id(field_code, &field_type)); - - TRY(gras_ddt_new_union_append(union_type, - field_name, field_type, - pre_cb, post_cb)); - - return no_error; -} - -gras_error_t -gras_datadesc_declare_ref_cb(const char *name, - gras_datadesc_type_t *referenced_type, - gras_datadesc_type_cb_int_t discriminant, - gras_datadesc_type_cb_void_t post, - long int *code){ - gras_error_t errcode; - gras_datadesc_type_t *type; - TRY(gras_ddt_new_ref(name, referenced_type,discriminant,post, &type)); - TRY(gras_ddt_register(type)); - *code = type->code; - return no_error; -} - -gras_error_t -gras_datadesc_declare_array_cb(const char *name, - gras_datadesc_type_t *element_type, - long int fixed_size, - gras_datadesc_type_cb_int_t dynamic_size, - gras_datadesc_type_cb_void_t post, - long int *code){ - gras_error_t errcode; - gras_datadesc_type_t *type; - TRY(gras_ddt_new_array(name, element_type, fixed_size, dynamic_size, post, &type)); - TRY(gras_ddt_register(type)); - *code = type->code; - return no_error; -} - -/** - * gras_datadesc_parse: - * - * Parse a C type declaration, and declare locally the corresponding type description - */ -gras_error_t -gras_datadesc_parse(const char *name, - const char *definition, - long int *code) { - gras_error_t errcode; - gras_datadesc_type_t *type; - TRY(gras_ddt_new_parse(name,definition,&type)); - TRY(gras_ddt_register( type)); - *code = type->code; - return no_error; -} - -/** - * gras_datadesc_parse: - * - * Parse a NWS type declaration, and declare locally the corresponding type description - */ -gras_error_t -gras_datadesc_from_nws(const char *name, - const DataDescriptor *desc, - size_t howmany, - long int *code) { - - gras_error_t errcode; - gras_datadesc_type_t *type; - TRY(gras_ddt_new_from_nws(name,desc,howmany,&type)); - TRY(gras_ddt_register(type)); - *code = type->code; - return no_error; -} diff --git a/src/gras/DataDesc/ddt_use.c b/src/gras/DataDesc/ddt_exchange.c similarity index 97% rename from src/gras/DataDesc/ddt_use.c rename to src/gras/DataDesc/ddt_exchange.c index ebad12795c..41b3ac05d9 100644 --- a/src/gras/DataDesc/ddt_use.c +++ b/src/gras/DataDesc/ddt_exchange.c @@ -1,6 +1,6 @@ /* $Id$ */ -/* ddt_use - use of datatypes structs (public) */ +/* ddt_exchange - send/recv data described */ /* Authors: Olivier Aumage, Martin Quinson */ /* Copyright (C) 2003, 2004 the GRAS posse. */ @@ -10,7 +10,7 @@ #include "DataDesc/datadesc_private.h" -GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(use,DataDesc); +GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(exchange,DataDesc); static const char *gras_datadesc_cat_names[9] = { "undefined", @@ -129,23 +129,6 @@ gras_dd_alloc_ref(gras_dict_t *refs, return no_error; } -/** - * gras_datadesc_get_id_from_name: - * Returns: -1 in case of error. - * - * Retrieve the ID of a previously declared datatype from its name. - */ -long int -gras_datadesc_get_id_from_name(const char *name) { - gras_error_t errcode; - gras_datadesc_type_t *type; - - errcode = gras_datadesc_by_name(name,&type); - if (errcode != no_error) - return -1; - return type->code; -} - /** * gras_datadesc_type_cmp: * @@ -685,6 +668,8 @@ gras_datadesc_recv(gras_socket_t *sock, TRY(gras_dict_new(&refs)); TRY(gras_dd_cbps_new(&state)); + if (!dst) + CRITICAL0("Cannot receive data into a NULL pointer!"); if (*dst) VERB0("'*dst' not NULL in datadesc_recv. Data to be copied there without malloc"); diff --git a/src/gras/Makefile.am b/src/gras/Makefile.am index edc7ff43ff..270ac050d3 100644 --- a/src/gras/Makefile.am +++ b/src/gras/Makefile.am @@ -12,7 +12,6 @@ lib_LIBRARIES= libgrasrl.a libgrassg.a # Core/dict_multi.c # Common/gras.c Common/gras_datadesc.c Common/gras_msg.c -# Messaging/messaging.c # Messaging/datadesc_simple.c # Transport/transport_sg.c @@ -31,11 +30,16 @@ COMMON_S=\ Transport/transport_plugin_tcp.c \ Transport/transport_plugin_sg.c \ \ - DataDesc/ddt_create.c DataDesc/ddt_declare.c \ - DataDesc/ddt_remote.c DataDesc/ddt_use.c \ - DataDesc/cbps.c DataDesc/datadesc.c \ - DataDesc/datadesc_interface.h DataDesc/datadesc_private.h + DataDesc/ddt_create.c \ + DataDesc/ddt_convert.c DataDesc/ddt_exchange.c \ + DataDesc/cbps.c DataDesc/datadesc.c \ + DataDesc/datadesc_interface.h DataDesc/datadesc_private.h \ + \ + Msg/msg.c Msg/msg_interface.h Msg/msg_private.h \ + \ + Virtu/process.c +# DataDesc/ddt_declare.c # DataDesc/datadesc.c \ # DataDesc/tools.c \ diff --git a/src/gras/Msg/msg.c b/src/gras/Msg/msg.c new file mode 100644 index 0000000000..4cb483b19e --- /dev/null +++ b/src/gras/Msg/msg.c @@ -0,0 +1,438 @@ +/* $Id$ */ + +/* messaging - Function related to messaging (code shared between RL and SG)*/ + +/* Authors: Martin Quinson */ +/* Copyright (C) 2003 the OURAGAN project. */ + +/* This program is free software; you can redistribute it and/or modify it + under the terms of the license (GNU LGPL) which comes with this package. */ + +#include "Msg/msg_private.h" + +GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(msg,GRAS); + +gras_set_t *_gras_msgtype_set = NULL; +static char GRAS_header[6]; +static char *make_namev(const char *name, short int ver); + +/** + * gras_msg_init: + * + * Initialize this submodule. + */ +void gras_msg_init(void) { + gras_error_t errcode; + + /* only initialize once */ + if (_gras_msgtype_set != NULL) + return; + + VERB0("Initializing Msg"); + + TRYFAIL(gras_set_new(&_gras_msgtype_set)); + + memcpy(GRAS_header,"GRAS", 4); + GRAS_header[4]=GRAS_PROTOCOL_VERSION; + GRAS_header[5]=(char)GRAS_THISARCH; +} + +/** + * gras_msg_exit: + * + * Finalize the msg module + **/ +void +gras_msg_exit(void) { + VERB0("Exiting Msg"); + gras_set_free(&_gras_msgtype_set); + _gras_msgtype_set = NULL; +} + +/** + * gras_msgtype_free: + * + * Reclamed memory + */ +void gras_msgtype_free(void *t) { + gras_msgtype_t *msgtype=(gras_msgtype_t *)t; + if (msgtype) { + free(msgtype->name); + free(msgtype); + } +} + +/** + * make_namev: + * + * Returns the versionned name of the message. If the version is 0, that's + * the name unchanged. Pay attention to this before free'ing the result. + */ +static char *make_namev(const char *name, short int ver) { + char *namev=malloc(strlen(name)+2+3+1); + + if (!ver) + return (char *)name; + + if (namev) { + sprintf(namev,"%s_v%d",name,ver); + } + return namev; +} + +/** + * gras_msgtype_declare: + * @name: name as it should be used for logging messages (must be uniq) + * @payload: datadescription of the payload + * + * Registers a message to the GRAS mecanism. + */ +gras_error_t +gras_msgtype_declare(const char *name, + gras_datadesc_type_t *payload, + gras_msgtype_t **dst) { + return gras_msgtype_declare_v(name, 0, payload, dst); +} + +/** + * gras_msgtype_declare_v: + * @name: name as it should be used for logging messages (must be uniq) + * @version: something like versionning symbol + * @payload: datadescription of the payload + * + * Registers a message to the GRAS mecanism. Use this version instead of + * gras_msgtype_declare when you change the semantic or syntax of a message and + * want your programs to be able to deal with both versions. Internally, each + * will be handled as an independent message type, so you can register + * differents for each of them. + */ +gras_error_t +gras_msgtype_declare_v(const char *name, + short int version, + gras_datadesc_type_t *payload, + gras_msgtype_t **dst) { + + gras_error_t errcode; + gras_msgtype_t *msgtype; + char *namev=make_namev(name,version); + + if (!namev) + RAISE_MALLOC; + + errcode = gras_set_get_by_name(_gras_msgtype_set, + namev,(gras_set_elm_t**)msgtype); + if (errcode == mismatch_error) { + /* create type */ + if (! (msgtype = malloc(sizeof(gras_msgtype_t))) ) + RAISE_MALLOC; + + msgtype->name = (namev == name ? strdup(name) : namev); + msgtype->name_len = strlen(namev); + msgtype->version = version; + msgtype->ctn_type = payload; + + TRY(gras_set_add(_gras_msgtype_set, (gras_set_elm_t*)msgtype, + &gras_msgtype_free)); + + DEBUG2("Register version %d of message '%s'.", version, name); + } else if (errcode == no_error) { /* found */ + if (namev != name) + free(namev); + + gras_assert1(!gras_datadesc_type_cmp(msgtype->ctn_type, payload), + "Message %s registred again with a different payload", + namev); + } else { + if (namev != name) + free(namev); + return errcode; /* Error is set lookup */ + } + + return no_error; +} + +/** + * gras_msgtype_by_name: + * + * Retrieve a datatype description from its name + */ +gras_error_t +gras_msgtype_by_name (const char *name, + gras_msgtype_t **dst) { + return gras_msgtype_by_namev(name,0,dst); +} +/** + * gras_msgtype_by_namev: + * + * Retrieve a datatype description from its name and version + */ +gras_error_t +gras_msgtype_by_namev(const char *name, + short int version, + gras_msgtype_t **dst) { + + gras_error_t errcode; + char *namev = make_namev(name,version); + + TRY(gras_set_get_by_name(_gras_msgtype_set, namev, + (gras_set_elm_t**)dst)); + if (name != namev) + free(namev); + + return no_error; +} + +/** + * gras_msg_send: + * + * Send the given message on the given socket + */ +gras_error_t +gras_msg_send(gras_socket_t *sock, + gras_msgtype_t *msgtype, + void *payload) { + + gras_error_t errcode; + static gras_datadesc_type_t *string_type=NULL; + if (!string_type) + TRY(gras_datadesc_by_name("string", &string_type)); + + TRY(gras_trp_chunk_send(sock, GRAS_header, 6)); + + TRY(gras_datadesc_send(sock, string_type, msgtype->name)); + TRY(gras_datadesc_send(sock, msgtype->ctn_type, payload)); + + return no_error; +} +/** + * gras_msg_recv: + * + * receive the next message on the given socket (which should be dropped + * when the function returns an error) + */ +gras_error_t +gras_msg_recv(gras_socket_t *sock, + gras_msgtype_t **msgtype, + void **payload) { + + gras_error_t errcode; + static gras_datadesc_type_t *string_type=NULL; + char header[6]; + int cpt; + int r_arch; + char *msg_name; + + if (!string_type) + TRY(gras_datadesc_by_name("string", &string_type)); + + TRY(gras_trp_chunk_recv(sock, header, 6)); + for (cpt=0; cpt<4; cpt++) + if (header[cpt] != GRAS_header[cpt]) + RAISE0(mismatch_error,"Incoming bytes do not look like a GRAS message"); + if (header[4] != GRAS_header[4]) + RAISE2(mismatch_error,"GRAS protocol mismatch (got %d, use %d)", + (int)header[4], (int)GRAS_header[4]); + r_arch = (int)header[5]; + + TRY(gras_datadesc_recv(sock, string_type, r_arch,(void**) &msg_name)); + TRY(gras_set_get_by_name(_gras_msgtype_set, + msg_name,(gras_set_elm_t**)msgtype)); + TRY(gras_datadesc_recv(sock, (*msgtype)->ctn_type, r_arch, payload)); + + return no_error; +} + +/** + * gras_msg_wait: + * @timeout: How long should we wait for this message. + * @id: id of awaited msg + * @Returns: the error code (or no_error). + * + * Waits for a message to come in over a given socket. + * + * Every message of another type received before the one waited will be queued + * and used by subsequent call to this function or MsgHandle(). + */ +gras_error_t +gras_msg_wait(double timeout, + gras_msgtype_t *msgt_want, + gras_socket_t **expeditor, + void **payload) { + + gras_msgtype_t *msgt_got; + gras_error_t errcode; + double start, now; + gras_procdata_t *pd=gras_procdata_get(); + int cpt; + gras_msg_t msg; + + *expeditor = NULL; + *payload = NULL; + + VERB1("Waiting for message %s",msgt_want->name); + + start = now = gras_time(); + + gras_dynar_foreach(pd->msg_queue,cpt,msg){ + if (msg.type->code == msgt_want->code) { + *expeditor = msg.expeditor; + *payload = msg.payload; + gras_dynar_cursor_rm(pd->msg_queue, &cpt); + VERB0("Waited message was queued"); + return no_error; + } + } + + while (1) { + TRY(gras_trp_select(timeout - now + start, expeditor)); + TRY(gras_msg_recv(*expeditor, &msgt_got, payload)); + if (msgt_got->code == msgt_want->code) { + VERB0("Got waited message"); + return no_error; + } + + /* not expected msg type. Queue it for later */ + msg.expeditor = *expeditor; + msg.type = msgt_got; + msg.payload = *payload; + TRY(gras_dynar_push(pd->msg_queue,&msg)); + + now=gras_time(); + if (now - start + 0.001 < timeout) { + RAISE1(timeout_error,"Timeout while waiting for msg %s",msgt_want->name); + } + } + + RAISE_IMPOSSIBLE; +} + +/** + * gras_msg_handle: + * @timeOut: How long to wait for incoming messages + * @Returns: the error code (or no_error). + * + * Waits up to #timeOut# seconds to see if a message comes in; if so, calls the + * registered listener for that message (see RegisterCallback()). + */ +gras_error_t +gras_msg_handle(double timeOut) { + + gras_error_t errcode; + int cpt; + + gras_msg_t msg; + gras_socket_t *expeditor; + void *payload; + gras_msgtype_t *msgtype; + + gras_procdata_t*pd=gras_procdata_get(); + gras_cblist_t *list; + gras_cb_t cb; + + + + VERB1("Handling message within the next %.2s",timeOut); + + /* get a message (from the queue or from the net) */ + if (gras_dynar_length(pd->msg_queue)) { + gras_dynar_shift(pd->msg_queue,&msg); + expeditor = msg.expeditor; + msgtype = msg.type; + payload = msg.payload; + + } else { + TRY(gras_trp_select(timeOut, &expeditor)); + TRY(gras_msg_recv(expeditor, &msgtype, &payload)); + } + + /* handle it */ + gras_dynar_foreach(pd->cbl_list,cpt,list) { + if (list->id == msgtype->code) { + break; + } else { + list=NULL; + } + } + if (!list) { + INFO1("Unexpected message '%s' ignored", msgtype->name); + WARN0("FIXME: gras_datadesc_free not implemented => leaking the payload"); + return no_error; + } + + gras_dynar_foreach(list->cbs,cpt,cb) { + if (cb(expeditor,msgtype->ctn_type,payload)) { + /* cb handled the message */ + return no_error; + } + } + + INFO1("Message '%s' refused by all registered callbacks", msgtype->name); + WARN0("FIXME: gras_datadesc_free not implemented => leaking the payload"); + return mismatch_error; +} + +gras_error_t +gras_cb_register(gras_msgtype_t *msgtype, + gras_cb_t cb) { + gras_error_t errcode; + gras_procdata_t *pd=gras_procdata_get(); + gras_cblist_t *list; + int cpt; + + /* search the list of cb for this message on this host (creating if NULL) */ + gras_dynar_foreach(pd->cbl_list,cpt,list) { + if (list->id == msgtype->code) { + break; + } else { + list=NULL; + } + } + if (!list) { + /* First cb? Create room */ + list = malloc(sizeof(gras_cblist_t)); + if (!list) + RAISE_MALLOC; + + list->id = msgtype->code; + TRY(gras_dynar_new(&(list->cbs), sizeof(gras_cb_t), NULL)); + TRY(gras_dynar_push(pd->cbl_list,&list)); + } + + /* Insert the new one into the set */ + TRY(gras_dynar_insert_at(list->cbs,0,cb)); + + return no_error; +} + +void +gras_cb_unregister(gras_msgtype_t *msgtype, + gras_cb_t cb) { + + gras_procdata_t *pd=gras_procdata_get(); + gras_cblist_t *list; + gras_cb_t cb_cpt; + int cpt; + int found = 0; + + /* search the list of cb for this message on this host */ + gras_dynar_foreach(pd->cbl_list,cpt,list) { + if (list->id == msgtype->code) { + break; + } else { + list=NULL; + } + } + + /* Remove it from the set */ + if (list) { + gras_dynar_foreach(list->cbs,cpt,cb_cpt) { + if (cb == cb_cpt) { + gras_dynar_cursor_rm(list->cbs, &cpt); + found = 1; + } + } + } + if (!found) + VERB1("Ignoring removal of unexisting callback to msg id %d", + msgtype->code); +} diff --git a/src/gras/Msg/msg_interface.h b/src/gras/Msg/msg_interface.h new file mode 100644 index 0000000000..c04cb16a58 --- /dev/null +++ b/src/gras/Msg/msg_interface.h @@ -0,0 +1,35 @@ +/* $Id$ */ + +/* messaging - high level communication (send/receive messages) */ + +/* module's public interface exported within GRAS, but not to end user. */ + +/* Authors: Martin Quinson */ +/* Copyright (C) 2003, 2004 Martin Quinson. */ + +/* This program is free software; you can redistribute it and/or modify it + under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef GRAS_MSG_INTERFACE_H +#define GRAS_MSG_INTERFACE_H + +void gras_msg_init(void); +void gras_msg_exit(void); + + +/* gras_msg_t is dereferenced to be stored in procdata, living in Virtu */ +typedef struct { + gras_socket_t *expeditor; + gras_msgtype_t *type; + void *payload; +} gras_msg_t; + +gras_error_t gras_msg_send_namev(gras_socket_t *sock, + const char *namev, + void *payload); + +#define GRAS_PROTOCOL_VERSION '\0'; + +typedef struct s_gras_cblist gras_cblist_t; + +#endif /* GRAS_MSG_INTERFACE_H */ diff --git a/src/gras/Msg/msg_private.h b/src/gras/Msg/msg_private.h new file mode 100644 index 0000000000..b233e1c606 --- /dev/null +++ b/src/gras/Msg/msg_private.h @@ -0,0 +1,56 @@ +/* $Id$ */ + +/* messaging - high level communication (send/receive messages) */ + +/* module's private interface masked even to other parts of GRAS. */ + +/* Authors: Martin Quinson */ +/* Copyright (C) 2003, 2004 Martin Quinson. */ + +/* This program is free software; you can redistribute it and/or modify it + under the terms of the license (GNU LGPL) which comes with this package. */ + +#ifndef GRAS_MESSAGE_PRIVATE_H +#define GRAS_MESSAGE_PRIVATE_H + +#include "gras_private.h" +#include "Msg/msg_interface.h" + +/** + * gras_msgtype_t: + * + * Message type descriptor. There one of these for each registered version. + */ +struct s_gras_msgtype { + /* headers for the data set */ + unsigned int code; + char *name; + unsigned int name_len; + + /* payload */ + short int version; + gras_datadesc_type_t *ctn_type; +}; + +extern gras_set_t *_gras_msgtype_set; /* of gras_msgtype_t */ +void gras_msgtype_free(void *msgtype); + + +gras_error_t gras_msg_recv(gras_socket_t *sock, + gras_msgtype_t **msgtype, + void **payload); + + +/** + * gras_cblist_t: + * + * association between msg ID and cb list for a given process + */ +struct s_gras_cblist { + long int id; + gras_dynar_t *cbs; /* of gras_msg_cb_t */ +}; + +void gras_cblist_free(void *cbl); + +#endif /* GRAS_MESSAGE_PRIVATE_H */ diff --git a/src/gras/Transport/rl_transport.c b/src/gras/Transport/rl_transport.c index 5069c428c5..279e4b3fdb 100644 --- a/src/gras/Transport/rl_transport.c +++ b/src/gras/Transport/rl_transport.c @@ -72,7 +72,7 @@ gras_trp_select(double timeout, /* we cannot have more than FD_SETSIZE sockets */ if (++max_fds > FD_SETSIZE) { - WARNING0("too many open sockets."); + WARN0("too many open sockets."); done = 0; break; } @@ -139,7 +139,7 @@ gras_trp_select(double timeout, recvd = recv(sock_iter->sd, &lookahead, 1, MSG_PEEK); if (recvd < 0) { - WARNING2("socket %d failed: %s", sock_iter->sd, strerror(errno)); + WARN2("socket %d failed: %s", sock_iter->sd, strerror(errno)); /* done with this socket */ gras_socket_close(&sock_iter); cursor--; diff --git a/src/gras/Transport/transport.c b/src/gras/Transport/transport.c index 4b5d45a78e..45c05316b8 100644 --- a/src/gras/Transport/transport.c +++ b/src/gras/Transport/transport.c @@ -9,7 +9,6 @@ under the terms of the license (GNU LGPL) which comes with this package. */ #include /* time() */ -//#include #include "Transport/transport_private.h" @@ -213,7 +212,7 @@ void gras_socket_close(gras_socket_t **sock) { return; } } - WARNING0("Ignoring request to free an unknown socket"); + WARN0("Ignoring request to free an unknown socket"); } } @@ -259,3 +258,12 @@ gras_trp_plugin_get_by_name(const char *name, return gras_dict_retrieve(_gras_trp_plugins,name,(void**)dst); } +int gras_socket_my_port (gras_socket_t *sock) { + return sock->port; +} +int gras_socket_peer_port(gras_socket_t *sock) { + return sock->peer_port; +} +char *gras_socket_peer_name(gras_socket_t *sock) { + return sock->peer_name; +} diff --git a/src/gras/Transport/transport_plugin_file.c b/src/gras/Transport/transport_plugin_file.c index bb3a4c345d..8bbb94253e 100644 --- a/src/gras/Transport/transport_plugin_file.c +++ b/src/gras/Transport/transport_plugin_file.c @@ -203,7 +203,7 @@ void gras_trp_file_close(gras_socket_t *sock){ /* close the socket */ if(close(sock->sd) < 0) { - WARNING2("error while closing file %d: %s", + WARN2("error while closing file %d: %s", sock->sd, strerror(errno)); } } diff --git a/src/gras/Transport/transport_plugin_tcp.c b/src/gras/Transport/transport_plugin_tcp.c index 3d0cd1625a..87009473c9 100644 --- a/src/gras/Transport/transport_plugin_tcp.c +++ b/src/gras/Transport/transport_plugin_tcp.c @@ -221,7 +221,7 @@ gras_trp_tcp_socket_accept(gras_socket_t *sock, if (setsockopt(sd, SOL_SOCKET, SO_KEEPALIVE, (char *)&i, s) || setsockopt(sd, TcpProtoNumber(), TCP_NODELAY, (char *)&i, s)) { - WARNING0("setsockopt failed, cannot condition the accepted socket"); + WARN0("setsockopt failed, cannot condition the accepted socket"); } /* FIXME: bufSize removed until we can have optionsets @@ -292,7 +292,7 @@ void gras_trp_tcp_socket_close(gras_socket_t *sock){ /* close the socket */ if(close(sock->sd) < 0) { - WARNING3("error while closing tcp socket %d: %d (%s)\n", + WARN3("error while closing tcp socket %d: %d (%s)\n", sock->sd, errno, strerror(errno)); } } diff --git a/src/gras/Virtu/process.c b/src/gras/Virtu/process.c new file mode 100644 index 0000000000..93475bf8a6 --- /dev/null +++ b/src/gras/Virtu/process.c @@ -0,0 +1,39 @@ +/* $Id$ */ + +/* process - GRAS process handling (common code for RL and SG) */ + +/* Authors: Martin Quinson */ +/* Copyright (C) 2003,2004 da GRAS posse. */ + +/* This program is free software; you can redistribute it and/or modify it + under the terms of the license (GNU LGPL) which comes with this package. */ + +#include "gras_private.h" +#include "Virtu/virtu_interface.h" + + +/* ************************************************************************** + * Process data + * **************************************************************************/ +void *gras_userdata_get(void) { + gras_procdata_t *pd=gras_procdata_get(); + return pd->userdata; +} + +void *gras_userdata_set(void *ud) { + gras_procdata_t *pd=gras_procdata_get(); + + pd->userdata = ud; + + return pd->userdata; +} + +gras_error_t +gras_procdata_init() { + gras_error_t errcode; + gras_procdata_t *pd=gras_procdata_get(); + pd->userdata = NULL; + TRY(gras_dynar_new( &(pd->msg_queue), sizeof(gras_msg_t), NULL )); + TRY(gras_dynar_new( &(pd->cbl_list), sizeof(gras_cblist_t *), NULL )); + return no_error; +} diff --git a/src/gras/Virtu/rl_process.c b/src/gras/Virtu/rl_process.c index 10066a6957..359c220e65 100644 --- a/src/gras/Virtu/rl_process.c +++ b/src/gras/Virtu/rl_process.c @@ -13,25 +13,19 @@ GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(process,GRAS); /* globals */ -static gras_process_data_t *_gras_process_data; +static gras_procdata_t *_gras_procdata = NULL; gras_error_t gras_process_init() { - // gras_error_t errcode; + gras_error_t errcode; - if (!(_gras_process_data=(gras_process_data_t *)malloc(sizeof(gras_process_data_t)))) + if (!(_gras_procdata=(gras_procdata_t *)malloc(sizeof(gras_procdata_t)))) RAISE_MALLOC; - WARNING0("Implement message queue"); - /* - TRY(gras_dynar_new( &(_gras_process_data->msg_queue) )); - TRY(gras_dynar_new( &(_gras_process_data->cbl_list) )); - */ - - _gras_process_data->userdata = NULL; + TRY(gras_procdata_init()); return no_error; } gras_error_t gras_process_exit() { - WARNING0("FIXME: not implemented (=> leaking on exit :)"); + WARN0("FIXME: not implemented (=> leaking on exit :)"); return no_error; } @@ -39,11 +33,8 @@ gras_error_t gras_process_exit() { * Process data * **************************************************************************/ -void *gras_userdata_get(void) { - return _gras_process_data->userdata; -} +gras_procdata_t *gras_procdata_get(void) { + gras_assert0(_gras_procdata,"Run gras_process_init!"); -void *gras_userdata_set(void *ud) { - _gras_process_data->userdata = ud; - return ud; + return _gras_procdata; } diff --git a/src/gras/Virtu/sg_process.c b/src/gras/Virtu/sg_process.c index 243093bf3b..ae0056dc35 100644 --- a/src/gras/Virtu/sg_process.c +++ b/src/gras/Virtu/sg_process.c @@ -14,25 +14,18 @@ GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(process,GRAS); gras_error_t gras_process_init() { + gras_error_t errcode; gras_hostdata_t *hd=(gras_hostdata_t *)MSG_host_get_data(MSG_host_self()); - gras_process_data_t *pd; + gras_procdata_t *pd; int i; - if (!(pd=(gras_process_data_t *)malloc(sizeof(gras_process_data_t)))) + if (!(pd=(gras_procdata_t *)malloc(sizeof(gras_procdata_t)))) RAISE_MALLOC; - WARNING0("Implement msg queue"); - /* - pd->grasMsgQueueLen=0; - pd->grasMsgQueue = NULL; - - pd->grasCblListLen = 0; - pd->grasCblList = NULL; - */ - if (MSG_process_set_data(MSG_process_self(),(void*)pd) != MSG_OK) { return unknown_error; } + TRY(gras_procdata_init()); if (!hd) { if (!(hd=(gras_hostdata_t *)malloc(sizeof(gras_hostdata_t)))) @@ -79,7 +72,7 @@ gras_process_init() { gras_error_t gras_process_exit() { gras_hostdata_t *hd=(gras_hostdata_t *)MSG_host_get_data(MSG_host_self()); - gras_process_data_t *pd=(gras_process_data_t *)MSG_process_get_data(MSG_process_self()); + gras_procdata_t *pd=(gras_procdata_t *)MSG_process_get_data(MSG_process_self()); int myPID=MSG_process_self_PID(); int i; @@ -88,12 +81,8 @@ gras_process_exit() { INFO2("GRAS: Finalizing process '%s' (%d)", MSG_process_get_name(MSG_process_self()),MSG_process_self_PID()); - WARNING0("Implement msg queue"); - /* - if (pd->grasMsgQueueLen) { - fprintf(stderr,"GRAS: Warning: process %d terminated, but some queued messages where not handled\n",MSG_process_self_PID()); - } - */ + if (gras_dynar_length(pd->msg_queue)) + WARN1("process %d terminated, but some queued messages where not handled",MSG_process_self_PID()); for (i=0; i< GRAS_MAX_CHANNEL; i++) if (myPID == hd->proc[i]) @@ -115,20 +104,11 @@ gras_process_exit() { * Process data * **************************************************************************/ -void *gras_userdata_get(void) { - gras_process_data_t *pd=(gras_process_data_t *)MSG_process_get_data(MSG_process_self()); +gras_procdata_t *gras_procdata_get(void) { + gras_procdata_t *pd=(gras_procdata_t *)MSG_process_get_data(MSG_process_self()); gras_assert0(pd,"Run gras_process_init!"); - return pd->userdata; + return pd; } -void *gras_userdata_set(void *ud) { - gras_process_data_t *pd=(gras_process_data_t *)MSG_process_get_data(MSG_process_self()); - - gras_assert0(pd,"Run gras_process_init!"); - - pd->userdata = ud; - - return pd->userdata; -} diff --git a/src/gras/Virtu/virtu_interface.h b/src/gras/Virtu/virtu_interface.h index f4fd3f9e61..170e9990a2 100644 --- a/src/gras/Virtu/virtu_interface.h +++ b/src/gras/Virtu/virtu_interface.h @@ -19,8 +19,7 @@ * Data for each process */ typedef struct { - /* queue of messages which where received but not wanted in msgWait, and therefore - temporarly queued until the next msgHandle */ + /*queue of msgs storing the ones got while msg_wait'ing for something else */ gras_dynar_t *msg_queue; /* elm type: gras_msg_t */ /* registered callbacks for each message */ @@ -34,7 +33,9 @@ typedef struct { /* globals of the process */ void *userdata; -} gras_process_data_t; - +} gras_procdata_t; +/* FIXME: mv to _private? */ +gras_procdata_t *gras_procdata_get(void); +gras_error_t gras_procdata_init(void); #endif /* GRAS_VIRTU_INTERFACE_H */ diff --git a/src/gras/gras_private.h b/src/gras/gras_private.h index 23b88e1989..7b691a7852 100644 --- a/src/gras/gras_private.h +++ b/src/gras/gras_private.h @@ -22,6 +22,8 @@ #define TRUE 1 #define FALSE 0 +#define GRAS_MAX_CHANNEL 10 /* FIXME: killme */ + #include "gras_config.h" #include "gras/error.h" @@ -42,7 +44,7 @@ #include "gras/datadesc.h" #include "DataDesc/datadesc_interface.h" #include "gras/messages.h" -#include "Messaging/messaging_interface.h" +#include "Msg/msg_interface.h" #include "Virtu/virtu_interface.h" diff --git a/src/xbt/config.c b/src/xbt/config.c index f74b84824f..b10cd74bdc 100644 --- a/src/xbt/config.c +++ b/src/xbt/config.c @@ -221,7 +221,7 @@ gras_cfg_register(gras_cfg_t *cfg, TRYCATCH(mismatch_error,gras_dict_retrieve((gras_dict_t*)cfg,name,(void**)&res)); if (errcode != mismatch_error) { - WARNING1("Config elem %s registered twice.",name); + WARN1("Config elem %s registered twice.",name); /* Will be removed by the insertion of the new one */ } @@ -956,7 +956,7 @@ gras_cfg_get_int (gras_cfg_t *cfg, TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_int,&cell)); if (gras_dynar_length(cell->content) > 1) { - WARNING2("You asked for the first value of the config element '%s', but there is %d values\n", + WARN2("You asked for the first value of the config element '%s', but there is %d values\n", name, gras_dynar_length(cell->content)); } @@ -987,7 +987,7 @@ gras_cfg_get_double(gras_cfg_t *cfg, TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_double,&cell)); if (gras_dynar_length(cell->content) > 1) { - WARNING2("You asked for the first value of the config element '%s', but there is %d values\n", + WARN2("You asked for the first value of the config element '%s', but there is %d values\n", name, gras_dynar_length(cell->content)); } @@ -1020,7 +1020,7 @@ gras_error_t gras_cfg_get_string(gras_cfg_t *cfg, TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_string,&cell)); if (gras_dynar_length(cell->content) > 1) { - WARNING2("You asked for the first value of the config element '%s', but there is %d values\n", + WARN2("You asked for the first value of the config element '%s', but there is %d values\n", name, gras_dynar_length(cell->content)); } @@ -1054,7 +1054,7 @@ gras_error_t gras_cfg_get_host (gras_cfg_t *cfg, TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_host,&cell)); if (gras_dynar_length(cell->content) > 1) { - WARNING2("You asked for the first value of the config element '%s', but there is %d values\n", + WARN2("You asked for the first value of the config element '%s', but there is %d values\n", name, gras_dynar_length(cell->content)); } diff --git a/src/xbt/module.c b/src/xbt/module.c index 290488eb66..5391c310b0 100644 --- a/src/xbt/module.c +++ b/src/xbt/module.c @@ -23,7 +23,7 @@ struct gras_module_ { }; void -gras_init(int argc, char **argv) { +gras_init(int *argc, char **argv) { gras_init_defaultlog(argc, argv, NULL); } @@ -35,8 +35,8 @@ gras_init(int argc, char **argv) { * Initialize the gras mecanisms. */ void -gras_init_defaultlog(int argc,char **argv, const char *defaultlog) { - int i; +gras_init_defaultlog(int *argc,char **argv, const char *defaultlog) { + int i,j; char *opt; gras_error_t errcode; int found=0; @@ -44,12 +44,20 @@ gras_init_defaultlog(int argc,char **argv, const char *defaultlog) { INFO0("Initialize GRAS"); /** Set logs and init log submodule */ - for (i=1; i -#include -#include -#include - -/* structs */ -struct list { - int v; - struct list *l; -}; - -struct s_pair { - int *pa; - int *pb; -}; - -struct s_mixed { - unsigned char c1; - unsigned long int l1; - unsigned char c2; - unsigned long int l2; -}; - -/* prototypes */ -void disp_l(struct list *l); -long int -string_size_callback(void *vars, - struct s_gs_type *p_type, - void *data); - -/* local functions */ -void -disp_l(struct list *l) { - if (l) { - printf("%d ", l->v); - disp_l(l->l); - } -} - -long int -string_size_callback(void *vars, - struct s_gs_type *p_type, - void *data) { - return 1+(long int)strlen(data); -} - -/* main */ -int -main(int argc, char **argv) { - struct list **pl = NULL; - int *array = NULL; - struct s_pair *p_pair = NULL; - char *str = NULL; - // struct s_mixed *mixed = NULL; - - struct s_gs_type_driver *t_driver = NULL; - struct s_gs_net_driver *n_driver = NULL; - struct s_gs_type_bag *bag = NULL; - struct s_gs_connection *cnx = NULL; - - struct s_gs_type_bag_ops *bag_ops = NULL; - - struct s_gs_type *t_signed_int = NULL; - struct s_gs_type *t_list = NULL; - struct s_gs_type *t_ref_list = NULL; - - struct s_gs_type *t_array = NULL; - - struct s_gs_type *t_ref_sint = NULL; - struct s_gs_type *t_pair = NULL; - - struct s_gs_type *t_char = NULL; - struct s_gs_type *t_string = NULL; - - struct s_gs_type *t_u_char = NULL; - struct s_gs_type *t_u_long_int = NULL; - struct s_gs_type *t_mixed = NULL; - - struct s_gs_message_instance *mi = NULL; - - gs_init(argc, argv); - gs_purge_cmd_line(&argc, argv); - - t_driver = gs_type_driver_init("rl"); - n_driver = gs_net_driver_init("fd"); - - bag = gs_type_bag_alloc(t_driver); - bag_ops = bag->bag_ops; - - { - int fd = 0; - cnx = gs_net_connection_accept(n_driver, &fd); - } - - bag_ops->register_incoming_connection(bag, cnx); - - /* sequence 1 */ - t_signed_int = bag_ops->get_type_by_name(bag, NULL, "signed int"); - t_list = gs_type_new_struct(bag, NULL, "list"); - t_ref_list = gs_type_new_ref(bag, NULL, "p_list", t_list); - - gs_type_struct_append_field(t_list, "v", t_signed_int); - gs_type_struct_append_field(t_list, "l", t_ref_list); - - /* sequence 2 */ - t_array = gs_type_new_array(bag, NULL, "array", 5, t_signed_int); - - /* sequence 3 */ - t_ref_sint = gs_type_new_ref(bag, NULL, "p_ref_sint", t_signed_int); - t_pair = gs_type_new_struct(bag, NULL, "pair"); - - gs_type_struct_append_field(t_pair, "pa", t_ref_sint); - gs_type_struct_append_field(t_pair, "pb", t_ref_sint); - - /* sequence 4 */ - t_char = bag_ops->get_type_by_name(bag, NULL, "signed char"); - t_string = gs_type_new_array_with_callback(bag, NULL, "string", -1, t_char, string_size_callback, NULL); - - /* sequence 5 */ - t_u_char = bag_ops->get_type_by_name(bag, NULL, "unsigned char"); - t_u_long_int = bag_ops->get_type_by_name(bag, NULL, "unsigned long int"); - t_mixed = gs_type_new_struct(bag, NULL, "mixed"); - - gs_type_struct_append_field(t_mixed, "c1", t_u_char); - gs_type_struct_append_field(t_mixed, "l1", t_u_long_int); - gs_type_struct_append_field(t_mixed, "c2", t_u_char); - gs_type_struct_append_field(t_mixed, "l2", t_u_long_int); - - /* message receive */ - mi = gs_message_init_receive(bag, cnx); - fprintf(stderr, "\nreceiving sequence 1\n----------------\n"); - pl = gs_message_receive_next_sequence(mi); - - printf("( "); - disp_l(*pl); - printf(")\n"); - - fprintf(stderr, "\nreceiving sequence 2\n----------------\n"); - array = gs_message_receive_next_sequence(mi); - - { - int i = 0; - for (i = 0; i < 5; i++) { - printf("array[%d] = %d\n", i, array[i]); - } - } - - fprintf(stderr, "\nreceiving sequence 3\n----------------\n"); - p_pair = gs_message_receive_next_sequence(mi); - printf("pair.pa = %p, *pair.pa = %d\n", (*p_pair).pa, *((*p_pair).pa)); - printf("pair.pb = %p, *pair.pb = %d\n", (*p_pair).pb, *((*p_pair).pb)); - - fprintf(stderr, "\nreceiving sequence 4\n----------------\n"); - str = gs_message_receive_next_sequence(mi); - printf("str = %s\n", str); - - /* - fprintf(stderr, "\nreceiving sequence 5\n----------------\n"); - mixed = gs_message_receive_next_sequence(mi); - printf("c1=%c c2=%c; l1=%ld l2=%ld\n", - mixed->c1, mixed->c2, mixed->l1, mixed->l2); - */ - gs_exit(); - - return 0; -} diff --git a/testsuite/gras/gs_example_send.c b/testsuite/gras/gs_example_send.c deleted file mode 100644 index 9ec9bfe291..0000000000 --- a/testsuite/gras/gs_example_send.c +++ /dev/null @@ -1,201 +0,0 @@ -/* gs_example_send */ - -#include -#include -#include -#include - -#undef PARSING - -/* structs */ -struct list { - int v; - struct list *l; -}; - -struct s_pair { - int *pa; - int *pb; -}; - -#ifdef PARSING -GRAS_DEFINE_TYPE(struct_s_mixed, - struct s_mixed { - unsigned char c1; - unsigned long int l1; - unsigned char c2; - unsigned long int l2; - } -); -#else - struct s_mixed { - unsigned char c1; - unsigned long int l1; - unsigned char c2; - unsigned long int l2; - }; -#endif - -/* prototypes */ -struct list * cons(int v, struct list *l); -long int -string_size_callback(void *vars, - struct s_gs_type *p_type, - void *data); - -/* local functions */ -struct list * -cons(int v, struct list *l) { - struct list *nl = malloc(sizeof (struct list)); - - nl->v = v; - nl->l = l; - - return nl; -} - -long int -string_size_callback(void *vars, - struct s_gs_type *p_type, - void *data) { - return 1+(long int)strlen(data); -} - -void parse_log_opt(int argc, char **argv,const char *deft); - -/* main */ -int -main(int argc, char **argv) { - struct list *l = NULL; - - struct s_pair pair; - - int array[5] = - { - 11, 12, 13, 14, 15, - }; - /* - struct s_mixed mixed = - { - 'a',1.0,'b',2.0 - }; - */ - struct s_gs_type_driver *t_driver = NULL; - struct s_gs_net_driver *n_driver = NULL; - struct s_gs_type_bag *bag = NULL; - struct s_gs_connection *cnx = NULL; - - struct s_gs_type_bag_ops *bag_ops = NULL; - - struct s_gs_type *t_signed_int = NULL; - struct s_gs_type *t_list = NULL; - struct s_gs_type *t_ref_list = NULL; - - struct s_gs_type *t_array = NULL; - - struct s_gs_type *t_ref_sint = NULL; - struct s_gs_type *t_pair = NULL; - - struct s_gs_type *t_char = NULL; - struct s_gs_type *t_string = NULL; - -#ifndef PARSING - struct s_gs_type *t_u_char = NULL; - struct s_gs_type *t_u_long_int = NULL; -#endif - - struct s_gs_type *t_mixed = NULL; - - struct s_gs_message *m = NULL; - struct s_gs_message_instance *mi = NULL; - - - parse_log_opt(argc,argv,"datadesc.thresh=debug"); - gs_init(argc, argv); - gs_purge_cmd_line(&argc, argv); - gras_log_control_set("NDR.thresh=debug"); - - t_driver = gs_type_driver_init("rl"); - n_driver = gs_net_driver_init("fd"); - - bag = gs_type_bag_alloc(t_driver); - bag_ops = bag->bag_ops; - - { - int fd = 1; - cnx = gs_net_connection_connect(n_driver, &fd); - } - - bag_ops->register_outgoing_connection(bag, cnx); - - /* sequence 1 */ - t_signed_int = bag_ops->get_type_by_name(bag, NULL, "signed int"); - t_list = gs_type_new_struct(bag, NULL, "list"); - t_ref_list = gs_type_new_ref(bag, NULL, "p_list", t_list); - - gs_type_struct_append_field(t_list, "v", t_signed_int); - gs_type_struct_append_field(t_list, "l", t_ref_list); - - /* sequence 2 */ - t_array = gs_type_new_array(bag, NULL, "array", 5, t_signed_int); - - /* sequence 3 */ - t_ref_sint = gs_type_new_ref(bag, NULL, "p_ref_sint", t_signed_int); - t_pair = gs_type_new_struct(bag, NULL, "pair"); - - gs_type_struct_append_field(t_pair, "pa", t_ref_sint); - gs_type_struct_append_field(t_pair, "pb", t_ref_sint); - - /* sequence 4 */ - t_char = bag_ops->get_type_by_name(bag, NULL, "signed char"); - t_string = gs_type_new_array_with_callback(bag, NULL, "string", -1, t_char, string_size_callback, NULL); - - /* sequence 5 */ -#ifdef PARSING - t_mixed = gs_type_get_by_symbol(bag,struct_s_mixed); -#else - t_u_char = bag_ops->get_type_by_name(bag, NULL, "unsigned char"); - t_u_long_int = bag_ops->get_type_by_name(bag, NULL, "unsigned long int"); - t_mixed = gs_type_new_struct(bag, NULL, "s_mixed"); - - gs_type_struct_append_field(t_mixed, "c1", t_u_char); - gs_type_struct_append_field(t_mixed, "l1", t_u_long_int); - gs_type_struct_append_field(t_mixed, "c2", t_u_char); - gs_type_struct_append_field(t_mixed, "l2", t_u_long_int); -#endif - - /* message declaration */ - m = gs_message_new(bag, NULL, "my msg"); - gs_message_append_new_sequence(m, t_ref_list); - gs_message_append_new_sequence(m, t_array); - gs_message_append_new_sequence(m, t_pair); - gs_message_append_new_sequence(m, t_string); - gs_message_append_new_sequence(m, t_mixed); - - /* data setup */ - l = cons (1, l); - l = cons (2, l); - l = cons (3, l); - - pair.pa = malloc(sizeof(int)); - pair.pb = pair.pa; - *(pair.pa) = 17; - - /* message send */ - mi = gs_message_init_send_by_name(bag, cnx, "my msg"); - fprintf(stderr, "\nsending sequence 1\n----------------\n"); - gs_message_send_next_sequence(mi, &l); - fprintf(stderr, "\nsending sequence 2\n----------------\n"); - gs_message_send_next_sequence(mi, (void*)array); - fprintf(stderr, "\nsending sequence 3\n----------------\n"); - gs_message_send_next_sequence(mi, &pair); - fprintf(stderr, "\nsending sequence 4\n----------------\n"); - gs_message_send_next_sequence(mi, (void*)"Hello, World"); - /* - fprintf(stderr, "\nsending sequence 5\n----------------\n"); - gs_message_send_next_sequence(mi, (void*)&mixed); - */ - gs_exit(); - - return 0; -} diff --git a/testsuite/gras/trp_file_client.c b/testsuite/gras/trp_file_client.c index 2504954d38..e458aa7686 100644 --- a/testsuite/gras/trp_file_client.c +++ b/testsuite/gras/trp_file_client.c @@ -19,7 +19,7 @@ int main(int argc,char *argv[]) { gras_error_t errcode; char data_send[256]; - gras_init_defaultlog(argc,argv,"trp.thresh=debug"); + gras_init_defaultlog(&argc,argv,"trp.thresh=debug"); fprintf(stderr,"===[CLIENT]=== Contact the server\n"); TRYFAIL(gras_socket_client_from_file("-",&sock)); @@ -30,5 +30,7 @@ int main(int argc,char *argv[]) { fprintf(stderr,"===[CLIENT]=== Exiting successfully\n"); gras_socket_close(&sock); + + gras_exit(); return 0; } diff --git a/testsuite/gras/trp_file_server.c b/testsuite/gras/trp_file_server.c index e1bfb99a92..3ac4e0cd65 100644 --- a/testsuite/gras/trp_file_server.c +++ b/testsuite/gras/trp_file_server.c @@ -19,7 +19,7 @@ int main(int argc,char *argv[]) { gras_error_t errcode; char data_recv[256]; - gras_init_defaultlog(argc,argv,"trp.thresh=debug"); + gras_init_defaultlog(&argc,argv,"trp.thresh=debug"); fprintf(stderr,"===[SERVER]=== Create the socket\n"); TRYFAIL(gras_socket_server_from_file("-",&sock)); @@ -34,5 +34,6 @@ int main(int argc,char *argv[]) { fprintf(stderr,"===[SERVER]=== Exiting successfully\n"); gras_socket_close(&sock); + gras_exit(); return 0; } diff --git a/testsuite/gras/trp_tcp_client.c b/testsuite/gras/trp_tcp_client.c index 671e283fcd..bddff1a8dc 100644 --- a/testsuite/gras/trp_tcp_client.c +++ b/testsuite/gras/trp_tcp_client.c @@ -20,7 +20,7 @@ int main(int argc,char *argv[]) { char data_send[256]; char data_recv[256]; - gras_init_defaultlog(argc,argv,"trp.thresh=debug"); + gras_init_defaultlog(&argc,argv,"trp.thresh=debug"); fprintf(stderr,"===[CLIENT]=== Contact the server\n"); TRYFAIL(gras_socket_client(NULL,55555,&sock)); @@ -39,5 +39,7 @@ int main(int argc,char *argv[]) { fprintf(stderr,"===[CLIENT]=== Exiting successfully\n"); gras_socket_close(&sock); + + gras_exit(); return 0; } diff --git a/testsuite/gras/trp_tcp_server.c b/testsuite/gras/trp_tcp_server.c index 7c33b4723f..a67bb45a00 100644 --- a/testsuite/gras/trp_tcp_server.c +++ b/testsuite/gras/trp_tcp_server.c @@ -19,7 +19,7 @@ int main(int argc,char *argv[]) { gras_error_t errcode; char data_recv[256]; - gras_init_defaultlog(argc,argv,"trp.thresh=debug"); + gras_init_defaultlog(&argc,argv,"trp.thresh=debug"); fprintf(stderr,"===[SERVER]=== Create the socket\n"); TRYFAIL(gras_socket_server(55555,&sock)); @@ -36,5 +36,6 @@ int main(int argc,char *argv[]) { fprintf(stderr,"===[SERVER]=== Exiting successfully\n"); gras_socket_close(&sock); + gras_exit(); return 0; } diff --git a/testsuite/xbt/config_usage.c b/testsuite/xbt/config_usage.c index ab6f278074..793afd2871 100644 --- a/testsuite/xbt/config_usage.c +++ b/testsuite/xbt/config_usage.c @@ -53,7 +53,7 @@ int main(int argc, char **argv) { gras_cfg_t *set; int ival; - gras_init_defaultlog(argc,argv,"config.thresh=debug root.thresh=info"); + gras_init_defaultlog(&argc,argv,"config.thresh=debug root.thresh=info"); fprintf(stderr,"==== Alloc and free a config set.\n"); set=make_set(); @@ -87,6 +87,7 @@ int main(int argc, char **argv) { "Count: 3; Options:\\nmquinson\\necaron\\nfsuter"); test5(); + gras_exit(); return 0; } diff --git a/testsuite/xbt/dict_crash.c b/testsuite/xbt/dict_crash.c index 0139085c44..82ddc2e411 100644 --- a/testsuite/xbt/dict_crash.c +++ b/testsuite/xbt/dict_crash.c @@ -55,7 +55,7 @@ int main(int argc,char **argv) { char *key; void *data; - gras_init_defaultlog(argc,argv,"dict.thresh=verbose"); + gras_init_defaultlog(&argc,argv,"dict.thresh=verbose"); srand((unsigned int)time(NULL)); printf("Dictionnary: CRASH test:\n"); @@ -149,5 +149,7 @@ int main(int argc,char **argv) { printf("\n Free the structure (twice)\n"); gras_dict_free(&head); gras_dict_free(&head); + + gras_exit(); return 0; } diff --git a/testsuite/xbt/dict_usage.c b/testsuite/xbt/dict_usage.c index 72542d6f3c..1c7a11d3a9 100644 --- a/testsuite/xbt/dict_usage.c +++ b/testsuite/xbt/dict_usage.c @@ -101,7 +101,7 @@ int main(int argc,char **argv) { gras_dict_t *head=NULL; char *data; - gras_init_defaultlog(argc,argv,"dict.thresh=verbose"); + gras_init_defaultlog(&argc,argv,"dict.thresh=verbose"); printf("\nGeneric dictionnary: USAGE test:\n"); diff --git a/testsuite/xbt/dynar_double.c b/testsuite/xbt/dynar_double.c index 1acaeb0328..e5005fe315 100644 --- a/testsuite/xbt/dynar_double.c +++ b/testsuite/xbt/dynar_double.c @@ -17,7 +17,7 @@ int main(int argc,char *argv[]) { int cpt,cursor; double d1,d2; - gras_init_defaultlog(argc,argv,"dynar.thresh=debug"); + gras_init_defaultlog(&argc,argv,"dynar.thresh=debug"); fprintf(stderr,"==== Traverse the empty dynar\n"); TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL)); diff --git a/testsuite/xbt/dynar_int.c b/testsuite/xbt/dynar_int.c index 70d3529ae4..aa8b8fe430 100644 --- a/testsuite/xbt/dynar_int.c +++ b/testsuite/xbt/dynar_int.c @@ -19,7 +19,7 @@ int main(int argc,char *argv[]) { gras_error_t errcode; int i,cpt,cursor; - gras_init_defaultlog(argc,argv,"dynar.thresh=debug"); + gras_init_defaultlog(&argc,argv,"dynar.thresh=debug"); fprintf(stderr,"==== Traverse the empty dynar\n"); TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL)); @@ -167,5 +167,6 @@ int main(int argc,char *argv[]) { } gras_dynar_free(d); + gras_exit(); return 0; } diff --git a/testsuite/xbt/dynar_string.c b/testsuite/xbt/dynar_string.c index 48522cbb7b..6651a4648a 100644 --- a/testsuite/xbt/dynar_string.c +++ b/testsuite/xbt/dynar_string.c @@ -27,7 +27,7 @@ int main(int argc,char *argv[]) { char buf[1024]; char *s1,*s2; - gras_init_defaultlog(argc,argv,"dynar.thresh=debug"); + gras_init_defaultlog(&argc,argv,"dynar.thresh=debug"); fprintf(stderr,"==== Traverse the empty dynar\n"); TRYFAIL(gras_dynar_new(&d,sizeof(char *),&free_string)); @@ -174,5 +174,6 @@ int main(int argc,char *argv[]) { } gras_dynar_free(d); + gras_exit(); return 0; } diff --git a/testsuite/xbt/log_usage.c b/testsuite/xbt/log_usage.c index e2a277ab36..26679d4c1d 100644 --- a/testsuite/xbt/log_usage.c +++ b/testsuite/xbt/log_usage.c @@ -41,10 +41,10 @@ GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(Test, Top); GRAS_LOG_NEW_CATEGORY(Top); int main(int argc, char **argv) { - gras_init_defaultlog(argc,argv,"root.thresh=debug log.thresh=debug"); + gras_init_defaultlog(&argc,argv,"root.thresh=debug log.thresh=debug"); DEBUG1("val=%d", 1); - WARNING1("val=%d", 2); + WARN1("val=%d", 2); CDEBUG2(Top, "val=%d%s", 3, "!"); CRITICAL6("false alarm%s%s%s%s%s%s", "","","","","","!"); diff --git a/testsuite/xbt/multidict_crash.c b/testsuite/xbt/multidict_crash.c index 0f7e5f0d11..5aec582afb 100644 --- a/testsuite/xbt/multidict_crash.c +++ b/testsuite/xbt/multidict_crash.c @@ -80,18 +80,12 @@ static gras_error_t test1() { return no_error; } -int main() { +int main(int argc, char *argv[]) { gras_error_t errcode; - TRY(gras_log_control_set("root.thresh=debug")); - /* - //DirectDiagnostics(DIAGDEBUG, stdout); - DirectDiagnostics(DIAGINFO, stdout); - // DirectDiagnostics(DIAGLOG, stdout); - DirectDiagnostics(DIAGWARN, stderr); - DirectDiagnostics(DIAGERROR, stderr); - DirectDiagnostics(DIAGFATAL, stderr); - */ + gras_init(argc,argv,"root.thresh=debug")); TRYFAIL(test1()); + + gras_exit(); return 0; } diff --git a/testsuite/xbt/set_usage.c b/testsuite/xbt/set_usage.c index e9eecddd86..6eed1e7f8b 100644 --- a/testsuite/xbt/set_usage.c +++ b/testsuite/xbt/set_usage.c @@ -166,7 +166,7 @@ int main(int argc,char **argv) { gras_set_t *set=NULL; my_elem_t *elm; - gras_init_defaultlog(argc,argv,"set.thresh=verbose"); + gras_init_defaultlog(&argc,argv,"set.thresh=verbose"); printf("\nData set: USAGE test:\n"); @@ -235,5 +235,6 @@ int main(int argc,char **argv) { printf(" - Traverse the resulting data set\n"); TRYFAIL(traverse(set)); + gras_exit(); return 0; } -- 2.20.1