3 /* base - several addons to do specific stuff not in GRAS itself */
5 /* Authors: Martin Quinson */
6 /* Copyright (C) 2003 the OURAGAN project. */
8 /* This program is free software; you can redistribute it and/or modify it
9 under the terms of the license (GNU LGPL) which comes with this package. */
15 #include "xbt/error.h"
16 #include "gras/datadesc.h"
17 #include "amok/base.h"
19 GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(amok,GRAS_LOG_ROOT_CAT,"All AMOK categories");
21 amok_remoterr_t *amok_remoterr_new(gras_error_t param_errcode,
22 const char* format,...) {
28 res = amok_remoterr_new_va(param_errcode,format,ap);
33 amok_remoterr_t *amok_remoterr_new_va(gras_error_t param_errcode,
34 const char* format,va_list ap) {
35 amok_remoterr_t *res=gras_new(amok_remoterr_t,1);
36 res->code=param_errcode;
38 res->msg=(char*)gras_malloc(1024);
39 vsnprintf(res->msg,1024,format,ap);
47 void amok_remoterr_free(amok_remoterr_t*err) {
49 if (err->msg) gras_free(err->msg);
56 amok_repport_error (gras_socket_t *sock, gras_msgtype_t *msgtype,
57 gras_error_t param_errcode, const char* format,...) {
58 amok_remoterr_t *error;
62 error=gras_new(amok_remoterr_t,1);
63 error->code=param_errcode;
64 error->msg=(char*)gras_malloc(1024); /* FIXME */
66 vsnprintf(error->msg,1024,format,ap);
69 errcode = gras_msg_send(sock,msgtype,error);
70 if (errcode != no_error) {
71 CRITICAL4("Error '%s' while reporting error '%s' to %s:%d",
72 gras_error_name(errcode),error->msg,
73 gras_socket_peer_name(sock),gras_socket_peer_port(sock) );
77 void amok_base_init(void) {
78 gras_datadesc_type_t *host_desc, *remoterr_desc;
80 /* Build the datatype descriptions */
81 host_desc = gras_datadesc_struct("gras_host_t");
82 gras_datadesc_struct_append(host_desc,"name",gras_datadesc_by_name("string"));
83 gras_datadesc_struct_append(host_desc,"exp_size",gras_datadesc_by_name("int"));
84 gras_datadesc_struct_close(host_desc);
85 host_desc = gras_datadesc_ref("gras_host_t*",host_desc);
87 remoterr_desc = gras_datadesc_struct("amok_remoterr_t");
88 gras_datadesc_struct_append(remoterr_desc,"msg",gras_datadesc_by_name("string"));
89 gras_datadesc_struct_append(remoterr_desc,"code",gras_datadesc_by_name("unsigned int"));
90 gras_datadesc_struct_close(remoterr_desc);
91 remoterr_desc = gras_datadesc_ref("amok_remoterr_t*",remoterr_desc);
94 void amok_base_exit(void) {
95 /* No real module mecanism in GRAS so far, nothing to do. */