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. */
11 #include "xbt/error.h"
12 #include "gras/datadesc.h"
13 #include "amok/base.h"
15 GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(amok,GRAS_LOG_ROOT_CAT,"All AMOK categories");
17 amok_remoterr_t amok_remoterr_new(gras_error_t param_errcode,
18 const char* format,...) {
24 res = amok_remoterr_new_va(param_errcode,format,ap);
29 amok_remoterr_t amok_remoterr_new_va(gras_error_t param_errcode,
30 const char* format,va_list ap) {
31 amok_remoterr_t res=gras_new(s_amok_remoterr_t,1);
32 res->code=param_errcode;
34 res->msg=(char*)gras_malloc(1024);
35 vsnprintf(res->msg,1024,format,ap);
43 void amok_remoterr_free(amok_remoterr_t *err) {
45 if ((*err)->msg) gras_free((*err)->msg);
53 amok_repport_error (gras_socket_t sock, gras_msgtype_t msgtype,
54 gras_error_t param_errcode, const char* format,...) {
55 amok_remoterr_t error;
59 error=gras_new(s_amok_remoterr_t,1);
60 error->code=param_errcode;
61 error->msg=(char*)gras_malloc(1024); /* FIXME */
63 vsnprintf(error->msg,1024,format,ap);
66 errcode = gras_msg_send(sock,msgtype,error);
67 if (errcode != no_error) {
68 CRITICAL4("Error '%s' while reporting error '%s' to %s:%d",
69 gras_error_name(errcode),error->msg,
70 gras_socket_peer_name(sock),gras_socket_peer_port(sock) );
74 void amok_base_init(void) {
75 gras_datadesc_type_t host_desc, remoterr_desc;
77 /* Build the datatype descriptions */
78 host_desc = gras_datadesc_struct("gras_host_t");
79 gras_datadesc_struct_append(host_desc,"name",gras_datadesc_by_name("string"));
80 gras_datadesc_struct_append(host_desc,"exp_size",gras_datadesc_by_name("int"));
81 gras_datadesc_struct_close(host_desc);
82 host_desc = gras_datadesc_ref("gras_host_t*",host_desc);
84 remoterr_desc = gras_datadesc_struct("s_amok_remoterr_t");
85 gras_datadesc_struct_append(remoterr_desc,"msg",gras_datadesc_by_name("string"));
86 gras_datadesc_struct_append(remoterr_desc,"code",gras_datadesc_by_name("unsigned int"));
87 gras_datadesc_struct_close(remoterr_desc);
88 remoterr_desc = gras_datadesc_ref("amok_remoterr_t",remoterr_desc);
91 void amok_base_exit(void) {
92 /* No real module mecanism in GRAS so far, nothing to do. */