if test "x$enable_compile_warnings" = "xyes"; then
warnCFLAGS=`echo $warnCFLAGS -Wmissing-prototypes -Wmissing-declarations \
-Wpointer-arith -Wchar-subscripts -Wcomment -Wformat -Wwrite-strings \
- -Wno-unused-variable -Wno-unused-function -Wno-unused-label \
+ -Wno-unused-function \
-Werror \
| sed 's/ +/ /g'`
+ # -Wno-unused-variable -Wno-unused-label
fi
fi
AC_MSG_RESULT($warnCFLAGS)
int sensor (int argc,char *argv[]);
int sensor (int argc,char *argv[]) {
- xbt_error_t errcode;
sensor_data_t g;
gras_init(&argc, argv);
g=gras_userdata_new(s_sensor_data_t);
amok_bw_init();
- if ((errcode=gras_socket_server(atoi(argv[1]),&(g->sock)))) {
- ERROR1("Error %s encountered while opening the server socket",xbt_error_name(errcode));
- return 1;
- }
+ g->sock=gras_socket_server(atoi(argv[1]));
g->done = 0;
gras_msgtype_declare("quit",NULL);
gras_cb_register(gras_msgtype_by_name("quit"),&sensor_cb_quit);
- while (! g->done ) {
- errcode=gras_msg_handle(60.0);
- if (errcode != no_error) {
- ERROR1("Error '%s' while handling message",xbt_error_name(errcode));
- return errcode;
- }
- }
+ while (! g->done )
+ gras_msg_handle(60.0);
gras_socket_close(g->sock);
return 0;
int maestro (int argc,char *argv[]);
int maestro(int argc,char *argv[]) {
- xbt_error_t errcode;
maestro_data_t g;
double sec, bw;
int buf_size=32;
/* wait to ensure that all server sockets are there before starting the experiment */
gras_os_sleep(0.5);
- if ((errcode=gras_socket_client(argv[1],atoi(argv[2]),&peer))) {
- ERROR3("Unable to connect to my peer on %s:%s. Got %s",
- argv[1],argv[2],xbt_error_name(errcode));
- return 1;
- }
+ peer = gras_socket_client(argv[1],atoi(argv[2]));
INFO0("Test the BW between me and one of the sensors");
- TRYOLD(amok_bw_test(peer,buf_size,exp_size,msg_size,&sec,&bw));
+ amok_bw_test(peer,buf_size,exp_size,msg_size,&sec,&bw);
INFO6("Experience between me and %s:%d (%d kb in msgs of %d kb) took %f sec, achieving %f kb/s",
argv[1],atoi(argv[2]),
exp_size,msg_size,
sec,bw);
INFO0("Test the BW between the two sensors");
- TRYOLD(amok_bw_request(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
- buf_size,exp_size,msg_size,&sec,&bw));
+ amok_bw_request(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
+ buf_size,exp_size,msg_size,&sec,&bw);
INFO2("Experience took took %f sec, achieving %f kb/s",
sec,bw);
/* ask sensors to quit */
gras_msgtype_declare("quit",NULL);
- TRYOLD(gras_msg_send(peer,gras_msgtype_by_name("quit"), NULL));
+ gras_msg_send(peer,gras_msgtype_by_name("quit"), NULL);
gras_socket_close(peer);
- TRYOLD(gras_socket_client(argv[3],atoi(argv[4]),&peer));
- TRYOLD(gras_msg_send(peer,gras_msgtype_by_name("quit"), NULL));
+
+ peer = gras_socket_client(argv[3],atoi(argv[4]));
+ gras_msg_send(peer,gras_msgtype_by_name("quit"), NULL);
gras_socket_close(peer);
gras_socket_close(g->sock);
static int server_cb_ping_handler(gras_socket_t expeditor,
void *payload_data) {
- xbt_error_t errcode;
+ xbt_ex_t e;
/* 1. Get the payload into the msg variable */
int msg=*(int*)payload_data;
/* 4. Change the value of the msg variable */
msg = 4321;
/* 5. Send it back as payload of a pong message to the expeditor */
- errcode = gras_msg_send(expeditor, gras_msgtype_by_name("pong"), &msg);
+ TRY {
+ gras_msg_send(expeditor, gras_msgtype_by_name("pong"), &msg);
- /* 6. Deal with errors */
- if (errcode != no_error) {
- ERROR1("Unable answer with PONG: %s\n", xbt_error_name(errcode));
+ /* 6. Deal with errors: add some details to the exception */
+ } CATCH(e) {
gras_socket_close(globals->sock);
- return 1;
+ RETHROW0("Unable answer with PONG: %s");
}
INFO0(">>>>>>>> Answered with PONG(4321) <<<<<<<<");
} /* end_of_server_cb_ping_handler */
int server (int argc,char *argv[]) {
- xbt_error_t errcode;
server_data_t *globals;
int port = 4000;
INFO1("Launch server (port=%d)", port);
/* 3. Create my master socket */
- if ((errcode=gras_socket_server(port,&(globals->sock)))) {
- CRITICAL1("Error %s encountered while opening the server socket",
- xbt_error_name(errcode));
- return 1;
- }
+ globals->sock = gras_socket_server(port);
/* 4. Register the known messages. This function is called twice here, but it's because
this file also acts as regression test, no need to do so yourself of course. */
globals->endcondition=0;
/* 6. Wait up to 10 minutes for an incomming message to handle */
- errcode = gras_msg_handle(600.0);
+ gras_msg_handle(600.0);
/* 7. Housekeeping */
- if (errcode != no_error)
- return errcode;
if (!globals->endcondition)
WARN0("An error occured, the endcondition was not set by the callback");
/* Function prototypes */
int client(int argc,char *argv[]) {
- xbt_error_t errcode;
+ xbt_ex_t e;
gras_socket_t toserver; /* peer */
gras_socket_t from;
gras_os_sleep(1);
/* 4. Create a socket to speak to the server */
- if ((errcode=gras_socket_client(host,port,&toserver))) {
- ERROR1("Unable to connect to the server. Got %s",
- xbt_error_name(errcode));
- return 1;
+ TRY {
+ toserver=gras_socket_client(host,port);
+ } CATCH(e) {
+ RETHROW0("Unable to connect to the server: %s");
}
INFO2("Connected to %s:%d.",host,port);
/* 7. Prepare and send the ping message to the server */
ping = 1234;
- errcode = gras_msg_send(toserver, gras_msgtype_by_name("ping"), &ping);
- if (errcode != no_error) {
- fprintf(stderr, "Unable send PING to server (%s)\n",
- xbt_error_name(errcode));
+ TRY {
+ gras_msg_send(toserver, gras_msgtype_by_name("ping"), &ping);
+ } CATCH(e) {
gras_socket_close(toserver);
- return 1;
+ RETHROW0("Failed to send PING to server: %s");
}
INFO3(">>>>>>>> Message PING(%d) sent to %s:%d <<<<<<<<",
ping,
gras_socket_peer_name(toserver),gras_socket_peer_port(toserver));
/* 8. Wait for the answer from the server, and deal with issues */
- if ((errcode=gras_msg_wait(6000,gras_msgtype_by_name("pong"),
- &from,&pong))) {
- ERROR1("Why can't I get my PONG message like everyone else (%s)?",
- xbt_error_name(errcode));
+ TRY {
+ gras_msg_wait(6000,gras_msgtype_by_name("pong"),
+ &from,&pong);
+ } CATCH(e) {
gras_socket_close(toserver);
- return 1;
+ RETHROW0("Why can't I get my PONG message like everyone else: %s");
}
/* 9. Keep the user informed of what's going on, again */
/* Callback function */
static int node_cb_stoken_handler(gras_socket_t expeditor,
void *payload_data) {
-
- xbt_error_t errcode;
+
+ xbt_ex_t e;
/* 1. Get the payload into the msg variable */
int msg=*(int*)payload_data;
/* 6. Send it as payload of a stoken message to the successor */
- errcode = gras_msg_send(globals->tosuccessor,
- gras_msgtype_by_name("stoken"), &msg);
+ TRY {
+ gras_msg_send(globals->tosuccessor,
+ gras_msgtype_by_name("stoken"), &msg);
/* 7. Deal with errors */
- if (errcode != no_error) {
- ERROR1("Unable to forward token: %s\n", xbt_error_name(errcode));
+ } CATCH(e) {
gras_socket_close(globals->sock);
- return 1;
+ RETHROW0("Unable to forward token: %s");
}
}
int node (int argc,char *argv[]) {
- xbt_error_t errcode;
node_data_t *globals;
const char *host;
gras_os_getpid(), host,peerport, myport);
/* 4. Create my master socket for listening */
- if ((errcode=gras_socket_server(myport,&(globals->sock)))) {
- CRITICAL1("Error %s encountered while opening the server socket. Bailing out.",
- xbt_error_name(errcode));
- return 1;
- }
+ globals->sock = gras_socket_server(myport);
gras_os_sleep(1.0); /* Make sure all server sockets are created */
/* 5. Create socket to the successor on the ring */
DEBUG2("Connect to my successor on %s:%d",host,peerport);
- if ((errcode=gras_socket_client(host,peerport,
- &(globals->tosuccessor)))) {
- ERROR1("Unable to connect to the node (got %s). Bailing out.",
- xbt_error_name(errcode));
- return 1;
- }
-
+ globals->tosuccessor = gras_socket_client(host,peerport);
/* 6. Register the known messages. This function is called twice here,
but it's because this file also acts as regression test.
INFO3("Create the token (with value %d) and send it to %s:%d",
token, host, peerport);
- errcode = gras_msg_send(globals->tosuccessor,
- gras_msgtype_by_name("stoken"), &token);
-
- if (errcode != no_error) {
- fprintf(stderr, "Unable send 'stoken' to successor (%s)\n",
- xbt_error_name(errcode));
- return 1;
- }
+ gras_msg_send(globals->tosuccessor,
+ gras_msgtype_by_name("stoken"), &token);
}
/* 8. Wait up to 10 seconds for an incomming message to handle */
while (globals->remaining_loop > (globals->create ? -1 : 0)) {
- errcode = gras_msg_handle(10.0);
+ gras_msg_handle(10.0);
- /* 9. Housekeeping */
- if (errcode != no_error) {
- ERROR1("Got error %s in msg_handle", xbt_error_name(errcode));
- return errcode;
- }
-
DEBUG1("looping (remaining_loop=%d)", globals->remaining_loop);
}
free(globals);
gras_exit();
- return no_error;
+ return 0;
} /* end_of_node */
#define GRAS_H
#include <xbt.h> /* our toolbox */
+#include <xbt/ex.h> /* There's a whole bunch of exception handling in GRAS */
#include <gras/process.h>
#include <gras/virtu.h>
/** @name 3. Message exchange */
/** @{ */
- xbt_error_t gras_msg_send(gras_socket_t sock,
- gras_msgtype_t msgtype,
- void *payload);
- xbt_error_t gras_msg_wait(double timeout,
- gras_msgtype_t msgt_want,
- gras_socket_t *expeditor,
- void *payload);
- xbt_error_t gras_msg_handle(double timeOut);
+ void gras_msg_send(gras_socket_t sock,
+ gras_msgtype_t msgtype,
+ void *payload);
+ void gras_msg_wait(double timeout,
+ gras_msgtype_t msgt_want,
+ gras_socket_t *expeditor,
+ void *payload);
+ void gras_msg_handle(double timeOut);
/* @} */
*
* Perform the various intialisations needed by gras. Each process must run it
*/
-xbt_error_t gras_process_init(void);
+void gras_process_init(void);
/**
* gras_process_exit:
*
* Frees the memory allocated by gras. Processes should run it
*/
-xbt_error_t gras_process_exit(void);
+void gras_process_exit(void);
/****************************************************************************/
/* Manipulating User Data */
void gras_timer_delay(double delay, void_f_void_t action);
void gras_timer_repeat(double interval, void_f_void_t action);
- xbt_error_t gras_timer_cancel_delay(double interval, void_f_void_t action);
- xbt_error_t gras_timer_cancel_repeat(double interval, void_f_void_t action);
+ void gras_timer_cancel_delay(double interval, void_f_void_t action);
+ void gras_timer_cancel_repeat(double interval, void_f_void_t action);
- xbt_error_t gras_timer_cancel_delay_all(void);
- xbt_error_t gras_timer_cancel_repeat_all(void);
+ void gras_timer_cancel_delay_all(void);
+ void gras_timer_cancel_repeat_all(void);
void gras_timer_cancel_all(void);
typedef struct s_gras_socket *gras_socket_t;
/** \brief Simply create a client socket (to speak to a remote host) */
-xbt_error_t gras_socket_client(const char *host,
- unsigned short port,
- /* OUT */ gras_socket_t *dst);
+gras_socket_t gras_socket_client(const char *host, unsigned short port);
/** \brief Simply create a server socket (to ear from remote hosts speaking to you) */
-xbt_error_t gras_socket_server(unsigned short port,
- /* OUT */ gras_socket_t *dst);
+gras_socket_t gras_socket_server(unsigned short port);
/** \brief Close socket */
-void gras_socket_close(gras_socket_t sd);
+void gras_socket_close(gras_socket_t sd);
/** \brief Create a client socket, full interface to all relevant settings */
-xbt_error_t gras_socket_client_ext(const char *host,
- unsigned short port,
- unsigned long int bufSize,
- int measurement,
- /* OUT */ gras_socket_t *dst);
+gras_socket_t gras_socket_client_ext(const char *host,
+ unsigned short port,
+ unsigned long int bufSize,
+ int measurement);
/** \brief Create a server socket, full interface to all relevant settings */
-xbt_error_t gras_socket_server_ext(unsigned short port,
- unsigned long int bufSize,
- int measurement,
- /* OUT */ gras_socket_t *dst);
+gras_socket_t gras_socket_server_ext(unsigned short port,
+ unsigned long int bufSize,
+ int measurement);
/* @}*/
/** \name Retrieving data about sockets and peers
* \ingroup GRAS_sock
int gras_socket_is_meas(gras_socket_t sock);
-xbt_error_t gras_socket_meas_send(gras_socket_t peer,
- unsigned int timeout,
- unsigned long int expSize,
- unsigned long int msgSize);
-xbt_error_t gras_socket_meas_recv(gras_socket_t peer,
- unsigned int timeout,
- unsigned long int expSize,
- unsigned long int msgSize);
-xbt_error_t gras_socket_meas_accept(gras_socket_t peer,gras_socket_t *accepted);
+void gras_socket_meas_send(gras_socket_t peer,
+ unsigned int timeout,
+ unsigned long int expSize,
+ unsigned long int msgSize);
+void gras_socket_meas_recv(gras_socket_t peer,
+ unsigned int timeout,
+ unsigned long int expSize,
+ unsigned long int msgSize);
+gras_socket_t gras_socket_meas_accept(gras_socket_t peer);
/* @}*/
*/
/* @{*/
/* debuging functions */
-xbt_error_t gras_socket_client_from_file(const char*path,
- /* OUT */ gras_socket_t *dst);
-xbt_error_t gras_socket_server_from_file(const char*path,
- /* OUT */ gras_socket_t *dst);
+gras_socket_t gras_socket_client_from_file(const char*path);
+gras_socket_t gras_socket_server_from_file(const char*path);
/* @} */
#include "msg/datatypes.h"
/************************** Global ******************************************/
-xbt_error_t MSG_config(const char *name, ...);
+void MSG_config(const char *name, ...);
void MSG_global_init(void);
void MSG_global_init_args(int *argc, char **argv);
void MSG_set_verbosity(MSG_outputmode_t mode);
* @{
*/
- xbt_error_t xbt_cfg_set(xbt_cfg_t cfg, const char *name, ...);
- xbt_error_t xbt_cfg_set_vargs(xbt_cfg_t cfg, const char *name, va_list pa);
- xbt_error_t xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options);
+ void xbt_cfg_set(xbt_cfg_t cfg, const char *name, ...);
+ void xbt_cfg_set_vargs(xbt_cfg_t cfg, const char *name, va_list pa);
+ void xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options);
/*
Set the value of the cell \a name in \a cfg with the provided value.
*/
-xbt_error_t xbt_cfg_set_int (xbt_cfg_t cfg, const char *name,
- int val);
-xbt_error_t xbt_cfg_set_double(xbt_cfg_t cfg, const char *name,
- double val);
-xbt_error_t xbt_cfg_set_string(xbt_cfg_t cfg, const char *name,
- const char *val);
-xbt_error_t xbt_cfg_set_host (xbt_cfg_t cfg, const char *name,
- const char *host,int port);
+void xbt_cfg_set_int (xbt_cfg_t cfg, const char *name,
+ int val);
+void xbt_cfg_set_double(xbt_cfg_t cfg, const char *name,
+ double val);
+void xbt_cfg_set_string(xbt_cfg_t cfg, const char *name,
+ const char *val);
+void xbt_cfg_set_host (xbt_cfg_t cfg, const char *name,
+ const char *host,int port);
/*
Remove the provided value from the cell @name in @cfg.
*/
-xbt_error_t xbt_cfg_rm_int (xbt_cfg_t cfg, const char *name,
- int val);
-xbt_error_t xbt_cfg_rm_double(xbt_cfg_t cfg, const char *name,
- double val);
-xbt_error_t xbt_cfg_rm_string(xbt_cfg_t cfg, const char *name,
- const char *val);
-xbt_error_t xbt_cfg_rm_host (xbt_cfg_t cfg, const char *name,
- const char *host,int port);
+void xbt_cfg_rm_int (xbt_cfg_t cfg, const char *name,
+ int val);
+void xbt_cfg_rm_double(xbt_cfg_t cfg, const char *name,
+ double val);
+void xbt_cfg_rm_string(xbt_cfg_t cfg, const char *name,
+ const char *val);
+void xbt_cfg_rm_host (xbt_cfg_t cfg, const char *name,
+ const char *host,int port);
/*
Remove the value at position \e pos from the config \e cfg
*/
-xbt_error_t xbt_cfg_rm_at (xbt_cfg_t cfg, const char *name, int pos);
+void xbt_cfg_rm_at (xbt_cfg_t cfg, const char *name, int pos);
/* rm every values */
-xbt_error_t xbt_cfg_empty(xbt_cfg_t cfg, const char *name);
+void xbt_cfg_empty(xbt_cfg_t cfg, const char *name);
/* @} */
/** @name 3. Registering stuff
xbt_error_t xbt_cfg_unregister(xbt_cfg_t cfg, const char *name);
xbt_error_t xbt_cfg_register_str(xbt_cfg_t cfg, const char *entry);
xbt_error_t xbt_cfg_check(xbt_cfg_t cfg);
- xbt_error_t xbt_cfg_get_type(xbt_cfg_t cfg, const char *name,
- /* OUT */ e_xbt_cfgelm_type_t *type);
+ e_xbt_cfgelm_type_t xbt_cfg_get_type(xbt_cfg_t cfg, const char *name);
/* @} */
/** @name 4. Getting the stored values
*
* @{
*/
- xbt_error_t xbt_cfg_get_int (xbt_cfg_t cfg, const char *name, int *val);
- xbt_error_t xbt_cfg_get_double(xbt_cfg_t cfg, const char *name, double *val);
- xbt_error_t xbt_cfg_get_string(xbt_cfg_t cfg, const char *name, char **val);
- xbt_error_t xbt_cfg_get_host (xbt_cfg_t cfg, const char *name, char **host, int *port);
- xbt_error_t xbt_cfg_get_dynar (xbt_cfg_t cfg, const char *name, xbt_dynar_t *dynar);
+ int xbt_cfg_get_int (xbt_cfg_t cfg, const char *name);
+ double xbt_cfg_get_double(xbt_cfg_t cfg, const char *name);
+ char* xbt_cfg_get_string(xbt_cfg_t cfg, const char *name);
+ void xbt_cfg_get_host (xbt_cfg_t cfg, const char *name, char **host, int *port);
+ xbt_dynar_t xbt_cfg_get_dynar (xbt_cfg_t cfg, const char *name);
- xbt_error_t xbt_cfg_get_int_at (xbt_cfg_t cfg, const char *name, int pos, int *val);
- xbt_error_t xbt_cfg_get_double_at(xbt_cfg_t cfg, const char *name, int pos, double *val);
- xbt_error_t xbt_cfg_get_string_at(xbt_cfg_t cfg, const char *name, int pos, char **val);
- xbt_error_t xbt_cfg_get_host_at (xbt_cfg_t cfg, const char *name, int pos, char **host, int *port);
+ int xbt_cfg_get_int_at (xbt_cfg_t cfg, const char *name, int pos);
+ double xbt_cfg_get_double_at(xbt_cfg_t cfg, const char *name, int pos);
+ char* xbt_cfg_get_string_at(xbt_cfg_t cfg, const char *name, int pos);
+ void xbt_cfg_get_host_at (xbt_cfg_t cfg, const char *name, int pos, char **host, int *port);
/** @} */
/** @} */
#define _XBT_DICT_H
#include "xbt/misc.h" /* BEGIN_DECL */
-#include "xbt/error.h"
#include "xbt/dynar.h" /* void_f_pvoid_t */
+#include "xbt/error.h"
BEGIN_DECL()
*
* @{ */
- void xbt_dict_set(xbt_dict_t head, const char *key, void *data, void_f_pvoid_t *free_ctn);
- xbt_error_t xbt_dict_get(xbt_dict_t head,const char *key, /* OUT */void **data);
- xbt_error_t xbt_dict_remove(xbt_dict_t head,const char *key);
+ void xbt_dict_set(xbt_dict_t head, const char *key, void *data, void_f_pvoid_t *free_ctn);
+ void *xbt_dict_get(xbt_dict_t head,const char *key);
+ void *xbt_dict_get_or_null(xbt_dict_t dict, const char *key);
+
+ xbt_error_t xbt_dict_remove(xbt_dict_t head, const char *key);
void xbt_dict_dump(xbt_dict_t head,void (*output)(void*));
/** @} */
*
* @{
*/
- void xbt_dict_set_ext(xbt_dict_t head,
- const char *key, int key_len,
- void *data,
- void_f_pvoid_t *free_ctn);
- xbt_error_t xbt_dict_get_ext(xbt_dict_t head,const char *key, int key_len,
- /* OUT */void **data);
+ void xbt_dict_set_ext(xbt_dict_t head,
+ const char *key, int key_len,
+ void *data,
+ void_f_pvoid_t *free_ctn);
+ void *xbt_dict_get_ext(xbt_dict_t head,const char *key, int key_len);
xbt_error_t xbt_dict_remove_ext(xbt_dict_t head,
const char *key, int key_len);
void xbt_dict_cursor_rewind(xbt_dict_cursor_t cursor);
- xbt_error_t xbt_dict_cursor_get_key (xbt_dict_cursor_t cursor,
- /*OUT*/char **key);
- xbt_error_t xbt_dict_cursor_get_data (xbt_dict_cursor_t cursor,
- /*OUT*/void **data);
+ char * xbt_dict_cursor_get_key (xbt_dict_cursor_t cursor);
+ void * xbt_dict_cursor_get_data (xbt_dict_cursor_t cursor);
void xbt_dict_cursor_first (const xbt_dict_t dict,
xbt_dict_cursor_t *cursor);
/*----[ xbt_multidict_set ]--------------------------------------------------*/
-xbt_error_t
+void
xbt_multidict_set(xbt_dict_t mdict,
xbt_dynar_t keys,
void *data,void (*free_ctn)(void*));
-xbt_error_t
+void
xbt_multidict_set_ext(xbt_dict_t mdict,
xbt_dynar_t keys, xbt_dynar_t lens,
void *data,void_f_pvoid_t *free_ctn);
/*----[ xbt_multidict_get ]--------------------------------------------------*/
-xbt_error_t
-xbt_multidict_get(xbt_dict_t mdict,
- xbt_dynar_t keys,
- /*OUT*/void **data);
-xbt_error_t
-xbt_multidict_get_ext(xbt_dict_t mdict,
- xbt_dynar_t keys, xbt_dynar_t lens,
- /*OUT*/void **data);
+void *xbt_multidict_get (xbt_dict_t mdict, xbt_dynar_t keys);
+void *xbt_multidict_get_ext(xbt_dict_t mdict, xbt_dynar_t keys, xbt_dynar_t lens);
/*----[ xbt_multidict_remove ]-----------------------------------------------*/
/*---------------------------------------------------------------------------*/
* @{
*/
- void xbt_dynar_get_cpy(const xbt_dynar_t dynar, int idx, void *const dst);
+ void xbt_dynar_get_cpy(const xbt_dynar_t dynar, int idx, void * const dst);
void xbt_dynar_set(xbt_dynar_t dynar, int idx, const void *src);
void xbt_dynar_replace(xbt_dynar_t dynar, int idx, const void *object);
void xbt_dynar_insert_at(xbt_dynar_t dynar, int idx, const void *src);
- void xbt_dynar_remove_at(xbt_dynar_t dynar, int idx, void *object);
+ void xbt_dynar_remove_at(xbt_dynar_t dynar, int idx, void * const dst);
/** @} */
/** @name 2. Perl-like functions
* @{
*/
- void xbt_dynar_push (xbt_dynar_t dynar, const void *src);
- void xbt_dynar_pop (xbt_dynar_t dynar, void *const dst);
- void xbt_dynar_unshift (xbt_dynar_t dynar, const void *src);
- void xbt_dynar_shift (xbt_dynar_t dynar, void *const dst);
- void xbt_dynar_map (const xbt_dynar_t dynar, void_f_pvoid_t *operator);
+ void xbt_dynar_push (xbt_dynar_t dynar, const void *src);
+ void xbt_dynar_pop (xbt_dynar_t dynar, void *const dst);
+ void xbt_dynar_unshift (xbt_dynar_t dynar, const void *src);
+ void xbt_dynar_shift (xbt_dynar_t dynar, void *const dst);
+ void xbt_dynar_map (const xbt_dynar_t dynar, void_f_pvoid_t *operator);
/** @} */
/** @name 3. Manipulating pointers to the content
#ifndef XBT_ERROR_H
#define XBT_ERROR_H
-#include <stdio.h> /* FIXME: Get rid of it */
-
#include "xbt/misc.h" /* BEGIN_DECL */
#include "xbt/log.h"
/** \brief Error types */
typedef enum {
no_error=0, /**< succes */
- mismatch_error=1, /**< The provided ID does not match */
- system_error=2, /**< a syscall did fail */
- network_error=3, /**< error while sending/receiving data */
- timeout_error=4, /**< not quick enough, dude */
- thread_error=5, /**< error while [un]locking */
- unknown_error=6, /**< unknown error */
+ old_mismatch_error=1, /**< The provided ID does not match */
+ old_system_error=2, /**< a syscall did fail */
+ old_network_error=3, /**< error while sending/receiving data */
+ old_timeout_error=4, /**< not quick enough, dude */
+ old_thread_error=5, /**< error while [un]locking */
+ old_unknown_error=6 /**< unknown error */
- /* remote errors: result of a RMI/RPC.
- no_error(=0) is the same for both */
- remote_mismatch_error=129,
- remote_system_error,
- remote_network_error,
- remote_timeout_error,
- remote_thread_error,
- remote_unknown_error
} xbt_error_t;
const char *xbt_error_name(xbt_error_t errcode);
*/
/** @hideinitializer */
-#define RAISE0(code,fmt) _XBT_ERR_PRE ERROR0(fmt); _XBT_ERR_POST(code)
+#define OLDRAISE0(code,fmt) _XBT_ERR_PRE ERROR0(fmt); _XBT_ERR_POST(code)
/** @hideinitializer */
-#define RAISE1(code,fmt,a1) _XBT_ERR_PRE ERROR1(fmt,a1); _XBT_ERR_POST(code)
+#define OLDRAISE1(code,fmt,a1) _XBT_ERR_PRE ERROR1(fmt,a1); _XBT_ERR_POST(code)
/** @hideinitializer */
-#define RAISE2(code,fmt,a1,a2) _XBT_ERR_PRE ERROR2(fmt,a1,a2); _XBT_ERR_POST(code)
+#define OLDRAISE2(code,fmt,a1,a2) _XBT_ERR_PRE ERROR2(fmt,a1,a2); _XBT_ERR_POST(code)
/** @hideinitializer */
-#define RAISE3(code,fmt,a1,a2,a3) _XBT_ERR_PRE ERROR3(fmt,a1,a2,a3); _XBT_ERR_POST(code)
+#define OLDRAISE3(code,fmt,a1,a2,a3) _XBT_ERR_PRE ERROR3(fmt,a1,a2,a3); _XBT_ERR_POST(code)
/** @hideinitializer */
-#define RAISE4(code,fmt,a1,a2,a3,a4) _XBT_ERR_PRE ERROR4(fmt,a1,a2,a3,a4); _XBT_ERR_POST(code)
+#define OLDRAISE4(code,fmt,a1,a2,a3,a4) _XBT_ERR_PRE ERROR4(fmt,a1,a2,a3,a4); _XBT_ERR_POST(code)
/** @hideinitializer */
-#define RAISE5(code,fmt,a1,a2,a3,a4,a5) _XBT_ERR_PRE ERROR5(fmt,a1,a2,a3,a4,a5); _XBT_ERR_POST(code)
+#define OLDRAISE5(code,fmt,a1,a2,a3,a4,a5) _XBT_ERR_PRE ERROR5(fmt,a1,a2,a3,a4,a5); _XBT_ERR_POST(code)
/** @hideinitializer */
-#define RAISE6(code,fmt,a1,a2,a3,a4,a5,a6) _XBT_ERR_PRE ERROR6(fmt,a1,a2,a3,a4,a5,a6); _XBT_ERR_POST(code)
+#define OLDRAISE6(code,fmt,a1,a2,a3,a4,a5,a6) _XBT_ERR_PRE ERROR6(fmt,a1,a2,a3,a4,a5,a6); _XBT_ERR_POST(code)
/** @} */
/**
*
* @{
*/
-#define RAISE_IMPOSSIBLE RAISE0(unknown_error,"The Impossible did happen")
-#define RAISE_UNIMPLEMENTED RAISE1(unknown_error,"Function %s unimplemented",__FUNCTION__)
+#define RAISE_IMPOSSIBLE RAISE0(old_unknown_error,"The Impossible did happen (yet again)")
+#define RAISE_UNIMPLEMENTED RAISE1(old_unknown_error,"Function %s unimplemented",__FUNCTION__)
-#define DIE_IMPOSSIBLE xbt_assert0(0,"The Impossible did happen (yet again)")
-#define xbt_assert_error(a) xbt_assert1(errcode == (a), "Error %s unexpected",xbt_error_name(errcode))
+#define OLDDIE_IMPOSSIBLE xbt_assert0(0,"The Impossible did happen (yet again)")
+#define OLDxbt_assert_error(a) xbt_assert1(errcode == (a), "Error %s unexpected",xbt_error_name(errcode))
/** @} */
/** @} */
#include <xbt/sysdep.h>
/* required ISO-C standard facilities */
+#include <errno.h>
#include <stdio.h>
+//#define __EX_MCTX_MCSC__ 1
+#define __EX_MCTX_SSJLJ__ 1
/* the machine context */
#if defined(__EX_MCTX_MCSC__)
#include <ucontext.h> /* POSIX.1 ucontext(3) */
/* declare the machine context type */
typedef struct { __ex_mctx_struct } __ex_mctx_t;
+
/** @addtogroup XBT_ex
*
* This module is a small ISO-C++ style exception handling library
* only in combination and form a language clause as a whole.
* - In contrast to the syntax of other languages (such as C++ or Jave) there
* is only one CATCH block and not multiple ones (all exceptions are
- * of the same \em ex_t C type).
+ * of the same \em xbt_ex_t C type).
* - the variable of CATCH can naturally be reused in subsequent
* CATCH clauses.
* - it is possible to nest TRY clauses.
* between the TRY and the THROW may be discarded if you forget the
* "volatile" keyword.
*
- * @section XBT_ex_advanced ADVANCED USAGE
- *
- * @subsection DEFER DEFERING_BLOCK XBT_ex_defer
- *
- * This directive executes DEFERING_BLOCK while deferring the throwing of
- * exceptions, i.e., exceptions thrown within this block are remembered, but
- * the control flow still continues until the end of the block. At its end, the
- * first exception which occured within the block (if any) is rethrown (any
- * subsequent exceptions are ignored).
- *
- * DEFERING_BLOCK is a regular ISO-C language statement block, but it is not
- * allowed to jump into it via "goto" or longjmp(3) or out of it via "break",
- * "return", "goto" or longjmp(3). It is however allowed to nest DEFER
- * clauses.
- *
- * @subsection XBT_ex_shield SHIELD SHIELDED_BLOCK
- *
- * This directive executes SHIELDED_BLOCK while shielding it against the
- * throwing of exceptions, i.e., any exception thrown from this block or its
- * subroutines are silently ignored.
- *
- * SHIELDED_BLOCK is a regular ISO-C language statement block, but it is not
- * allowed to jump into it via "goto" or longjmp(3) or out of it via "break",
- * "return", "goto" or longjmp(3). It is however allowed to nest SHIELD
- * clauses.
- *
- * @subsection XBT_ex_conditions Retrieving the current execution condition
- *
- * \a IS_CATCHED, \a IS_DEFERRED and \a IS_SHIELDED return a boolean
- * indicating whether the current scope is within a TRYIED_BLOCK,
- * DEFERING_BLOCK and SHIELDED_BLOCK (respectively)
- *
* \section XBT_ex_pitfalls PROGRAMMING PITFALLS
*
* Exception handling is a very elegant and efficient way of dealing with
* @{
*/
+typedef enum {
+ unknown_error=0, /**< unknown error */
+ arg_error, /**< Invalid argument */
+ mismatch_error, /**< The provided ID does not match */
+
+ system_error, /**< a syscall did fail */
+ network_error, /**< error while sending/receiving data */
+ timeout_error, /**< not quick enough, dude */
+ thread_error /**< error while [un]locking */
+} xbt_errcat_t;
+
+const char *xbt_errcat_name(xbt_error_t errcode);
+
/** @brief Structure describing an exception */
typedef struct {
- char *msg; /**< human readable message; to be freed */
- int category; /**< category like HTTP (what went wrong) */
- int value; /**< like errno (why did it went wrong) */
+ char *msg; /**< human readable message; to be freed */
+ xbt_errcat_t category; /**< category like HTTP (what went wrong) */
+ int value; /**< like errno (why did it went wrong) */
/* throw point */
char *host; /* NULL for localhost; hostname:port if remote */
char *procname;
char *file; /**< to be freed only for remote exceptions */
int line;
char *func; /**< to be freed only for remote exceptions */
-} ex_t;
+ /* Backtrace */
+ void *bt[10];
+ int used;
+} xbt_ex_t;
/* declare the context type (private) */
typedef struct {
__ex_mctx_t *ctx_mctx; /* permanent machine context of enclosing try/catch */
- int ctx_deferred; /* permanent flag whether exception is deferred */
- int ctx_deferring;/* permanent counter of exception deferring level */
- int ctx_defer; /* temporary flag for exception deferring macro */
- int ctx_shielding;/* permanent counter of exception shielding level */
- int ctx_shield; /* temporary flag for exception shielding macro */
int ctx_caught; /* temporary flag whether exception was caught */
- volatile ex_t ctx_ex; /* temporary exception storage */
+ volatile xbt_ex_t ctx_ex; /* temporary exception storage */
} ex_ctx_t;
/* the static and dynamic initializers for a context structure */
#define XBT_CTX_INITIALIZER \
- { NULL, 0, 0, 0, 0, 0, 0, { /* content */ NULL, 0, 0, \
- /*throw point*/ NULL, NULL, NULL, 0, NULL } }
+ { NULL, 0, { /* content */ NULL, 0, 0, \
+ /* throw point*/ NULL, NULL, NULL, 0, NULL,\
+ /* backtrace */ {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL},0 } }
#define XBT_CTX_INITIALIZE(ctx) \
do { \
(ctx)->ctx_mctx = NULL; \
- (ctx)->ctx_deferred = 0; \
- (ctx)->ctx_deferring = 0; \
- (ctx)->ctx_defer = 0; \
- (ctx)->ctx_shielding = 0; \
- (ctx)->ctx_shield = 0; \
(ctx)->ctx_caught = 0; \
(ctx)->ctx_ex.msg = NULL; \
(ctx)->ctx_ex.category = 0; \
(ctx)->ctx_ex.file = NULL; \
(ctx)->ctx_ex.line = 0; \
(ctx)->ctx_ex.func = NULL; \
+ (ctx)->ctx_ex.bt[0] = NULL; \
+ (ctx)->ctx_ex.bt[1] = NULL; \
+ (ctx)->ctx_ex.bt[2] = NULL; \
+ (ctx)->ctx_ex.bt[3] = NULL; \
+ (ctx)->ctx_ex.bt[4] = NULL; \
+ (ctx)->ctx_ex.bt[5] = NULL; \
+ (ctx)->ctx_ex.bt[6] = NULL; \
+ (ctx)->ctx_ex.bt[7] = NULL; \
+ (ctx)->ctx_ex.bt[8] = NULL; \
+ (ctx)->ctx_ex.bt[9] = NULL; \
+ (ctx)->ctx_ex.used = 0; \
} while (0)
/* the exception context */
extern ex_ctx_t *__xbt_ex_ctx_default(void);
/* the termination handler */
-typedef void (*ex_term_cb_t)(ex_t *);
+typedef void (*ex_term_cb_t)(xbt_ex_t *);
extern ex_term_cb_t __xbt_ex_terminate;
-extern void __xbt_ex_terminate_default(ex_t *e);
+extern void __xbt_ex_terminate_default(xbt_ex_t *e) __attribute__((__noreturn__));
/** @brief Introduce a block where exception may be dealed with
* @hideinitializer
*/
+/* xbt_assert1(1,\
+ "Severe error in exception mecanism: cannot save the catching context: %s", \
+ strerror(errno)); \
+*/
#define TRY \
{ \
ex_ctx_t *__xbt_ex_ctx_ptr = __xbt_ex_ctx(); \
else { \
} \
__xbt_ex_ctx_ptr->ctx_caught = 0; \
- } \
- else { \
+ } else { \
__ex_mctx_restored(&__ex_mctx_me); \
__xbt_ex_ctx_ptr->ctx_caught = 1; \
} \
} \
if (!(__ex_cleanup)) \
__xbt_ex_ctx_ptr->ctx_caught = 0; \
- } \
- else { \
+ } else { \
if (!(__ex_cleanup)) { \
__ex_mctx_restored(&__ex_mctx_me); \
__xbt_ex_ctx_ptr->ctx_caught = 1; \
* @param v: value (integer)
* @param m: message text
*
- * If called from within a sg_try/sg_catch construct, this exception
- * is copied into the sg_catch relevant variable program control flow
- * is derouted to the sg_catch (after the optional sg_cleanup).
+ * If called from within a TRY/CATCH construct, this exception
+ * is copied into the CATCH relevant variable program control flow
+ * is derouted to the CATCH (after the optional sg_cleanup).
*
- * If no sg_try/sg_catch conctruct embeeds this call, the program calls
+ * If no TRY/CATCH construct embeeds this call, the program calls
* abort(3).
*
- * The sg_throw can be performed everywhere, including inside sg_try,
- * sg_cleanup and sg_catch blocks.
+ * The THROW can be performed everywhere, including inside TRY,
+ * CLEANUP and CATCH blocks.
*/
-#define THROW(c,v,m) \
- (( __xbt_ex_ctx()->ctx_shielding > 0 \
- || (__xbt_ex_ctx()->ctx_deferring > 0 && __xbt_ex_ctx()->ctx_deferred == 1)) ? 0 : \
- (__xbt_ex_ctx()->ctx_ex.msg = bprintf(m), \
- __xbt_ex_ctx()->ctx_ex.category = (c), \
- __xbt_ex_ctx()->ctx_ex.value = (v), \
- __xbt_ex_ctx()->ctx_ex.host = (char*)NULL, \
- __xbt_ex_ctx()->ctx_ex.procname = strdup(xbt_procname()), \
- __xbt_ex_ctx()->ctx_ex.file = (char*)__FILE__, \
- __xbt_ex_ctx()->ctx_ex.line = __LINE__, \
- __xbt_ex_ctx()->ctx_ex.func = (char*)_XBT_FUNCTION, \
- __xbt_ex_ctx()->ctx_deferred = 1, \
- (__xbt_ex_ctx()->ctx_deferring > 0 ? 0 : \
- (__xbt_ex_ctx()->ctx_mctx == NULL \
- ? (__xbt_ex_terminate((ex_t *)&(__xbt_ex_ctx()->ctx_ex)), -1) \
- : (__ex_mctx_restore(__xbt_ex_ctx()->ctx_mctx), 1) ))))
+#include <execinfo.h>
+#define _THROW(c,v,m) \
+ do { /* change this sequence into one block */ \
+ /* build the exception */ \
+ __xbt_ex_ctx()->ctx_ex.msg = (m); \
+ __xbt_ex_ctx()->ctx_ex.category = (c); \
+ __xbt_ex_ctx()->ctx_ex.value = (v); \
+ __xbt_ex_ctx()->ctx_ex.host = (char*)NULL; \
+ __xbt_ex_ctx()->ctx_ex.procname = strdup(xbt_procname()); \
+ __xbt_ex_ctx()->ctx_ex.file = (char*)__FILE__; \
+ __xbt_ex_ctx()->ctx_ex.line = __LINE__; \
+ __xbt_ex_ctx()->ctx_ex.func = (char*)_XBT_FUNCTION; \
+ __xbt_ex_ctx()->ctx_ex.used = backtrace((void**)__xbt_ex_ctx()->ctx_ex.bt,10);\
+ /* deal with the exception */ \
+ if (__xbt_ex_ctx()->ctx_mctx == NULL) \
+ __xbt_ex_terminate((xbt_ex_t *)&(__xbt_ex_ctx()->ctx_ex)); /* not catched */\
+ else \
+ __ex_mctx_restore(__xbt_ex_ctx()->ctx_mctx); /* catched somewhere */ \
+ abort();/* nope, stupid GCC, we won't survive a THROW (this won't be reached) */ \
+ } while (0)
+
+#define THROW0(c,v,m) _THROW(c,v,bprintf(m))
+#define THROW1(c,v,m,a1) _THROW(c,v,bprintf(m,a1))
+#define THROW2(c,v,m,a1,a2) _THROW(c,v,bprintf(m,a1,a2))
+#define THROW3(c,v,m,a1,a2,a3) _THROW(c,v,bprintf(m,a1,a2,a3))
+#define THROW4(c,v,m,a1,a2,a3,a4) _THROW(c,v,bprintf(m,a1,a2,a3,a4))
+#define THROW5(c,v,m,a1,a2,a3,a4,a5) _THROW(c,v,bprintf(m,a1,a2,a3,a4,a5))
+#define THROW6(c,v,m,a1,a2,a3,a4,a5,a6) _THROW(c,v,bprintf(m,a1,a2,a3,a4,a5,a6))
+
+#define THROW_IMPOSSIBLE THROW0(unknown_error,0,"The Impossible Did Happen (yet again)")
+#define DIE_IMPOSSIBLE xbt_assert0(0,"The Impossible Did Happen (yet again)")
+#define THROW_UNIMPLEMENTED THROW1(unknown_error,0,"Function %s unimplemented",__FUNCTION__)
/** @brief re-throwing of an already caught exception (ie, pass it to the upper catch block)
* @hideinitializer
*/
#define RETHROW \
- (( __xbt_ex_ctx()->ctx_shielding > 0 \
- || __xbt_ex_ctx()->ctx_deferring > 0) ? 0 : \
- ( __xbt_ex_ctx()->ctx_mctx == NULL \
- ? (__xbt_ex_terminate((ex_t *)&(__xbt_ex_ctx()->ctx_ex)), -1) \
- : (__ex_mctx_restore(__xbt_ex_ctx()->ctx_mctx), 1) ))
+ do { \
+ if (__xbt_ex_ctx()->ctx_mctx == NULL) \
+ __xbt_ex_terminate((xbt_ex_t *)&(__xbt_ex_ctx()->ctx_ex)); \
+ else \
+ __ex_mctx_restore(__xbt_ex_ctx()->ctx_mctx); \
+ abort();\
+ } while(0)
-/** @brief shield an operation from exception handling
+/** @brief like RETHROW, but adding some details to the message
* @hideinitializer
*/
-#define SHIELD \
- for (__xbt_ex_ctx()->ctx_shielding++, \
- __xbt_ex_ctx()->ctx_shield = 1; \
- __xbt_ex_ctx()->ctx_shield == 1; \
- __xbt_ex_ctx()->ctx_shield = 0, \
- __xbt_ex_ctx()->ctx_shielding--)
-/** @brief defer immediate exception handling
- * @hideinitializer
- */
-#define DEFER \
- for (((__xbt_ex_ctx()->ctx_deferring)++ == 0 ? __xbt_ex_ctx()->ctx_deferred = 0 : 0), \
- __xbt_ex_ctx()->ctx_defer = 1; \
- __xbt_ex_ctx()->ctx_defer == 1; \
- __xbt_ex_ctx()->ctx_defer = 0, \
- ((--(__xbt_ex_ctx()->ctx_deferring) == 0 && __xbt_ex_ctx()->ctx_deferred == 1) ? RETHROW : 0))
-/** @brief exception handling tests
- * @hideinitializer
- */
-#define IS_CATCHED \
- (__xbt_ex_ctx()->ctx_mctx != NULL)
-/** @brief exception handling tests
- * @hideinitializer
- */
-#define IS_SHIELDED \
- (__xbt_ex_ctx()->ctx_shielding > 0)
-/** @brief exception handling tests
- * @hideinitializer
- */
-#define IS_DEFERRED \
- (__xbt_ex_ctx()->ctx_deferring > 0)
+#define _XBT_PRE_RETHROW \
+ do { \
+ char *_xbt_ex_internal_msg = __xbt_ex_ctx()->ctx_ex.msg; \
+ __xbt_ex_ctx()->ctx_ex.msg = bprintf(
+#define _XBT_POST_RETHROW \
+ _xbt_ex_internal_msg); \
+ free(_xbt_ex_internal_msg); \
+ RETHROW; \
+ } while (0)
+
+#define RETHROW0(msg) _XBT_PRE_RETHROW msg, _XBT_POST_RETHROW
+#define RETHROW1(msg,a) _XBT_PRE_RETHROW msg,a, _XBT_POST_RETHROW
+#define RETHROW2(msg,a,b) _XBT_PRE_RETHROW msg,a,b, _XBT_POST_RETHROW
+#define RETHROW3(msg,a,b,c) _XBT_PRE_RETHROW msg,a,b,c, _XBT_POST_RETHROW
+#define RETHROW4(msg,a,b,c,d) _XBT_PRE_RETHROW msg,a,b,c, _XBT_POST_RETHROW
+#define RETHROW5(msg,a,b,c,d,e) _XBT_PRE_RETHROW msg,a,b,c,d,e _XBT_POST_RETHROW
+
+void xbt_ex_free(xbt_ex_t e);
+const char * xbt_ex_catname(xbt_errcat_t cat);
/** @}Â */
#endif /* __XBT_EX_H__ */
* @{
*/
-void xbt_set_add (xbt_set_t set,
- xbt_set_elm_t elm,
- void_f_pvoid_t *free_func);
-
-xbt_error_t xbt_set_get_by_name (xbt_set_t set,
- const char *key,
- /* OUT */xbt_set_elm_t *dst);
-xbt_error_t xbt_set_get_by_name_ext(xbt_set_t set,
- const char *name,
- int name_len,
- /* OUT */xbt_set_elm_t *dst);
-xbt_error_t xbt_set_get_by_id (xbt_set_t set,
- int id,
- /* OUT */xbt_set_elm_t *dst);
+void xbt_set_add (xbt_set_t set, xbt_set_elm_t elm, void_f_pvoid_t *free_func);
+
+xbt_set_elm_t xbt_set_get_by_name (xbt_set_t set, const char *key);
+xbt_set_elm_t xbt_set_get_by_name_ext(xbt_set_t set, const char *key, int key_len);
+xbt_set_elm_t xbt_set_get_by_id (xbt_set_t set, int id);
/** @} */
/** @name 3. Cursors
#include <string.h>
#include <stdlib.h>
+#include <stdio.h>
#include "xbt/misc.h"
#include "xbt/error.h"
endif
libgras_la_SOURCES= $(COMMON_SRC) $(RL_SRC) $(AMOK_SRC)
-libgras_la_LDFLAGS = $(VERSION_INFO) @GRAS_DEP@ -lm
+libgras_la_LDFLAGS = $(VERSION_INFO) @GRAS_DEP@ -lm -Wl,--export-dynamic
libsimgrid_la_SOURCES= $(COMMON_SRC) $(SG_SRC) $(AMOK_SRC)
-libsimgrid_la_LDFLAGS = $(VERSION_INFO) @SIMGRID_DEP@ -lm
+libsimgrid_la_LDFLAGS = $(VERSION_INFO) @SIMGRID_DEP@ -lm -Wl,--export-dynamic
include $(top_srcdir)/acmacro/dist-files.mk
/* 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 "xbt/ex.h"
#include "amok/Bandwidth/bandwidth_private.h"
#include "gras/messages.h"
/*OUT*/ double *sec, double *bw) {
/* Measurement sockets for the experiments */
- gras_socket_t measMasterIn,measIn,measOut;
+ gras_socket_t measMasterIn=NULL,measIn,measOut;
int port;
xbt_error_t errcode;
bw_request_t request,request_ack;
+ xbt_ex_t e;
- for (port = 5000, errcode = system_error;
- errcode == system_error && port < 10000;
- errcode = gras_socket_server_ext(++port,buf_size,1,&measMasterIn));
- if (errcode != no_error) {
- ERROR1("Error %s encountered while opening a measurement socket",
- xbt_error_name(errcode));
- return errcode;
+ for (port = 5000; port < 10000 && measMasterIn == NULL; port++) {
+ TRY {
+ measMasterIn = gras_socket_server_ext(++port,buf_size,1);
+ } CATCH(e) {
+ measMasterIn = NULL;
+ if (port < 10000) {
+ xbt_ex_free(e);
+ } else {
+ RETHROW0("Error caught while opening a measurement socket: %s");
+ }
+ }
}
-
+
request=xbt_new0(s_bw_request_t,1);
request->buf_size=buf_size*1024;
request->exp_size=exp_size*1024;
gras_socket_peer_name(peer),gras_socket_peer_port(peer), request->host.port,
buf_size,request->buf_size);
- if ((errcode=gras_msg_send(peer,gras_msgtype_by_name("BW handshake"),&request))) {
- ERROR1("Error %s encountered while sending the BW request.", xbt_error_name(errcode));
- return errcode;
+ TRY {
+ gras_msg_send(peer,gras_msgtype_by_name("BW handshake"),&request);
+ } CATCH(e) {
+ RETHROW0("Error encountered while sending the BW request: %s");
}
- TRYOLD(gras_socket_meas_accept(measMasterIn,&measIn));
+ measIn = gras_socket_meas_accept(measMasterIn);
- if ((errcode=gras_msg_wait(60,gras_msgtype_by_name("BW handshake ACK"),
- NULL,&request_ack))) {
- ERROR1("Error %s encountered while waiting for the answer to BW request.\n",
- xbt_error_name(errcode));
- return errcode;
+ TRY {
+ gras_msg_wait(60,gras_msgtype_by_name("BW handshake ACK"),NULL,&request_ack);
+ } CATCH(e) {
+ RETHROW0("Error encountered while waiting for the answer to BW request: %s");
}
/* FIXME: What if there is a remote error? */
- if((errcode=gras_socket_client_ext(gras_socket_peer_name(peer),
- request_ack->host.port,
- request->buf_size,1,&measOut))) {
- ERROR3("Error %s encountered while opening the measurement socket to %s:%d for BW test\n",
- xbt_error_name(errcode),gras_socket_peer_name(peer),request_ack->host.port);
- return errcode;
+ TRY {
+ measOut=gras_socket_client_ext(gras_socket_peer_name(peer),
+ request_ack->host.port,
+ request->buf_size,1);
+ } CATCH(e) {
+ RETHROW2("Error encountered while opening the measurement socket to %s:%d for BW test",
+ gras_socket_peer_name(peer),request_ack->host.port);
}
DEBUG1("Got ACK; conduct the experiment (msg_size=%ld)",request->msg_size);
*sec=gras_os_time();
- TRYOLD(gras_socket_meas_send(measOut,120,request->exp_size,request->msg_size));
- TRYOLD(gras_socket_meas_recv(measIn,120,1,1));
+ gras_socket_meas_send(measOut,120,request->exp_size,request->msg_size);
+ gras_socket_meas_recv(measIn,120,1,1);
/*catch
ERROR1("Error %s encountered while sending the BW experiment.",
*/
int amok_bw_cb_bw_handshake(gras_socket_t expeditor,
void *payload) {
- gras_socket_t measMasterIn,measIn,measOut;
+ gras_socket_t measMasterIn=NULL,measIn,measOut;
bw_request_t request=*(bw_request_t*)payload;
bw_request_t answer;
- xbt_error_t errcode;
+ xbt_ex_t e;
int port;
VERB5("Handshaked to connect to %s:%d (sizes: buf=%lu exp=%lu msg=%lu)",
/* Build our answer */
answer = xbt_new0(s_bw_request_t,1);
- for (port = 6000, errcode = system_error;
- errcode == system_error;
- errcode = gras_socket_server_ext(++port,request->buf_size,1,&measMasterIn));
- if (errcode != no_error) {
- ERROR1("Error %s encountered while opening a measurement server socket", xbt_error_name(errcode));
- /* FIXME: tell error to remote */
- return 1;
+ for (port = 6000; port < 10000 && measMasterIn == NULL; port++) {
+ TRY {
+ measMasterIn = gras_socket_server_ext(port,request->buf_size,1);
+ } CATCH(e) {
+ measMasterIn = NULL;
+ if (port < 10000)
+ xbt_ex_free(e);
+ else
+ /* FIXME: tell error to remote */
+ RETHROW0("Error encountered while opening a measurement server socket: %s");
+ }
}
answer->buf_size=request->buf_size;
answer->host.port=gras_socket_my_port(measMasterIn);
/* Don't connect asap to leave time to other side to enter the accept() */
- if ((errcode=gras_socket_client_ext(gras_socket_peer_name(expeditor),
- request->host.port,
- request->buf_size,1,&measOut))) {
- ERROR3("Error '%s' encountered while opening a measurement socket back to %s:%d",
- xbt_error_name(errcode),gras_socket_peer_name(expeditor),request->host.port);
+ TRY {
+ measOut = gras_socket_client_ext(gras_socket_peer_name(expeditor),
+ request->host.port,
+ request->buf_size,1);
+ } CATCH(e) {
+ RETHROW2("Error encountered while opening a measurement socket back to %s:%d : %s",
+ gras_socket_peer_name(expeditor),request->host.port);
/* FIXME: tell error to remote */
- return 1;
}
-
- if ((errcode=gras_msg_send(expeditor,
- gras_msgtype_by_name("BW handshake ACK"),
- &answer))) {
- ERROR1("Error %s encountered while sending the answer.",
- xbt_error_name(errcode));
+ TRY {
+ gras_msg_send(expeditor, gras_msgtype_by_name("BW handshake ACK"), &answer);
+ } CATCH(e) {
gras_socket_close(measMasterIn);
gras_socket_close(measOut);
/* FIXME: tell error to remote */
- return 1;
+ RETHROW0("Error encountered while sending the answer: %s");
}
- TRYOLD(gras_socket_meas_accept(measMasterIn,&measIn));
- DEBUG4("BW handshake answered. buf_size=%lu exp_size=%lu msg_size=%lu port=%d",
- answer->buf_size,answer->exp_size,answer->msg_size,answer->host.port);
- TRYOLD(gras_socket_meas_recv(measIn, 120,request->exp_size,request->msg_size));
- TRYOLD(gras_socket_meas_send(measOut,120,1,1));
+ TRY {
+ measIn = gras_socket_meas_accept(measMasterIn);
+ DEBUG4("BW handshake answered. buf_size=%lu exp_size=%lu msg_size=%lu port=%d",
+ answer->buf_size,answer->exp_size,answer->msg_size,answer->host.port);
- /*catch
- ERROR1("Error %s encountered while receiving the experiment.",
- xbt_error_name(errcode));
+ gras_socket_meas_recv(measIn, 120,request->exp_size,request->msg_size);
+ gras_socket_meas_send(measOut,120,1,1);
+ } CATCH(e) {
gras_socket_close(measMasterIn);
gras_socket_close(measIn);
gras_socket_close(measOut);
- * FIXME: tell error to remote ? *
- return 1;
- }*/
+ /* FIXME: tell error to remote ? */
+ RETHROW0("Error encountered while receiving the experiment: %s");
+ }
if (measIn != measMasterIn)
gras_socket_close(measMasterIn);
/*OUT*/ double *sec, double*bw) {
gras_socket_t sock;
- xbt_error_t errcode;
/* The request */
bw_request_t request;
bw_res_t result;
request->host.name = (char*)to_name;
request->host.port = to_port;
- TRYOLD(gras_socket_client(from_name,from_port,&sock));
- TRYOLD(gras_msg_send(sock,gras_msgtype_by_name("BW request"),&request));
+ sock = gras_socket_client(from_name,from_port);
+ gras_msg_send(sock,gras_msgtype_by_name("BW request"),&request);
free(request);
- TRYOLD(gras_msg_wait(240,gras_msgtype_by_name("BW result"),NULL, &result));
+ gras_msg_wait(240,gras_msgtype_by_name("BW result"),NULL, &result);
*sec=result->sec;
*bw =result->bw;
int amok_bw_cb_bw_request(gras_socket_t expeditor,
void *payload) {
- xbt_error_t errcode;
/* specification of the test to run, and our answer */
bw_request_t request = *(bw_request_t*)payload;
bw_res_t result = xbt_new0(s_bw_res,1);
gras_socket_t peer;
- TRYOLD(gras_socket_client(request->host.name,request->host.port,&peer));
- TRYOLD(amok_bw_test(peer,
- request->buf_size,request->exp_size,request->msg_size,
- &(result->sec),&(result->bw)));
+ peer = gras_socket_client(request->host.name,request->host.port);
+ amok_bw_test(peer,
+ request->buf_size,request->exp_size,request->msg_size,
+ &(result->sec),&(result->bw));
- TRYOLD(gras_msg_send(expeditor,gras_msgtype_by_name("BW result"),&result));
+ gras_msg_send(expeditor,gras_msgtype_by_name("BW result"),&result);
gras_os_sleep(1);
gras_socket_close(peer);
#include "amok/Bandwidth/bandwidth_private.h"
XBT_LOG_EXTERNAL_CATEGORY(bw);
-XBT_LOG_DEFAULT_CATEGORY(bw);
+/*XBT_LOG_DEFAULT_CATEGORY(bw);*/
#if 0
/* ***************************************************************************
#include "gras.h"
#include "amok/base.h"
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(amok,XBT_LOG_ROOT_CAT,"All AMOK categories");
+XBT_LOG_NEW_SUBCATEGORY(amok,XBT_LOG_ROOT_CAT,"All AMOK categories");
amok_remoterr_t amok_remoterr_new(xbt_error_t param_errcode,
const char* format,...) {
amok_repport_error (gras_socket_t sock, gras_msgtype_t msgtype,
xbt_error_t param_errcode, const char* format,...) {
amok_remoterr_t error;
- xbt_error_t errcode;
va_list ap;
error=xbt_new(s_amok_remoterr_t,1);
vsnprintf(error->msg,1024,format,ap);
va_end(ap);
- errcode = gras_msg_send(sock,msgtype,error);
+ gras_msg_send(sock,msgtype,error);
+ /* FIXME: error handling while error reporting :-/
if (errcode != no_error) {
CRITICAL4("Error '%s' while reporting error '%s' to %s:%d",
xbt_error_name(errcode),error->msg,
gras_socket_peer_name(sock),gras_socket_peer_port(sock) );
}
+ */
}
void amok_base_init(void) {
/* 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 "xbt/ex.h"
#include "gras/DataDesc/datadesc_private.h"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_cbps,datadesc,"callback persistant state");
xbt_dynar_t globals;
} s_gras_cbps_t;
-static void free_string(void *d);
+void free_string(void *d);
-static void free_string(void *d){
+void free_string(void *d){
free(*(void**)d);
}
void *data,
gras_datadesc_type_t ddt) {
- xbt_dynar_t varstack,frame;
- gras_cbps_elm_t var;
- xbt_error_t errcode;
- char *varname = (char*)strdup(name);
+ xbt_dynar_t varstack,frame;
+ gras_cbps_elm_t var;
+ char *varname = (char*)strdup(name);
+ xbt_ex_t e;
DEBUG2("push(%s,%p)",name,(void*)data);
- errcode = xbt_dict_get(ps->space, name, (void **)&varstack);
-
- if (errcode == mismatch_error) {
- DEBUG1("Create a new variable stack for '%s' into the space",name);
- varstack = xbt_dynar_new(sizeof (gras_cbps_elm_t *), NULL);
- xbt_dict_set(ps->space, varname, (void **)varstack, NULL);
+
+ TRY {
+ varstack = xbt_dict_get(ps->space, name);
+ } CATCH(e) {
+ if (e.category == mismatch_error) {
+ DEBUG1("Create a new variable stack for '%s' into the space",name);
+ varstack = xbt_dynar_new(sizeof (gras_cbps_elm_t *), NULL);
+ xbt_dict_set(ps->space, varname, (void **)varstack, NULL);
+ xbt_ex_free(e);
/* leaking, you think? only if you do not close all the openned blocks ;)*/
- } else if (errcode != no_error) {
- return errcode;
+ } else {
+ RETHROW;
+ }
}
var = xbt_new0(s_gras_cbps_elm_t,1);
xbt_dynar_t varstack,frame;
gras_cbps_elm_t var = NULL;
void *data = NULL;
- xbt_error_t errcode;
+ xbt_ex_t e;
DEBUG1("pop(%s)",name);
- /* FIXME: Error handling */
- errcode = xbt_dict_get(ps->space, name, (void **)&varstack);
- if (errcode == mismatch_error) {
- RAISE1(mismatch_error,"Asked to pop the non-existant %s",
- name);
+ TRY {
+ varstack = xbt_dict_get(ps->space, name);
+ } CATCH(e) {
+ if (e.category == mismatch_error) {
+ xbt_ex_free(e);
+ THROW1(mismatch_error,1,"Asked to pop the non-existant %s",
+ name);
+ }
+ RETHROW;
}
xbt_dynar_pop(varstack, &var);
if (ddt)
*ddt = var->type;
- data = var->data;
+ data = var->data;
free(var);
void *data,
gras_datadesc_type_t ddt) {
- xbt_dynar_t dynar = NULL;
- gras_cbps_elm_t elm = NULL;
- xbt_error_t errcode;
+ xbt_dynar_t dynar = NULL;
+ gras_cbps_elm_t elm = NULL;
+ xbt_ex_t e;
DEBUG1("set(%s)",name);
- errcode = xbt_dict_get(ps->space, name, (void **)&dynar);
-
- if (errcode == mismatch_error) {
+ TRY {
+ dynar = xbt_dict_get(ps->space, name);
+ } CATCH(e) {
+ if (e.category == mismatch_error) {
+ dynar = NULL;
+ xbt_ex_free(e);
+ } else {
+ RETHROW;
+ }
+ }
+
+ if (dynar == NULL) {
dynar = xbt_dynar_new(sizeof (gras_cbps_elm_t), NULL);
xbt_dict_set(ps->space, name, (void **)dynar, NULL);
gras_cbps_elm_t elm = NULL;
DEBUG1("get(%s)",name);
- /* FIXME: Error handling */
- xbt_dict_get(ps->space, name, (void **)&dynar);
+ dynar = xbt_dict_get(ps->space, name);
xbt_dynar_pop(dynar, &elm);
xbt_dynar_push(dynar, &elm);
gras_cbps_elm_t var = NULL;
DEBUG2("Get ride of %s (%p)",name,(void*)name);
- xbt_dict_get(ps->space, name, (void **)&varstack);
+ varstack = xbt_dict_get(ps->space, name);
xbt_dynar_pop(varstack, &var);
if (!xbt_dynar_length(varstack)) {
#ifndef GRAS_DATADESC_INTERFACE_H
#define GRAS_DATADESC_INTERFACE_H
-xbt_error_t gras_datadesc_by_id (long int code,
- gras_datadesc_type_t *type);
+gras_datadesc_type_t gras_datadesc_by_id (long int code);
/* to debug */
void gras_datadesc_type_dump(const gras_datadesc_type_t ddt);
int gras_datadesc_size(gras_datadesc_type_t type);
/* Described data exchanges: direct use */
xbt_error_t gras_datadesc_cpy(gras_datadesc_type_t type, void *src, void **dst);
-xbt_error_t gras_datadesc_send(gras_socket_t sock, gras_datadesc_type_t type, void *src);
-xbt_error_t gras_datadesc_recv(gras_socket_t sock, gras_datadesc_type_t type,
+void gras_datadesc_send(gras_socket_t sock, gras_datadesc_type_t type, void *src);
+void gras_datadesc_recv(gras_socket_t sock, gras_datadesc_type_t type,
int r_arch, void *dst);
/* Described data exchanges: IDL compilation */
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "xbt/misc.h" /* min()/max() */
+#include "xbt/ex.h"
#include "gras/DataDesc/datadesc_private.h"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_create,datadesc,"Creating new datadescriptions");
}
/**
- * This returns NULL when no type of this name can be found
+ * This returns NULL no type of this name can be found instead of throwing exceptions which would complicate the GRAS_DEFINE_TYPE macro
*/
gras_datadesc_type_t gras_datadesc_by_name(const char *name) {
-
- gras_datadesc_type_t type;
-
- XBT_IN1("(%s)",name);
- if (xbt_set_get_by_name(gras_datadesc_set_local,
- name,(xbt_set_elm_t*)&type) == no_error) {
- XBT_OUT;
- return type;
- } else {
- XBT_OUT;
- return NULL;
+ xbt_ex_t e;
+ gras_datadesc_type_t res;
+ TRY {
+ res = (gras_datadesc_type_t)xbt_set_get_by_name(gras_datadesc_set_local,name);
+ } CATCH(e) {
+ if (e.category != mismatch_error)
+ RETHROW;
+ res = NULL;
}
+ return res;
}
/**
* Retrieve a type from its code
*/
-xbt_error_t gras_datadesc_by_id(long int code,
- gras_datadesc_type_t *type) {
- XBT_IN;
- return xbt_set_get_by_id(gras_datadesc_set_local,
- code,(xbt_set_elm_t*)type);
+gras_datadesc_type_t gras_datadesc_by_id(long int code) {
+ return (gras_datadesc_type_t)xbt_set_get_by_id(gras_datadesc_set_local,code);
}
/**
"Redefinition of type %s does not match", name);
VERB1("Discarding redefinition of %s",name);
return res;
- }
+ }
res = gras_ddt_new(name);
for (arch = 0; arch < gras_arch_count; arch ++) {
XBT_IN1("(%s)",name);
res = gras_datadesc_by_name(name);
+
if (res) {
xbt_assert1(res->category_code == e_gras_datadesc_type_cat_ref,
"Redefinition of type %s does not match", name);
const DataDescriptor *desc,
unsigned long howmany,
/* OUT */ gras_datadesc_type_t *dst) {
- RAISE_UNIMPLEMENTED;
+ THROW_UNIMPLEMENTED;
}
/**
/* 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 "xbt/ex.h"
#include "gras/DataDesc/datadesc_private.h"
#include "gras/Transport/transport_interface.h" /* gras_trp_chunk_send/recv */
static gras_datadesc_type_t int_type = NULL;
static gras_datadesc_type_t pointer_type = NULL;
-static _XBT_INLINE xbt_error_t gras_dd_send_int(gras_socket_t sock, int i);
-static _XBT_INLINE xbt_error_t gras_dd_recv_int(gras_socket_t sock, int r_arch, int *i);
+static _XBT_INLINE void gras_dd_send_int(gras_socket_t sock, int i);
+static _XBT_INLINE void gras_dd_recv_int(gras_socket_t sock, int r_arch, int *i);
static _XBT_INLINE xbt_error_t
gras_dd_alloc_ref(xbt_dict_t refs, long int size,
static _XBT_INLINE int
gras_dd_is_r_null(char **r_ptr, long int length);
-static _XBT_INLINE xbt_error_t
+static _XBT_INLINE void
gras_dd_send_int(gras_socket_t sock,int i) {
if (!int_type) {
}
DEBUG1("send_int(%d)",i);
- return gras_trp_chunk_send(sock, (char*)&i, int_type->size[GRAS_THISARCH]);
+ gras_trp_chunk_send(sock, (char*)&i, int_type->size[GRAS_THISARCH]);
}
-static _XBT_INLINE xbt_error_t
+static _XBT_INLINE void
gras_dd_recv_int(gras_socket_t sock, int r_arch, int *i) {
- xbt_error_t errcode;
if (!int_type) {
int_type = gras_datadesc_by_name("int");
}
if (int_type->size[GRAS_THISARCH] >= int_type->size[r_arch]) {
- TRYOLD(gras_trp_chunk_recv(sock, (char*)i, int_type->size[r_arch]));
+ gras_trp_chunk_recv(sock, (char*)i, int_type->size[r_arch]);
if (r_arch != GRAS_THISARCH)
- TRYOLD(gras_dd_convert_elm(int_type,1,r_arch, i,i));
+ gras_dd_convert_elm(int_type,1,r_arch, i,i);
} else {
void *ptr = xbt_malloc(int_type->size[r_arch]);
- TRYOLD(gras_trp_chunk_recv(sock, (char*)ptr, int_type->size[r_arch]));
+ gras_trp_chunk_recv(sock, (char*)ptr, int_type->size[r_arch]);
if (r_arch != GRAS_THISARCH)
- TRYOLD(gras_dd_convert_elm(int_type,1,r_arch, ptr,i));
+ gras_dd_convert_elm(int_type,1,r_arch, ptr,i);
free(ptr);
}
DEBUG1("recv_int(%d)",*i);
-
- return no_error;
}
/*
xbt_error_t gras_datadesc_cpy(gras_datadesc_type_t type,
void *src,
void **dst) {
- RAISE_UNIMPLEMENTED;
+ THROW_UNIMPLEMENTED;
}
/***
*** Direct use functions
***/
-static xbt_error_t
+static void
gras_datadesc_send_rec(gras_socket_t sock,
gras_cbps_t state,
xbt_dict_t refs,
char *data,
int detect_cycle) {
- xbt_error_t errcode;
+ xbt_ex_t e;
int cpt;
gras_datadesc_type_t sub_type; /* type on which we recurse */
switch (type->category_code) {
case e_gras_datadesc_type_cat_scalar:
- TRYOLD(gras_trp_chunk_send(sock, data, type->size[GRAS_THISARCH]));
+ gras_trp_chunk_send(sock, data, type->size[GRAS_THISARCH]);
break;
case e_gras_datadesc_type_cat_struct: {
field->send(type,state,field_data);
VERB1("Send field %s",field->name);
- TRYOLD(gras_datadesc_send_rec(sock,state,refs,sub_type, field_data,
- detect_cycle || sub_type->cycle));
+ gras_datadesc_send_rec(sock,state,refs,sub_type, field_data,
+ detect_cycle || sub_type->cycle);
}
VERB1("<< Sent all fields of the structure %s", type->name);
type->name, field_num, xbt_dynar_length(union_data.fields));
/* Send the field number */
- TRYOLD(gras_dd_send_int(sock, field_num));
+ gras_dd_send_int(sock, field_num);
/* Send the content */
field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
if (field->send)
field->send(type,state,data);
- TRYOLD(gras_datadesc_send_rec(sock,state,refs, sub_type, data,
- detect_cycle || sub_type->cycle));
+ gras_datadesc_send_rec(sock,state,refs, sub_type, data,
+ detect_cycle || sub_type->cycle);
break;
}
case e_gras_datadesc_type_cat_ref: {
gras_dd_cat_ref_t ref_data;
-
void **ref=(void**)data;
- void *dummy;
+ int reference_is_to_send;
ref_data = type->category.ref_data;
sub_type = ref_data.type;
if (sub_type == NULL) {
sub_type = (*ref_data.selector)(type,state,data);
- TRYOLD(gras_dd_send_int(sock, sub_type->code));
+ gras_dd_send_int(sock, sub_type->code);
}
/* Send the actual value of the pointer for cycle handling */
xbt_assert(pointer_type);
}
- TRYOLD(gras_trp_chunk_send(sock, (char*)data,
- pointer_type->size[GRAS_THISARCH]));
+ gras_trp_chunk_send(sock, (char*)data,
+ pointer_type->size[GRAS_THISARCH]);
/* Send the pointed data only if not already sent */
if (*(void**)data == NULL) {
VERB0("Not sending NULL referenced data");
break;
}
- errcode = detect_cycle
- ? xbt_dict_get_ext(refs,(char*)ref, sizeof(void*), &dummy)
- : mismatch_error;
- if (errcode == mismatch_error) {
+
+ reference_is_to_send = 0;
+ TRY {
+ if (detect_cycle)
+ /* return ignored. Just checking whether it's known or not */
+ xbt_dict_get_ext(refs,(char*)ref, sizeof(void*));
+ else
+ reference_is_to_send = 1;
+ } CATCH(e) {
+ if (e.category == mismatch_error) {
+ reference_is_to_send = 1;
+ xbt_ex_free(e);
+ } else {
+ RETHROW;
+ }
+ }
+
+ if (reference_is_to_send) {
VERB1("Sending data referenced at %p", (void*)*ref);
if (detect_cycle)
xbt_dict_set_ext(refs, (char*)ref, sizeof(void*), ref, NULL);
- TRYOLD(gras_datadesc_send_rec(sock,state,refs, sub_type, *ref,
- detect_cycle || sub_type->cycle));
+ gras_datadesc_send_rec(sock,state,refs, sub_type, *ref,
+ detect_cycle || sub_type->cycle);
- } else if (errcode == no_error) {
- VERB1("Not sending data referenced at %p (already done)", (void*)*ref);
} else {
- return errcode;
- }
+ VERB1("Not sending data referenced at %p (already done)", (void*)*ref);
+ }
break;
}
count = array_data.dynamic_size(type,state,data);
xbt_assert1(count >=0,
"Invalid (negative) array size for type %s",type->name);
- TRYOLD(gras_dd_send_int(sock, count));
+ gras_dd_send_int(sock, count);
}
/* send the content */
elm_size = sub_type->aligned_size[GRAS_THISARCH];
if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
VERB1("Array of %ld scalars, send it in one shot",count);
- TRYOLD(gras_trp_chunk_send(sock, data,
- sub_type->aligned_size[GRAS_THISARCH] * count));
+ gras_trp_chunk_send(sock, data,
+ sub_type->aligned_size[GRAS_THISARCH] * count);
} else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
sub_type->category.array_data.fixed_size > 0 &&
sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
VERB1("Array of %ld fixed array of scalars, send it in one shot",count);
- TRYOLD(gras_trp_chunk_send(sock, data,
- sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
- * count * sub_type->category.array_data.fixed_size));
+ gras_trp_chunk_send(sock, data,
+ sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
+ * count * sub_type->category.array_data.fixed_size);
} else {
for (cpt=0; cpt<count; cpt++) {
- TRYOLD(gras_datadesc_send_rec(sock,state,refs, sub_type, ptr,
- detect_cycle || sub_type->cycle));
+ gras_datadesc_send_rec(sock,state,refs, sub_type, ptr,
+ detect_cycle || sub_type->cycle);
ptr += elm_size;
}
}
default:
xbt_assert0(0, "Invalid type");
}
-
- return no_error;
}
/**
* Copy the data pointed by src and described by type to the socket
*
*/
-xbt_error_t gras_datadesc_send(gras_socket_t sock,
- gras_datadesc_type_t type,
- void *src) {
+void gras_datadesc_send(gras_socket_t sock,
+ gras_datadesc_type_t type,
+ void *src) {
- xbt_error_t errcode;
+ xbt_ex_t e;
gras_cbps_t state;
xbt_dict_t refs; /* all references already sent */
refs = xbt_dict_new();
state = gras_cbps_new();
- errcode = gras_datadesc_send_rec(sock,state,refs,type,(char*)src, type->cycle);
-
- xbt_dict_free(&refs);
- gras_cbps_free(&state);
-
- return errcode;
+ TRY {
+ gras_datadesc_send_rec(sock,state,refs,type,(char*)src, type->cycle);
+ } CLEANUP {
+ xbt_dict_free(&refs);
+ gras_cbps_free(&state);
+ } CATCH(e) {
+ RETHROW;
+ }
}
/**
* Having this size passed as an argument of the recursive function is a crude
* hack, but I was told that working code is sometimes better than neat one ;)
*/
-static xbt_error_t
+static void
gras_datadesc_recv_rec(gras_socket_t sock,
gras_cbps_t state,
xbt_dict_t refs,
int subsize,
int detect_cycle) {
- xbt_error_t errcode;
int cpt;
gras_datadesc_type_t sub_type;
+ xbt_ex_t e;
VERB2("Recv a %s @%p", type->name, (void*)l_data);
xbt_assert(l_data);
switch (type->category_code) {
case e_gras_datadesc_type_cat_scalar:
if (type->size[GRAS_THISARCH] == type->size[r_arch]) {
- TRYOLD(gras_trp_chunk_recv(sock, (char*)l_data, type->size[r_arch]));
+ gras_trp_chunk_recv(sock, (char*)l_data, type->size[r_arch]);
if (r_arch != GRAS_THISARCH)
- TRYOLD(gras_dd_convert_elm(type,1,r_arch, l_data,l_data));
+ gras_dd_convert_elm(type,1,r_arch, l_data,l_data);
} else {
void *ptr = xbt_malloc(type->size[r_arch]);
- TRYOLD(gras_trp_chunk_recv(sock, (char*)ptr, type->size[r_arch]));
+ gras_trp_chunk_recv(sock, (char*)ptr, type->size[r_arch]);
if (r_arch != GRAS_THISARCH)
- TRYOLD(gras_dd_convert_elm(type,1,r_arch, ptr,l_data));
+ gras_dd_convert_elm(type,1,r_arch, ptr,l_data);
free(ptr);
}
break;
sub_type = field->type;
- TRYOLD(gras_datadesc_recv_rec(sock,state,refs, sub_type,
- r_arch,NULL,0,
- field_data,-1,
- detect_cycle || sub_type->cycle));
+ gras_datadesc_recv_rec(sock,state,refs, sub_type,
+ r_arch,NULL,0,
+ field_data,-1,
+ detect_cycle || sub_type->cycle);
if (field->recv)
field->recv(type,state,(void*)l_data);
"Please call gras_datadesc_declare_union_close on %s before receiving it",
type->name);
/* retrieve the field number */
- TRYOLD(gras_dd_recv_int(sock, r_arch, &field_num));
+ gras_dd_recv_int(sock, r_arch, &field_num);
if (field_num < 0)
- RAISE1(mismatch_error,
+ THROW1(mismatch_error,0,
"Received union field for %s is negative", type->name);
if (field_num < xbt_dynar_length(union_data.fields))
- RAISE3(mismatch_error,
- "Received union field for %s is %d but there is only %lu fields",
+ THROW3(mismatch_error,0,
+ "Received union field for %s is said to be #%d but there is only %lu fields",
type->name, field_num, xbt_dynar_length(union_data.fields));
/* Recv the content */
field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
sub_type = field->type;
- TRYOLD(gras_datadesc_recv_rec(sock,state,refs, sub_type,
- r_arch,NULL,0,
- l_data,-1,
- detect_cycle || sub_type->cycle));
+ gras_datadesc_recv_rec(sock,state,refs, sub_type,
+ r_arch,NULL,0,
+ l_data,-1,
+ detect_cycle || sub_type->cycle);
if (field->recv)
field->recv(type,state,l_data);
char **r_ref = NULL;
char **l_ref = NULL;
gras_dd_cat_ref_t ref_data;
+ int reference_is_to_recv = 0;
ref_data = type->category.ref_data;
sub_type = ref_data.type;
if (sub_type == NULL) {
int ref_code;
- TRYOLD(gras_dd_recv_int(sock, r_arch, &ref_code));
- TRYOLD(gras_datadesc_by_id(ref_code, &sub_type));
+ gras_dd_recv_int(sock, r_arch, &ref_code);
+ sub_type = gras_datadesc_by_id(ref_code);
}
/* Get the actual value of the pointer for cycle handling */
r_ref = xbt_malloc(pointer_type->size[r_arch]);
- TRYOLD(gras_trp_chunk_recv(sock, (char*)r_ref,
- pointer_type->size[r_arch]));
+ gras_trp_chunk_recv(sock, (char*)r_ref,
+ pointer_type->size[r_arch]);
/* Receive the pointed data only if not already sent */
if (gras_dd_is_r_null(r_ref, pointer_type->size[r_arch])) {
break;
}
- errcode = detect_cycle
- ? xbt_dict_get_ext(refs,
- (char*)r_ref, pointer_type->size[r_arch],
- (void**)&l_ref)
- : mismatch_error;
-
- if (errcode == mismatch_error) {
+ reference_is_to_recv = 0;
+ TRY {
+ if (detect_cycle)
+ l_ref = xbt_dict_get_ext(refs, (char*)r_ref, pointer_type->size[r_arch]);
+ else
+ reference_is_to_recv = 1;
+ } CATCH(e) {
+ if (e.category == mismatch_error) {
+ reference_is_to_recv = 1;
+ xbt_ex_free(e);
+ } else {
+ RETHROW;
+ }
+ }
+ if (reference_is_to_recv) {
int subsubcount = 0;
void *l_referenced=NULL;
VERB2("Receiving a ref to '%s', remotely @%p",
sub_type->name, *(void**)r_ref);
if (sub_type->category_code == e_gras_datadesc_type_cat_array) {
- /* Damn. Reference to a dynamic array. Allocating the size for it
+ /* Damn. Reference to a dynamic array. Allocating the space for it
is more complicated */
gras_dd_cat_array_t array_data = sub_type->category.array_data;
gras_datadesc_type_t subsub_type;
subsubcount = array_data.fixed_size;
if (subsubcount == 0)
- TRYOLD(gras_dd_recv_int(sock, r_arch, &subsubcount));
+ gras_dd_recv_int(sock, r_arch, &subsubcount);
subsub_type = array_data.type;
- TRYOLD(gras_dd_alloc_ref(refs,
- subsub_type->size[GRAS_THISARCH] * subsubcount,
- r_ref,pointer_type->size[r_arch],
- (char**)&l_referenced,
- detect_cycle));
+ gras_dd_alloc_ref(refs,
+ subsub_type->size[GRAS_THISARCH] * subsubcount,
+ r_ref,pointer_type->size[r_arch],
+ (char**)&l_referenced,
+ detect_cycle);
} else {
- TRYOLD(gras_dd_alloc_ref(refs,sub_type->size[GRAS_THISARCH],
- r_ref,pointer_type->size[r_arch],
- (char**)&l_referenced,
- detect_cycle));
+ gras_dd_alloc_ref(refs,sub_type->size[GRAS_THISARCH],
+ r_ref,pointer_type->size[r_arch],
+ (char**)&l_referenced,
+ detect_cycle);
}
- TRYOLD(gras_datadesc_recv_rec(sock,state,refs, sub_type,
- r_arch,r_ref,pointer_type->size[r_arch],
- (char*)l_referenced, subsubcount,
- detect_cycle || sub_type->cycle));
+ gras_datadesc_recv_rec(sock,state,refs, sub_type,
+ r_arch,r_ref,pointer_type->size[r_arch],
+ (char*)l_referenced, subsubcount,
+ detect_cycle || sub_type->cycle);
*(void**)l_data=l_referenced;
VERB3("'%s' remotely referenced at %p locally at %p",
sub_type->name, *(void**)r_ref, l_referenced);
- } else if (errcode == no_error) {
+ } else {
VERB2("NOT receiving data remotely referenced @%p (already done, @%p here)",
*(void**)r_ref, *(void**)l_ref);
*(void**)l_data=*l_ref;
- } else {
- return errcode;
- }
+ }
free(r_ref);
break;
}
if (count == 0)
count = subsize;
if (count == 0)
- TRYOLD(gras_dd_recv_int(sock, r_arch, &count));
+ gras_dd_recv_int(sock, r_arch, &count);
if (count == 0)
- RAISE1(mismatch_error,
+ THROW1(mismatch_error,0,
"Invalid (=0) array size for type %s",type->name);
/* receive the content */
VERB1("Array of %d scalars, get it in one shoot", count);
if (sub_type->aligned_size[GRAS_THISARCH] >=
sub_type->aligned_size[r_arch]) {
- TRYOLD(gras_trp_chunk_recv(sock, (char*)l_data,
- sub_type->aligned_size[r_arch] * count));
+ gras_trp_chunk_recv(sock, (char*)l_data,
+ sub_type->aligned_size[r_arch] * count);
if (r_arch != GRAS_THISARCH)
- TRYOLD(gras_dd_convert_elm(sub_type,count,r_arch, l_data,l_data));
+ gras_dd_convert_elm(sub_type,count,r_arch, l_data,l_data);
} else {
ptr = xbt_malloc(sub_type->aligned_size[r_arch] * count);
- TRYOLD(gras_trp_chunk_recv(sock, (char*)ptr,
- sub_type->size[r_arch] * count));
+ gras_trp_chunk_recv(sock, (char*)ptr,
+ sub_type->size[r_arch] * count);
if (r_arch != GRAS_THISARCH)
- TRYOLD(gras_dd_convert_elm(sub_type,count,r_arch, ptr,l_data));
+ gras_dd_convert_elm(sub_type,count,r_arch, ptr,l_data);
free(ptr);
}
} else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
VERB1("Array of %d fixed array of scalars, get it in one shot",count);
if (subsub_type->aligned_size[GRAS_THISARCH] >=
subsub_type->aligned_size[r_arch]) {
- TRYOLD(gras_trp_chunk_recv(sock, (char*)l_data,
- subsub_type->aligned_size[r_arch] * count *
- array_data.fixed_size));
+ gras_trp_chunk_recv(sock, (char*)l_data,
+ subsub_type->aligned_size[r_arch] * count *
+ array_data.fixed_size);
if (r_arch != GRAS_THISARCH)
- TRYOLD(gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, l_data,l_data));
+ gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, l_data,l_data);
} else {
ptr = xbt_malloc(subsub_type->aligned_size[r_arch] * count*array_data.fixed_size);
- TRYOLD(gras_trp_chunk_recv(sock, (char*)ptr,
- subsub_type->size[r_arch] * count*array_data.fixed_size));
+ gras_trp_chunk_recv(sock, (char*)ptr,
+ subsub_type->size[r_arch] * count*array_data.fixed_size);
if (r_arch != GRAS_THISARCH)
- TRYOLD(gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, ptr,l_data));
+ gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, ptr,l_data);
free(ptr);
}
ptr = l_data;
for (cpt=0; cpt<count; cpt++) {
- TRYOLD(gras_datadesc_recv_rec(sock,state,refs, sub_type,
- r_arch, NULL, 0, ptr,-1,
- detect_cycle || sub_type->cycle));
+ gras_datadesc_recv_rec(sock,state,refs, sub_type,
+ r_arch, NULL, 0, ptr,-1,
+ detect_cycle || sub_type->cycle);
ptr += elm_size;
}
if (type->recv)
type->recv(type,state,l_data);
- return no_error;
}
/**
* and store a pointer to it in @dst
*
*/
-xbt_error_t
+void
gras_datadesc_recv(gras_socket_t sock,
gras_datadesc_type_t type,
int r_arch,
void *dst) {
- xbt_error_t errcode;
+ xbt_ex_t e;
gras_cbps_t state; /* callback persistent state */
xbt_dict_t refs; /* all references already sent */
state = gras_cbps_new();
xbt_assert0(type,"called with NULL type descriptor");
- errcode = gras_datadesc_recv_rec(sock, state, refs, type,
- r_arch, NULL, 0,
- (char *) dst,-1,
- type->cycle);
-
- xbt_dict_free(&refs);
- gras_cbps_free(&state);
-
- return errcode;
+ TRY {
+ gras_datadesc_recv_rec(sock, state, refs, type,
+ r_arch, NULL, 0,
+ (char *) dst,-1,
+ type->cycle);
+ } CLEANUP {
+ xbt_dict_free(&refs);
+ gras_cbps_free(&state);
+ } CATCH(e) {
+ RETHROW;
+ }
}
#if 0
#include <ctype.h> /* isdigit */
+#include "xbt/ex.h"
#include "gras/DataDesc/datadesc_private.h"
#include "gras/DataDesc/ddt_parse.yy.h"
XBT_OUT;
}
+static void print_type_modifier(s_type_modifier_t tm) __attribute__((unused));
static void print_type_modifier(s_type_modifier_t tm) {
int i;
gras_ddt_parse_tok_num = gras_ddt_parse_lex_n_dump();
if(gras_ddt_parse_tok_num == GRAS_DDT_PARSE_TOKEN_RA) {
XBT_OUT;
- return mismatch_error; /* end of the englobing structure or union */
+ return old_mismatch_error; /* end of the englobing structure or union */
}
if (XBT_LOG_ISENABLED(ddt_parse,xbt_log_priority_debug)) {
identifier.type = gras_datadesc_by_name("unsigned char");
} else { /* impossible, gcc parses this shit before us */
- RAISE_IMPOSSIBLE;
+ THROW_IMPOSSIBLE;
}
} else if (!strcmp(identifier.type_name, "float")) {
continue;
}
}
- RAISE_IMPOSSIBLE;
+ THROW_IMPOSSIBLE;
} else {
PARSE_ERROR1("Unknown annotation type: '%s'",keyname);
XBT_OUT;
return res;
}
-
-
/* Copyright (c) 2004 Arnaud Legrand, Martin Quinson. All rights reserved. */
/* 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. */
-#line 12 "gras/DataDesc/ddt_parse.yy.l"
+/* char string_buf[GRAS_DDT_PARSE_MAX_STR_CONST];
+ char *string_buf_ptr = NULL; FIXME; killme*/
+#line 15 "gras/DataDesc/ddt_parse.yy.l"
#include "gras/DataDesc/datadesc_private.h"
#include "gras/DataDesc/ddt_parse.yy.h"
#include <string.h>
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lexer,ddt_parse,"The crude internals of the lexer used for type parsing");
#define SHOW_WHERE DEBUG4("%d:%d (char #%d): seen '%s'", gras_ddt_parse_line_pos,gras_ddt_parse_col_pos,gras_ddt_parse_char_pos,gras_ddt_parse_text)
-#line 505 "gras/DataDesc/ddt_parse.yy.c"
+#line 507 "gras/DataDesc/ddt_parse.yy.c"
#define INITIAL 0
#define annotate 1
register char *yy_cp, *yy_bp;
register int yy_act;
-#line 32 "gras/DataDesc/ddt_parse.yy.l"
+#line 35 "gras/DataDesc/ddt_parse.yy.l"
int comment_caller=0;
int annotate_caller=0;
- char string_buf[GRAS_DDT_PARSE_MAX_STR_CONST];
- char *string_buf_ptr = NULL;
-
-#line 667 "gras/DataDesc/ddt_parse.yy.c"
+#line 666 "gras/DataDesc/ddt_parse.yy.c"
if ( (yy_init) )
{
#line 175 "gras/DataDesc/ddt_parse.yy.l"
ECHO;
YY_BREAK
-#line 986 "gras/DataDesc/ddt_parse.yy.c"
+#line 985 "gras/DataDesc/ddt_parse.yy.c"
case YY_STATE_EOF(INITIAL):
case YY_STATE_EOF(annotate):
case YY_STATE_EOF(comment):
gras_ddt_parse_line_pos = 1;
gras_ddt_parse_char_pos = 0;
gras_ddt_parse_tok_num = 0;
+
+ if (0)
+ yyunput('\0',NULL); /* fake a use of this function to calm gcc down */
}
/* Local variables:*/
/* 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. */
+/* char string_buf[GRAS_DDT_PARSE_MAX_STR_CONST];
+ char *string_buf_ptr = NULL; FIXME; killme*/
+
%option noyywrap
%{
#include "gras/DataDesc/datadesc_private.h"
int comment_caller=0;
int annotate_caller=0;
- char string_buf[GRAS_DDT_PARSE_MAX_STR_CONST];
- char *string_buf_ptr = NULL;
-
"//"[^\n]*
"/*g"{space}* { /****************** ANNOTATION ************************/
gras_ddt_parse_line_pos = 1;
gras_ddt_parse_char_pos = 0;
gras_ddt_parse_tok_num = 0;
+
+ if (0)
+ yyunput('\0',NULL); /* fake a use of this function to calm gcc down */
}
/* Local variables:*/
/* 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 "xbt/ex.h"
#include "gras/Msg/msg_private.h"
#include "gras/DataDesc/datadesc_interface.h"
#include "gras/Transport/transport_interface.h" /* gras_trp_chunk_send/recv */
short int version,
gras_datadesc_type_t payload) {
- xbt_error_t errcode;
gras_msgtype_t msgtype;
char *namev=make_namev(name,version);
-
- errcode = xbt_set_get_by_name(_gras_msgtype_set,
- namev,(xbt_set_elm_t*)&msgtype);
+ int found = 0;
+ xbt_ex_t e;
+
+ TRY {
+ msgtype = (gras_msgtype_t)xbt_set_get_by_name(_gras_msgtype_set,namev);
+ found = 1;
+ } CATCH(e) {
+ if (e.category != mismatch_error)
+ RETHROW;
+ xbt_ex_free(e);
+ }
- if (errcode == no_error) {
+ if (found) {
VERB2("Re-register version %d of message '%s' (same payload, ignored).",
version, name);
xbt_assert3(!gras_datadesc_type_cmp(msgtype->ctn_type, payload),
return ; /* do really ignore it */
}
- xbt_assert_error(mismatch_error); /* expect this error */
+
VERB3("Register version %d of message '%s' (payload: %s).",
version, name, gras_datadesc_get_name(payload));
gras_msgtype_t gras_msgtype_by_namev(const char *name,
short int version) {
gras_msgtype_t res;
-
- xbt_error_t errcode;
char *namev = make_namev(name,version);
- errcode = xbt_set_get_by_name(_gras_msgtype_set, namev,
- (xbt_set_elm_t*)&res);
- if (errcode != no_error)
- res = NULL;
- if (!res)
- WARN1("msgtype_by_name(%s) returns NULL",namev);
+ res = (gras_msgtype_t)xbt_set_get_by_name(_gras_msgtype_set, namev);
if (name != namev)
free(namev);
/** \brief Send the data pointed by \a payload as a message of type
* \a msgtype to the peer \a sock */
-xbt_error_t
+void
gras_msg_send(gras_socket_t sock,
gras_msgtype_t msgtype,
void *payload) {
- xbt_error_t errcode;
static gras_datadesc_type_t string_type=NULL;
if (!msgtype)
- RAISE0(mismatch_error,
+ THROW0(mismatch_error,0,
"Cannot send the NULL message (did msgtype_by_name fail?)");
if (!string_type) {
DEBUG3("send '%s' to %s:%d", msgtype->name,
gras_socket_peer_name(sock),gras_socket_peer_port(sock));
- TRYOLD(gras_trp_chunk_send(sock, GRAS_header, 6));
+ gras_trp_chunk_send(sock, GRAS_header, 6);
- TRYOLD(gras_datadesc_send(sock, string_type, &msgtype->name));
+ gras_datadesc_send(sock, string_type, &msgtype->name);
if (msgtype->ctn_type)
- TRYOLD(gras_datadesc_send(sock, msgtype->ctn_type, payload));
- TRYOLD(gras_trp_flush(sock));
-
- return no_error;
+ gras_datadesc_send(sock, msgtype->ctn_type, payload);
+ gras_trp_flush(sock);
}
/*
* receive the next message on the given socket.
*/
-xbt_error_t
+void
gras_msg_recv(gras_socket_t sock,
gras_msgtype_t *msgtype,
void **payload,
int *payload_size) {
- xbt_error_t errcode;
+ xbt_ex_t e;
static gras_datadesc_type_t string_type=NULL;
char header[6];
int cpt;
xbt_assert(string_type);
}
- errcode=gras_trp_chunk_recv(sock, header, 6);
- if (errcode!=no_error)
- RAISE2(errcode,"Got '%s' while trying to get the mesage header on socket %p",
- xbt_error_name(errcode),sock);
+ TRY {
+ gras_trp_chunk_recv(sock, header, 6);
+ } CATCH(e) {
+ THROW2(e.category,e.value,
+ "Exception caught while trying to get the mesage header on socket %p : %s",
+ sock,e.msg);
+ }
+
for (cpt=0; cpt<4; cpt++)
if (header[cpt] != GRAS_header[cpt])
- RAISE2(mismatch_error,"Incoming bytes do not look like a GRAS message (header='%.4s' not '%.4s')",header,GRAS_header);
+ THROW2(mismatch_error,0,
+ "Incoming bytes do not look like a GRAS message (header='%.4s' not '%.4s')",header,GRAS_header);
if (header[4] != GRAS_header[4])
- RAISE2(mismatch_error,"GRAS protocol mismatch (got %d, use %d)",
+ THROW2(mismatch_error,0,"GRAS protocol mismatch (got %d, use %d)",
(int)header[4], (int)GRAS_header[4]);
r_arch = (int)header[5];
DEBUG2("Handle an incoming message using protocol %d (remote is %s)",
(int)header[4],gras_datadesc_arch_name(r_arch));
- TRYOLD(gras_datadesc_recv(sock, string_type, r_arch, &msg_name));
- errcode = xbt_set_get_by_name(_gras_msgtype_set,
- msg_name,(xbt_set_elm_t*)msgtype);
- if (errcode != no_error)
- RAISE2(errcode,
- "Got error %s while retrieving the type associated to messages '%s'",
- xbt_error_name(errcode),msg_name);
- /* FIXME: Survive unknown messages */
+ gras_datadesc_recv(sock, string_type, r_arch, &msg_name);
+ TRY {
+ *msgtype = (gras_msgtype_t)xbt_set_get_by_name(_gras_msgtype_set,msg_name);
+ } CATCH(e) {
+ /* FIXME: Survive unknown messages */
+ RETHROW1("Exception caught while retrieving the type associated to messages '%s' : %s",
+ msg_name);
+ }
free(msg_name);
if ((*msgtype)->ctn_type) {
"Dynamic array as payload is forbided for now (FIXME?).",
"Reference to dynamic array is allowed.");
*payload = xbt_malloc(*payload_size);
- TRYOLD(gras_datadesc_recv(sock, (*msgtype)->ctn_type, r_arch, *payload));
+ gras_datadesc_recv(sock, (*msgtype)->ctn_type, r_arch, *payload);
} else {
*payload = NULL;
*payload_size = 0;
}
- return no_error;
}
/** \brief 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 gras_msg_handle().
*/
-xbt_error_t
+void
gras_msg_wait(double timeout,
gras_msgtype_t msgt_want,
gras_socket_t *expeditor,
gras_msgtype_t msgt_got;
void *payload_got;
int payload_size_got;
- xbt_error_t errcode;
double start, now;
gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_get("gras_msg");
int cpt;
payload_got = NULL;
- if (!msgt_want)
- RAISE0(mismatch_error,
- "Cannot wait for the NULL message (did msgtype_by_name fail?)");
+ xbt_assert0(msgt_want,"Cannot wait for the NULL message");
VERB1("Waiting for message '%s'",msgt_want->name);
free(msg.payload);
xbt_dynar_cursor_rm(pd->msg_queue, &cpt);
VERB0("The waited message was queued");
- return no_error;
+ return;
}
}
while (1) {
- TRYOLD(gras_trp_select(timeout - now + start, &expeditor_res));
- TRYOLD(gras_msg_recv(expeditor_res, &msgt_got, &payload_got, &payload_size_got));
+ expeditor_res = gras_trp_select(timeout - now + start);
+ gras_msg_recv(expeditor_res, &msgt_got, &payload_got, &payload_size_got);
if (msgt_got->code == msgt_want->code) {
if (expeditor)
*expeditor=expeditor_res;
memcpy(payload, payload_got, payload_size_got);
free(payload_got);
VERB0("Got waited message");
- return no_error;
+ return;
}
/* not expected msg type. Queue it for later */
now=gras_os_time();
if (now - start + 0.001 < timeout) {
- RAISE1(timeout_error,"Timeout while waiting for msg %s",msgt_want->name);
+ THROW1(timeout_error, now-start+0.001-timeout,
+ "Timeout while waiting for msg %s",msgt_want->name);
}
}
- RAISE_IMPOSSIBLE;
+ THROW_IMPOSSIBLE;
}
/** @brief Handle an incomming message or timer (or wait up to \a timeOut seconds)
*
* Messages are passed to the callbacks.
*/
-xbt_error_t
+void
gras_msg_handle(double timeOut) {
double untiltimer;
- xbt_error_t errcode;
int cpt;
s_gras_msg_t msg;
gras_cblist_t *list=NULL;
gras_msg_cb_t cb;
- int timerexpected;
+ int timerexpected, timeouted;
+ xbt_ex_t e;
VERB1("Handling message within the next %.2fs",timeOut);
DEBUG2("[%.0f] Next timer in %f sec", gras_os_time(), untiltimer);
if (untiltimer == 0.0) {
/* A timer was already elapsed and handled */
- return no_error;
+ return;
}
if (untiltimer != -1.0) {
timerexpected = 1;
}
/* get a message (from the queue or from the net) */
+ timeouted = 0;
if (xbt_dynar_length(pd->msg_queue)) {
DEBUG0("Get a message from the queue");
xbt_dynar_shift(pd->msg_queue,&msg);
expeditor = msg.expeditor;
msgtype = msg.type;
payload = msg.payload;
- errcode = no_error;
} else {
- errcode = gras_trp_select(timeOut, &expeditor);
- if (errcode != no_error && errcode != timeout_error)
- return errcode;
- if (errcode == no_error) {
- errcode = gras_msg_recv(expeditor, &msgtype, &payload, &payload_size);
- if (errcode != no_error)
- RAISE2(errcode, "Error '%s' while receiving a message on select()ed socket %p",
- xbt_error_name(errcode),expeditor);
+ TRY {
+ expeditor = gras_trp_select(timeOut);
+ } CATCH(e) {
+ if (e.category != timeout_error)
+ RETHROW;
+ xbt_ex_free(e);
+ timeouted = 1;
+ }
+
+ if (!timeouted) {
+ TRY {
+ gras_msg_recv(expeditor, &msgtype, &payload, &payload_size);
+ } CATCH(e) {
+ RETHROW1("Error caught while receiving a message on select()ed socket %p: %s",
+ expeditor);
+ }
}
}
- if (errcode == timeout_error ) {
+ if (timeouted) {
if (timerexpected) {
/* A timer elapsed before the arrival of any message even if we select()ed a bit */
untiltimer = gras_msg_timer_handle();
if (untiltimer == 0.0) {
- return no_error;
+ /* we served a timer, we're done */
+ return;
} else {
- xbt_assert1(untiltimer>0, "Negative timer (%f). I'm puzzeled", untiltimer);
+ xbt_assert1(untiltimer>0, "Negative timer (%f). I'm 'puzzeled'", untiltimer);
WARN1("No timer elapsed, in contrary to expectations (next in %f sec)",
untiltimer);
- return timeout_error;
+ THROW1(timeout_error,0,
+ "No timer elapsed, in contrary to expectations (next in %f sec)",
+ untiltimer);
}
} else {
/* select timeouted, and no timer elapsed. Nothing to do */
- return timeout_error;
+ THROW0(timeout_error, 0, "No new message or timer");
}
}
INFO1("No callback for the incomming '%s' message. Discarded.",
msgtype->name);
WARN0("FIXME: gras_datadesc_free not implemented => leaking the payload");
- return no_error;
+ return;
}
xbt_dynar_foreach(list->cbs,cpt,cb) {
if ((*cb)(expeditor,payload)) {
/* cb handled the message */
free(payload);
- return no_error;
+ return;
}
}
- INFO1("Message '%s' refused by all registered callbacks", msgtype->name);
- WARN0("FIXME: gras_datadesc_free not implemented => leaking the payload");
- return mismatch_error;
+ THROW1(mismatch_error,0,
+ "Message '%s' refused by all registered callbacks", msgtype->name);
}
void
void gras_msgtype_free(void *msgtype);
-xbt_error_t gras_msg_recv(gras_socket_t sock,
- gras_msgtype_t *msgtype,
- void **payload,
- int *payload_size);
+void gras_msg_recv(gras_socket_t sock,
+ gras_msgtype_t *msgtype,
+ void **payload,
+ int *payload_size);
/**
* gras_cblist_t:
/* 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 "xbt/ex.h"
#include "gras/Msg/msg_private.h"
#include "gras/timer.h"
#include "gras/Virtu/virtu_interface.h"
}
/** @brief Cancel a delayed task */
-xbt_error_t gras_timer_cancel_delay(double interval, void_f_void_t action) {
+void gras_timer_cancel_delay(double interval, void_f_void_t action) {
gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_get("gras_msg");
int cursor,found;
s_gras_timer_t timer;
}
if (!found)
- RAISE2(mismatch_error,"Cannot remove the action %p delayed of %f second: not found",
+ THROW2(mismatch_error,0,"Cannot remove the action %p delayed of %f second: not found",
action,interval);
- return no_error;
}
/** @brief Cancel a repetitive task */
-xbt_error_t gras_timer_cancel_repeat(double interval, void_f_void_t action) {
+void gras_timer_cancel_repeat(double interval, void_f_void_t action) {
gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_get("gras_msg");
int cursor,found;
s_gras_timer_t timer;
}
if (!found)
- RAISE2(mismatch_error,"Cannot remove the action %p delayed of %f second: not found",
+ THROW2(mismatch_error,0,"Cannot remove the action %p delayed of %f second: not found",
action,interval);
-
- return no_error;
}
/** @brief Cancel all delayed tasks */
-xbt_error_t gras_timer_cancel_delay_all(void) {
+void gras_timer_cancel_delay_all(void) {
gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_get("gras_msg");
int cursor, found;
s_gras_timer_t timer;
}
if (!found)
- RAISE0(mismatch_error,"No delayed action to remove");
+ THROW0(mismatch_error,0,"No delayed action to remove");
- return no_error;
}
/** @brief Cancel all repetitive tasks */
-xbt_error_t gras_timer_cancel_repeat_all(void){
+void gras_timer_cancel_repeat_all(void){
gras_msg_procdata_t pd=(gras_msg_procdata_t)gras_libdata_get("gras_msg");
int cursor, found;
s_gras_timer_t timer;
found = FALSE;
xbt_dynar_foreach(pd->timers,cursor,timer){
- if (timer.repeat == FALSE) {
-
- found = TRUE;
- xbt_dynar_cursor_rm(pd->timers, &cursor);
- }
+ if (timer.repeat == FALSE) {
+
+ found = TRUE;
+ xbt_dynar_cursor_rm(pd->timers, &cursor);
+ }
}
if (!found)
- RAISE0(mismatch_error,"No repetitive action to remove");
-
- return no_error;
+ THROW0(mismatch_error,0,"No repetitive action to remove");
}
/** @brief Cancel all delayed and repetitive tasks */
/* 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 "xbt/ex.h"
#include "portable.h"
#include "gras/Transport/transport_private.h"
XBT_LOG_EXTERNAL_CATEGORY(transport);
*
* if timeout>0 and no message there, wait at most that amount of time before giving up.
*/
-xbt_error_t
-gras_trp_select(double timeout,
- gras_socket_t *dst) {
-
- xbt_error_t errcode;
+gras_socket_t gras_trp_select(double timeout) {
xbt_dynar_t sockets= gras_socketset_get();
int done = -1;
double wakeup = gras_os_time() + timeout;
# endif /* !USE_SYSCONF */
#endif
- *dst=NULL;
while (done == -1) {
if (timeout > 0) { /* did we timeout already? */
now = gras_os_time();
if (timeout > 0) {
DEBUG1("No socket to select onto. Sleep %f sec instead.",timeout);
gras_os_sleep(timeout);
- return timeout_error;
+ THROW1(timeout_error,0,"No socket to select onto. Sleep %f sec instead",timeout);
} else {
DEBUG0("No socket to select onto. Return directly.");
- return timeout_error;
+ THROW0(timeout_error,0, "No socket to select onto. Return directly.");
}
}
/* if we cared, we would have set an handler */
continue;
case EINVAL: /* invalid value */
- RAISE3(system_error,"invalid select: nb fds: %d, timeout: %d.%d",
+ THROW3(system_error,EINVAL,"invalid select: nb fds: %d, timeout: %d.%d",
max_fds, (int)tout.tv_sec,(int) tout.tv_usec);
case ENOMEM:
xbt_assert0(0,"Malloc error during the select");
default:
- RAISE2(system_error,"Error during select: %s (%d)",
+ THROW2(system_error,errno,"Error during select: %s (%d)",
strerror(errno),errno);
}
- RAISE_IMPOSSIBLE;
+ THROW_IMPOSSIBLE;
} else if (ready == 0) {
continue; /* this was a timeout */
}
/* not a socket but an ear. accept on it and serve next socket */
gras_socket_t accepted=NULL;
- TRYOLD((sock_iter->plugin->socket_accept)(sock_iter,&accepted));
+ accepted = (sock_iter->plugin->socket_accept)(sock_iter);
DEBUG2("accepted=%p,&accepted=%p",accepted,&accepted);
accepted->meas = sock_iter->meas;
} else {
} else {
#endif
/* Got a suited socket ! */
- *dst = sock_iter;
XBT_OUT;
- return no_error;
+ return sock_iter;
#if 0
}
#endif
}
XBT_OUT;
- return timeout_error;
+ return NULL;
}
-xbt_error_t gras_trp_sg_setup(gras_trp_plugin_t plug) {
- return mismatch_error;
+void gras_trp_sg_setup(gras_trp_plugin_t plug) {
+ THROW0(mismatch_error,0,"No SG transport on live platforms");
}
/* 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 "xbt/ex.h"
#include "gras/Transport/transport_private.h"
#include "msg/msg.h"
#include "gras/Virtu/virtu_sg.h"
*
* if timeout>0 and no message there, wait at most that amount of time before giving up.
*/
-xbt_error_t
-gras_trp_select(double timeout,
- gras_socket_t *dst) {
-
- xbt_error_t errcode;
- double startTime=gras_os_time();
+gras_socket_t gras_trp_select(double timeout) {
+
+ gras_socket_t res;
gras_trp_procdata_t pd=(gras_trp_procdata_t)gras_libdata_get("gras_trp");
gras_trp_sg_sock_data_t *sockdata;
gras_trp_plugin_t trp;
MSG_host_get_name(MSG_host_self()),
timeout);
- TRYOLD(MSG_channel_select_from((m_channel_t) pd->chan, timeout, &r_pid));
+ MSG_channel_select_from((m_channel_t) pd->chan, timeout, &r_pid);
if (r_pid < 0) {
DEBUG0("TIMEOUT");
- return timeout_error;
+ THROW0(timeout_error,0,"Timeout");
}
/* Ok, got something. Open a socket back to the expeditor */
continue;
if (sockdata->to_PID == r_pid) {
- *dst=sock_iter;
- return no_error;
+ return sock_iter;
}
}
/* Socket to expeditor not created yet */
DEBUG0("Create a socket to the expeditor");
- TRYOLD(gras_trp_plugin_get_by_name("buf",&trp));
+ trp = gras_trp_plugin_get_by_name("buf");
- gras_trp_socket_new(1,dst);
- (*dst)->plugin = trp;
+ gras_trp_socket_new(1,&res);
+ res->plugin = trp;
- (*dst)->incoming = 1;
- (*dst)->outgoing = 1;
- (*dst)->accepting = 0;
- (*dst)->sd = -1;
+ res->incoming = 1;
+ res->outgoing = 1;
+ res->accepting = 0;
+ res->sd = -1;
- (*dst)->port = -1;
+ res->port = -1;
sockdata = xbt_new(gras_trp_sg_sock_data_t,1);
sockdata->from_PID = MSG_process_self_PID();
sockdata->to_PID = r_pid;
sockdata->to_host = MSG_process_get_host(MSG_process_from_PID(r_pid));
- (*dst)->data = sockdata;
- gras_trp_buf_init_sock(*dst);
+ res->data = sockdata;
+ gras_trp_buf_init_sock(res);
- (*dst)->peer_name = strdup(MSG_host_get_name(sockdata->to_host));
+ res->peer_name = strdup(MSG_host_get_name(sockdata->to_host));
remote_hd=(gras_hostdata_t *)MSG_host_get_data(sockdata->to_host);
xbt_assert0(remote_hd,"Run gras_process_init!!");
sockdata->to_chan = -1;
- (*dst)->peer_port = -10;
+ res->peer_port = -10;
for (cursor=0; cursor<XBT_MAX_CHANNEL; cursor++) {
if (remote_hd->proc[cursor] == r_pid) {
sockdata->to_chan = cursor;
DEBUG2("Chan %d on %s is for my pal",
- cursor,(*dst)->peer_name);
+ cursor,res->peer_name);
xbt_dynar_foreach(remote_hd->ports, cpt, pr) {
if (sockdata->to_chan == pr.tochan) {
continue;
}
- (*dst)->peer_port = pr.port;
+ res->peer_port = pr.port;
DEBUG1("Cool, it points to port %d", pr.port);
break;
} else {
pr.tochan,sockdata->to_chan);
}
}
- if ((*dst)->peer_port == -10) {
+ if (res->peer_port == -10) {
/* was for measurement */
sockdata->to_chan = -1;
} else {
xbt_assert0(sockdata->to_chan != -1,
"Got a message from a process without channel");
- return no_error;
+ return res;
}
/* dummy implementations of the functions used in RL mode */
-xbt_error_t gras_trp_tcp_setup(gras_trp_plugin_t plug) {
- return mismatch_error;
+void gras_trp_tcp_setup(gras_trp_plugin_t plug) {
}
-xbt_error_t gras_trp_file_setup(gras_trp_plugin_t plug) {
- return mismatch_error;
+void gras_trp_file_setup(gras_trp_plugin_t plug) {
+ THROW0(mismatch_error,0,"No file within SG realm");
}
/* 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 "xbt/ex.h"
#include "portable.h"
#include "gras/Transport/transport_private.h"
static void
gras_trp_plugin_new(const char *name, gras_trp_setup_t setup) {
- xbt_error_t errcode;
+ xbt_ex_t e;
gras_trp_plugin_t plug = xbt_new0(s_gras_trp_plugin_t, 1);
plug->name=xbt_strdup(name);
- errcode = setup(plug);
- switch (errcode) {
- case mismatch_error:
- /* SG plugin return mismatch when in RL mode (and vice versa) */
- free(plug->name);
- free(plug);
- break;
-
- case no_error:
- xbt_dict_set(_gras_trp_plugins,
- name, plug, gras_trp_plugin_free);
- break;
-
- default:
- DIE_IMPOSSIBLE;
+ TRY {
+ setup(plug);
+ } CATCH(e) {
+ if (e.category == mismatch_error) {
+ /* SG plugin raise mismatch when in RL mode (and vice versa) */
+ free(plug->name);
+ free(plug);
+ xbt_ex_free(e);
+ } else {
+ RETHROW;
+ }
}
+ xbt_dict_set(_gras_trp_plugins, name, plug, gras_trp_plugin_free);
}
void gras_trp_init(void){
* Opens a server socket and make it ready to be listened to.
* In real life, you'll get a TCP socket.
*/
-xbt_error_t
+gras_socket_t
gras_socket_server_ext(unsigned short port,
unsigned long int bufSize,
- int measurement,
-
- /* OUT */ gras_socket_t *dst) {
+ int measurement) {
- xbt_error_t errcode;
+ xbt_ex_t e;
gras_trp_plugin_t trp;
gras_socket_t sock;
- *dst = NULL;
-
DEBUG2("Create a server socket from plugin %s on port %d",
gras_if_RL() ? "tcp" : "sg",
port);
- TRYOLD(gras_trp_plugin_get_by_name((measurement? (gras_if_RL() ? "tcp" : "sg")
- :"buf"),
- &trp));
+ trp = gras_trp_plugin_get_by_name((measurement? (gras_if_RL() ? "tcp" : "sg")
+ :"buf"));
/* defaults settings */
gras_trp_socket_new(1,&sock);
/* Call plugin socket creation function */
DEBUG1("Prepare socket with plugin (fct=%p)",trp->socket_server);
- errcode = trp->socket_server(trp, sock);
- DEBUG3("in=%c out=%c accept=%c",
- sock->incoming?'y':'n',
- sock->outgoing?'y':'n',
- sock->accepting?'y':'n');
-
- if (errcode != no_error) {
+ TRY {
+ trp->socket_server(trp, sock);
+ DEBUG3("in=%c out=%c accept=%c",
+ sock->incoming?'y':'n',
+ sock->outgoing?'y':'n',
+ sock->accepting?'y':'n');
+ } CATCH(e) {
free(sock);
- return errcode;
+ RETHROW;
}
- *dst = sock;
-
- return no_error;
+ return sock;
}
/**
* Opens a client socket to a remote host.
* In real life, you'll get a TCP socket.
*/
-xbt_error_t
+gras_socket_t
gras_socket_client_ext(const char *host,
unsigned short port,
unsigned long int bufSize,
- int measurement,
-
- /* OUT */ gras_socket_t *dst) {
+ int measurement) {
- xbt_error_t errcode;
+ xbt_ex_t e;
gras_trp_plugin_t trp;
gras_socket_t sock;
- *dst = NULL;
-
- TRYOLD(gras_trp_plugin_get_by_name((measurement? (gras_if_RL() ? "tcp" : "sg")
- :"buf"),
- &trp));
+ trp = gras_trp_plugin_get_by_name((measurement? (gras_if_RL() ? "tcp" : "sg")
+ : "buf"));
DEBUG1("Create a client socket from plugin %s",gras_if_RL() ? "tcp" : "sg");
/* defaults settings */
sock->meas = measurement;
/* plugin-specific */
- errcode= (*trp->socket_client)(trp, sock);
- DEBUG3("in=%c out=%c accept=%c",
- sock->incoming?'y':'n',
- sock->outgoing?'y':'n',
- sock->accepting?'y':'n');
-
- if (errcode != no_error) {
+ TRY {
+ (*trp->socket_client)(trp, sock);
+ DEBUG3("in=%c out=%c accept=%c",
+ sock->incoming?'y':'n',
+ sock->outgoing?'y':'n',
+ sock->accepting?'y':'n');
+ } CATCH(e) {
free(sock);
- return errcode;
+ RETHROW;
}
- *dst = sock;
-
- return no_error;
+ return sock;
}
/**
* Opens a server socket and make it ready to be listened to.
* In real life, you'll get a TCP socket.
*/
-xbt_error_t
-gras_socket_server(unsigned short port,
- /* OUT */ gras_socket_t *dst) {
- return gras_socket_server_ext(port,32,0,dst);
+gras_socket_t
+gras_socket_server(unsigned short port) {
+ return gras_socket_server_ext(port,32,0);
}
/**
* Opens a client socket to a remote host.
* In real life, you'll get a TCP socket.
*/
-xbt_error_t
+gras_socket_t
gras_socket_client(const char *host,
- unsigned short port,
- /* OUT */ gras_socket_t *dst) {
- return gras_socket_client_ext(host,port,32,0,dst);
+ unsigned short port) {
+ return gras_socket_client_ext(host,port,32,0);
}
*
* Send a bunch of bytes from on socket
*/
-xbt_error_t
+void
gras_trp_chunk_send(gras_socket_t sd,
char *data,
long int size) {
xbt_assert1(sd->plugin->chunk_send,
"No function chunk_send on transport plugin %s",
sd->plugin->name);
- return (*sd->plugin->chunk_send)(sd,data,size);
+ (*sd->plugin->chunk_send)(sd,data,size);
}
/**
* gras_trp_chunk_recv:
*
* Receive a bunch of bytes from a socket
*/
-xbt_error_t
+void
gras_trp_chunk_recv(gras_socket_t sd,
char *data,
long int size) {
xbt_assert1(sd->plugin->chunk_recv,
"No function chunk_recv on transport plugin %s",
sd->plugin->name);
- return (sd->plugin->chunk_recv)(sd,data,size);
+ (sd->plugin->chunk_recv)(sd,data,size);
}
/**
*
* Make sure all pending communications are done
*/
-xbt_error_t
+void
gras_trp_flush(gras_socket_t sd) {
- return (sd->plugin->flush)(sd);
+ (sd->plugin->flush)(sd);
}
-xbt_error_t
-gras_trp_plugin_get_by_name(const char *name,
- gras_trp_plugin_t *dst){
-
- return xbt_dict_get(_gras_trp_plugins,name,(void**)dst);
+gras_trp_plugin_t
+gras_trp_plugin_get_by_name(const char *name){
+ return xbt_dict_get(_gras_trp_plugins,name);
}
int gras_socket_my_port (gras_socket_t sock) {
* there is no way to control what is sent (ie, you cannot use these
* functions to exchange data out of band).
*/
-xbt_error_t gras_socket_meas_send(gras_socket_t peer,
- unsigned int timeout,
- unsigned long int exp_size,
- unsigned long int msg_size) {
- xbt_error_t errcode;
+void gras_socket_meas_send(gras_socket_t peer,
+ unsigned int timeout,
+ unsigned long int exp_size,
+ unsigned long int msg_size) {
char *chunk = xbt_malloc0(msg_size);
unsigned long int exp_sofar;
CDEBUG5(trp_meas,"Sent %lu of %lu (msg_size=%ld) to %s:%d",
exp_sofar,exp_size,msg_size,
gras_socket_peer_name(peer), gras_socket_peer_port(peer));
- TRYOLD(gras_trp_chunk_send(peer,chunk,msg_size));
+ gras_trp_chunk_send(peer,chunk,msg_size);
}
CDEBUG5(trp_meas,"Sent %lu of %lu (msg_size=%ld) to %s:%d",
exp_sofar,exp_size,msg_size,
free(chunk);
XBT_OUT;
- return no_error;
}
/** \brief Receive a chunk of data over a measurement socket
* Calls to gras_socket_meas_send() and gras_socket_meas_recv() on
* each side of the socket should be paired.
*/
-xbt_error_t gras_socket_meas_recv(gras_socket_t peer,
- unsigned int timeout,
- unsigned long int exp_size,
- unsigned long int msg_size){
+void gras_socket_meas_recv(gras_socket_t peer,
+ unsigned int timeout,
+ unsigned long int exp_size,
+ unsigned long int msg_size){
- xbt_error_t errcode;
char *chunk = xbt_malloc(msg_size);
unsigned long int exp_sofar;
CDEBUG5(trp_meas,"Recvd %ld of %lu (msg_size=%ld) from %s:%d",
exp_sofar,exp_size,msg_size,
gras_socket_peer_name(peer), gras_socket_peer_port(peer));
- TRYOLD(gras_trp_chunk_recv(peer,chunk,msg_size));
+ gras_trp_chunk_recv(peer,chunk,msg_size);
}
CDEBUG5(trp_meas,"Recvd %ld of %lu (msg_size=%ld) from %s:%d",
exp_sofar,exp_size,msg_size,
free(chunk);
XBT_OUT;
-
- return no_error;
}
/**
* done for regular sockets, but you usually want more control about
* what's going on with measurement sockets.
*/
-xbt_error_t gras_socket_meas_accept(gras_socket_t peer, gras_socket_t *accepted){
- xbt_error_t errcode;
+gras_socket_t gras_socket_meas_accept(gras_socket_t peer){
gras_socket_t res;
-
+
xbt_assert0(peer->meas,
"No need to accept on non-measurement sockets (it's automatic)");
if (!peer->accepting) {
/* nothing to accept here */
- *accepted=peer;
- return no_error;
+ return peer;
}
- TRYOLD((peer->plugin->socket_accept)(peer,accepted));
- (*accepted)->meas = peer->meas;
- CDEBUG1(trp_meas,"meas_accepted onto %d",(*accepted)->sd);
+ res = (peer->plugin->socket_accept)(peer);
+ res->meas = peer->meas;
+ CDEBUG1(trp_meas,"meas_accepted onto %d",res->sd);
- return no_error;
+ return res;
}
/***
*** Main user functions
***/
-xbt_error_t gras_trp_chunk_send(gras_socket_t sd,
- char *data,
- long int size);
-xbt_error_t gras_trp_chunk_recv(gras_socket_t sd,
- char *data,
- long int size);
-xbt_error_t gras_trp_flush(gras_socket_t sd);
+void gras_trp_chunk_send(gras_socket_t sd,
+ char *data,
+ long int size);
+void gras_trp_chunk_recv(gras_socket_t sd,
+ char *data,
+ long int size);
+void gras_trp_flush(gras_socket_t sd);
/* Find which socket needs to be read next */
-xbt_error_t
-gras_trp_select(double timeout,
- gras_socket_t *dst);
+gras_socket_t gras_trp_select(double timeout);
/***
/* dst pointers are created and initialized with default values
before call to socket_client/server.
Retrive the info you need from there. */
- xbt_error_t (*socket_client)(gras_trp_plugin_t self,
- gras_socket_t dst);
- xbt_error_t (*socket_server)(gras_trp_plugin_t self,
- gras_socket_t dst);
+ void (*socket_client)(gras_trp_plugin_t self,
+ gras_socket_t dst);
+ void (*socket_server)(gras_trp_plugin_t self,
+ gras_socket_t dst);
- xbt_error_t (*socket_accept)(gras_socket_t sock,
- gras_socket_t *dst);
+ gras_socket_t (*socket_accept)(gras_socket_t from);
/* socket_close() is responsible of telling the OS that the socket is over,
but should not free the socket itself (beside the specific part) */
- void (*socket_close)(gras_socket_t sd);
+ void (*socket_close)(gras_socket_t sd);
- xbt_error_t (*chunk_send)(gras_socket_t sd,
- const char *data,
- unsigned long int size);
- xbt_error_t (*chunk_recv)(gras_socket_t sd,
- char *data,
- unsigned long int size);
+ void (*chunk_send)(gras_socket_t sd,
+ const char *data,
+ unsigned long int size);
+ void (*chunk_recv)(gras_socket_t sd,
+ char *data,
+ unsigned long int size);
/* flush has to make sure that the pending communications are achieved */
- xbt_error_t (*flush)(gras_socket_t sd);
+ void (*flush)(gras_socket_t sd);
- void *data; /* plugin-specific data */
+ void *data; /* plugin-specific data */
/* exit is responsible for freeing data and telling the OS this plugin goes */
/* exit=NULL, data gets freed. (ie exit function needed only when data contains pointers) */
- void (*exit)(gras_trp_plugin_t);
+ void (*exit)(gras_trp_plugin_t);
};
-xbt_error_t
-gras_trp_plugin_get_by_name(const char *name,
- gras_trp_plugin_t *dst);
+gras_trp_plugin_t
+gras_trp_plugin_get_by_name(const char *name);
/* Data of this module specific to each process
* (used by sg_process.c to cleanup the SG channel cruft)
#include "portable.h"
#include "xbt/misc.h"
#include "xbt/sysdep.h"
+#include "xbt/ex.h"
#include "transport_private.h"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(trp_buf,transport,
***/
void hexa_print(const char*name, unsigned char *data, int size); /* in gras.c */
-xbt_error_t gras_trp_buf_socket_client(gras_trp_plugin_t self,
- gras_socket_t sock);
-xbt_error_t gras_trp_buf_socket_server(gras_trp_plugin_t self,
- gras_socket_t sock);
-xbt_error_t gras_trp_buf_socket_accept(gras_socket_t sock,
- gras_socket_t *dst);
+void gras_trp_buf_socket_client(gras_trp_plugin_t self,
+ gras_socket_t sock);
+void gras_trp_buf_socket_server(gras_trp_plugin_t self,
+ gras_socket_t sock);
+gras_socket_t gras_trp_buf_socket_accept(gras_socket_t sock);
void gras_trp_buf_socket_close(gras_socket_t sd);
-xbt_error_t gras_trp_buf_chunk_send(gras_socket_t sd,
- const char *data,
- unsigned long int size);
+void gras_trp_buf_chunk_send(gras_socket_t sd,
+ const char *data,
+ unsigned long int size);
-xbt_error_t gras_trp_buf_chunk_recv(gras_socket_t sd,
- char *data,
- unsigned long int size);
-xbt_error_t gras_trp_buf_flush(gras_socket_t sock);
+void gras_trp_buf_chunk_recv(gras_socket_t sd,
+ char *data,
+ unsigned long int size);
+void gras_trp_buf_flush(gras_socket_t sock);
/***
/***
*** Code
***/
-xbt_error_t
+void
gras_trp_buf_setup(gras_trp_plugin_t plug) {
- xbt_error_t errcode;
gras_trp_buf_plug_data_t *data =xbt_new(gras_trp_buf_plug_data_t,1);
XBT_IN;
- TRYOLD(gras_trp_plugin_get_by_name(gras_if_RL() ? "tcp" : "sg",
- &_buf_super));
+ _buf_super = gras_trp_plugin_get_by_name(gras_if_RL() ? "tcp" : "sg");
+
DEBUG1("Derivate a buffer plugin from %s",gras_if_RL() ? "tcp" : "sg");
plug->socket_client = gras_trp_buf_socket_client;
plug->data = (void*)data;
plug->exit = NULL;
-
- return no_error;
}
-xbt_error_t gras_trp_buf_socket_client(gras_trp_plugin_t self,
- /* OUT */ gras_socket_t sock){
- xbt_error_t errcode;
+void gras_trp_buf_socket_client(gras_trp_plugin_t self,
+ /* OUT */ gras_socket_t sock){
XBT_IN;
- TRYOLD(_buf_super->socket_client(_buf_super,sock));
+ _buf_super->socket_client(_buf_super,sock);
sock->plugin = self;
gras_trp_buf_init_sock(sock);
-
- return no_error;
}
/**
*
* Open a socket used to receive messages.
*/
-xbt_error_t gras_trp_buf_socket_server(gras_trp_plugin_t self,
- /* OUT */ gras_socket_t sock){
- xbt_error_t errcode;
+void gras_trp_buf_socket_server(gras_trp_plugin_t self,
+ /* OUT */ gras_socket_t sock){
XBT_IN;
- TRYOLD(_buf_super->socket_server(_buf_super,sock));
+ _buf_super->socket_server(_buf_super,sock);
sock->plugin = self;
gras_trp_buf_init_sock(sock);
- return no_error;
}
-xbt_error_t
-gras_trp_buf_socket_accept(gras_socket_t sock,
- gras_socket_t *dst) {
- xbt_error_t errcode;
+gras_socket_t
+gras_trp_buf_socket_accept(gras_socket_t sock) {
+
+ gras_socket_t res;
XBT_IN;
- TRYOLD(_buf_super->socket_accept(sock,dst));
- (*dst)->plugin = sock->plugin;
- gras_trp_buf_init_sock(*dst);
+ res = _buf_super->socket_accept(sock);
+ res->plugin = sock->plugin;
+ gras_trp_buf_init_sock(res);
XBT_OUT;
- return no_error;
+ return res;
}
void gras_trp_buf_socket_close(gras_socket_t sock){
- xbt_error_t errcode;
gras_trp_bufdata_t *data=sock->bufdata;
XBT_IN;
*
* Send data on a buffered socket
*/
-xbt_error_t
+void
gras_trp_buf_chunk_send(gras_socket_t sock,
const char *chunk,
unsigned long int size) {
- xbt_error_t errcode;
gras_trp_bufdata_t *data=(gras_trp_bufdata_t*)sock->bufdata;
int chunk_pos=0;
data->out.size,size-chunk_pos,size,(int)chunk_pos,chunk);
if (data->out.size == data->buffsize) /* out of space. Flush it */
- TRYOLD(gras_trp_buf_flush(sock));
+ gras_trp_buf_flush(sock);
}
XBT_OUT;
- return no_error;
}
/**
*
* Receive data on a buffered socket.
*/
-xbt_error_t
+void
gras_trp_buf_chunk_recv(gras_socket_t sock,
char *chunk,
unsigned long int size) {
- xbt_error_t errcode;
+ xbt_ex_t e;
gras_trp_bufdata_t *data=sock->bufdata;
long int chunck_pos = 0;
int nextsize;
if (gras_if_RL()) {
DEBUG0("Recv the size");
- errcode=_buf_super->chunk_recv(sock,(char*)&nextsize, 4);
- if (errcode!=no_error)
- RAISE4(errcode,"Got '%s' while trying to get the chunk size on %p (peer = %s:%d)",
- xbt_error_name(errcode),sock,gras_socket_peer_name(sock),gras_socket_peer_port(sock));
+ TRY {
+ _buf_super->chunk_recv(sock,(char*)&nextsize, 4);
+ } CATCH(e) {
+ RETHROW3("Unable to get the chunk size on %p (peer = %s:%d): %s",
+ sock,gras_socket_peer_name(sock),gras_socket_peer_port(sock));
+ }
data->in.size = (int)ntohl(nextsize);
VERB1("Recv the chunk (size=%d)",data->in.size);
} else {
data->in.size = -1;
}
- TRYOLD(_buf_super->chunk_recv(sock, data->in.data, data->in.size));
+ _buf_super->chunk_recv(sock, data->in.data, data->in.size);
if (gras_if_RL()) {
data->in.pos=0;
}
XBT_OUT;
- return no_error;
}
/**
*
* Make sure the data is sent
*/
-xbt_error_t
+void
gras_trp_buf_flush(gras_socket_t sock) {
- xbt_error_t errcode;
int size;
gras_trp_bufdata_t *data=sock->bufdata;
XBT_IN;
hexa_print("chunck to send ",data->out.data,data->out.size);
if ((data->out.size - data->out.pos) == (gras_if_RL()?0:4) ) { /* 4 first bytes=size in SG mode*/
DEBUG2("Nothing to flush (size=%d; pos=%d)",data->out.size,data->out.pos);
- return no_error;
+ return;
}
size = (int)data->out.size - data->out.pos;
gras_socket_peer_name(sock),gras_socket_peer_port(sock));
if (gras_if_RL()) {
size = (int)htonl(size);
- TRYOLD(_buf_super->chunk_send(sock,(char*) &size, 4));
+ _buf_super->chunk_send(sock,(char*) &size, 4);
} else {
memcpy(data->out.data, &size, 4);
}
DEBUG3("Send the chunk (size=%d) to %s:%d",data->out.size,
gras_socket_peer_name(sock),gras_socket_peer_port(sock));
- TRYOLD(_buf_super->chunk_send(sock, data->out.data, data->out.size));
+ _buf_super->chunk_send(sock, data->out.data, data->out.size);
VERB1("Chunk sent (size=%d)",data->out.size);
if (XBT_LOG_ISENABLED(trp_buf,xbt_log_priority_debug))
hexa_print("chunck sent ",data->out.data,data->out.size);
data->out.size = gras_if_RL()?0:4;
- return no_error;
}
#include "portable.h"
#include "transport_private.h"
-
-#if 0
-# include <sys/types.h>
-#endif
+#include "xbt/ex.h"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(trp_file,transport,
"Pseudo-transport to write to/read from a file");
/***
*** Prototypes
***/
-void gras_trp_file_close(gras_socket_t sd);
+void gras_trp_file_close(gras_socket_t sd);
-xbt_error_t gras_trp_file_chunk_send(gras_socket_t sd,
- const char *data,
- unsigned long int size);
+void gras_trp_file_chunk_send(gras_socket_t sd,
+ const char *data,
+ unsigned long int size);
-xbt_error_t gras_trp_file_chunk_recv(gras_socket_t sd,
- char *data,
- unsigned long int size);
+void gras_trp_file_chunk_recv(gras_socket_t sd,
+ char *data,
+ unsigned long int size);
/***
/***
*** Code
***/
-xbt_error_t
+void
gras_trp_file_setup(gras_trp_plugin_t plug) {
gras_trp_file_plug_data_t *file = xbt_new(gras_trp_file_plug_data_t,1);
plug->chunk_send = gras_trp_file_chunk_send;
plug->chunk_recv = gras_trp_file_chunk_recv;
plug->data = (void*)file;
-
- return no_error;
}
/**
*
* This only possible in RL, and is mainly for debugging.
*/
-xbt_error_t
-gras_socket_client_from_file(const char*path,
- /* OUT */ gras_socket_t *dst) {
- xbt_error_t errcode;
- gras_trp_plugin_t trp;
+gras_socket_t
+gras_socket_client_from_file(const char*path) {
+ gras_socket_t res;
xbt_assert0(gras_if_RL(),
"Cannot use file as socket in the simulator");
- gras_trp_socket_new(0,dst);
+ gras_trp_socket_new(0,&res);
- TRYOLD(gras_trp_plugin_get_by_name("file",&trp));
- (*dst)->plugin=trp;
+ res->plugin=gras_trp_plugin_get_by_name("file");
if (strcmp("-", path)) {
- (*dst)->sd = open(path, O_WRONLY|O_CREAT | O_BINARY, S_IRUSR|S_IWUSR|S_IRGRP );
+ res->sd = open(path, O_WRONLY|O_CREAT | O_BINARY, S_IRUSR|S_IWUSR|S_IRGRP );
- if ( (*dst)->sd < 0) {
- RAISE2(system_error,
+ if ( res->sd < 0) {
+ THROW2(system_error,0,
"Cannot create a client socket from file %s: %s",
path, strerror(errno));
}
} else {
- (*dst)->sd = 1; /* stdout */
+ res->sd = 1; /* stdout */
}
DEBUG5("sock_client_from_file(%s): sd=%d in=%c out=%c accept=%c",
path,
- (*dst)->sd,
- (*dst)->incoming?'y':'n',
- (*dst)->outgoing?'y':'n',
- (*dst)->accepting?'y':'n');
-
- return no_error;
+ res->sd,
+ res->incoming?'y':'n',
+ res->outgoing?'y':'n',
+ res->accepting?'y':'n');
+
+ return res;
}
/**
*
* This only possible in RL, and is mainly for debugging.
*/
-xbt_error_t
-gras_socket_server_from_file(const char*path,
- /* OUT */ gras_socket_t *dst) {
- xbt_error_t errcode;
- gras_trp_plugin_t trp;
+gras_socket_t gras_socket_server_from_file(const char*path) {
+ gras_socket_t res;
xbt_assert0(gras_if_RL(),
"Cannot use file as socket in the simulator");
- gras_trp_socket_new(1,dst);
+ gras_trp_socket_new(1,&res);
- TRYOLD(gras_trp_plugin_get_by_name("file",&trp));
- (*dst)->plugin=trp;
+ res->plugin=gras_trp_plugin_get_by_name("file");
if (strcmp("-", path)) {
- (*dst)->sd = open(path, O_RDONLY | O_BINARY);
+ res->sd = open(path, O_RDONLY | O_BINARY);
- if ( (*dst)->sd < 0) {
- RAISE2(system_error,
+ if ( res->sd < 0) {
+ THROW2(system_error,0,
"Cannot create a server socket from file %s: %s",
path, strerror(errno));
}
} else {
- (*dst)->sd = 0; /* stdin */
+ res->sd = 0; /* stdin */
}
DEBUG4("sd=%d in=%c out=%c accept=%c",
- (*dst)->sd,
- (*dst)->incoming?'y':'n',
- (*dst)->outgoing?'y':'n',
- (*dst)->accepting?'y':'n');
+ res->sd,
+ res->incoming?'y':'n',
+ res->outgoing?'y':'n',
+ res->accepting?'y':'n');
- return no_error;
+ return res;
}
void gras_trp_file_close(gras_socket_t sock){
*
* Send data on a file pseudo-socket
*/
-xbt_error_t
+void
gras_trp_file_chunk_send(gras_socket_t sock,
const char *data,
unsigned long int size) {
status = write(sock->sd, data, (long int)size);
if (status == -1) {
- RAISE4(system_error,"write(%d,%p,%d) failed: %s",
+ THROW4(system_error,0,"write(%d,%p,%d) failed: %s",
sock->sd, data, (int)size,
strerror(errno));
}
size -= status;
data += status;
} else {
- RAISE0(system_error,"file descriptor closed");
+ THROW0(system_error,0,"file descriptor closed");
}
}
-
- return no_error;
}
/**
* gras_trp_file_chunk_recv:
*
* Receive data on a file pseudo-socket.
*/
-xbt_error_t
+void
gras_trp_file_chunk_recv(gras_socket_t sock,
- char *data,
- unsigned long int size) {
+ char *data,
+ unsigned long int size) {
xbt_assert0(sock, "Cannot recv on an NULL socket");
xbt_assert0(sock->incoming, "Cannot recv on client file socket");
DEBUG3("read(%d, %p, %ld);", sock->sd, data, size);
if (status == -1) {
- RAISE4(system_error,"read(%d,%p,%d) failed: %s",
+ THROW4(system_error,0,"read(%d,%p,%d) failed: %s",
sock->sd, data, (int)size,
strerror(errno));
}
size -= status;
data += status;
} else {
- RAISE0(system_error,"file descriptor closed");
+ THROW0(system_error,0,"file descriptor closed");
}
}
-
- return no_error;
}
/* 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 "xbt/ex.h"
+
#include "msg/msg.h"
#include "transport_private.h"
void hexa_print(unsigned char *data, int size); /* in gras.c */
/* retrieve the port record associated to a numerical port on an host */
-static xbt_error_t find_port(gras_hostdata_t *hd, int port,
- gras_sg_portrec_t *hpd);
+static void find_port(gras_hostdata_t *hd, int port, gras_sg_portrec_t *hpd);
-xbt_error_t gras_trp_sg_socket_client(gras_trp_plugin_t self,
- /* OUT */ gras_socket_t sock);
-xbt_error_t gras_trp_sg_socket_server(gras_trp_plugin_t self,
- /* OUT */ gras_socket_t sock);
-void gras_trp_sg_socket_close(gras_socket_t sd);
+void gras_trp_sg_socket_client(gras_trp_plugin_t self,
+ /* OUT */ gras_socket_t sock);
+void gras_trp_sg_socket_server(gras_trp_plugin_t self,
+ /* OUT */ gras_socket_t sock);
+void gras_trp_sg_socket_close(gras_socket_t sd);
-xbt_error_t gras_trp_sg_chunk_send(gras_socket_t sd,
- const char *data,
- unsigned long int size);
+void gras_trp_sg_chunk_send(gras_socket_t sd,
+ const char *data,
+ unsigned long int size);
-xbt_error_t gras_trp_sg_chunk_recv(gras_socket_t sd,
- char *data,
- unsigned long int size);
+void gras_trp_sg_chunk_recv(gras_socket_t sd,
+ char *data,
+ unsigned long int size);
/***
*** Specific plugin part
/***
*** Code
***/
-static xbt_error_t find_port(gras_hostdata_t *hd, int port,
- gras_sg_portrec_t *hpd) {
+static void find_port(gras_hostdata_t *hd, int port,
+ gras_sg_portrec_t *hpd) {
int cpt;
gras_sg_portrec_t pr;
xbt_dynar_foreach(hd->ports, cpt, pr) {
if (pr.port == port) {
memcpy(hpd,&pr,sizeof(gras_sg_portrec_t));
- return no_error;
+ return;
}
}
- return mismatch_error;
+ THROW1(mismatch_error,0,"Unable to find any portrec for port #%d",port);
}
-xbt_error_t
+void
gras_trp_sg_setup(gras_trp_plugin_t plug) {
gras_trp_sg_plug_data_t *data=xbt_new(gras_trp_sg_plug_data_t,1);
plug->chunk_recv = gras_trp_sg_chunk_recv;
plug->flush = NULL; /* nothing cached */
-
- return no_error;
}
-xbt_error_t gras_trp_sg_socket_client(gras_trp_plugin_t self,
- /* OUT */ gras_socket_t sock){
-
- xbt_error_t errcode;
+void gras_trp_sg_socket_client(gras_trp_plugin_t self,
+ /* OUT */ gras_socket_t sock){
+ xbt_ex_t e;
m_host_t peer;
gras_hostdata_t *hd;
gras_sg_portrec_t pr;
/* make sure this socket will reach someone */
- if (!(peer=MSG_get_host_by_name(sock->peer_name))) {
- fprintf(stderr,"GRAS: can't connect to %s: no such host.\n",sock->peer_name);
- return mismatch_error;
- }
- if (!(hd=(gras_hostdata_t *)MSG_host_get_data(peer))) {
- RAISE1(mismatch_error,
+ if (!(peer=MSG_get_host_by_name(sock->peer_name)))
+ THROW1(mismatch_error,0,"Can't connect to %s: no such host.\n",sock->peer_name);
+
+ if (!(hd=(gras_hostdata_t *)MSG_host_get_data(peer)))
+ THROW1(mismatch_error,0,
"can't connect to %s: no process on this host",
sock->peer_name);
+
+ TRY {
+ find_port(hd,sock->peer_port,&pr);
+ } CATCH(e) {
+ if (e.category == mismatch_error) {
+ xbt_ex_free(e);
+ THROW2(mismatch_error,0,
+ "can't connect to %s:%d, no process listen on this port",
+ sock->peer_name,sock->peer_port);
+ }
+ RETHROW;
}
- errcode = find_port(hd,sock->peer_port,&pr);
- if (errcode != no_error && errcode != mismatch_error)
- return errcode;
-
- if (errcode == mismatch_error) {
- RAISE2(mismatch_error,
- "can't connect to %s:%d, no process listen on this port",
- sock->peer_name,sock->peer_port);
- }
if (pr.meas && !sock->meas) {
- RAISE2(mismatch_error,
+ THROW2(mismatch_error,0,
"can't connect to %s:%d in regular mode, the process listen "
"in meas mode on this port",sock->peer_name,sock->peer_port);
}
if (!pr.meas && sock->meas) {
- RAISE2(mismatch_error,
+ THROW2(mismatch_error,0,
"can't connect to %s:%d in meas mode, the process listen "
"in regular mode on this port",sock->peer_name,sock->peer_port);
}
MSG_process_get_name(MSG_process_self()), MSG_process_self_PID(),
sock->meas?"meas":"regular",
sock->peer_name,sock->peer_port,data->to_PID);
-
- return no_error;
}
-xbt_error_t gras_trp_sg_socket_server(gras_trp_plugin_t self,
- gras_socket_t sock){
-
- xbt_error_t errcode;
+void gras_trp_sg_socket_server(gras_trp_plugin_t self,
+ gras_socket_t sock){
gras_hostdata_t *hd=(gras_hostdata_t *)MSG_host_get_data(MSG_host_self());
gras_trp_procdata_t pd=(gras_trp_procdata_t)gras_libdata_get("gras_trp");
gras_sg_portrec_t pr;
gras_trp_sg_sock_data_t *data;
+ int found;
const char *host=MSG_host_get_name(MSG_host_self());
+ xbt_ex_t e;
+
xbt_assert0(hd,"Please run gras_process_init on each process");
sock->accepting = 0; /* no such nuisance in SG */
- errcode = find_port(hd,sock->port,&pr);
- switch (errcode) {
- case no_error: /* Port already used... */
- RAISE2(mismatch_error,
- "can't listen on address %s:%d: port already in use\n.",
- host,sock->port);
- break;
-
- case mismatch_error: /* Port not used so far. Do it */
- pr.tochan = sock->meas ? pd->measChan : pd->chan;
- pr.port = sock->port;
- pr.meas = sock->meas;
- xbt_dynar_push(hd->ports,&pr);
- break;
-
- default:
- return errcode;
+ found = 0;
+ TRY {
+ find_port(hd,sock->port,&pr);
+ found = 1;
+ } CATCH(e) {
+ if (e.category == mismatch_error)
+ xbt_ex_free(e);
+ else
+ RETHROW;
}
+
+ if (found)
+ THROW2(mismatch_error,0,
+ "can't listen on address %s:%d: port already in use.",
+ host,sock->port);
+
+ pr.tochan = sock->meas ? pd->measChan : pd->chan;
+ pr.port = sock->port;
+ pr.meas = sock->meas;
+ xbt_dynar_push(hd->ports,&pr);
/* Create the socket */
data = xbt_new(gras_trp_sg_sock_data_t,1);
VERB6("'%s' (%d) ears on %s:%d%s (%p)",
MSG_process_get_name(MSG_process_self()), MSG_process_self_PID(),
host,sock->port,sock->meas? " (mode meas)":"",sock);
-
- return no_error;
}
void gras_trp_sg_socket_close(gras_socket_t sock){
void *data;
} sg_task_data_t;
-xbt_error_t gras_trp_sg_chunk_send(gras_socket_t sock,
- const char *data,
- unsigned long int size) {
+void gras_trp_sg_chunk_send(gras_socket_t sock,
+ const char *data,
+ unsigned long int size) {
m_task_t task=NULL;
static unsigned int count=0;
char name[256];
name, MSG_host_get_name(MSG_host_self()),
MSG_host_get_name(sock_data->to_host), sock_data->to_chan,size);
if (MSG_task_put(task, sock_data->to_host,sock_data->to_chan) != MSG_OK) {
- RAISE0(system_error,"Problem during the MSG_task_put");
+ THROW0(system_error,0,"Problem during the MSG_task_put");
}
-
- return no_error;
}
-xbt_error_t gras_trp_sg_chunk_recv(gras_socket_t sock,
- char *data,
- unsigned long int size){
+void gras_trp_sg_chunk_recv(gras_socket_t sock,
+ char *data,
+ unsigned long int size){
gras_trp_procdata_t pd=(gras_trp_procdata_t)gras_libdata_get("gras_trp");
m_task_t task=NULL;
MSG_host_get_name(sock_data->to_host),
MSG_host_get_name(MSG_host_self()), sock_data->to_chan, size);
if (MSG_task_get(&task, (sock->meas ? pd->measChan : pd->chan)) != MSG_OK)
- RAISE0(unknown_error,"Error in MSG_task_get()");
+ THROW0(system_error,0,"Error in MSG_task_get()");
DEBUG1("Got chuck %s",MSG_task_get_name(task));
task_data = MSG_task_get_data(task);
if (size != -1) {
if (task_data->size != size)
- RAISE5(mismatch_error,
+ THROW5(mismatch_error,0,
"Got %d bytes when %ld where expected (in %s->%s:%d)",
task_data->size, size,
MSG_host_get_name(sock_data->to_host),
free(task_data);
if (MSG_task_destroy(task) != MSG_OK)
- RAISE0(unknown_error,"Error in MSG_task_destroy()");
+ THROW0(system_error,0,"Error in MSG_task_destroy()");
XBT_OUT;
- return no_error;
}
#if 0
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "portable.h"
-
+#include "xbt/ex.h"
#if 0
# include <signal.h> /* close() pipe() read() write() */
# include <sys/wait.h> /* waitpid() */
/***
*** Prototypes
***/
-xbt_error_t gras_trp_tcp_socket_client(gras_trp_plugin_t self,
- gras_socket_t sock);
-xbt_error_t gras_trp_tcp_socket_server(gras_trp_plugin_t self,
- gras_socket_t sock);
-xbt_error_t gras_trp_tcp_socket_accept(gras_socket_t sock,
- gras_socket_t *dst);
-
-void gras_trp_tcp_socket_close(gras_socket_t sd);
+void gras_trp_tcp_socket_client(gras_trp_plugin_t self, gras_socket_t sock);
+void gras_trp_tcp_socket_server(gras_trp_plugin_t self, gras_socket_t sock);
+gras_socket_t gras_trp_tcp_socket_accept(gras_socket_t sock);
+
+void gras_trp_tcp_socket_close(gras_socket_t sd);
-xbt_error_t gras_trp_tcp_chunk_send(gras_socket_t sd,
- const char *data,
- unsigned long int size);
+void gras_trp_tcp_chunk_send(gras_socket_t sd,
+ const char *data,
+ unsigned long int size);
-xbt_error_t gras_trp_tcp_chunk_recv(gras_socket_t sd,
- char *data,
- unsigned long int size);
+void gras_trp_tcp_chunk_recv(gras_socket_t sd,
+ char *data,
+ unsigned long int size);
void gras_trp_tcp_exit(gras_trp_plugin_t plug);
/***
*** Code
***/
-xbt_error_t gras_trp_tcp_setup(gras_trp_plugin_t plug) {
+void gras_trp_tcp_setup(gras_trp_plugin_t plug) {
gras_trp_tcp_plug_data_t *data = xbt_new(gras_trp_tcp_plug_data_t,1);
plug->data = (void*)data;
plug->exit = gras_trp_tcp_exit;
-
- return no_error;
}
void gras_trp_tcp_exit(gras_trp_plugin_t plug) {
free(plug->data);
}
-xbt_error_t gras_trp_tcp_socket_client(gras_trp_plugin_t self,
- gras_socket_t sock){
+void gras_trp_tcp_socket_client(gras_trp_plugin_t self, gras_socket_t sock){
struct sockaddr_in addr;
struct hostent *he;
sock->sd = socket (AF_INET, SOCK_STREAM, 0);
if (sock->sd < 0) {
- RAISE1(system_error,
- "Failed to create socket: %s",
- sock_errstr);
+ THROW1(system_error,0, "Failed to create socket: %s", sock_errstr);
}
if (setsockopt(sock->sd, SOL_SOCKET, SO_RCVBUF, (char *)&size, sizeof(size)) ||
he = gethostbyname (sock->peer_name);
if (he == NULL) {
- RAISE2(system_error,
- "Failed to lookup hostname %s: %s",
+ THROW2(system_error,0, "Failed to lookup hostname %s: %s",
sock->peer_name, sock_errstr);
}
if (connect (sock->sd, (struct sockaddr*) &addr, sizeof (addr)) < 0) {
tcp_close(sock->sd);
- RAISE3(system_error,
+ THROW3(system_error,0,
"Failed to connect socket to %s:%d (%s)",
sock->peer_name, sock->peer_port, sock_errstr);
}
VERB4("Connect to %s:%d (sd=%d, port %d here)",sock->peer_name, sock->peer_port, sock->sd, sock->port);
-
- return no_error;
}
/**
*
* Open a socket used to receive messages.
*/
-xbt_error_t gras_trp_tcp_socket_server(gras_trp_plugin_t self,
- /* OUT */ gras_socket_t sock){
+void gras_trp_tcp_socket_server(gras_trp_plugin_t self, gras_socket_t sock){
int size = sock->bufSize * 1024;
int on = 1;
struct sockaddr_in server;
server.sin_port = htons((u_short)sock->port);
server.sin_addr.s_addr = INADDR_ANY;
server.sin_family = AF_INET;
- if((sock->sd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
- RAISE1(system_error,"Socket allocation failed: %s", sock_errstr);
- }
+ if((sock->sd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+ THROW1(system_error,0,"Socket allocation failed: %s", sock_errstr);
- if (setsockopt(sock->sd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on))) {
- RAISE1(system_error,"setsockopt failed, cannot condition the socket: %s",
+ if (setsockopt(sock->sd, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)))
+ THROW1(system_error,0,"setsockopt failed, cannot condition the socket: %s",
sock_errstr);
- }
if (setsockopt(sock->sd, SOL_SOCKET, SO_RCVBUF, (char *)&size, sizeof(size)) ||
setsockopt(sock->sd, SOL_SOCKET, SO_SNDBUF, (char *)&size, sizeof(size))) {
if (bind(sock->sd, (struct sockaddr *)&server, sizeof(server)) == -1) {
tcp_close(sock->sd);
- RAISE2(system_error,"Cannot bind to port %d: %s",sock->port, sock_errstr);
+ THROW2(system_error,0,"Cannot bind to port %d: %s",sock->port, sock_errstr);
}
DEBUG2("Listen on port %d (sd=%d)",sock->port, sock->sd);
if (listen(sock->sd, 5) < 0) {
tcp_close(sock->sd);
- RAISE2(system_error,"Cannot listen on port %d: %s",sock->port,sock_errstr);
+ THROW2(system_error,0,"Cannot listen on port %d: %s",sock->port,sock_errstr);
}
if (sock->meas)
FD_SET(sock->sd, &(tcp->msg_socks));
VERB2("Openned a server socket on port %d (sd=%d)",sock->port,sock->sd);
-
- return no_error;
}
-xbt_error_t
-gras_trp_tcp_socket_accept(gras_socket_t sock,
- gras_socket_t *dst) {
+gras_socket_t gras_trp_tcp_socket_accept(gras_socket_t sock) {
gras_socket_t res;
struct sockaddr_in peer_in;
int sd;
int tmp_errno;
int size;
+
+ int i = 1;
+ socklen_t s = sizeof(int);
XBT_IN;
gras_trp_socket_new(1,&res);
if (sd == -1) {
gras_socket_close(sock);
- RAISE1(system_error,
+ THROW1(system_error,0,
"Accept failed (%s). Droping server socket.", sock_errstr);
- } else {
- int i = 1;
- socklen_t s = sizeof(int);
+ }
- if (setsockopt(sd, SOL_SOCKET, SO_KEEPALIVE, (char *)&i, s)
- || setsockopt(sd, TcpProtoNumber(), TCP_NODELAY, (char *)&i, s)) {
- RAISE1(system_error,"setsockopt failed, cannot condition the socket: %s",
- sock_errstr);
- }
+ if (setsockopt(sd, SOL_SOCKET, SO_KEEPALIVE, (char *)&i, s)
+ || setsockopt(sd, TcpProtoNumber(), TCP_NODELAY, (char *)&i, s))
+ THROW1(system_error,0,"setsockopt failed, cannot condition the socket: %s",
+ sock_errstr);
- res->bufSize = sock->bufSize;
- size = sock->bufSize * 1024;
- if (setsockopt(sd, SOL_SOCKET, SO_RCVBUF, (char *)&size, sizeof(size))
- || setsockopt(sd, SOL_SOCKET, SO_SNDBUF, (char *)&size, sizeof(size))) {
- WARN1("setsockopt failed, cannot set buffer size: %s",
- sock_errstr);
- }
+ res->bufSize = sock->bufSize;
+ size = sock->bufSize * 1024;
+ if (setsockopt(sd, SOL_SOCKET, SO_RCVBUF, (char *)&size, sizeof(size))
+ || setsockopt(sd, SOL_SOCKET, SO_SNDBUF, (char *)&size, sizeof(size)))
+ WARN1("setsockopt failed, cannot set buffer size: %s", sock_errstr);
- res->plugin = sock->plugin;
- res->incoming = sock->incoming;
- res->outgoing = sock->outgoing;
- res->accepting = 0;
- res->sd = sd;
- res->port = -1;
- res->peer_port = peer_in.sin_port;
-
- /* FIXME: Lock to protect inet_ntoa */
- if (((struct sockaddr *)&peer_in)->sa_family != AF_INET) {
- res->peer_name = (char*)strdup("unknown");
+ res->plugin = sock->plugin;
+ res->incoming = sock->incoming;
+ res->outgoing = sock->outgoing;
+ res->accepting = 0;
+ res->sd = sd;
+ res->port = -1;
+ res->peer_port = peer_in.sin_port;
+
+ /* FIXME: Lock to protect inet_ntoa */
+ if (((struct sockaddr *)&peer_in)->sa_family != AF_INET) {
+ res->peer_name = (char*)strdup("unknown");
+ } else {
+ struct in_addr addrAsInAddr;
+ char *tmp;
+
+ addrAsInAddr.s_addr = peer_in.sin_addr.s_addr;
+
+ tmp = inet_ntoa(addrAsInAddr);
+ if (tmp != NULL) {
+ res->peer_name = (char*)strdup(tmp);
} else {
- struct in_addr addrAsInAddr;
- char *tmp;
-
- addrAsInAddr.s_addr = peer_in.sin_addr.s_addr;
-
- tmp = inet_ntoa(addrAsInAddr);
- if (tmp != NULL) {
- res->peer_name = (char*)strdup(tmp);
- } else {
- res->peer_name = (char*)strdup("unknown");
- }
+ res->peer_name = (char*)strdup("unknown");
}
-
- VERB3("Accepted from %s:%d (sd=%d)", res->peer_name,res->peer_port,sd);
-
- *dst = res;
-
- XBT_OUT;
- return no_error;
}
+
+ VERB3("Accepted from %s:%d (sd=%d)", res->peer_name,res->peer_port,sd);
+
+ XBT_OUT;
+ return res;
}
void gras_trp_tcp_socket_close(gras_socket_t sock){
*
* Send data on a TCP socket
*/
-xbt_error_t
+void
gras_trp_tcp_chunk_send(gras_socket_t sock,
const char *data,
unsigned long int size) {
DEBUG3("write(%d, %p, %ld);", sock->sd, data, size);
if (status < 0) {
- RAISE4(system_error,"write(%d,%p,%ld) failed: %s",
+ THROW4(system_error,0,"write(%d,%p,%ld) failed: %s",
sock->sd, data, size,
sock_errstr);
}
size -= status;
data += status;
} else {
- RAISE1(system_error,"file descriptor closed (%s)",
+ THROW1(system_error,0,"file descriptor closed (%s)",
sock_errstr);
}
}
-
- return no_error;
}
/**
* gras_trp_tcp_chunk_recv:
*
* Receive data on a TCP socket.
*/
-xbt_error_t
+void
gras_trp_tcp_chunk_recv(gras_socket_t sock,
char *data,
unsigned long int size) {
status = tcp_read(sock->sd, data, (size_t)size);
if (status < 0) {
- RAISE4(system_error,"read(%d,%p,%d) failed: %s",
+ THROW4(system_error,0,"read(%d,%p,%d) failed: %s",
sock->sd, data, (int)size,
sock_errstr);
}
size -= status;
data += status;
} else {
- RAISE3(system_error,"file descriptor closed (nothing read(%d, %p, %ld) on the socket)",
+ THROW3(system_error,0,
+ "file descriptor closed (nothing read(%d, %p, %ld) on the socket)",
sock->sd, data, size);
}
}
-
- return no_error;
}
gras_socket_t *dst);
/* The drivers */
-typedef xbt_error_t (*gras_trp_setup_t)(gras_trp_plugin_t dst);
+typedef void (*gras_trp_setup_t)(gras_trp_plugin_t dst);
-xbt_error_t gras_trp_tcp_setup(gras_trp_plugin_t plug);
-xbt_error_t gras_trp_file_setup(gras_trp_plugin_t plug);
-xbt_error_t gras_trp_sg_setup(gras_trp_plugin_t plug);
-xbt_error_t gras_trp_buf_setup(gras_trp_plugin_t plug);
+void gras_trp_tcp_setup(gras_trp_plugin_t plug);
+void gras_trp_file_setup(gras_trp_plugin_t plug);
+void gras_trp_sg_setup(gras_trp_plugin_t plug);
+void gras_trp_buf_setup(gras_trp_plugin_t plug);
/*
/* 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 "xbt/ex.h"
#include "xbt/sysdep.h"
#include "xbt/log.h"
#include "xbt/error.h"
void *gras_libdata_get(const char *name) {
gras_procdata_t *pd=gras_procdata_get();
void *res;
- xbt_error_t errcode;
-
- errcode = xbt_dict_get(pd->libdata, name, &res);
- xbt_assert2(errcode == no_error,
- "Cannot retrive the libdata associated to %s: %s",
- name, xbt_error_name(errcode));
+ xbt_ex_t e;
+ TRY {
+ res = xbt_dict_get(pd->libdata, name);
+ } CATCH(e) {
+ RETHROW1("Cannot retrive the libdata associated to %s: %s",name);
+ }
return res;
}
int cursor;
- xbt_error_t errcode;
+ xbt_ex_t e;
void *data;
pd->userdata = NULL;
pd->libdata = xbt_dict_new();
xbt_dynar_foreach(_gras_procdata_fabrics,cursor,fab){
+ int found = 0;
- xbt_assert1(fab.name,"Name of fabric #%d is NULL!",cursor);
- DEBUG1("Create the procdata for %s",fab.name);
- /* Check for our own errors */
- errcode = xbt_dict_get(pd->libdata, fab.name, &data);
- xbt_assert1(errcode == mismatch_error,
- "MayDay: two modules use '%s' as libdata name", fab.name);
-
- /* Add the data in place */
- xbt_dict_set(pd->libdata, fab.name, (fab.creator)(), fab.destructor);
-
+ xbt_assert1(fab.name,"Name of fabric #%d is NULL!",cursor);
+ DEBUG1("Create the procdata for %s",fab.name);
+ /* Check for our own errors */
+ TRY {
+ data = xbt_dict_get(pd->libdata, fab.name);
+ found = 1;
+ } CATCH(e) {
+ xbt_ex_free(e);
+ }
+ xbt_assert1(!found,
+ "MayDay: two modules use '%s' as libdata name", fab.name);
+
+ /* Add the data in place */
+ xbt_dict_set(pd->libdata, fab.name, (fab.creator)(), fab.destructor);
}
}
#include "gras/Virtu/virtu_rl.h"
#include "gras_modinter.h"
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(emul,gras,"Emulation support");
+XBT_LOG_NEW_SUBCATEGORY(emul,gras,"Emulation support");
/*** Timing macros: nothing to do in RL. Actually do the job and shutup ***/
static gras_procdata_t *_gras_procdata = NULL;
char const *_gras_procname = NULL;
-xbt_error_t gras_process_init() {
+void gras_process_init() {
_gras_procdata=xbt_new(gras_procdata_t,1);
gras_procdata_init();
- return no_error;
}
-xbt_error_t gras_process_exit() {
+void gras_process_exit() {
gras_procdata_exit();
free(_gras_procdata);
- return no_error;
}
const char *xbt_procname(void) {
#include "xbt/xbt_portability.h" /* timers */
#include "xbt/dict.h"
+#include "xbt/ex.h"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(emul,gras,"Emulation support");
static void store_in_dict(xbt_dict_t dict, const char *key, double value)
{
- double *ir = NULL;
-
- xbt_dict_get(dict, key, (void *) &ir);
+ double *ir;
+ xbt_ex_t e;
+
+ TRY {
+ ir = xbt_dict_get(dict, key);
+ } CATCH(e) {
+ if (e.category == mismatch_error) {
+ ir = NULL;
+ xbt_ex_free(e);
+ } else {
+ RETHROW;
+ }
+ }
if (!ir) {
ir = xbt_new0(double,1);
xbt_dict_set(dict, key, ir, free);
*ir = value;
}
-static double get_from_dict(xbt_dict_t dict, const char *key)
-{
- double *ir = NULL;
-
- xbt_dict_get(dict, key, (void *) &ir);
+static double get_from_dict(xbt_dict_t dict, const char *key) {
+ double *ir = xbt_dict_get(dict, key);
return *ir;
}
return 0;
}
-int gras_bench_once_begin(const char *location,int line)
-{
+int gras_bench_once_begin(const char *location,int line) {
double *ir = NULL;
+ xbt_ex_t e;
xbt_assert0(!benchmarking,"Already benchmarking");
benchmarking = 1;
}
sprintf(locbuf,"%s:%d",location, line);
- xbt_dict_get(benchmark_set, locbuf, (void *) &ir);
+ TRY {
+ ir = xbt_dict_get(benchmark_set, locbuf);
+ } CATCH(e) {
+ if (e.category == mismatch_error) {
+ xbt_ex_free(e);
+ ir = NULL;
+ } else {
+ RETHROW;
+ }
+ }
if(!ir) {
DEBUG1("%s",locbuf);
duration = 1;
/* 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 "xbt/ex.h"
#include "gras_modinter.h" /* module initialization interface */
#include "gras/Virtu/virtu_sg.h"
#include "gras/Msg/msg_interface.h" /* For some checks at simulation end */
XBT_LOG_EXTERNAL_CATEGORY(process);
XBT_LOG_DEFAULT_CATEGORY(process);
-xbt_error_t
+void
gras_process_init() {
- xbt_error_t errcode;
gras_hostdata_t *hd=(gras_hostdata_t *)MSG_host_get_data(MSG_host_self());
gras_procdata_t *pd=xbt_new(gras_procdata_t,1);
gras_trp_procdata_t trp_pd;
int i;
if (MSG_process_set_data(MSG_process_self(),(void*)pd) != MSG_OK)
- return unknown_error;
+ THROW0(system_error,0,"Error in MSG_process_set_data()");
gras_procdata_init();
memset(hd->proc, 0, sizeof(hd->proc[0]) * XBT_MAX_CHANNEL);
if (MSG_host_set_data(MSG_host_self(),(void*)hd) != MSG_OK)
- return unknown_error;
+ THROW0(system_error,0,"Error in MSG_host_set_data()");
}
/* take a free channel for this process */
trp_pd = (gras_trp_procdata_t)gras_libdata_get("gras_trp");
for (i=0; i<XBT_MAX_CHANNEL && hd->proc[i]; i++);
if (i == XBT_MAX_CHANNEL)
- RAISE2(system_error,
- "GRAS: Can't add a new process on %s, because all channel are already in use. Please increase MAX CHANNEL (which is %d for now) and recompile GRAS\n.",
+ THROW2(system_error,0,
+ "Can't add a new process on %s, because all channels are already in use. Please increase MAX CHANNEL (which is %d for now) and recompile GRAS.",
MSG_host_get_name(MSG_host_self()),XBT_MAX_CHANNEL);
trp_pd->chan = i;
/* take a free meas channel for this process */
for (i=0; i<XBT_MAX_CHANNEL && hd->proc[i]; i++);
if (i == XBT_MAX_CHANNEL) {
- RAISE2(system_error,
- "GRAS: Can't add a new process on %s, because all channel are already in use. Please increase MAX CHANNEL (which is %d for now) and recompile GRAS\n.",
+ THROW2(system_error,0,
+ "Can't add a new process on %s, because all channels are already in use. Please increase MAX CHANNEL (which is %d for now) and recompile GRAS.",
MSG_host_get_name(MSG_host_self()),XBT_MAX_CHANNEL);
}
trp_pd->measChan = i;
VERB2("Creating process '%s' (%d)",
MSG_process_get_name(MSG_process_self()),
MSG_process_self_PID());
- return no_error;
}
-xbt_error_t
+void
gras_process_exit() {
gras_hostdata_t *hd=(gras_hostdata_t *)MSG_host_get_data(MSG_host_self());
gras_msg_procdata_t msg_pd=(gras_msg_procdata_t)gras_libdata_get("gras_msg");
xbt_dynar_cursor_rm(hd->ports, &cpt);
}
}
-
- return no_error;
}
/* **************************************************************************
#ifndef _SURF_SURF_PARSE_H
#define _SURF_SURF_PARSE_H
+#include <stdio.h>
#include "xbt/misc.h"
#include "surf/trace_mgr.h"
#include "surfxml.h"
xbt_assert0(msg_global,"MSG_global_init_args has to be called before MSG_get_registered_function.");
- xbt_dict_get(msg_global->registered_functions,name,(void **) &code);
+ code = xbt_dict_get(msg_global->registered_functions,name);
return code;
}
return MSG_OK;
}
-/** \ingroup msg_easier_life
+/* \ingroup msg_easier_life
* \brief Set the arguments of a process.
*
* This functions sets the argument number and the arguments table for a
*/
MSG_error_t MSG_set_arguments(m_process_t process,int argc, char *argv[])
{
- simdata_process_t simdata = NULL;
-
xbt_assert0(0,"Deprecated ! Do not use anymore. "
"Use MSG_process_create_with_arguments instead.\n");
surf_timer_resource_init(file);
/* which model do you want today? */
- xbt_cfg_get_string (_msg_cfg_set, "surf_workstation_model",
- &workstation_model_name);
+ workstation_model_name = xbt_cfg_get_string (_msg_cfg_set, "surf_workstation_model");
+
DEBUG1("Model : %s", workstation_model_name);
if (!strcmp(workstation_model_name,"KCCFLN05")) {
surf_workstation_resource_init_KCCFLN05(file);
*/
int MSG_process_killall(int reset_PIDs)
{
- xbt_fifo_item_t i = NULL;
m_process_t p = NULL;
m_process_t self = MSG_process_self();
m_host_t h = NULL;
simdata_task_t t_simdata = NULL;
simdata_host_t h_simdata = NULL;
- int warning = 0;
int first_time = 1;
e_surf_action_state_t state = SURF_ACTION_NOT_IN_THE_SYSTEM;
{
simdata_process_t simdata = NULL;
simdata_task_t simdata_task = NULL;
- int i;
xbt_assert0(((process) && (process->simdata)), "Invalid parameters");
{
simdata_process_t simdata = NULL;
simdata_task_t simdata_task = NULL;
- int i;
xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
CHECK_HOST();
{
simdata_process_t simdata = NULL;
simdata_task_t simdata_task = NULL;
- int i;
xbt_assert0(((process != NULL) && (process->simdata)), "Invalid parameters");
CHECK_HOST();
/* callback of the surf_workstation_model variable */
static void _msg_cfg_cb__surf_workstation_model(const char *name, int pos) {
- xbt_error_t errcode;
char *val;
xbt_assert0(_msg_init_status<2, "Cannot change the model after the initialization");
- TRYFAIL(xbt_cfg_get_string (_msg_cfg_set, name, &val));
+ val = xbt_cfg_get_string (_msg_cfg_set, name);
xbt_assert1(!strcmp(val, "CLM03") ||
!strcmp(val, "KCCFLN05"),
/* create the config set and register what should be */
void msg_config_init(void) {
- xbt_error_t errcode;
if (_msg_init_status)
return; /* Already inited, nothing to do */
"surf_workstation_model", xbt_cfgelm_string, 1,1,
&_msg_cfg_cb__surf_workstation_model,NULL);
- TRYFAIL(xbt_cfg_set_string(_msg_cfg_set,"surf_workstation_model", "CLM03"));
+ xbt_cfg_set_string(_msg_cfg_set,"surf_workstation_model", "CLM03");
}
/** \brief set a configuration variable
* Example:
* MSG_config("surf_workstation_model","CLM03");
*/
-xbt_error_t
+void
MSG_config(const char *name, ...) {
va_list pa;
- xbt_error_t errcode;
if (!_msg_init_status) {
msg_config_init();
}
-xbt_cfg_dump("msg_cfg_set","",_msg_cfg_set);
+ /* xbt_cfg_dump("msg_cfg_set","",_msg_cfg_set);*/
va_start(pa,name);
- errcode=xbt_cfg_set_vargs(_msg_cfg_set,name,pa);
+ xbt_cfg_set_vargs(_msg_cfg_set,name,pa);
va_end(pa);
-
- return errcode;
+
}
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(task, msg,
"Logging specific to MSG (task)");
-static char sprint_buffer[64];
-
/** \defgroup m_task_management Managing functions of Tasks
* \brief This section describes the task structure of MSG
* (#m_task_t) and the functions for managing it.
*/
MSG_error_t MSG_task_destroy(m_task_t task)
{
- simdata_task_t simdata = NULL;
surf_action_t action = NULL;
- int i;
xbt_assert0((task != NULL), "Invalid parameter");
* \brief Returns the computation amount needed to process a task #m_task_t.
* Once a task has been processed, this amount is thus set to 0...
*/
-double MSG_task_get_compute_duration(m_task_t task)
-{
- simdata_task_t simdata = NULL;
-
+double MSG_task_get_compute_duration(m_task_t task) {
xbt_assert0((task != NULL) && (task->simdata != NULL), "Invalid parameter");
return task->simdata->computation_amount;
*/
double MSG_task_get_remaining_computation(m_task_t task)
{
- simdata_task_t simdata = NULL;
-
xbt_assert0((task != NULL) && (task->simdata != NULL), "Invalid parameter");
if(task->simdata->compute) {
* \brief Returns the size of the data attached to a task #m_task_t.
*
*/
-double MSG_task_get_data_size(m_task_t task)
-{
- simdata_task_t simdata = NULL;
-
+double MSG_task_get_data_size(m_task_t task) {
xbt_assert0((task != NULL) && (task->simdata != NULL), "Invalid parameter");
return task->simdata->message_size;
static void *name_service(const char *name)
{
- void *cpu = NULL;
-
- xbt_dict_get(cpu_set, name, &cpu);
-
- return cpu;
+ return xbt_dict_get_or_null(cpu_set, name);
}
static const char *get_resource_name(void *resource_id)
surf_action_cpu_Cas01_t next_action = NULL;
xbt_swag_t running_actions =
surf_cpu_resource->common_public->states.running_action_set;
+ /* FIXME: UNUSED
xbt_swag_t failed_actions =
surf_cpu_resource->common_public->states.failed_action_set;
+ */
xbt_swag_foreach_safe(action, next_action, running_actions) {
surf_double_update(&(action->generic_action.remains),
static int network_card_new(const char *card_name)
{
- network_card_CM02_t card = NULL;
-
- xbt_dict_get(network_card_set, card_name, (void *) &card);
+ network_card_CM02_t card = xbt_dict_get_or_null(network_card_set, card_name);
if (!card) {
card = xbt_new0(s_network_card_CM02_t, 1);
ROUTE_SIZE(src_id, dst_id) = nb_link;
link_list = (ROUTE(src_id, dst_id) = xbt_new0(network_link_CM02_t, nb_link));
for (i = 0; i < nb_link; i++) {
- xbt_dict_get(network_link_set, links[i], (void *) &(link_list[i]));
+ link_list[i] = xbt_dict_get_or_null(network_link_set, links[i]);
free(links[i]);
}
free(links);
static void *name_service(const char *name)
{
- network_card_CM02_t card = NULL;
-
- xbt_dict_get(network_card_set, name, (void *) &card);
-
+ network_card_CM02_t card = xbt_dict_get_or_null(network_card_set, name);
return card;
}
surf_action_network_CM02_t next_action = NULL;
xbt_swag_t running_actions =
surf_network_resource->common_public->states.running_action_set;
+ /*
xbt_swag_t failed_actions =
surf_network_resource->common_public->states.failed_action_set;
+ */
xbt_swag_foreach_safe(action, next_action, running_actions) {
deltap = delta;
static int network_card_new(const char *card_name)
{
- network_card_DASSF_t card = NULL;
-
- xbt_dict_get(network_card_set, card_name, (void *) &card);
+ network_card_DASSF_t card = xbt_dict_get_or_null(network_card_set, card_name);
if (!card) {
card = xbt_new0(s_network_card_DASSF_t, 1);
ROUTE_SIZE(src_id, dst_id) = nb_link;
link_list = (ROUTE(src_id, dst_id) = xbt_new0(network_link_DASSF_t, nb_link));
for (i = 0; i < nb_link; i++) {
- xbt_dict_get(network_link_set, links[i], (void *) &(link_list[i]));
+ link_list[i] = xbt_dict_get_or_null(network_link_set, links[i]);
free(links[i]);
}
free(links);
static void *name_service(const char *name)
{
- network_card_DASSF_t card = NULL;
-
- xbt_dict_get(network_card_set, name, (void *) &card);
-
- return card;
+ return xbt_dict_get_or_null(network_card_set, name);
}
static const char *get_resource_name(void *resource_id)
surf_action_network_DASSF_t next_action = NULL;
xbt_swag_t running_actions =
surf_network_resource->common_public->states.running_action_set;
+ /* KILLME: unused
xbt_swag_t failed_actions =
surf_network_resource->common_public->states.failed_action_set;
+ */
xbt_swag_foreach_safe(action, next_action, running_actions) {
deltap = delta;
int surf_parse(void)
{
- int ret=0;
return surf_parse_lex();
}
/* 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 "xbt/ex.h"
#include "surf_timer_private.h"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(timer, surf,
tmgr_event_t last_event = NULL;
if (trace_list) {
- xbt_dict_get(trace_list, filename, (void **) &trace);
+ trace = xbt_dict_get_or_null(trace_list, filename);
if (trace)
return trace;
}
tmgr_trace_t tmgr_empty_trace_new(void)
{
tmgr_trace_t trace = NULL;
- double periodicity = -1.0; /* No periodicity by default */
+ /*double periodicity = -1.0; No periodicity by default; unused variables
+ tmgr_event_t last_event = NULL;*/
s_tmgr_event_t event;
- tmgr_event_t last_event = NULL;
trace = xbt_new0(s_tmgr_trace_t, 1);
trace->event_list = xbt_dynar_new(sizeof(s_tmgr_event_t), NULL);
/* 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 "xbt/ex.h"
#include "xbt/dict.h"
#include "workstation_private.h"
#include "cpu_private.h"
static void create_workstations(void)
{
- xbt_dict_cursor_t cursor = NULL;
+ xbt_dict_cursor_t cursor = NULL;
char *name = NULL;
void *cpu = NULL;
void *nw_card = NULL;
xbt_dict_foreach(cpu_set, cursor, name, cpu) {
- nw_card = NULL;
- xbt_dict_get(network_card_set, name, (void *) &nw_card);
- xbt_assert1(nw_card, "No corresponding card found for %s",name);
+ nw_card = xbt_dict_get_or_null(network_card_set, name);
+ xbt_assert1(nw_card,
+ "No corresponding card found for %s",name);
+
xbt_dict_set(workstation_set, name,
workstation_new(name, cpu, nw_card), workstation_free);
}
static void *name_service(const char *name)
{
- void *workstation = NULL;
-
- xbt_dict_get(workstation_set, name, &workstation);
-
- return workstation;
+ return xbt_dict_get_or_null(workstation_set, name);
}
static const char *get_resource_name(void *resource_id)
surf_action_parallel_task_CSL05_t next_action = NULL;
xbt_swag_t running_actions =
surf_workstation_resource->common_public->states.running_action_set;
+ /* FIXME: unused
xbt_swag_t failed_actions =
surf_workstation_resource->common_public->states.failed_action_set;
+ */
xbt_swag_foreach_safe(action, next_action, running_actions) {
surf_double_update(&(action->generic_action.remains),
/* 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 "xbt/ex.h"
#include "xbt/dict.h"
#include "workstation_KCCFLN05_private.h"
static void *name_service(const char *name)
{
- void *workstation = NULL;
-
- xbt_dict_get(workstation_set, name, &workstation);
-
- return workstation;
+ return xbt_dict_get_or_null(workstation_set, name);
}
static const char *get_resource_name(void *resource_id)
route->size= nb_link;
link_list = route->links = xbt_new0(network_link_KCCFLN05_t, nb_link);
for (i = 0; i < nb_link; i++) {
- xbt_dict_get(network_link_set, links[i], (void *) &(link_list[i]));
+ link_list[i] = xbt_dict_get(network_link_set, links[i]);
free(links[i]);
}
free(links);
surf_action_network_KCCFLN05_t next_action = NULL;
xbt_swag_t running_actions =
surf_network_resource->common_public->states.running_action_set;
+ /* FIXME: unused
xbt_swag_t failed_actions =
surf_network_resource->common_public->states.failed_action_set;
-
+ */
xbt_swag_foreach_safe(action, next_action, running_actions) {
surf_double_update(&(action->generic_action.remains),
lmm_variable_getvalue(action->variable) * delta);
surf_action_cpu_KCCFLN05_t next_action = NULL;
xbt_swag_t running_actions =
surf_cpu_resource->common_public->states.running_action_set;
+ /*
xbt_swag_t failed_actions =
surf_cpu_resource->common_public->states.failed_action_set;
+ */
xbt_swag_foreach_safe(action, next_action, running_actions) {
surf_double_update(&(action->generic_action.remains),
/* 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 <stdio.h> /* FIXME: killme */
+
#include "xbt/misc.h"
#include "xbt/sysdep.h"
#include "xbt/log.h"
-#include "xbt/error.h"
+#include "xbt/ex.h"
#include "xbt/dynar.h"
#include "xbt/dict.h"
static void xbt_cfgelm_free(void *data);
/* Retrieve the variable we'll modify */
-static xbt_error_t xbt_cfgelm_get(xbt_cfg_t cfg, const char *name,
- e_xbt_cfgelm_type_t type,
- /* OUT */ xbt_cfgelm_t *whereto);
+static xbt_cfgelm_t xbt_cfgelm_get(xbt_cfg_t cfg, const char *name,
+ e_xbt_cfgelm_type_t type);
static void xbt_cfg_str_free(void *d){
free(*(void**)d);
void
xbt_cfg_register(xbt_cfg_t cfg,
- const char *name, e_xbt_cfgelm_type_t type,
- int min, int max,
- xbt_cfg_cb_t cb_set, xbt_cfg_cb_t cb_rm){
+ const char *name, e_xbt_cfgelm_type_t type,
+ int min, int max,
+ xbt_cfg_cb_t cb_set, xbt_cfg_cb_t cb_rm){
xbt_cfgelm_t res;
- xbt_error_t errcode;
+ xbt_ex_t e;
+ int found=0;
+ xbt_assert(cfg);
xbt_assert4(type>=xbt_cfgelm_int && type<=xbt_cfgelm_host,
"type of %s not valid (%d should be between %d and %d)",
name,type,xbt_cfgelm_int, xbt_cfgelm_host);
DEBUG5("Register cfg elm %s (%d to %d %s (=%d))",name,min,max,xbt_cfgelm_type_name[type],type);
- errcode = xbt_dict_get((xbt_dict_t)cfg,name,(void**)&res);
+ TRY {
+ res = xbt_dict_get((xbt_dict_t)cfg,name);
+ } CATCH(e) {
+ if (e.category == mismatch_error) {
+ found = 1;
+ xbt_ex_free(e);
+ } else {
+ RETHROW;
+ }
+ }
- if (errcode == no_error) {
+ if (!found) {
WARN1("Config elem %s registered twice.",name);
/* Will be removed by the insertion of the new one */
}
- xbt_assert_error(mismatch_error);
res=xbt_new(s_xbt_cfgelm_t,1);
return no_error;
}
-static xbt_error_t xbt_cfgelm_get(xbt_cfg_t cfg,
- const char *name,
- e_xbt_cfgelm_type_t type,
- /* OUT */ xbt_cfgelm_t *whereto){
-
- xbt_error_t errcode = xbt_dict_get((xbt_dict_t)cfg,name,
- (void**)whereto);
-
- if (errcode == mismatch_error) {
- RAISE1(mismatch_error,
- "No registered variable '%s' in this config set",
- name);
+static xbt_cfgelm_t xbt_cfgelm_get(xbt_cfg_t cfg,
+ const char *name,
+ e_xbt_cfgelm_type_t type){
+ xbt_cfgelm_t res;
+ xbt_ex_t e;
+
+ TRY {
+ res = xbt_dict_get((xbt_dict_t)cfg,name);
+ } CATCH(e) {
+ if (e.category == mismatch_error) {
+ THROW1(mismatch_error,0,
+ "No registered variable '%s' in this config set",name);
+ xbt_ex_free(e);
+ }
+ RETHROW;
}
- if (errcode != no_error)
- return errcode;
- xbt_assert3(type == xbt_cfgelm_any || (*whereto)->type == type,
+ xbt_assert3(type == xbt_cfgelm_any || res->type == type,
"You tried to access to the config element %s as an %s, but its type is %s.",
name,
xbt_cfgelm_type_name[type],
- xbt_cfgelm_type_name[(*whereto)->type]);
+ xbt_cfgelm_type_name[res->type]);
- return no_error;
+ return res;
}
/** @brief Get the type of this variable in that configuration set
*
*/
-xbt_error_t
-xbt_cfg_get_type(xbt_cfg_t cfg, const char *name,
- /* OUT */e_xbt_cfgelm_type_t *type) {
+e_xbt_cfgelm_type_t
+xbt_cfg_get_type(xbt_cfg_t cfg, const char *name) {
- xbt_cfgelm_t variable;
- xbt_error_t errcode;
-
- errcode=xbt_dict_get((xbt_dict_t)cfg,name,(void**)&variable);
+ xbt_cfgelm_t variable = NULL;
+ xbt_ex_t e;
- if (errcode == mismatch_error) {
- RAISE1(mismatch_error,"Can't get the type of '%s' since this variable does not exist",
- name);
- } else if (errcode != no_error) {
- return errcode;
+ TRY {
+ variable = xbt_dict_get((xbt_dict_t)cfg,name);
+ } CATCH(e) {
+ if (e.category == mismatch_error) {
+ THROW1(mismatch_error,0,
+ "Can't get the type of '%s' since this variable does not exist",name);
+ xbt_ex_free(e);
+ }
+ RETHROW;
}
INFO1("type in variable = %d",variable->type);
- *type=variable->type;
- return no_error;
+ return variable->type;
}
/*----[ Setting ]---------------------------------------------------------*/
*
* Add some values to the config set.
*/
-xbt_error_t
+void
xbt_cfg_set_vargs(xbt_cfg_t cfg, const char *name, va_list pa) {
char *str;
int i;
double d;
e_xbt_cfgelm_type_t type;
- xbt_error_t errcode;
+ xbt_ex_t e;
- errcode = xbt_cfg_get_type(cfg,name,&type);
- if (errcode != no_error) {
- ERROR1("Can't set the property '%s' since it's not registered",name);
- return mismatch_error;
+ TRY {
+ type = xbt_cfg_get_type(cfg,name);
+ } CATCH(e) {
+ if (e.category == mismatch_error) {
+ xbt_ex_free(e);
+ THROW1(mismatch_error,0,"Can't set the property '%s' since it's not registered",name);
+ }
+ RETHROW;
}
switch (type) {
case xbt_cfgelm_host:
str = va_arg(pa, char *);
i=va_arg(pa,int);
- TRYOLD(xbt_cfg_set_host(cfg,name,str,i));
+ xbt_cfg_set_host(cfg,name,str,i);
break;
case xbt_cfgelm_string:
str=va_arg(pa, char *);
- TRYOLD(xbt_cfg_set_string(cfg, name, str));
+ xbt_cfg_set_string(cfg, name, str);
break;
case xbt_cfgelm_int:
i=va_arg(pa,int);
- TRYOLD(xbt_cfg_set_int(cfg,name,i));
+ xbt_cfg_set_int(cfg,name,i);
break;
case xbt_cfgelm_double:
d=va_arg(pa,double);
- TRYOLD(xbt_cfg_set_double(cfg,name,d));
+ xbt_cfg_set_double(cfg,name,d);
break;
default:
xbt_assert2(0,"Config element variable %s not valid (type=%d)",name,type);
}
-
- return no_error;
}
/** @brief Add a NULL-terminated list of pairs {(char*)key, value} to the set
* \arg varargs variable value
*
*/
-xbt_error_t xbt_cfg_set(xbt_cfg_t cfg, const char *name, ...) {
+void xbt_cfg_set(xbt_cfg_t cfg, const char *name, ...) {
va_list pa;
- xbt_error_t errcode;
va_start(pa,name);
- errcode=xbt_cfg_set_vargs(cfg,name,pa);
+ xbt_cfg_set_vargs(cfg,name,pa);
va_end(pa);
- return errcode;
}
/** @brief Add values parsed from a string into a config set
* @todo This is a crude manual parser, it should be a proper lexer.
*/
-xbt_error_t
+void
xbt_cfg_set_parse(xbt_cfg_t cfg, const char *options) {
+ xbt_ex_t e;
+
int i;
double d;
char *str;
char *option, *name,*val;
int len;
- xbt_error_t errcode;
XBT_IN;
if (!options || !strlen(options)) { /* nothing to do */
- return no_error;
+ return;
}
optionlist_cpy=xbt_strdup(options);
DEBUG2("name='%s';val='%s'",name,val);
- errcode=xbt_dict_get((xbt_dict_t)cfg,name,(void**)&variable);
- switch (errcode) {
- case no_error:
- break;
- case mismatch_error:
- ERROR1("No registrated variable corresponding to '%s'.",name);
+ TRY {
+ variable = xbt_dict_get((xbt_dict_t)cfg,name);
+ } CATCH(e) {
free(optionlist_cpy);
- return mismatch_error;
- break;
- default:
- free(optionlist_cpy);
- return errcode;
- }
-
- switch (variable->type) {
- case xbt_cfgelm_string:
- errcode = xbt_cfg_set_string(cfg, name, val);
- if (errcode != no_error) {
- free(optionlist_cpy);
- return errcode;
- }
- break;
-
- case xbt_cfgelm_int:
- i=strtol(val, &val, 0);
- if (val==NULL) {
- free(optionlist_cpy);
- xbt_assert1(FALSE,
- "Value of option %s not valid. Should be an integer",
- name);
- }
-
- errcode = xbt_cfg_set_int(cfg,name,i);
- if (errcode != no_error) {
- free(optionlist_cpy);
- return errcode;
- }
- break;
-
- case xbt_cfgelm_double:
- d=strtod(val, &val);
- if (val==NULL) {
- free(optionlist_cpy);
- xbt_assert1(FALSE,
- "Value of option %s not valid. Should be a double",
- name);
- }
-
- errcode = xbt_cfg_set_double(cfg,name,d);
- if (errcode != no_error) {
- free(optionlist_cpy);
- return errcode;
- }
- break;
-
- case xbt_cfgelm_host:
- str=val;
- val=strchr(val,':');
- if (!val) {
- free(optionlist_cpy);
- xbt_assert1(FALSE,
- "Value of option %s not valid. Should be an host (machine:port)",
- name);
- }
-
- *(val++)='\0';
- i=strtol(val, &val, 0);
- if (val==NULL) {
- free(optionlist_cpy);
- xbt_assert1(FALSE,
- "Value of option %s not valid. Should be an host (machine:port)",
- name);
+ if (e.category == mismatch_error) {
+ xbt_ex_free(e);
+ THROW1(mismatch_error,0,"No registrated variable corresponding to '%s'.",name);
}
+ RETHROW;
+ }
- errcode = xbt_cfg_set_host(cfg,name,str,i);
- if (errcode != no_error) {
- free(optionlist_cpy);
- return errcode;
+ TRY {
+ switch (variable->type) {
+ case xbt_cfgelm_string:
+ xbt_cfg_set_string(cfg, name, val); /* throws */
+ break;
+
+ case xbt_cfgelm_int:
+ i=strtol(val, &val, 0);
+ if (val==NULL) {
+ free(optionlist_cpy);
+ xbt_assert1(FALSE,
+ "Value of option %s not valid. Should be an integer",
+ name);
+ }
+
+ xbt_cfg_set_int(cfg,name,i); /* throws */
+ break;
+
+ case xbt_cfgelm_double:
+ d=strtod(val, &val);
+ if (val==NULL) {
+ free(optionlist_cpy);
+ xbt_assert1(FALSE,
+ "Value of option %s not valid. Should be a double",
+ name);
+ }
+
+ xbt_cfg_set_double(cfg,name,d); /* throws */
+ break;
+
+ case xbt_cfgelm_host:
+ str=val;
+ val=strchr(val,':');
+ if (!val) {
+ free(optionlist_cpy);
+ xbt_assert1(FALSE,
+ "Value of option %s not valid. Should be an host (machine:port)",
+ name);
+ }
+
+ *(val++)='\0';
+ i=strtol(val, &val, 0);
+ if (val==NULL) {
+ free(optionlist_cpy);
+ xbt_assert1(FALSE,
+ "Value of option %s not valid. Should be an host (machine:port)",
+ name);
+ }
+
+ xbt_cfg_set_host(cfg,name,str,i); /* throws */
+ break;
+
+ default:
+ THROW1(unknown_error,0,"Type of config element %s is not valid.",name);
}
- break;
-
- default:
+ } CATCH(e) {
free(optionlist_cpy);
- RAISE1(unknown_error,"Type of config element %s is not valid.",name);
+ RETHROW;
}
-
}
free(optionlist_cpy);
- return no_error;
+
}
/** @brief Set or add an integer value to \a name within \a cfg
* \arg name the name of the variable
* \arg val the value of the variable
*/
-xbt_error_t
+void
xbt_cfg_set_int(xbt_cfg_t cfg,const char*name, int val) {
xbt_cfgelm_t variable;
- xbt_error_t errcode;
VERB2("Configuration setting: %s=%d",name,val);
- TRYOLD(xbt_cfgelm_get(cfg,name,xbt_cfgelm_int,&variable));
+ variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_int);
if (variable->max == 1) {
if (variable->cb_rm && xbt_dynar_length(variable->content))
xbt_dynar_set(variable->content,0,&val);
} else {
if (variable->max && xbt_dynar_length(variable->content) == variable->max)
- RAISE3(mismatch_error,
+ THROW3(mismatch_error,0,
"Cannot add value %d to the config element %s since it's already full (size=%d)",
val,name,variable->max);
if (variable->cb_set)
(*variable->cb_set)(name, xbt_dynar_length(variable->content) -1);
- return no_error;
}
/** @brief Set or add a double value to \a name within \a cfg
* \arg val the doule to set
*/
-xbt_error_t
+void
xbt_cfg_set_double(xbt_cfg_t cfg,const char*name, double val) {
xbt_cfgelm_t variable;
- xbt_error_t errcode;
VERB2("Configuration setting: %s=%f",name,val);
- TRYOLD(xbt_cfgelm_get(cfg,name,xbt_cfgelm_double,&variable));
+ variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_double);
if (variable->max == 1) {
if (variable->cb_rm && xbt_dynar_length(variable->content))
xbt_dynar_set(variable->content,0,&val);
} else {
if (variable->max && xbt_dynar_length(variable->content) == variable->max)
- RAISE3(mismatch_error,
+ THROW3(mismatch_error,0,
"Cannot add value %f to the config element %s since it's already full (size=%d)",
val,name,variable->max);
if (variable->cb_set)
(*variable->cb_set)(name, xbt_dynar_length(variable->content) -1);
- return no_error;
}
/** @brief Set or add a string value to \a name within \a cfg
*
*/
-xbt_error_t
+void
xbt_cfg_set_string(xbt_cfg_t cfg,const char*name, const char*val) {
xbt_cfgelm_t variable;
- xbt_error_t errcode;
char *newval = xbt_strdup(val);
VERB2("Configuration setting: %s=%s",name,val);
- TRYOLD(xbt_cfgelm_get(cfg,name,xbt_cfgelm_string,&variable));
+ variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_string);
if (variable->max == 1) {
if (variable->cb_rm && xbt_dynar_length(variable->content))
xbt_dynar_set(variable->content,0,&newval);
} else {
if (variable->max && xbt_dynar_length(variable->content) == variable->max)
- RAISE3(mismatch_error,
+ THROW3(mismatch_error,0,
"Cannot add value %s to the config element %s since it's already full (size=%d)",
name,val,variable->max);
if (variable->cb_set)
(*variable->cb_set)(name, xbt_dynar_length(variable->content) -1);
- return no_error;
}
/** @brief Set or add an host value to \a name within \a cfg
* \e host values are composed of a string (hostname) and an integer (port)
*/
-xbt_error_t
+void
xbt_cfg_set_host(xbt_cfg_t cfg,const char*name,
const char *host,int port) {
xbt_cfgelm_t variable;
- xbt_error_t errcode;
xbt_host_t *val=xbt_new(xbt_host_t,1);
VERB3("Configuration setting: %s=%s:%d",name,host,port);
val->name = xbt_strdup(name);
val->port = port;
- TRYOLD(xbt_cfgelm_get(cfg,name,xbt_cfgelm_host,&variable));
+ variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_host);
if (variable->max == 1) {
if (variable->cb_rm && xbt_dynar_length(variable->content))
xbt_dynar_set(variable->content,0,&val);
} else {
if (variable->max && xbt_dynar_length(variable->content) == variable->max)
- RAISE4(mismatch_error,
+ THROW4(mismatch_error,0,
"Cannot add value %s:%d to the config element %s since it's already full (size=%d)",
host,port,name,variable->max);
if (variable->cb_set)
(*variable->cb_set)(name, xbt_dynar_length(variable->content) -1);
- return no_error;
}
/* ---- [ Removing ] ---- */
* \arg name the name of the variable
* \arg val the value to be removed
*/
-xbt_error_t xbt_cfg_rm_int(xbt_cfg_t cfg,const char*name, int val) {
+void xbt_cfg_rm_int(xbt_cfg_t cfg,const char*name, int val) {
xbt_cfgelm_t variable;
int cpt,seen;
- xbt_error_t errcode;
+ variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_int);
+
if (xbt_dynar_length(variable->content) == variable->min)
- RAISE3(mismatch_error,
+ THROW3(mismatch_error,0,
"Cannot remove value %d from the config element %s since it's already at its minimal size (=%d)",
val,name,variable->min);
- TRYOLD(xbt_cfgelm_get(cfg,name,xbt_cfgelm_int,&variable));
-
xbt_dynar_foreach(variable->content,cpt,seen) {
if (seen == val) {
if (variable->cb_rm) (*variable->cb_rm)(name, cpt);
xbt_dynar_cursor_rm(variable->content,&cpt);
- return no_error;
+ return;
}
}
- ERROR2("Can't remove the value %d of config element %s: value not found.",
- val,name);
- return mismatch_error;
+ THROW2(mismatch_error,0,
+ "Can't remove the value %d of config element %s: value not found.",val,name);
}
/** @brief Remove the provided \e val double value from a variable
* \arg val the value to be removed
*/
-xbt_error_t xbt_cfg_rm_double(xbt_cfg_t cfg,const char*name, double val) {
+void xbt_cfg_rm_double(xbt_cfg_t cfg,const char*name, double val) {
xbt_cfgelm_t variable;
int cpt;
double seen;
- xbt_error_t errcode;
+ variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_double);
+
if (xbt_dynar_length(variable->content) == variable->min)
- RAISE3(mismatch_error,
+ THROW3(mismatch_error,0,
"Cannot remove value %f from the config element %s since it's already at its minimal size (=%d)",
val,name,variable->min);
- TRYOLD(xbt_cfgelm_get(cfg,name,xbt_cfgelm_double,&variable));
-
xbt_dynar_foreach(variable->content,cpt,seen) {
if (seen == val) {
xbt_dynar_cursor_rm(variable->content,&cpt);
- if (variable->cb_rm) (*variable->cb_rm)(name, cpt);
- return no_error;
+ if (variable->cb_rm)
+ (*variable->cb_rm)(name, cpt);
+ return;
}
}
- ERROR2("Can't remove the value %f of config element %s: value not found.",
- val,name);
- return mismatch_error;
+ THROW2(mismatch_error,0,
+ "Can't remove the value %f of config element %s: value not found.",val,name);
}
/** @brief Remove the provided \e val string value from a variable
* \arg name the name of the variable
* \arg val the value of the string which will be removed
*/
-xbt_error_t
+void
xbt_cfg_rm_string(xbt_cfg_t cfg,const char*name, const char *val) {
xbt_cfgelm_t variable;
int cpt;
char *seen;
- xbt_error_t errcode;
+ variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_string);
+
if (xbt_dynar_length(variable->content) == variable->min)
- RAISE3(mismatch_error,
+ THROW3(mismatch_error,0,
"Cannot remove value %s from the config element %s since it's already at its minimal size (=%d)",
name,val,variable->min);
- TRYOLD(xbt_cfgelm_get(cfg,name,xbt_cfgelm_string,&variable));
-
xbt_dynar_foreach(variable->content,cpt,seen) {
if (!strcpy(seen,val)) {
- if (variable->cb_rm) (*variable->cb_rm)(name, cpt);
+ if (variable->cb_rm)
+ (*variable->cb_rm)(name, cpt);
xbt_dynar_cursor_rm(variable->content,&cpt);
- return no_error;
+ return;
}
}
- ERROR2("Can't remove the value %s of config element %s: value not found.",
- val,name);
- return mismatch_error;
+ THROW2(mismatch_error,0,
+ "Can't remove the value %s of config element %s: value not found.",val,name);
}
/** @brief Remove the provided \e val host value from a variable
* \arg port the port number
*/
-xbt_error_t
+void
xbt_cfg_rm_host(xbt_cfg_t cfg,const char*name, const char *host,int port) {
xbt_cfgelm_t variable;
int cpt;
xbt_host_t *seen;
- xbt_error_t errcode;
+ variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_host);
+
if (xbt_dynar_length(variable->content) == variable->min)
- RAISE4(mismatch_error,
+ THROW4(mismatch_error,0,
"Cannot remove value %s:%d from the config element %s since it's already at its minimal size (=%d)",
host,port,name,variable->min);
- TRYOLD(xbt_cfgelm_get(cfg,name,xbt_cfgelm_host,&variable));
-
xbt_dynar_foreach(variable->content,cpt,seen) {
if (!strcpy(seen->name,host) && seen->port == port) {
if (variable->cb_rm) (*variable->cb_rm)(name, cpt);
xbt_dynar_cursor_rm(variable->content,&cpt);
- return no_error;
+ return;
}
}
- ERROR3("Can't remove the value %s:%d of config element %s: value not found.",
+ THROW3(mismatch_error,0,
+ "Can't remove the value %s:%d of config element %s: value not found.",
host,port,name);
- return mismatch_error;
}
/** @brief Remove the \e pos th value from the provided variable */
-xbt_error_t xbt_cfg_rm_at (xbt_cfg_t cfg, const char *name, int pos) {
+void xbt_cfg_rm_at (xbt_cfg_t cfg, const char *name, int pos) {
xbt_cfgelm_t variable;
- int cpt;
- xbt_host_t *seen;
- xbt_error_t errcode;
+ variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_any);
+
if (xbt_dynar_length(variable->content) == variable->min)
- RAISE3(mismatch_error,
+ THROW3(mismatch_error,0,
"Cannot remove %dth value from the config element %s since it's already at its minimal size (=%d)",
pos,name,variable->min);
-
- TRYOLD(xbt_cfgelm_get(cfg,name,xbt_cfgelm_any,&variable));
if (variable->cb_rm) (*variable->cb_rm)(name, pos);
xbt_dynar_remove_at(variable->content, pos, NULL);
-
- return mismatch_error;
}
/** @brief Remove all the values from a variable
* \arg name the name of the variable
*/
-xbt_error_t
+void
xbt_cfg_empty(xbt_cfg_t cfg,const char*name) {
xbt_cfgelm_t variable;
-
- xbt_error_t errcode;
-
- TRYCATCH(mismatch_error,
- xbt_dict_get((xbt_dict_t)cfg,name,(void**)&variable));
- if (errcode == mismatch_error) {
- ERROR1("Can't empty '%s' since this config element does not exist",
- name);
- return mismatch_error;
+ xbt_ex_t e;
+
+ TRY {
+ variable = xbt_dict_get((xbt_dict_t)cfg,name);
+ } CATCH(e) {
+ if (e.category == mismatch_error) {
+ xbt_ex_free(e);
+ THROW1(mismatch_error,0,
+ "Can't empty '%s' since this config element does not exist", name);
+ }
+ RETHROW;
}
if (variable) {
}
xbt_dynar_reset(variable->content);
}
- return no_error;
}
/*----[ Getting ]---------------------------------------------------------*/
*
* \warning the returned value is the actual content of the config set
*/
-xbt_error_t
-xbt_cfg_get_int (xbt_cfg_t cfg,
- const char *name,
- int *val) {
- xbt_cfgelm_t variable;
- xbt_error_t errcode;
-
- TRYOLD(xbt_cfgelm_get(cfg,name,xbt_cfgelm_int,&variable));
+int
+xbt_cfg_get_int (xbt_cfg_t cfg, const char *name) {
+ xbt_cfgelm_t variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_int);
if (xbt_dynar_length(variable->content) > 1) {
WARN2("You asked for the first value of the config element '%s', but there is %lu values",
- name, xbt_dynar_length(variable->content));
+ name, xbt_dynar_length(variable->content));
}
- *val = xbt_dynar_get_as(variable->content, 0, int);
- return no_error;
+ return xbt_dynar_get_as(variable->content, 0, int);
}
/** @brief Retrieve a double value of a variable (get a warning if not uniq)
* \warning the returned value is the actual content of the config set
*/
-xbt_error_t
-xbt_cfg_get_double(xbt_cfg_t cfg,
- const char *name,
- double *val) {
- xbt_cfgelm_t variable;
- xbt_error_t errcode;
-
- TRYOLD(xbt_cfgelm_get(cfg,name,xbt_cfgelm_double,&variable));
+double
+xbt_cfg_get_double(xbt_cfg_t cfg, const char *name) {
+ xbt_cfgelm_t variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_double);
if (xbt_dynar_length(variable->content) > 1) {
WARN2("You asked for the first value of the config element '%s', but there is %lu values\n",
name, xbt_dynar_length(variable->content));
}
- *val = xbt_dynar_get_as(variable->content, 0, double);
- return no_error;
+ return xbt_dynar_get_as(variable->content, 0, double);
}
/** @brief Retrieve a string value of a variable (get a warning if not uniq)
* \warning the returned value is the actual content of the config set
*/
-xbt_error_t xbt_cfg_get_string(xbt_cfg_t cfg,
- const char *name,
- char **val) {
- xbt_cfgelm_t variable;
- xbt_error_t errcode;
-
- *val=NULL;
-
- TRYOLD(xbt_cfgelm_get(cfg,name,xbt_cfgelm_string,&variable));
+char* xbt_cfg_get_string(xbt_cfg_t cfg, const char *name) {
+ xbt_cfgelm_t variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_string);
if (xbt_dynar_length(variable->content) > 1) {
WARN2("You asked for the first value of the config element '%s', but there is %lu values\n",
- name, xbt_dynar_length(variable->content));
+ name, xbt_dynar_length(variable->content));
}
- *val = xbt_dynar_get_as(variable->content, 0, char *);
- return no_error;
+ return xbt_dynar_get_as(variable->content, 0, char *);
}
/** @brief Retrieve an host value of a variable (get a warning if not uniq)
* \warning the returned value is the actual content of the config set
*/
-xbt_error_t xbt_cfg_get_host (xbt_cfg_t cfg,
- const char *name,
- char **host,
- int *port) {
+void xbt_cfg_get_host (xbt_cfg_t cfg, const char *name,
+ char **host, int *port) {
xbt_cfgelm_t variable;
- xbt_error_t errcode;
xbt_host_t *val;
- TRYOLD(xbt_cfgelm_get(cfg,name,xbt_cfgelm_host,&variable));
+ variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_host);
if (xbt_dynar_length(variable->content) > 1) {
WARN2("You asked for the first value of the config element '%s', but there is %lu values\n",
val = xbt_dynar_get_as(variable->content, 0, xbt_host_t*);
*host=val->name;
*port=val->port;
-
- return no_error;
}
/** @brief Retrieve the dynar of all the values stored in a variable
*
* \warning the returned value is the actual content of the config set
*/
-xbt_error_t xbt_cfg_get_dynar (xbt_cfg_t cfg,
- const char *name,
- xbt_dynar_t *dynar) {
+xbt_dynar_t xbt_cfg_get_dynar (xbt_cfg_t cfg, const char *name) {
xbt_cfgelm_t variable;
- xbt_error_t errcode = xbt_dict_get((xbt_dict_t)cfg,name,
- (void**)&variable);
-
- if (errcode == mismatch_error) {
- ERROR1("No registered variable %s in this config set",
- name);
- return mismatch_error;
+ xbt_ex_t e;
+
+ TRY {
+ variable = xbt_dict_get((xbt_dict_t)cfg,name);
+ } CATCH(e) {
+ if (e.category == mismatch_error) {
+ xbt_ex_free(e);
+ THROW1(mismatch_error,0,
+ "No registered variable %s in this config set",name);
+ }
+ RETHROW;
}
- if (errcode != no_error)
- return errcode;
- *dynar = variable->content;
- return no_error;
+ return variable->content;
}
/** @brief Retrieve one of the integer value of a variable */
-xbt_error_t
-xbt_cfg_get_int_at(xbt_cfg_t cfg,
- const char *name,
- int pos,
- int *val) {
+int
+xbt_cfg_get_int_at(xbt_cfg_t cfg, const char *name, int pos) {
- xbt_cfgelm_t variable;
- xbt_error_t errcode;
-
- TRYOLD(xbt_cfgelm_get(cfg,name,xbt_cfgelm_int,&variable));
- *val = xbt_dynar_get_as(variable->content, pos, int);
- return no_error;
+ xbt_cfgelm_t variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_int);
+ return xbt_dynar_get_as(variable->content, pos, int);
}
/** @brief Retrieve one of the double value of a variable */
-xbt_error_t
-xbt_cfg_get_double_at(xbt_cfg_t cfg,
- const char *name,
- int pos,
- double *val) {
+double
+xbt_cfg_get_double_at(xbt_cfg_t cfg, const char *name, int pos) {
- xbt_cfgelm_t variable;
- xbt_error_t errcode;
-
- TRYOLD(xbt_cfgelm_get(cfg,name,xbt_cfgelm_double,&variable));
- *val = xbt_dynar_get_as(variable->content, pos, double);
- return no_error;
+ xbt_cfgelm_t variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_double);
+ return xbt_dynar_get_as(variable->content, pos, double);
}
/** @brief Retrieve one of the string value of a variable */
-xbt_error_t
-xbt_cfg_get_string_at(xbt_cfg_t cfg,
- const char *name,
- int pos,
- char **val) {
+char*
+xbt_cfg_get_string_at(xbt_cfg_t cfg, const char *name, int pos) {
- xbt_cfgelm_t variable;
- xbt_error_t errcode;
-
- TRYOLD(xbt_cfgelm_get(cfg,name,xbt_cfgelm_string,&variable));
- *val = xbt_dynar_get_as(variable->content, pos, char*);
- return no_error;
+ xbt_cfgelm_t variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_string);
+ return xbt_dynar_get_as(variable->content, pos, char*);
}
/** @brief Retrieve one of the host value of a variable */
-xbt_error_t
-xbt_cfg_get_host_at(xbt_cfg_t cfg,
- const char *name,
- int pos,
- char **host,
- int *port) {
+void
+xbt_cfg_get_host_at(xbt_cfg_t cfg, const char *name, int pos,
+ char **host, int *port) {
- xbt_cfgelm_t variable;
- xbt_error_t errcode;
- xbt_host_t *val;
+ xbt_cfgelm_t variable = xbt_cfgelm_get(cfg,name,xbt_cfgelm_int);
+ xbt_host_t *val = xbt_dynar_get_ptr(variable->content, pos);
- TRYOLD(xbt_cfgelm_get(cfg,name,xbt_cfgelm_int,&variable));
- val = xbt_dynar_get_ptr(variable->content, pos);
*port = val->port;
*host = val->name;
- return no_error;
}
}
/* callback: termination */
-static void __context_ex_terminate(ex_t *e)
+static void __context_ex_terminate(xbt_ex_t *e)
{
exit(e->value);
}
/* 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 "xbt/ex.h"
#include "dict_private.h"
-
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(dict,xbt,
"Dictionaries provide the same functionnalities than hash tables");
/*####[ Private prototypes ]#################################################*/
*
* Search the given \a key. mismatch_error when not found.
*/
-xbt_error_t
-xbt_dict_get_ext(xbt_dict_t dict,
- const char *key,
- int key_len,
- /* OUT */void **data) {
+void *
+xbt_dict_get_ext(xbt_dict_t dict,
+ const char *key,
+ int key_len) {
xbt_assert(dict);
- return xbt_dictelm_get_ext(dict->head, key, key_len, data);
+ return xbt_dictelm_get_ext(dict->head, key, key_len);
}
/**
* \param data the data that we are looking for
* \return xbt_error
*
- * Search the given \a key. mismatch_error when not found.
+ * Search the given \a key. THROWs mismatch_error when not found.
+ * Check xbt_dict_get_or_null() for a version returning NULL without exception when
+ * not found.
*/
-xbt_error_t
+void *
xbt_dict_get(xbt_dict_t dict,
- const char *key,
- /* OUT */void **data) {
+ const char *key) {
xbt_assert(dict);
- return xbt_dictelm_get(dict->head, key, data);
+ return xbt_dictelm_get(dict->head, key);
+}
+
+/**
+ * \brief like xbt_dict_get(), but returning NULL when not found
+ */
+void *
+xbt_dict_get_or_null(xbt_dict_t dict,
+ const char *key) {
+ xbt_ex_t e;
+ void *res;
+ TRY {
+ res = xbt_dictelm_get(dict->head, key);
+ } CATCH(e) {
+ if (e.category != mismatch_error)
+ RETHROW;
+ xbt_ex_free(e);
+ res=NULL;
+ }
+ return res;
}
xbt_error_t
xbt_dict_remove(xbt_dict_t dict,
const char *key) {
- if (!dict)
- RAISE1(mismatch_error,"Asked to remove key %s from NULL dict",key);
+ if (!dict)
+ THROW1(arg_error,0,"Asked to remove key %s from NULL dict",key);
return xbt_dictelm_remove(dict->head, key);
}
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "xbt/misc.h"
+#include "xbt/ex.h"
#include "dict_private.h"
#include <string.h> /* strlen() */
* Sanity check to see if the head contains something
*/
static _XBT_INLINE
-xbt_error_t
+void
__cursor_not_null(xbt_dict_cursor_t cursor) {
xbt_assert0(cursor, "Null cursor");
- if (!cursor->head) {
- return mismatch_error;
- }
-
- return no_error;
+ if (!cursor->head)
+ THROW0(arg_error,0,"Null headed cursor");
}
xbt_dict_cursor_get_or_free(xbt_dict_cursor_t *cursor,
char **key,
void **data) {
- xbt_error_t errcode = no_error;
- int key_len = 0;
+ int key_len = 0;
+ xbt_ex_t e;
if (!cursor || !(*cursor))
return FALSE;
*key = xbt_dynar_get_as((*cursor)->keys, (*cursor)->pos, char*);
key_len = xbt_dynar_get_as((*cursor)->key_lens, (*cursor)->pos_len, int);
- errcode = xbt_dictelm_get_ext((*cursor)->head, *key, key_len, data);
- if (errcode == mismatch_error) {
- xbt_dict_cursor_free(cursor);
- return FALSE;
+ TRY {
+ *data = xbt_dictelm_get_ext((*cursor)->head, *key, key_len);
+ } CATCH(e) {
+ if (e.category == mismatch_error) {
+ xbt_dict_cursor_free(cursor);
+ xbt_ex_free(e);
+ return FALSE;
+ }
+ RETHROW;
}
-
- xbt_assert1(errcode == no_error,
- "Unexpected problem while retrieving the content of cursor. Got %s",
- xbt_error_name(errcode));
-
return TRUE;
}
* @param cursor: the cursor
* @param key where to put the key
*/
-xbt_error_t
-xbt_dict_cursor_get_key(xbt_dict_cursor_t cursor,
- /*OUT*/char **key) {
- xbt_error_t errcode = no_error;
+char *
+xbt_dict_cursor_get_key(xbt_dict_cursor_t cursor) {
+ __cursor_not_null(cursor);
- TRYOLD(__cursor_not_null(cursor));
-
- *key = xbt_dynar_get_as(cursor->keys, cursor->pos - 1, char*);
-
- return errcode;
+ return xbt_dynar_get_as(cursor->keys, cursor->pos - 1, char*);
}
/**
* @param cursor the cursor
* @param data where to put the data
*/
-xbt_error_t
-xbt_dict_cursor_get_data(xbt_dict_cursor_t cursor,
- /*OUT*/void **data) {
- xbt_error_t errcode = no_error;
+void *
+xbt_dict_cursor_get_data(xbt_dict_cursor_t cursor) {
char *key = NULL;
int key_len = 0;
- TRYOLD(__cursor_not_null(cursor));
+ __cursor_not_null(cursor);
key = xbt_dynar_get_as(cursor->keys, cursor->pos-1, char *);
key_len = xbt_dynar_get_as(cursor->key_lens, cursor->pos_len-1, int);
- TRYOLD(xbt_dictelm_get_ext(cursor->head, key, key_len, data));
-
- return errcode;
+ return xbt_dictelm_get_ext(cursor->head, key, key_len);
}
/* 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 "xbt/ex.h"
#include "portable.h" /* PRINTF_STR */
#include "dict_private.h" /* prototypes of this module */
int offset,
void *data,
void_f_pvoid_t *free_f);
-static xbt_error_t _xbt_dictelm_get_rec(s_xbt_dictelm_t *head,
- const char *key,
- int key_len,
- int offset,
- /* OUT */void **data);
+static void * _xbt_dictelm_get_rec(s_xbt_dictelm_t *head,
+ const char *key,
+ int key_len,
+ int offset);
static xbt_error_t _xbt_dictelm_remove_rec(s_xbt_dictelm_t *head,
const char *key,
int key_len,
}
default:
- DIE_IMPOSSIBLE;
+ THROW_IMPOSSIBLE;
}
}
* Search the given @key. mismatch_error when not found.
*/
static
-xbt_error_t
+void *
_xbt_dictelm_get_rec(s_xbt_dictelm_t *p_head,
const char *key,
int key_len,
- int offset,
- void **data) {
+ int offset) {
CDEBUG3(dict_search, "Search %.*s in %p", key_len, key, (void*)p_head);
/* we did enough recursion, we're done */
if (offset >= key_len) {
- *data = p_head->content;
-
- return no_error;
+ return p_head->content;
}
{
int match = 0;
int pos = 0;
- *data = NULL; /* Let's be clean */
-
/*** Search where is the good child, and how good it is ***/
_xbt_dictelm_child_search(p_head, key, key_len, &pos, &offset, &match);
switch (match) {
case 0: /* no child have a common prefix */
- return mismatch_error;
+ THROW1(mismatch_error,0,"key '%s' not found",key);
case 1: /* A child have exactly this key => Got it */
{
s_xbt_dictelm_t *p_child = NULL;
-
p_child = xbt_dynar_get_as(p_head->sub, pos, s_xbt_dictelm_t*);
- *data = p_child->content;
-
- return no_error;
+ return p_child->content;
}
case 2: /* A child constitutes a prefix of the key => recurse */
p_child = xbt_dynar_get_as(p_head->sub, pos, s_xbt_dictelm_t*);
- return _xbt_dictelm_get_rec(p_child, key, key_len, offset, data);
+ return _xbt_dictelm_get_rec(p_child, key, key_len, offset);
}
case 3: /* The key is a prefix of the child => not found */
- return mismatch_error;
+ THROW1(mismatch_error,0,"key %s not found",key);
case 4: /* A child share a common prefix with this key => not found */
- return mismatch_error;
+ THROW1(mismatch_error,0,"key %s not found",key);
default:
- RAISE_IMPOSSIBLE;
+ THROW_IMPOSSIBLE;
}
}
}
*
* Search the given @key. mismatch_error when not found.
*/
-xbt_error_t
+void *
xbt_dictelm_get_ext(s_xbt_dictelm_t *p_head,
- const char *key,
- int key_len,
- /* OUT */void **data) {
+ const char *key,
+ int key_len) {
/* there is no head, go to hell */
- if (!p_head) {
- return mismatch_error;
- }
+ if (!p_head)
+ THROW1(mismatch_error,0,"Key '%s' not found in dict",key);
- return _xbt_dictelm_get_rec(p_head, key, key_len, 0, data);
+ return _xbt_dictelm_get_rec(p_head, key, key_len, 0);
}
/**
*
* Search the given @key. mismatch_error when not found.
*/
-xbt_error_t
-xbt_dictelm_get(s_xbt_dictelm_t *p_head,
- const char *key,
- /* OUT */void **data) {
+void *
+xbt_dictelm_get(s_xbt_dictelm_t *p_head,
+ const char *key) {
- return xbt_dictelm_get_ext(p_head, key, strlen(key), data);
+ return xbt_dictelm_get_ext(p_head, key, strlen(key));
}
/*----[ _xbt_dict_collapse ]------------------------------------------------*/
p_child = xbt_dynar_get_as(head->sub, pos, s_xbt_dictelm_t*);
/*DEBUG5("Recurse on child %d of %p to remove %.*s (prefix=%d)",
pos, (void*)p_child, key+offset, key_len-offset,offset);*/
- TRYOLD(_xbt_dictelm_remove_rec(p_child, key, key_len, offset));
+ _xbt_dictelm_remove_rec(p_child, key, key_len, offset);
_collapse_if_need(head, pos, old_offset);
return no_error;
default:
- RAISE_IMPOSSIBLE;
+ THROW_IMPOSSIBLE;
}
}
const char *key,
int key_len) {
/* there is no head, go to hell */
- if (!head) {
- RAISE0(mismatch_error, "there is no head, go to hell");
- }
+ if (!head)
+ THROW1(arg_error,0,"Asked to remove key %s from NULL dict",key);
return _xbt_dictelm_remove_rec(head, key, key_len, 0);
}
* Dynars are not modified during the operation.
*/
-xbt_error_t
+void
xbt_multidict_set_ext(xbt_dict_t mdict,
xbt_dynar_t keys, xbt_dynar_t lens,
void *data, void_f_pvoid_t *free_ctn) {
-
- xbt_error_t errcode;
- xbt_dict_t thislevel,nextlevel;
+
+ xbt_ex_t e;
+ xbt_dict_t thislevel,nextlevel=NULL;
int i;
unsigned long int thislen;
DEBUG5("multi_set: at level %d, len=%ld, key=%p |%*s|", i, thislen, thiskey, (int)thislen,thiskey);
/* search the dict of next level */
- TRYCATCH(xbt_dict_get_ext(thislevel, thiskey, thislen, (void*)&nextlevel), mismatch_error);
-
- /* make sure the dict of next level exists */
- if (errcode == mismatch_error) {
- nextlevel=xbt_dict_new();
- VERB1("Create a dict (%p)",nextlevel);
- xbt_dict_set_ext(thislevel, thiskey, thislen, nextlevel, &_free_dict);
+ TRY {
+ nextlevel = xbt_dict_get_ext(thislevel, thiskey, thislen);
+ } CATCH(e) {
+ if (e.category == arg_error || e.category == mismatch_error) {
+ /* make sure the dict of next level exists */
+ nextlevel=xbt_dict_new();
+ VERB1("Create a dict (%p)",nextlevel);
+ xbt_dict_set_ext(thislevel, thiskey, thislen, nextlevel, &_free_dict);
+ } else {
+ RETHROW;
+ }
}
}
xbt_dynar_get_cpy(lens, i, &thislen);
xbt_dict_set_ext(thislevel, thiskey, thislen, data, free_ctn);
-
- return no_error;
}
/** \brief Insert \e data under all the keys contained in \e keys
* \arg data: what to store in the structure
* \arg free_ctn: function to use to free the pushed content on need
*/
-xbt_error_t
+void
xbt_multidict_set(xbt_dict_t mdict,
xbt_dynar_t keys,
void *data, void_f_pvoid_t *free_ctn) {
- xbt_error_t errcode;
xbt_dynar_t lens = xbt_dynar_new(sizeof(unsigned long int),NULL);
int i;
xbt_dynar_push(lens,&thislen);
}
- errcode = xbt_multidict_set_ext(mdict, keys, lens, data, free_ctn);
+ xbt_multidict_set_ext(mdict, keys, lens, data, free_ctn);
xbt_dynar_free(&lens);
- return errcode;
+
}
/** \brief Insert \e data under all the keys contained in \e keys, providing their sizes in \e lens.
*
* Dynars are not modified during the operation.
*/
-xbt_error_t
+void *
xbt_multidict_get_ext(xbt_dict_t mdict,
- xbt_dynar_t keys, xbt_dynar_t lens,
- /*OUT*/void **data) {
- xbt_error_t errcode;
+ xbt_dynar_t keys, xbt_dynar_t lens) {
xbt_dict_t thislevel,nextlevel;
int i;
i, thislevel, thislen, thiskey, (int)thislen,thiskey);
/* search the dict of next level: let mismatch raise if not found */
- TRYOLD(xbt_dict_get_ext(thislevel, thiskey, thislen, (void*)&nextlevel));
+ nextlevel = xbt_dict_get_ext(thislevel, thiskey, thislen);
}
xbt_dynar_get_cpy(keys, i, &thiskey);
xbt_dynar_get_cpy(lens, i, &thislen);
- return xbt_dict_get_ext(thislevel, thiskey, thislen, data);
+ return xbt_dict_get_ext(thislevel, thiskey, thislen);
}
-xbt_error_t
-xbt_multidict_get(xbt_dict_t mdict, xbt_dynar_t keys, /*OUT*/void **data) {
- xbt_error_t errcode;
+void *
+xbt_multidict_get(xbt_dict_t mdict, xbt_dynar_t keys) {
xbt_dynar_t lens = xbt_dynar_new(sizeof(unsigned long int),NULL);
int i;
+ void *res;
for (i = 0; i < xbt_dynar_length(keys); i++) {
char *thiskey = xbt_dynar_get_as(keys, i, char*);
xbt_dynar_push(lens,&thislen);
}
- errcode = xbt_multidict_get_ext(mdict, keys, lens, data),
+ res = xbt_multidict_get_ext(mdict, keys, lens),
xbt_dynar_free(&lens);
- return errcode;
+ return res;
}
xbt_error_t
xbt_multidict_remove_ext(xbt_dict_t mdict, xbt_dynar_t keys, xbt_dynar_t lens) {
- xbt_error_t errcode;
- xbt_dict_t thislevel,nextlevel;
+ xbt_dict_t thislevel,nextlevel=NULL;
int i;
+ xbt_ex_t e;
unsigned long int thislen;
char *thiskey;
xbt_dynar_get_cpy(lens, i, &thislen);
/* search the dict of next level */
- TRYCATCH(xbt_dict_get_ext(thislevel, thiskey, thislen, (void*)&nextlevel), mismatch_error);
-
- /* If non-existant entry, nothing to do */
- if (errcode == mismatch_error)
- return no_error;
+ TRY {
+ nextlevel = xbt_dict_get_ext(thislevel, thiskey, thislen);
+ } CATCH(e) {
+ /* If non-existant entry, nothing to do */
+ if (e.category == arg_error)
+ xbt_ex_free(e);
+ else
+ RETHROW;
+ }
}
xbt_dynar_get_cpy(keys, i, &thiskey);
#include "xbt/sysdep.h"
#include "xbt/log.h"
#include "xbt/error.h"
+#include "xbt/ex.h"
#include "xbt/dynar.h"
#include "xbt/dict.h"
typedef struct xbt_dict_cursor_ s_xbt_dict_cursor_t;
/*####[ Function prototypes ]################################################*/
-void xbt_dictelm_free (s_xbt_dictelm_t **pp_elm);
+void xbt_dictelm_free (s_xbt_dictelm_t **pp_elm);
-void xbt_dictelm_set (s_xbt_dictelm_t **pp_head,
+void xbt_dictelm_set (s_xbt_dictelm_t **pp_head,
const char *_key,
void *data,
void_f_pvoid_t *free_ctn);
-void xbt_dictelm_set_ext (s_xbt_dictelm_t **pp_head,
+void xbt_dictelm_set_ext (s_xbt_dictelm_t **pp_head,
const char *_key,
int key_len,
void *data,
void_f_pvoid_t *free_ctn);
-xbt_error_t xbt_dictelm_get (s_xbt_dictelm_t *p_head,
- const char *key,
- /* OUT */void **data);
-xbt_error_t xbt_dictelm_get_ext (s_xbt_dictelm_t *p_head,
- const char *key,
- int key_len,
- /* OUT */void **data);
+void* xbt_dictelm_get (s_xbt_dictelm_t *p_head,
+ const char *key);
+void* xbt_dictelm_get_ext (s_xbt_dictelm_t *p_head,
+ const char *key,
+ int key_len);
xbt_error_t xbt_dictelm_remove (s_xbt_dictelm_t *p_head,
const char *key);
/** @brief Get and remove the last element of the dynar */
void
xbt_dynar_pop(xbt_dynar_t const dynar,
- void * const dst) {
+ void * const dst) {
/* sanity checks done by remove_at */
DEBUG1("Pop %p",(void*)dynar);
switch (errcode) {
case no_error: return "success";
- case mismatch_error: return "mismatch";
- case system_error: return "system";
- case network_error: return "network";
- case timeout_error: return "timeout";
- case thread_error: return "thread";
- case unknown_error: return "unclassified";
+ case old_mismatch_error: return "mismatch";
+ case old_system_error: return "system";
+ case old_network_error: return "network";
+ case old_timeout_error: return "timeout";
+ case old_thread_error: return "thread";
+ case old_unknown_error: return "unclassified";
default:
return "SEVERE ERROR in error repporting module";
}
#include <stdio.h>
#include <stdlib.h>
+#include <execinfo.h>
#include "xbt/ex.h"
}
/* default __ex_terminate callback function */
-void __xbt_ex_terminate_default(ex_t *e) {
-
- fprintf(stderr,
- "** SimGrid: UNCAUGHT EXCEPTION:\n"
- "** (%d/%d) %s\n"
- "** Thrown by %s%s%s at %s:%d:%s\n",
- e->category, e->value, e->msg,
- e->procname, (e->host?"@":""),(e->host?e->host:""),
- e->file,e->line,e->func);
- abort();
+void __xbt_ex_terminate_default(xbt_ex_t *e) {
+ char **strings;
+ size_t i;
+
+ fprintf(stderr,
+ "** SimGrid: UNCAUGHT EXCEPTION: category: %s; value: %d\n"
+ "** %s\n"
+ "** Thrown by %s%s%s at %s:%d:%s\n",
+ xbt_ex_catname(e->category), e->value, e->msg,
+ e->procname, (e->host?"@":""),(e->host?e->host:"localhost"),
+ e->file,e->line,e->func);
+
+ fprintf(stderr,"** Backtrace:\n");
+ strings = backtrace_symbols (e->bt, e->used);
+
+ for (i = 0; i < e->used; i++)
+ printf (" %s\n", strings[i]);
+
+ free (strings);
+ abort();
}
/* the externally visible API */
ex_ctx_cb_t __xbt_ex_ctx = &__xbt_ex_ctx_default;
ex_term_cb_t __xbt_ex_terminate = &__xbt_ex_terminate_default;
+void xbt_ex_free(xbt_ex_t e) {
+ free(e.msg);
+}
+
+/** \brief returns a short name for the given exception category */
+const char * xbt_ex_catname(xbt_errcat_t cat) {
+ switch (cat) {
+ case unknown_error: return "unknown_err";
+ case arg_error: return "invalid_arg";
+ case mismatch_error: return "mismatch";
+ case system_error: return "system_err";
+ case network_error: return "network_err";
+ case timeout_error: return "timeout";
+ case thread_error: return "thread_err";
+ default: return "INVALID_ERR";
+ }
+}
#include "xbt/error.h"
#include "fifo_private.h"
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(fifo,xbt,"FIFO");
+/*XBT_LOG_NEW_DEFAULT_SUBCATEGORY(fifo,xbt,"FIFO"); UNUSED SO FAR */
/** \defgroup XBT_fifo A generic workqueue
* \brief This section describes the API to generic workqueue. These functions
#include <stdarg.h>
-#include "gras_config.h" /* to get a workgin stdarg.h */
+#include "gras_config.h" /* to get a working stdarg.h */
#include <ctype.h>
+#include <stdio.h> /* snprintf */
#include "xbt_modinter.h"
if (errcode==no_error)
return no_error;
}
- return mismatch_error;
+ return old_mismatch_error;
}
static void _cleanup_double_spaces(char *s) {
_xbt_log_parse_setting(p,set);
errcode = _xbt_log_cat_searchsub(&_XBT_LOGV(root),set->catname,&cat);
- if (errcode == mismatch_error) {
+ if (errcode == old_mismatch_error) {
DEBUG0("Store for further application");
DEBUG1("push %p to the settings",(void*)set);
xbt_dynar_push(xbt_log_settings,&set);
#include "xbt/misc.h"
#include "xbt/sysdep.h"
#include "xbt/log.h"
-#include "xbt/error.h"
+#include "xbt/ex.h"
#include "xbt/dynar.h"
#include "xbt/dict.h"
xbt_set_elm_t elm,
void_f_pvoid_t *free_func) {
- xbt_error_t errcode;
- xbt_set_elm_t found_in_dict;
+ int found = 1;
+ xbt_set_elm_t found_in_dict = NULL;
+ xbt_ex_t e;
if (elm->name_len <= 0) {
elm->name_len = strlen(elm->name);
}
- errcode = xbt_dict_get_ext (set->dict,
- elm->name, elm->name_len,
- (void**)&found_in_dict);
- if (errcode == no_error) {
+ TRY {
+ found_in_dict = xbt_dict_get_ext (set->dict,
+ elm->name, elm->name_len);
+ } CATCH(e) {
+ if (e.category != mismatch_error)
+ RETHROW;
+ found = 0;
+ elm->ID = xbt_dynar_length( set->dynar );
+ xbt_dict_set_ext(set->dict, elm->name, elm->name_len, elm, free_func);
+ xbt_dynar_set(set->dynar, elm->ID, &elm);
+ DEBUG2("Insertion of key '%s' (id %d)", elm->name, elm->ID);
+ xbt_ex_free(e);
+ }
+
+ if (found) {
if (elm == found_in_dict) {
DEBUG2("Ignoring request to insert the same element twice (key %s ; id %d)",
elm->name, elm->ID);
xbt_dynar_set(set->dynar, elm->ID, &elm);
return;
}
- } else {
- xbt_assert_error(mismatch_error);
}
-
- elm->ID = xbt_dynar_length( set->dynar );
- xbt_dict_set_ext(set->dict, elm->name, elm->name_len, elm, free_func);
- xbt_dynar_set(set->dynar, elm->ID, &elm);
- DEBUG2("Insertion of key '%s' (id %d)", elm->name, elm->ID);
-
}
/** @brief Retrive data by providing its name.
* \param name Name of the searched cell
* \param dst where to put the found data into
*/
-xbt_error_t xbt_set_get_by_name (xbt_set_t set,
- const char *name,
- /* OUT */xbt_set_elm_t *dst) {
- xbt_error_t errcode;
- errcode = xbt_dict_get_ext(set->dict, name, strlen(name), (void**) dst);
- DEBUG2("Lookup key %s: %s",name,xbt_error_name(errcode));
- return errcode;
+xbt_set_elm_t xbt_set_get_by_name (xbt_set_t set,
+ const char *name) {
+ DEBUG1("Lookup key %s",name);
+ return xbt_dict_get_ext(set->dict, name, strlen(name));
}
/** @brief Retrive data by providing its name and the length of the name
* This is useful when strlen cannot be trusted because you don't use a char*
* as name, you weirdo.
*/
-xbt_error_t xbt_set_get_by_name_ext(xbt_set_t set,
+xbt_set_elm_t xbt_set_get_by_name_ext(xbt_set_t set,
const char *name,
- int name_len,
- /* OUT */xbt_set_elm_t *dst) {
+ int name_len) {
- return xbt_dict_get_ext (set->dict, name, name_len, (void**)dst);
+ return xbt_dict_get_ext (set->dict, name, name_len);
}
/** @brief Retrive data by providing its ID
*
* @warning, if the ID does not exists, you're getting into trouble
*/
-xbt_error_t xbt_set_get_by_id (xbt_set_t set,
- int id,
- /* OUT */xbt_set_elm_t *dst) {
-
+xbt_set_elm_t xbt_set_get_by_id (xbt_set_t set, int id) {
+ xbt_set_elm_t res;
+
/* Don't bother checking the bounds, the dynar does so */
- *dst = xbt_dynar_get_as(set->dynar,id,xbt_set_elm_t);
+ res = xbt_dynar_get_as(set->dynar,id,xbt_set_elm_t);
DEBUG3("Lookup type of id %d (of %lu): %s",
- id, xbt_dynar_length(set->dynar), (*dst)->name);
+ id, xbt_dynar_length(set->dynar), res->name);
- return no_error;
+ return res;
}
/***
#endif /* HAVE_GETTIMEOFDAY? */
}
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sysdep, xbt, "System dependency");
+/*XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sysdep, xbt, "System dependency");*/
struct s_xbt_os_timer {
int r_arch;
const char *filename = "datadesc_usage.out";
-xbt_error_t
+void
write_read(gras_datadesc_type_t type,void *src, void *dst,
gras_socket_t sock, int direction);
-xbt_error_t
+void
write_read(gras_datadesc_type_t type,void *src, void *dst,
gras_socket_t sock, int direction) {
- xbt_error_t errcode;
/* write */
if (direction == RW)
- TRYOLD(gras_socket_client_from_file(filename,&sock));
+ sock = gras_socket_client_from_file(filename);
if (direction == WRITE || direction == RW)
- TRYOLD(gras_datadesc_send(sock, type, src));
-/* TRYOLD(gras_datadesc_gen_send(sock, type, src));*/
+ gras_datadesc_send(sock, type, src);
+/* gras_datadesc_gen_send(sock, type, src);*/
if (direction == RW)
gras_socket_close(sock);
/* read */
if (direction == RW)
- TRYOLD(gras_socket_server_from_file(filename,&sock));
+ sock = gras_socket_server_from_file(filename);
if (direction == READ || direction == RW)
- TRYOLD(gras_datadesc_recv(sock, type, r_arch, dst));
+ gras_datadesc_recv(sock, type, r_arch, dst);
if (direction == RW)
gras_socket_close(sock);
-
- return no_error;
}
-xbt_error_t test_int(gras_socket_t sock, int direction);
-xbt_error_t test_float(gras_socket_t sock, int direction);
-xbt_error_t test_double(gras_socket_t sock, int direction);
-xbt_error_t test_array(gras_socket_t sock, int direction);
-xbt_error_t test_dynar_scal(gras_socket_t sock, int direction);
-xbt_error_t test_intref(gras_socket_t sock, int direction);
-xbt_error_t test_string(gras_socket_t sock, int direction);
+void test_int(gras_socket_t sock, int direction);
+void test_float(gras_socket_t sock, int direction);
+void test_double(gras_socket_t sock, int direction);
+void test_array(gras_socket_t sock, int direction);
+void test_dynar_scal(gras_socket_t sock, int direction);
+void test_intref(gras_socket_t sock, int direction);
+void test_string(gras_socket_t sock, int direction);
-xbt_error_t test_homostruct(gras_socket_t sock, int direction);
-xbt_error_t test_hetestruct(gras_socket_t sock, int direction);
-xbt_error_t test_nestedstruct(gras_socket_t sock, int direction);
-xbt_error_t test_chain_list(gras_socket_t sock, int direction);
-xbt_error_t test_graph(gras_socket_t sock, int direction);
-xbt_error_t test_dynar_ref(gras_socket_t sock, int direction);
+void test_homostruct(gras_socket_t&n