BEGIN_DECL
+/* datadesc */
typedef struct s_gras_datadesc_type gras_datadesc_type_t;
+/* callbacks prototypes */
+typedef void (*gras_datadesc_type_cb_void_t)(void *vars,
+ gras_datadesc_type_t *p_type,
+ void *data);
+typedef int (*gras_datadesc_type_cb_int_t)(void *vars,
+ gras_datadesc_type_t *p_type,
+ void *data);
+
/***********************************************
**** Search and retrieve declared datatype ****
***********************************************/
-long int gras_datadesc_get_id_from_name(const char *name);
-
gras_error_t gras_datadesc_by_name(const char *name,
gras_datadesc_type_t **type);
-gras_error_t gras_datadesc_by_id (long int code,
- gras_datadesc_type_t **type);
-#define gras_datadesc_by_code(a,b) gras_datadesc_by_id(a,b)
-/*********************************************
- **** DataDesc callback persistent states ****
- *********************************************/
+/******************************************
+ **** Declare datadescription yourself ****
+ ******************************************/
+
+gras_error_t
+gras_datadesc_declare_struct(const char *name,
+ gras_datadesc_type_t **dst);
+gras_error_t
+gras_datadesc_declare_struct_append(gras_datadesc_type_t *struct_type,
+ const char *name,
+ gras_datadesc_type_t *field_type);
+gras_error_t
+gras_datadesc_declare_struct_append_name(gras_datadesc_type_t *struct_type,
+ const char *name,
+ const char *field_type_name);
+gras_error_t
+gras_datadesc_declare_union(const char *name,
+ gras_datadesc_type_cb_int_t selector,
+ gras_datadesc_type_t **dst);
+gras_error_t
+gras_datadesc_declare_union_append(gras_datadesc_type_t *union_type,
+ const char *name,
+ gras_datadesc_type_t *field_type);
+gras_error_t
+gras_datadesc_declare_union_append_name(gras_datadesc_type_t *union_type,
+ const char *name,
+ const char *field_type_name);
+gras_error_t
+gras_datadesc_declare_ref(const char *name,
+ gras_datadesc_type_t *referenced_type,
+ gras_datadesc_type_t **dst);
+gras_error_t
+gras_datadesc_declare_ref_generic(const char *name,
+ gras_datadesc_type_cb_int_t discriminant,
+ gras_datadesc_type_t **dst);
+gras_error_t
+gras_datadesc_declare_array_fixed(const char *name,
+ gras_datadesc_type_t *element_type,
+ long int fixed_size,
+ gras_datadesc_type_t **dst);
+gras_error_t
+gras_datadesc_declare_array_dyn(const char *name,
+ gras_datadesc_type_t *element_type,
+ gras_datadesc_type_cb_int_t dynamic_size,
+ gras_datadesc_type_t **dst);
+
+/*********************************
+ * Change stuff within datadescs *
+ *********************************/
+
typedef struct s_gras_dd_cbps gras_dd_cbps_t;
+void gras_datadesc_cb_set_pre (gras_datadesc_type_t *type,
+ gras_datadesc_type_cb_void_t pre);
+void gras_datadesc_cb_set_post(gras_datadesc_type_t *type,
+ gras_datadesc_type_cb_void_t post);
+
+/********************************************************
+ * Advanced data describing: callback persistent states *
+ ********************************************************/
void *
gras_dd_cbps_pop (gras_dd_cbps_t *ps,
gras_dd_cbps_block_end(gras_dd_cbps_t *ps);
-/******************************************
- **** Declare datadescription manually ****
- ******************************************/
-
-typedef void (*gras_datadesc_type_cb_void_t)(void *vars,
- gras_datadesc_type_t *p_type,
- void *data);
-typedef int (*gras_datadesc_type_cb_int_t)(void *vars,
- gras_datadesc_type_t *p_type,
- void *data);
-
-/* Create a new type and register it on the local machine */
-#define gras_datadesc_declare_struct( name, code) \
- gras_datadesc_declare_struct_cb(name, NULL, NULL, code)
-
-#define gras_datadesc_declare_struct_add_name( struct_code,field_name,field_type_name) \
- gras_datadesc_declare_struct_add_name_cb(struct_code,field_name,field_type_name, NULL, NULL)
-
-#define gras_datadesc_declare_struct_add_code( struct_code,field_name,field_type_code) \
- gras_datadesc_declare_struct_add_code_cb(struct_code,field_name,field_type_code, NULL, NULL)
-
-gras_error_t
-gras_datadesc_declare_struct_cb(const char *name,
- gras_datadesc_type_cb_void_t pre_cb,
- gras_datadesc_type_cb_void_t post_cb,
- long int *code);
-gras_error_t
-gras_datadesc_declare_struct_add_name_cb(long int struct_code,
- const char *field_name,
- const char *field_type_name,
- gras_datadesc_type_cb_void_t pre_cb,
- gras_datadesc_type_cb_void_t post_cb);
-
-gras_error_t
-gras_datadesc_declare_struct_add_code_cb(long int struct_code,
- const char *field_name,
- long int field_code,
- gras_datadesc_type_cb_void_t pre_cb,
- gras_datadesc_type_cb_void_t post_cb);
-/* union */
-#define gras_datadesc_declare_union( name, code) \
- gras_datadesc_declare_union_cb(name, NULL, NULL, code)
-
-#define gras_datadesc_declare_union_add_name( union_code,field_name,field_type_name) \
- gras_datadesc_declare_union_add_name_cb(union_code,field_name,field_type_name, NULL, NULL)
-
-#define gras_datadesc_declare_union_add_code( union_code,field_name,field_type_code) \
- gras_datadesc_declare_union_add_code_cb(union_code,field_name,field_type_code, NULL, NULL)
-
-gras_error_t
-gras_datadesc_declare_union_cb(const char *name,
- gras_datadesc_type_cb_int_t field_count,
- gras_datadesc_type_cb_void_t post,
- long int *code);
-gras_error_t
-gras_datadesc_declare_union_add_name_cb(long int union_code,
- const char *field_name,
- const char *field_type_name,
- gras_datadesc_type_cb_void_t pre_cb,
- gras_datadesc_type_cb_void_t post_cb);
-gras_error_t
-gras_datadesc_declare_union_add_code_cb(long int union_code,
- const char *field_name,
- long int field_code,
- gras_datadesc_type_cb_void_t pre_cb,
- gras_datadesc_type_cb_void_t post_cb);
-/* ref */
-#define gras_datadesc_declare_ref(name,ref_type, code) \
- gras_datadesc_declare_ref_cb(name, ref_type, NULL, NULL, code)
-#define gras_datadesc_declare_ref_disc(name,discriminant, code) \
- gras_datadesc_declare_ref_cb(name, NULL, discriminant, NULL, code)
-
-gras_error_t
-gras_datadesc_declare_ref_cb(const char *name,
- gras_datadesc_type_t *referenced_type,
- gras_datadesc_type_cb_int_t discriminant,
- gras_datadesc_type_cb_void_t post,
- long int *code);
-/* array */
-#define gras_datadesc_declare_array(name,elm_type, size, code) \
- gras_datadesc_declare_array_cb(name, elm_type, size, NULL, NULL, code)
-#define gras_datadesc_declare_array_dyn(name,elm_type, dynamic_size, code) \
- gras_datadesc_declare_array_cb(name, elm_type, -1, dynamic_size, NULL, code)
-
-gras_error_t
-gras_datadesc_declare_array_cb(const char *name,
- gras_datadesc_type_t *element_type,
- long int fixed_size,
- gras_datadesc_type_cb_int_t dynamic_size,
- gras_datadesc_type_cb_void_t post,
- long int *code);
-
/*******************************
**** About data convertion ****
*******************************/
gras_error_t
gras_datadesc_parse(const char *name,
const char *Cdefinition,
- long int *code);
+ gras_datadesc_type_t **dst);
#define GRAS_DEFINE_TYPE(name,def) \
static const char * _gras_this_type_symbol_does_not_exist__##name=#def; def
-#define gras_type_symbol_parse(bag,name) \
- _gs_type_parse(bag, _gs_this_type_symbol_does_not_exist__##name)
-
-#define gs_type_get_by_symbol(bag,name) \
+/*#define gras_type_symbol_parse(name) \
+ _gras_datadesc_parse(_gras_this_datadesc_type_symbol_does_not_exist__##name)
+*/
+#define gras_datadesc_by_symbol(name) \
(bag->bag_ops->get_type_by_name(bag, NULL, #name) ? \
bag->bag_ops->get_type_by_name(bag, NULL, #name) : \
- gras_type_symbol_parse(bag, name) \
+ gras_datadesc_parse(name) \
)
/*****************************
sizeof(memberType) * repetitions
gras_error_t
-gras_datadesc_from_nws(const char *name,
- const DataDescriptor *desc,
- size_t howmany,
- long int *code);
-
+gras_datadesc_import_nws(const char *name,
+ const DataDescriptor *desc,
+ size_t howmany,
+ gras_datadesc_type_t **dst);
END_DECL
#define TRUE 1
#define FALSE 0
+#define GRAS_MAX_CHANNEL 10 /* FIXME: killme */
+
#include <gras/error.h>
#include <gras/log.h>
#include <gras/virtu.h>
#include <gras/cond.h>
-
#include <gras/transport.h>
#include <gras/datadesc.h>
#include <gras/messages.h>
#define CINFO5(c, f,a1,a2,a3,a4,a5) CLOG5(c, gras_log_priority_info, f,a1,a2,a3,a4,a5)
#define CINFO6(c, f,a1,a2,a3,a4,a5,a6) CLOG6(c, gras_log_priority_info, f,a1,a2,a3,a4,a5,a6)
-#define CWARNING0(c, f) CLOG0(c, gras_log_priority_warning, f)
-#define CWARNING1(c, f,a1) CLOG1(c, gras_log_priority_warning, f,a1)
-#define CWARNING2(c, f,a1,a2) CLOG2(c, gras_log_priority_warning, f,a1,a2)
-#define CWARNING3(c, f,a1,a2,a3) CLOG3(c, gras_log_priority_warning, f,a1,a2,a3)
-#define CWARNING4(c, f,a1,a2,a3,a4) CLOG4(c, gras_log_priority_warning, f,a1,a2,a3,a4)
-#define CWARNING5(c, f,a1,a2,a3,a4,a5) CLOG5(c, gras_log_priority_warning, f,a1,a2,a3,a4,a5)
-#define CWARNING6(c, f,a1,a2,a3,a4,a5,a6) CLOG6(c, gras_log_priority_warning, f,a1,a2,a3,a4,a5,a6)
+#define CWARN0(c, f) CLOG0(c, gras_log_priority_warning, f)
+#define CWARN1(c, f,a1) CLOG1(c, gras_log_priority_warning, f,a1)
+#define CWARN2(c, f,a1,a2) CLOG2(c, gras_log_priority_warning, f,a1,a2)
+#define CWARN3(c, f,a1,a2,a3) CLOG3(c, gras_log_priority_warning, f,a1,a2,a3)
+#define CWARN4(c, f,a1,a2,a3,a4) CLOG4(c, gras_log_priority_warning, f,a1,a2,a3,a4)
+#define CWARN5(c, f,a1,a2,a3,a4,a5) CLOG5(c, gras_log_priority_warning, f,a1,a2,a3,a4,a5)
+#define CWARN6(c, f,a1,a2,a3,a4,a5,a6) CLOG6(c, gras_log_priority_warning, f,a1,a2,a3,a4,a5,a6)
#define CERROR0(c, f) CLOG0(c, gras_log_priority_error, f)
#define CERROR1(c, f,a1) CLOG1(c, gras_log_priority_error, f,a1)
#define INFO6(f,a1,a2,a3,a4,a5,a6) LOG6(gras_log_priority_info, f,a1,a2,a3,a4,a5,a6)
/**
- * WARNING6:
+ * WARN6:
* @f: the format string
* @a1: first argument of the format
* @a2: second argument of the format
*
* Log something to the current default category under the warning priority.
*
- * The macros WARNING0 ... WARNING5 naturally also exist, but are not listed here
+ * The macros WARN0 ... WARN5 naturally also exist, but are not listed here
* for sake of clarity. They just differ in the number of arguments passed
* along with the format string.
*/
-#define WARNING0(f) LOG0(gras_log_priority_warning, f)
-#define WARNING1(f,a1) LOG1(gras_log_priority_warning, f,a1)
-#define WARNING2(f,a1,a2) LOG2(gras_log_priority_warning, f,a1,a2)
-#define WARNING3(f,a1,a2,a3) LOG3(gras_log_priority_warning, f,a1,a2,a3)
-#define WARNING4(f,a1,a2,a3,a4) LOG4(gras_log_priority_warning, f,a1,a2,a3,a4)
-#define WARNING5(f,a1,a2,a3,a4,a5) LOG5(gras_log_priority_warning, f,a1,a2,a3,a4,a5)
-#define WARNING6(f,a1,a2,a3,a4,a5,a6) LOG6(gras_log_priority_warning, f,a1,a2,a3,a4,a5,a6)
+#define WARN0(f) LOG0(gras_log_priority_warning, f)
+#define WARN1(f,a1) LOG1(gras_log_priority_warning, f,a1)
+#define WARN2(f,a1,a2) LOG2(gras_log_priority_warning, f,a1,a2)
+#define WARN3(f,a1,a2,a3) LOG3(gras_log_priority_warning, f,a1,a2,a3)
+#define WARN4(f,a1,a2,a3,a4) LOG4(gras_log_priority_warning, f,a1,a2,a3,a4)
+#define WARN5(f,a1,a2,a3,a4,a5) LOG5(gras_log_priority_warning, f,a1,a2,a3,a4,a5)
+#define WARN6(f,a1,a2,a3,a4,a5,a6) LOG6(gras_log_priority_warning, f,a1,a2,a3,a4,a5,a6)
/**
* ERROR6:
/* $Id$ */
-/* gras/messages.h - Public interface to GRAS messages */
+/* messaging - high level communication (send/receive messages) */
+
+/* module's public interface exported to end user. */
/* Authors: Martin Quinson */
-/* Copyright (C) 2003,2004 Martin Quinson. */
+/* Copyright (C) 2003, 2004 Martin Quinson. */
/* This program is free software; you can redistribute it and/or modify it
under the terms of the license (GNU LGPL) which comes with this package. */
-#ifndef GRAS_MSG_H
-#define GRAS_MSG_H
-
-#include <stddef.h> /* offsetof() */
-#include <sys/types.h> /* size_t */
-#include <stdarg.h>
-
+#ifndef GRAS_MESSAGES_H
+#define GRAS_MESSAGES_H
/*! C++ users need love */
#ifndef BEGIN_DECL
BEGIN_DECL
-typedef unsigned int gras_msgid_t;
-typedef struct gras_msgheader_s gras_msgheader_t;
-typedef struct gras_msgentry_s gras_msgentry_t;
-
-/**
- * A message sent or received to/from the network
- *
- * Do not mess with the content of this structure. Only access it through the following functions:
- * @gras_msg_new() or @gras_msg_copy() to create such struct.
- * @gras_msg_free() to get ride of it.
- * @gras_msg_ctn() to read its content.
- *
- */
-typedef struct {
- /* public */
- gras_socket_t *sock; /** the socket on which the message was received (to answer) */
-
- /* private */
- gras_msgheader_t *header;
- gras_msgentry_t *entry;
- unsigned int *dataCount;
- void **data;
- e_gras_free_directive_t freeDirective;
-} gras_msg_t;
-
-/**
- * gras_msgtype_register:
- * @msgId: identificator of such messages
- * @name: name as it should be used for logging messages
- * @sequence_count: number of groups in variadics
- * @Varargs: List of (const DataDescriptor *, int DDcount), describing the
- * elements in each sequence (DDlength is the length of the corresponding
- * DataDescriptor).
- * @Returns: the error code (or no_error).
- *
- * Registers a message to the GRAS mecanism.
- */
-gras_error_t
-gras_msgtype_register(gras_msgid_t msgId,
- const char *name,
- int sequence_count,
- ...);
-
-/**
- * gras_msg_new_and_send:
- * @sd: Socket on which the message should be sent
- * @msgId: identificator this messages
- * @Varargs: List of (void **data, int seqLen) forming the payload of the message.
- * The number of sequences is given by the registration of ht
- * @Returns: the error code (or no_error).
- *
- * Create a new message, and send it on the network through the given socket.
- */
-gras_error_t
-gras_msg_new_and_send(gras_socket_t *sd,
- gras_msgid_t msgId,
- int seqCount,
- ...);
-
-
-/**
- * gras_msg_new:
- * @msgId: identificator this messages
- * @free_data_on_free: boolean indicating wheater the data must be freed when the msg get freed.
- * @seqCount: number of sequences in this message (must be the same than the value
- * registered using gras_msgtype_register() for that msgId)
- * @Varargs: List of (void **data, int seqLen) forming the payload of the message.
- * The number of sequences is given by the registration of ht
- * @Returns: the message built or NULL on error
- *
- * Build a message to be sent
- */
-
-gras_msg_t *gras_msg_new(gras_msgid_t msgId,
- e_gras_free_directive_t free_data_on_free,
- int seqCount,
- ...);
-
-/**
- * gras_msg_new_va:
- *
- * Build a new message in the exact same way than gras_msg_new(), but taking its arguments as
- * variadic ones.
- */
-gras_msg_t *gras_msg_new_va(gras_msgid_t msgId,
- e_gras_free_directive_t free_data,
- int seqCount,
- va_list ap);
-
-/**
- * gras_msg_copy:
- * @msg: original to copy.
- *
- * Copy a message.
- */
+/* msgtype declaration and retrival */
+typedef struct s_gras_msgtype gras_msgtype_t;
-gras_msg_t *gras_msg_copy(gras_msg_t *msg);
+gras_error_t gras_msgtype_declare (const char *name,
+ gras_datadesc_type_t *payload,
+ gras_msgtype_t **dst);
+gras_error_t gras_msgtype_declare_v(const char *name,
+ short int version,
+ gras_datadesc_type_t *payload,
+ gras_msgtype_t **dst);
-/**
- * gras_msg_free:
- * @msg: poor guy going to diediedie.
- *
- * Free a msg built with gras_msg_new().
- */
-void gras_msg_free(gras_msg_t *msg);
+gras_error_t gras_msgtype_by_name (const char *name,
+ gras_msgtype_t **dst);
+gras_error_t gras_msgtype_by_namev(const char *name,
+ short int version,
+ gras_msgtype_t **dst);
-/**
- * gras_msg_ctn:
- * @msg: the carrier of the data
- * @sequence: Sequence in which you want to see the data.
- * @num: Number in this sequence of the element to access.
- * @type: type of the element to access.
- *
- * Access to the content of a message.
- */
-#define gras_msg_ctn(msg,sequence,num,type) \
- ((type *)msg->data[sequence])[num]
/**
* gras_cb_t:
* @msg: The message itself
- * @Returns: true if the message was accepted by the callback and false if it should be passed to the next one.
+ * @Returns: true if the message was consumed by the callback.
*
* Type of message callback functions. Once a such a function is registered to
* handle messages of a given type with RegisterCallback(), it will be called
*
* If the callback accepts the message, it should free it after use.
*/
-
-typedef int (*gras_cb_t)(gras_msg_t *msg);
-
-/**
- * gras_cb_register:
- * @message: id of the concerned messages
- * @TTL: How many time should this callback be used
- * @cb: The callback.
- * @Returns: the error code (or no_error).
- *
- * Indicates a desire that the function #cb# be called whenever a
- * #message# message comes in.
- * #TTL# is how many time this callback should be used. After that, this
- * callback will be unregistred. If <0, the callback will never be unregistered.
- * (ie, it will be permanent)
- */
-gras_error_t
-gras_cb_register(gras_msgid_t message,
- int TTL,
- gras_cb_t cb);
-
-/**
- * gras_msg_handle:
- * @timeOut: How long to wait for incoming messages
- * @Returns: the error code (or no_error).
- *
- * Waits up to #timeOut# seconds to see if a message comes in; if so, calls the
- * registered listener for that message (see RegisterCallback()).
- */
+typedef int (*gras_cb_t)(gras_socket_t *expeditor,
+ gras_datadesc_type_t *payload_type,
+ void *payload_data);
+gras_error_t gras_cb_register (gras_msgtype_t *msgtype,
+ gras_cb_t cb);
+void gras_cb_unregister(gras_msgtype_t *msgtype,
+ gras_cb_t cb);
+
+gras_error_t gras_msg_send(gras_socket_t *sock,
+ gras_msgtype_t *msgtype,
+ void *payload);
+gras_error_t gras_msg_wait(double timeout,
+ gras_msgtype_t *msgt_want,
+ gras_socket_t **expeditor,
+ void **payload);
gras_error_t gras_msg_handle(double timeOut);
-/**
- * gras_msg_send:
- * @sd: Socket to write on
- * @msg: to send (build it with @gras_msg_new())
- * @freeDirective: if the msg passed as argument should be gras_msg_free'ed after sending.
- * @Returns: the error code (or no_error).
- *
- * Sends the message on the socket sd using an automatic and adaptative timeout.
- */
-
-gras_error_t
-gras_msg_send(gras_socket_t *sd,
- gras_msg_t *msg,
- e_gras_free_directive_t freeDirective);
-
-/**
- * gras_msg_wait:
- * @timeout: How long should we wait for this message.
- * @id: id of awaited msg
- * @message: where to store the message when it comes.
- * @Returns: the error code (or no_error).
- *
- * Waits for a message to come in over a given socket.
- *
- * Every message of another type received before the one waited will be queued
- * and used by subsequent call to this function or MsgHandle().
- */
-gras_error_t
-gras_msg_wait(double timeout,
- gras_msgid_t id,
- gras_msg_t **message);
-
-
END_DECL
#endif /* GRAS_MSG_H */
typedef gras_module_t (*gras_module_new_fct_t)(int argc, char **argv);
typedef int (*gras_module_finalize_fct_t)(void);
-void gras_init(int argc,char **argv);
-void gras_init_defaultlog(int argc,char **argv, const char *defaultlog);
+void gras_init(int *argc,char **argv);
+void gras_init_defaultlog(int *argc,char **argv, const char *defaultlog);
void gras_exit(void);
#endif /* _GRAS_MODULE_H */
* on localhost's stderr.
*/
void
-grasRepportError (gras_socket_t *sock, gras_msgid_t id, int SeqCount,
+grasRepportError (gras_socket_t *sock, int id, int SeqCount,
const char *severeError,
gras_error_t errcode, const char* format,...);
/* OUT */ gras_socket_t **dst);
void gras_socket_close(gras_socket_t **sd);
+/* get information about socket */
+int gras_socket_my_port (gras_socket_t *sock);
+int gras_socket_peer_port(gras_socket_t *sock);
+char *gras_socket_peer_name(gras_socket_t *sock);
/* debuging functions */
gras_error_t gras_socket_client_from_file(const char*path,
+++ /dev/null
-/* $Id$ */
-
-/* gras.c - common parts for the Grid Reality And Simulation */
-
-/* Authors: Martin Quinson */
-/* Copyright (C) 2003 the OURAGAN project. */
-
-/* This program is free software; you can redistribute it and/or modify it
- under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "gras_private.h"
-
-/**************************************************************************/
-/**************************************************************************/
-/* Lock handling */
-/**************************************************************************/
-/**************************************************************************/
-
-#ifdef HAVE_LIBPTHREAD
-#include <pthread.h>
-
-/* this is the lock for this module. Every other module will use a void *
- * as a variable as mutex. */
-pthread_mutex_t gras_thelock = PTHREAD_MUTEX_INITIALIZER;
-#endif
-
-int
-gras_lock() {
- //fprintf(stderr,"Get Lock... ");
-#ifdef HAVE_LIBPTHREAD
- int ret;
-
- ret = pthread_mutex_lock((pthread_mutex_t *)(&gras_thelock));
- if (ret != 0) {
- fprintf(stderr, "gras_lock: Unable to lock (errno = %d)!\n", ret);
- return 0;
- }
-#endif
- //fprintf(stderr,"ok\n");
- return 1;
-}
-
-int
-gras_unlock() {
-
- // fprintf(stderr,"Release Lock... ");
-#ifdef HAVE_LIBPTHREAD
- int ret;
-
- ret = pthread_mutex_unlock((pthread_mutex_t *)&gras_thelock);
- if (ret != 0) {
- fprintf(stderr, "grasReleaseLock: Unable to release lock (errno = %d)!\n", ret);
- return 0;
- }
-#endif
- //fprintf(stderr,"ok\n");
- return 1;
-}
-
-/* **************************************************************************
- * Manipulating Callback list
- * **************************************************************************/
-gras_cblist_t *gras_cb_get(gras_msgid_t id) {
- grasProcessData_t *pd=grasProcessDataGet();
- int i;
-
- for (i=0 ; i<pd->grasCblListLen && pd->grasCblList[i].id != id ; i++);
- return i==pd->grasCblListLen ? NULL : &(pd->grasCblList[i]);
-}
-
-gras_error_t gras_cb_create(gras_msgid_t message) {
- grasProcessData_t *pd=grasProcessDataGet();
-
- if (pd->grasCblListLen++) {
- pd->grasCblList = (gras_cblist_t *)realloc(pd->grasCblList,
- sizeof(gras_cblist_t)*pd->grasCblListLen);
- } else {
- pd->grasCblList = (gras_cblist_t *)malloc(sizeof(gras_cblist_t)*
- pd->grasCblListLen);
- }
- if (!pd->grasCblList) {
- fprintf(stderr,"PANIC: Malloc error (All callbacks for all hosts are lost)\n");
- pd->grasCblListLen=0;
- return malloc_error;
- }
-
- pd->grasCblList[pd->grasCblListLen-1].id=message;
-
- pd->grasCblList[pd->grasCblListLen-1].cbCount=0;
- pd->grasCblList[pd->grasCblListLen-1].cb=NULL;
- pd->grasCblList[pd->grasCblListLen-1].cbTTL=NULL;
-
- return no_error;
-}
-
-/* **************************************************************************
- * Manipulating User Data
- * **************************************************************************/
-void *gras_userdata_get(void) {
- grasProcessData_t *pd=grasProcessDataGet();
-
- return pd ? pd->userdata : NULL;
-}
-
-void *gras_userdata_set(void *ud) {
- grasProcessData_t *pd=grasProcessDataGet();
-
- ASSERT(pd,"ProcessData==NULL => This process did not run grasInit()\n");
- return pd->userdata=ud;
-}
-
+++ /dev/null
-/* $Id$ */
-
-/* gras_datadesc.c - manipulating datadescriptors */
-
-/* Authors: Martin Quinson */
-/* Copyright (C) 2003 the OURAGAN project. */
-
-/* This program is free software; you can redistribute it and/or modify it
- under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "gras_private.h"
-
-void *gras_datadesc_copy_data(const DataDescriptor *dd, unsigned int c,
- void *data) {
- size_t s=DataSize(dd,c,HOST_FORMAT);
- void *res=malloc(s);
-
- if (!res) {
- fprintf(stderr,"grasDataDescCpyData: malloc of %d bytes failed.\n",s);
- return NULL;
- }
-
- memcpy(res,data,s);
-
- return data;
-}
-
-int gras_datadesc_cmp(const DataDescriptor *dd1, unsigned int c1,
- const DataDescriptor *dd2, unsigned int c2) {
- unsigned int i;
- int subcmp;
-
- if (c1 != c2)
- return c1 < c2;
-
- if (!dd1 && !dd2) return 0;
- if (!dd1 || !dd2) return 1;
-
- for (i=0;i<c1;i++) {
- if (dd1[i].type != dd2[i].type)
- return dd1[i].type < dd2[i].type;
- if (dd1[i].repetitions != dd2[i].repetitions)
- return dd1[i].repetitions < dd2[i].repetitions;
- if (dd1[i].type == STRUCT_TYPE) {
- subcmp = gras_datadesc_cmp(dd1[i].members, dd1[i].length,
- dd2[i].members, dd2[i].length);
- if (subcmp)
- return subcmp;
- }
- }
-
- return 0;
-}
-
-void gras_datadesc_dump(const DataDescriptor *dd, unsigned int c) {
- unsigned int i;
-
- if (!dd) return;
-
- for (i=0;i<c;i++) {
- fprintf(stderr,"DD[%d] = {%s,repetitions=%d,offset=%d,members=%p,len=%d,pad=%d}\n",
- (int)i,
- (dd[i].type == CHAR_TYPE ? "char" :
- (dd[i].type == DOUBLE_TYPE ? "double" :
- (dd[i].type == FLOAT_TYPE ? "float" :
- (dd[i].type == INT_TYPE ? "int" :
- (dd[i].type == LONG_TYPE ? "long" :
- (dd[i].type == SHORT_TYPE ? "short" :
- (dd[i].type == UNSIGNED_INT_TYPE ? "uint" :
- (dd[i].type == UNSIGNED_LONG_TYPE ? "ulong" :
- (dd[i].type == UNSIGNED_SHORT_TYPE ? "ushort":
- (dd[i].type == STRUCT_TYPE ? "struct" : "UNKNOWN")))))))))),
- dd[i].repetitions, dd[i].offset,
- dd[i].members, dd[i].length,
- dd[i].tailPadding);
- if (dd[i].type == STRUCT_TYPE) {
- gras_datadesc_dump(dd[i].members, dd[i].length);
- }
- }
-}
-
-
/* only initialize once */
if (gras_datadesc_set_local != NULL)
return;
-
+
VERB0("Initializing DataDesc");
-
+
TRYFAIL(gras_set_new(&gras_datadesc_set_local));
-
- TRYFAIL(gras_ddt_new_scalar("signed char",
- gras_ddt_scalar_char,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_ddt_new_scalar("char",
- gras_ddt_scalar_char,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
-
- TRYFAIL(gras_ddt_new_scalar("unsigned char",
- gras_ddt_scalar_char,
- e_gras_dd_scalar_encoding_uint,
- NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
-
-
- TRYFAIL(gras_ddt_new_scalar("signed short int",
- gras_ddt_scalar_short,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
- TRYFAIL(gras_ddt_new_scalar("short int",
- gras_ddt_scalar_short,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
- TRYFAIL(gras_ddt_new_scalar("unsigned short int",
- gras_ddt_scalar_short,
- e_gras_dd_scalar_encoding_uint,
- NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
-
-
- TRYFAIL(gras_ddt_new_scalar("signed int",
- gras_ddt_scalar_int,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
- TRYFAIL(gras_ddt_new_scalar("int",
- gras_ddt_scalar_int,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
- TRYFAIL(gras_ddt_new_scalar("unsigned int",
- gras_ddt_scalar_int,
- e_gras_dd_scalar_encoding_uint,
- NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
-
-
- TRYFAIL(gras_ddt_new_scalar("signed long int",
- gras_ddt_scalar_long,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
- TRYFAIL(gras_ddt_new_scalar("long int",
- gras_ddt_scalar_long,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
- TRYFAIL(gras_ddt_new_scalar("unsigned long int",
- gras_ddt_scalar_long,
- e_gras_dd_scalar_encoding_uint,
- NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
-
-
- TRYFAIL(gras_ddt_new_scalar("signed long long int",
- gras_ddt_scalar_long_long,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
- TRYFAIL(gras_ddt_new_scalar("long long int",
- gras_ddt_scalar_long_long,
- e_gras_dd_scalar_encoding_sint,
- NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
- TRYFAIL(gras_ddt_new_scalar("unsigned long long int",
- gras_ddt_scalar_long_long,
- e_gras_dd_scalar_encoding_uint,
- NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
-
-
- TRYFAIL(gras_ddt_new_scalar("data pointer",
- gras_ddt_scalar_pdata,
- e_gras_dd_scalar_encoding_uint,
- NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
- TRYFAIL(gras_ddt_new_scalar("function pointer",
- gras_ddt_scalar_pfunc,
- e_gras_dd_scalar_encoding_uint,
- NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
-
-
- TRYFAIL(gras_ddt_new_scalar("float",
- gras_ddt_scalar_float,
- e_gras_dd_scalar_encoding_float,
- NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
-
- TRYFAIL(gras_ddt_new_scalar("double",
- gras_ddt_scalar_float,
- e_gras_dd_scalar_encoding_float,
- NULL,&ddt));
- TRYFAIL(gras_ddt_register(ddt));
+
+ TRYFAIL(gras_datadesc_declare_scalar("signed char",
+ gras_ddt_scalar_char,
+ e_gras_dd_scalar_encoding_sint,
+ NULL, &ddt));
+ TRYFAIL(gras_datadesc_declare_scalar("char",
+ gras_ddt_scalar_char,
+ e_gras_dd_scalar_encoding_sint,
+ NULL, &ddt));
+ TRYFAIL(gras_datadesc_declare_scalar("unsigned char",
+ gras_ddt_scalar_char,
+ e_gras_dd_scalar_encoding_uint,
+ NULL, &ddt));
+
+ TRYFAIL(gras_datadesc_declare_scalar("signed short int",
+ gras_ddt_scalar_short,
+ e_gras_dd_scalar_encoding_sint,
+ NULL, &ddt));
+ TRYFAIL(gras_datadesc_declare_scalar("short int",
+ gras_ddt_scalar_short,
+ e_gras_dd_scalar_encoding_sint,
+ NULL, &ddt));
+ TRYFAIL(gras_datadesc_declare_scalar("unsigned short int",
+ gras_ddt_scalar_short,
+ e_gras_dd_scalar_encoding_uint,
+ NULL, &ddt));
+
+ TRYFAIL(gras_datadesc_declare_scalar("signed int",
+ gras_ddt_scalar_int,
+ e_gras_dd_scalar_encoding_sint,
+ NULL, &ddt));
+ TRYFAIL(gras_datadesc_declare_scalar("int",
+ gras_ddt_scalar_int,
+ e_gras_dd_scalar_encoding_sint,
+ NULL, &ddt));
+ TRYFAIL(gras_datadesc_declare_scalar("unsigned int",
+ gras_ddt_scalar_int,
+ e_gras_dd_scalar_encoding_uint,
+ NULL, &ddt));
+
+ TRYFAIL(gras_datadesc_declare_scalar("signed long int",
+ gras_ddt_scalar_long,
+ e_gras_dd_scalar_encoding_sint,
+ NULL, &ddt));
+ TRYFAIL(gras_datadesc_declare_scalar("long int",
+ gras_ddt_scalar_long,
+ e_gras_dd_scalar_encoding_sint,
+ NULL, &ddt));
+ TRYFAIL(gras_datadesc_declare_scalar("unsigned long int",
+ gras_ddt_scalar_long,
+ e_gras_dd_scalar_encoding_uint,
+ NULL, &ddt));
+
+ TRYFAIL(gras_datadesc_declare_scalar("signed long long int",
+ gras_ddt_scalar_long_long,
+ e_gras_dd_scalar_encoding_sint,
+ NULL, &ddt));
+ TRYFAIL(gras_datadesc_declare_scalar("long long int",
+ gras_ddt_scalar_long_long,
+ e_gras_dd_scalar_encoding_sint,
+ NULL, &ddt));
+ TRYFAIL(gras_datadesc_declare_scalar("unsigned long long int",
+ gras_ddt_scalar_long_long,
+ e_gras_dd_scalar_encoding_uint,
+ NULL, &ddt));
+
+ TRYFAIL(gras_datadesc_declare_scalar("data pointer",
+ gras_ddt_scalar_pdata,
+ e_gras_dd_scalar_encoding_uint,
+ NULL, &ddt));
+ TRYFAIL(gras_datadesc_declare_scalar("function pointer",
+ gras_ddt_scalar_pfunc,
+ e_gras_dd_scalar_encoding_uint,
+ NULL, &ddt));
+
+ TRYFAIL(gras_datadesc_declare_scalar("float",
+ gras_ddt_scalar_float,
+ e_gras_dd_scalar_encoding_float,
+ NULL, &ddt));
+ TRYFAIL(gras_datadesc_declare_scalar("double",
+ gras_ddt_scalar_float,
+ e_gras_dd_scalar_encoding_float,
+ NULL,&ddt));
TRYFAIL(gras_datadesc_by_name("char",&elm));
- TRYFAIL(gras_ddt_new_array("char array", elm, -1, _strlen_cb, NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
+ TRYFAIL(gras_datadesc_declare_array_dyn("string", elm, _strlen_cb,&ddt));
- elm=ddt;
- TRYFAIL(gras_ddt_new_ref("string", elm, NULL, NULL, &ddt));
- TRYFAIL(gras_ddt_register(ddt));
+ // elm=ddt;
+ // TRYFAIL(gras_datadesc_declare_ref("string", elm, &ddt));
}
/**
void gras_datadesc_init(void);
void gras_datadesc_exit(void);
-/* - main functions - */
+gras_error_t gras_datadesc_by_id (long int code,
+ gras_datadesc_type_t **type);
/* compare two data type description */
int
gras_datadesc_type_cmp(const gras_datadesc_type_t *d1,
const gras_datadesc_type_t *d2);
-/* Copy a described data in memory */
+/* Described data exchanges */
gras_error_t
gras_datadesc_cpy(gras_datadesc_type_t *type, void *src, void **dst);
-
-/* Send stuff */
gras_error_t
gras_datadesc_send(gras_socket_t *sock, gras_datadesc_type_t *type, void *src);
-
-/* Receive (and convert) stuff */
gras_error_t
gras_datadesc_recv(gras_socket_t *sock, gras_datadesc_type_t *type,
int r_arch, void **dst);
-/* -- */
-
-/* free a given ddt */
-void gras_ddt_free(gras_datadesc_type_t **type);
-
-/* declare in the given set, and retrieve afterward */
-gras_error_t gras_ddt_register(gras_datadesc_type_t *type);
-gras_error_t gras_ddt_get_by_name(const char *name,
- gras_datadesc_type_t **type);
-gras_error_t gras_ddt_get_by_code(int code,
- gras_datadesc_type_t **type);
-
-
#endif /* GRAS_DATADESC_INTERFACE_H */
* Type creation functions *
***************************/
gras_error_t
-gras_ddt_new_scalar(const char *name,
- gras_ddt_scalar_type_t type,
- enum e_gras_dd_scalar_encoding encoding,
- gras_datadesc_type_cb_void_t cb,
- gras_datadesc_type_t **dst);
-gras_error_t
-gras_ddt_new_struct(const char *name,
- gras_datadesc_type_cb_void_t pre,
- gras_datadesc_type_cb_void_t post,
- gras_datadesc_type_t **dst);
-gras_error_t
-gras_ddt_new_struct_append(gras_datadesc_type_t *struct_type,
- const char *name,
- gras_datadesc_type_t *field_type,
- gras_datadesc_type_cb_void_t pre,
- gras_datadesc_type_cb_void_t post);
-gras_error_t
-gras_ddt_new_union(const char *name,
- gras_datadesc_type_cb_int_t field_count,
- gras_datadesc_type_cb_void_t post,
- gras_datadesc_type_t **dst);
-gras_error_t
-gras_ddt_new_union_append(gras_datadesc_type_t *union_type,
- const char *name,
- gras_datadesc_type_t *field_type,
- gras_datadesc_type_cb_void_t pre,
- gras_datadesc_type_cb_void_t post);
-gras_error_t
-gras_ddt_new_ref(const char *name,
- gras_datadesc_type_t *referenced_type,
- gras_datadesc_type_cb_int_t discriminant,
- gras_datadesc_type_cb_void_t post,
- gras_datadesc_type_t **dst);
-gras_error_t
-gras_ddt_new_array(const char *name,
- gras_datadesc_type_t *element_type,
- long int fixed_size,
- gras_datadesc_type_cb_int_t dynamic_size,
- gras_datadesc_type_cb_void_t post,
- gras_datadesc_type_t **dst);
-gras_error_t
-gras_ddt_new_ignored(const char *name,
- void *default_value,
- void_f_pvoid_t *free_func,
- long int size,
- long int alignment,
- gras_datadesc_type_cb_void_t post,
- gras_datadesc_type_t **dst);
-
-
-gras_error_t
-gras_ddt_new_parse(const char *name,
- const char *C_definition,
- gras_datadesc_type_t **dst);
-gras_error_t
-gras_ddt_new_from_nws(const char *name,
- const DataDescriptor *desc,
- size_t howmany,
- gras_datadesc_type_t **dst);
+gras_datadesc_declare_scalar(const char *name,
+ gras_ddt_scalar_type_t type,
+ enum e_gras_dd_scalar_encoding encoding,
+ gras_datadesc_type_cb_void_t cb,
+ gras_datadesc_type_t **dst);
+
+/* Do not use it on a registered type ! */
+void gras_ddt_free(gras_datadesc_type_t **type);
/****************************************************
* Callback persistant state constructor/destructor *
{"i386", 0, {1,2,4,4,8, 4,4, 4,8}}
};
-/**
- * gras_free_ddt:
- *
- * gime that memory back, dude. I mean it.
- */
-static void gras_free_ddt(void *ddt) {
- gras_datadesc_type_t *type= (gras_datadesc_type_t *)ddt;
-
- if (type) {
- gras_ddt_free(&type);
- }
-}
-
-/**
- * gras_ddt_register:
- *
- * Add a type to a type set
- */
-gras_error_t gras_ddt_register(gras_datadesc_type_t *type) {
- return gras_set_add(gras_datadesc_set_local,
- (gras_set_elm_t*)type,
- &gras_free_ddt);
-
-}
-
-/**
- * gras_datadesc_by_name:
- *
- * Retrieve a type from its name
- */
-gras_error_t gras_datadesc_by_name(const char *name,
- gras_datadesc_type_t **type) {
- return gras_set_get_by_name(gras_datadesc_set_local,
- name,(gras_set_elm_t**)type);
-}
-
-/**
- * gras_datadesc_by_id:
- *
- * Retrieve a type from its code
- */
-gras_error_t gras_datadesc_by_id(long int code,
- gras_datadesc_type_t **type) {
- return gras_set_get_by_id(gras_datadesc_set_local,
- code,(gras_set_elm_t**)type);
-}
/**
* gras_dd_convert_elm:
GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(new,DataDesc);
+/**
+ * gras_ddt_freev:
+ *
+ * gime that memory back, dude. I mean it.
+ */
+static void gras_ddt_freev(void *ddt) {
+ gras_datadesc_type_t *type= (gras_datadesc_type_t *)ddt;
+
+ if (type) {
+ gras_ddt_free(&type);
+ }
+}
+
static gras_error_t
gras_ddt_new(const char *name,
gras_datadesc_type_t **dst) {
+ gras_error_t errcode;
gras_datadesc_type_t *res=malloc(sizeof(gras_datadesc_type_t));
if (!res)
RAISE_MALLOC;
- memset(res, 0, sizeof(res));
+ memset(res, 0, sizeof(gras_datadesc_type_t));
res->name = strdup(name);
res->name_len = strlen(name);
- res->pre = NULL;
- res->post = NULL;
+ TRY(gras_set_add(gras_datadesc_set_local,
+ (gras_set_elm_t*)res,&gras_ddt_freev));
+
*dst=res;
return no_error;
}
/**
- * gras_ddt_new_scalar:
+ * gras_datadesc_by_name:
+ *
+ * Retrieve a type from its name
+ */
+gras_error_t gras_datadesc_by_name(const char *name,
+ gras_datadesc_type_t **type) {
+ return gras_set_get_by_name(gras_datadesc_set_local,
+ name,(gras_set_elm_t**)type);
+}
+
+/**
+ * gras_datadesc_by_id:
+ *
+ * Retrieve a type from its code
+ */
+gras_error_t gras_datadesc_by_id(long int code,
+ gras_datadesc_type_t **type) {
+ return gras_set_get_by_id(gras_datadesc_set_local,
+ code,(gras_set_elm_t**)type);
+}
+
+/**
+ * gras_datadesc_declare_scalar:
*
* Create a new scalar and give a pointer to it
*/
gras_error_t
-gras_ddt_new_scalar(const char *name,
- gras_ddt_scalar_type_t type,
- enum e_gras_dd_scalar_encoding encoding,
- gras_datadesc_type_cb_void_t cb,
- gras_datadesc_type_t **dst) {
+gras_datadesc_declare_scalar(const char *name,
+ gras_ddt_scalar_type_t type,
+ enum e_gras_dd_scalar_encoding encoding,
+ gras_datadesc_type_cb_void_t cb,
+ gras_datadesc_type_t **dst) {
gras_error_t errcode;
gras_datadesc_type_t *res;
}
/**
- * gras_ddt_new_struct:
+ * gras_datadesc_declare_struct:
*
* Create a new struct and give a pointer to it
*/
gras_error_t
-gras_ddt_new_struct(const char *name,
- gras_datadesc_type_cb_void_t pre,
- gras_datadesc_type_cb_void_t post,
- gras_datadesc_type_t **dst) {
+gras_datadesc_declare_struct(const char *name,
+ gras_datadesc_type_t **dst) {
gras_error_t errcode;
gras_datadesc_type_t *res;
TRY(gras_dynar_new(&(res->category.struct_data.fields),
sizeof(gras_dd_cat_field_t*),
&gras_dd_cat_field_free));
- res->pre = pre;
- res->post = post;
return no_error;
}
+gras_error_t
+gras_datadesc_declare_struct_append_name(gras_datadesc_type_t *struct_type,
+ const char *name,
+ const char *field_type_name){
+ gras_error_t errcode;
+ gras_datadesc_type_t *field_type;
+
+ errcode = gras_datadesc_by_name(field_type_name, &field_type);
+ if (errcode != no_error) {
+ WARN2("Got error '%s' while looking for '%s'",
+ gras_error_name(errcode), field_type_name);
+ return errcode;
+ }
+ return gras_datadesc_declare_struct_append(struct_type,name,field_type);
+}
/**
- * gras_ddt_new_struct_append:
+ * gras_datadesc_declare_struct_append:
*
* Append a field to the struct
*/
gras_error_t
-gras_ddt_new_struct_append(gras_datadesc_type_t *struct_type,
- const char *name,
- gras_datadesc_type_t *field_type,
- gras_datadesc_type_cb_void_t pre,
- gras_datadesc_type_cb_void_t post) {
+gras_datadesc_declare_struct_append(gras_datadesc_type_t *struct_type,
+ const char *name,
+ gras_datadesc_type_t *field_type) {
gras_error_t errcode;
gras_dd_cat_field_t *field;
field->offset[arch] = aligned(struct_type->size[arch], field_type->alignment[arch]);
}
field->code = field_type->code;
- field->pre = pre;
- field->post = post;
+ field->pre = NULL;
+ field->post = NULL;
TRY(gras_dynar_push(struct_type->category.struct_data.fields, &field));
}
/**
- * gras_ddt_new_union:
+ * gras_datadesc_declare_union:
*
* Create a new union and give a pointer to it
*/
gras_error_t
-gras_ddt_new_union(const char *name,
+gras_datadesc_declare_union(const char *name,
gras_datadesc_type_cb_int_t selector,
- gras_datadesc_type_cb_void_t post,
gras_datadesc_type_t **dst) {
gras_error_t errcode;
sizeof(gras_dd_cat_field_t*),
&gras_dd_cat_field_free));
res->category.union_data.selector = selector;
- res->pre = NULL;
- res->post = post;
return no_error;
}
/**
- * gras_ddt_new_union_append:
+ * gras_datadesc_declare_union_append:
*
* Append a field to the union
*/
gras_error_t
-gras_ddt_new_union_append(gras_datadesc_type_t *union_type,
+gras_datadesc_declare_union_append(gras_datadesc_type_t *union_type,
const char *name,
- gras_datadesc_type_t *field_type,
- gras_datadesc_type_cb_void_t pre,
- gras_datadesc_type_cb_void_t post) {
+ gras_datadesc_type_t *field_type) {
gras_error_t errcode;
gras_dd_cat_field_t *field;
field->offset[arch] = 0; /* that's the purpose of union ;) */
}
field->code = field_type->code;
- field->pre = pre;
- field->post = post;
+ field->pre = NULL;
+ field->post = NULL;
TRY(gras_dynar_push(union_type->category.union_data.fields, &field));
}
/**
- * gras_ddt_new_ref:
+ * gras_datadesc_declare_ref:
*
- * Create a new ref and give a pointer to it
+ * Create a new ref to a fixed type and give a pointer to it
*/
gras_error_t
-gras_ddt_new_ref(const char *name,
- gras_datadesc_type_t *referenced_type,
- gras_datadesc_type_cb_int_t selector,
- gras_datadesc_type_cb_void_t post,
- gras_datadesc_type_t **dst) {
+gras_datadesc_declare_ref(const char *name,
+ gras_datadesc_type_t *referenced_type,
+ gras_datadesc_type_t **dst) {
gras_error_t errcode;
gras_datadesc_type_t *res;
gras_datadesc_type_t *pointer_type;
int arch;
- gras_assert0(selector || referenced_type,
- "Attempt to create a generic reference without selector");
+ TRY(gras_ddt_new(name,dst));
+ res=*dst;
+
+ TRY(gras_datadesc_by_name("data pointer", &pointer_type));
+
+ for (arch=0; arch<gras_arch_count; arch ++) {
+ res->size[arch] = pointer_type->size[arch];
+ res->alignment[arch] = pointer_type->alignment[arch];
+ res->aligned_size[arch] = pointer_type->aligned_size[arch];
+ }
+
+ res->category_code = e_gras_datadesc_type_cat_ref;
+
+ res->category.ref_data.code = referenced_type->code;
+ res->category.ref_data.selector = NULL;
+
+ return no_error;
+}
+/**
+ * gras_datadesc_declare_ref_generic:
+ *
+ * Create a new ref to a type given at use time, and give a pointer to it
+ */
+gras_error_t
+gras_datadesc_declare_ref_generic(const char *name,
+ gras_datadesc_type_cb_int_t selector,
+ gras_datadesc_type_t **dst) {
+
+ gras_error_t errcode;
+ gras_datadesc_type_t *res;
+ gras_datadesc_type_t *pointer_type;
+ int arch;
TRY(gras_ddt_new(name,dst));
res=*dst;
res->category_code = e_gras_datadesc_type_cat_ref;
- res->category.ref_data.code = referenced_type ? referenced_type->code : -1;
+ res->category.ref_data.code = -1;
res->category.ref_data.selector = selector;
- res->pre = NULL;
- res->post = post;
return no_error;
}
/**
- * gras_ddt_new_array:
+ * gras_datadesc_declare_array_fixed:
*
* Create a new array and give a pointer to it
*/
gras_error_t
-gras_ddt_new_array(const char *name,
- gras_datadesc_type_t *element_type,
- long int fixed_size,
- gras_datadesc_type_cb_int_t dynamic_size,
- gras_datadesc_type_cb_void_t post,
- gras_datadesc_type_t **dst) {
+gras_datadesc_declare_array_fixed(const char *name,
+ gras_datadesc_type_t *element_type,
+ long int fixed_size,
+ gras_datadesc_type_t **dst) {
gras_error_t errcode;
gras_datadesc_type_t *res;
int arch;
- gras_assert0(dynamic_size || fixed_size>0,
- "Attempt to create a dynamic array without size discriminant");
-
TRY(gras_ddt_new(name,dst));
res=*dst;
+ gras_assert1(fixed_size > 0, "'%s' is a array of negative fixed size",name);
for (arch=0; arch<gras_arch_count; arch ++) {
- if (fixed_size <= 0) {
- res->size[arch] = fixed_size; /* make sure it indicates "dynamic" */
- } else {
- res->size[arch] = fixed_size * element_type->aligned_size[arch];
- }
+ res->size[arch] = fixed_size * element_type->aligned_size[arch];
res->alignment[arch] = element_type->alignment[arch];
res->aligned_size[arch] = fixed_size; /*FIXME: That was so in GS, but looks stupid*/
}
res->category.array_data.code = element_type->code;
res->category.array_data.fixed_size = fixed_size;
- res->category.array_data.dynamic_size = dynamic_size;
-
- res->pre = NULL;
- res->post = post;
+ res->category.array_data.dynamic_size = NULL;
return no_error;
}
-
/**
- * gras_ddt_new_ignored:
- *
- * Create a new ignored field and give a pointer to it.
+ * gras_datadesc_declare_array_dyn:
*
- * If you give a default value, it will be copied away so that you can free your copy.
+ * Create a new array and give a pointer to it
*/
gras_error_t
-gras_ddt_new_ignored(const char *name,
- void *default_value,
- void_f_pvoid_t *free_func,
- long int size,
- long int alignment,
- gras_datadesc_type_cb_void_t post,
- gras_datadesc_type_t **dst) {
- RAISE_UNIMPLEMENTED;
- /*
+gras_datadesc_declare_array_dyn(const char *name,
+ gras_datadesc_type_t *element_type,
+ gras_datadesc_type_cb_int_t dynamic_size,
+ gras_datadesc_type_t **dst) {
+
gras_error_t errcode;
gras_datadesc_type_t *res;
+ int arch;
+
+ gras_assert1(dynamic_size,
+ "'%s' is a dynamic array without size discriminant",
+ name);
TRY(gras_ddt_new(name,dst));
res=*dst;
- res->size = size > 0?size:0;
- res->alignment = alignment;
-
- if (size > 0) {
- res->aligned_size = aligned(size, alignment);
- } else {
- res->aligned_size = 0;
- }
-
- if (default_value && res->size) {
- res->category.ignored_data.default_value = malloc((size_t)size);
- if (! (res->category.ignored_data.default_value) )
- RAISE_MALLOC;
- memcpy(res->category.ignored_data.default_value,
- default_value, (size_t)size);
+ for (arch=0; arch<gras_arch_count; arch ++) {
+ res->size[arch] = -1; /* make sure it indicates "dynamic" */
+ res->alignment[arch] = element_type->alignment[arch];
+ res->aligned_size[arch] = -1; /*FIXME: That was so in GS, but looks stupid*/
}
+ res->category_code = e_gras_datadesc_type_cat_array;
- res->category_code = e_gras_datadesc_type_cat_ignored;
- res->category.ignored_data.free_func = free_func;
-
- res->post = post;
-
-
- res->size = size;
+ res->category.array_data.code = element_type->code;
+ res->category.array_data.fixed_size = -1;
+ res->category.array_data.dynamic_size = dynamic_size;
return no_error;
- */
}
/**
- * gras_ddt_new_parse:
+ * gras_datadesc_declare_parse:
*
* Create a datadescription from the result of parsing the C type description
*/
gras_error_t
-gras_ddt_new_parse(const char *name,
- const char *C_statement,
- gras_datadesc_type_t **dst) {
+gras_datadesc_parse(const char *name,
+ const char *C_statement,
+ gras_datadesc_type_t **dst) {
RAISE_UNIMPLEMENTED;
}
gras_error_t
-gras_ddt_new_from_nws(const char *name,
- const DataDescriptor *desc,
- size_t howmany,
- gras_datadesc_type_t **dst) {
+gras_datadesc_import_nws(const char *name,
+ const DataDescriptor *desc,
+ size_t howmany,
+ gras_datadesc_type_t **dst) {
RAISE_UNIMPLEMENTED;
}
}
}
}
+
+/**
+ * gras_datadesc_cb_set_pre:
+ *
+ * Add a pre-send callback to this datadexc
+ */
+void gras_datadesc_cb_set_pre (gras_datadesc_type_t *type,
+ gras_datadesc_type_cb_void_t pre) {
+ type->pre = pre;
+}
+/**
+ * gras_datadesc_cb_set_post:
+ *
+ * Add a post-send callback to this datadexc
+ */
+void gras_datadesc_cb_set_post(gras_datadesc_type_t *type,
+ gras_datadesc_type_cb_void_t post) {
+ type->post = post;
+}
+++ /dev/null
-/* $Id$ */
-
-/* ddt_declare - user functions to create datatypes on locale machine */
-
-/* Authors: Olivier Aumage, Martin Quinson */
-/* Copyright (C) 2003, 2004 the GRAS posse. */
-
-/* This program is free software; you can redistribute it and/or modify it
- under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "DataDesc/datadesc_private.h"
-
-gras_error_t
-gras_datadesc_declare_struct_cb(const char *name,
- gras_datadesc_type_cb_void_t pre,
- gras_datadesc_type_cb_void_t post,
- long int *code) {
- gras_error_t errcode;
- gras_datadesc_type_t *type;
- TRY(gras_ddt_new_struct(name, pre, post, &type));
- TRY(gras_ddt_register(type));
- *code = type->code;
- return no_error;
-}
-
-gras_error_t
-gras_datadesc_declare_struct_add_name_cb(long int struct_code,
- const char *field_name,
- const char *field_type_name,
- gras_datadesc_type_cb_void_t pre_cb,
- gras_datadesc_type_cb_void_t post_cb) {
-
- gras_error_t errcode;
- gras_datadesc_type_t *struct_type;
- gras_datadesc_type_t *field_type;
-
- TRY(gras_datadesc_by_id(struct_code,&struct_type));
- TRY(gras_datadesc_by_name(field_type_name,&field_type));
-
- TRY(gras_ddt_new_struct_append(struct_type,
- field_name, field_type,
- pre_cb, post_cb));
-
- return no_error;
-}
-gras_error_t
-gras_datadesc_declare_struct_add_code_cb(long int struct_code,
- const char *field_name,
- long int field_code,
- gras_datadesc_type_cb_void_t pre_cb,
- gras_datadesc_type_cb_void_t post_cb) {
- gras_error_t errcode;
- gras_datadesc_type_t *struct_type;
- gras_datadesc_type_t *field_type;
-
- TRY(gras_datadesc_by_id(struct_code,&struct_type));
- TRY(gras_datadesc_by_id(field_code, &field_type));
-
- TRY(gras_ddt_new_struct_append(struct_type,
- field_name, field_type,
- pre_cb, post_cb));
-
- return no_error;
-}
-
-gras_error_t
-gras_datadesc_declare_union_cb(const char *name,
- gras_datadesc_type_cb_int_t field_count,
- gras_datadesc_type_cb_void_t post,
- long int *code) {
- gras_error_t errcode;
- gras_datadesc_type_t *type;
- TRY(gras_ddt_new_union(name, field_count, post, &type));
- TRY(gras_ddt_register(type));
- *code = type->code;
- return no_error;
-}
-
-gras_error_t
-gras_datadesc_declare_union_add_name_cb(long int union_code,
- const char *field_name,
- const char *field_type_name,
- gras_datadesc_type_cb_void_t pre_cb,
- gras_datadesc_type_cb_void_t post_cb) {
- gras_error_t errcode;
- gras_datadesc_type_t *union_type;
- gras_datadesc_type_t *field_type;
-
- TRY(gras_datadesc_by_id (union_code, &union_type));
- TRY(gras_datadesc_by_name(field_type_name, &field_type));
-
- TRY(gras_ddt_new_union_append(union_type,
- field_name, field_type,
- pre_cb, post_cb));
-
- return no_error;
-}
-gras_error_t
-gras_datadesc_declare_union_add_code_cb(long int union_code,
- const char *field_name,
- long int field_code,
- gras_datadesc_type_cb_void_t pre_cb,
- gras_datadesc_type_cb_void_t post_cb) {
- gras_error_t errcode;
- gras_datadesc_type_t *union_type;
- gras_datadesc_type_t *field_type;
-
- TRY(gras_datadesc_by_id(union_code, &union_type));
- TRY(gras_datadesc_by_id(field_code, &field_type));
-
- TRY(gras_ddt_new_union_append(union_type,
- field_name, field_type,
- pre_cb, post_cb));
-
- return no_error;
-}
-
-gras_error_t
-gras_datadesc_declare_ref_cb(const char *name,
- gras_datadesc_type_t *referenced_type,
- gras_datadesc_type_cb_int_t discriminant,
- gras_datadesc_type_cb_void_t post,
- long int *code){
- gras_error_t errcode;
- gras_datadesc_type_t *type;
- TRY(gras_ddt_new_ref(name, referenced_type,discriminant,post, &type));
- TRY(gras_ddt_register(type));
- *code = type->code;
- return no_error;
-}
-
-gras_error_t
-gras_datadesc_declare_array_cb(const char *name,
- gras_datadesc_type_t *element_type,
- long int fixed_size,
- gras_datadesc_type_cb_int_t dynamic_size,
- gras_datadesc_type_cb_void_t post,
- long int *code){
- gras_error_t errcode;
- gras_datadesc_type_t *type;
- TRY(gras_ddt_new_array(name, element_type, fixed_size, dynamic_size, post, &type));
- TRY(gras_ddt_register(type));
- *code = type->code;
- return no_error;
-}
-
-/**
- * gras_datadesc_parse:
- *
- * Parse a C type declaration, and declare locally the corresponding type description
- */
-gras_error_t
-gras_datadesc_parse(const char *name,
- const char *definition,
- long int *code) {
- gras_error_t errcode;
- gras_datadesc_type_t *type;
- TRY(gras_ddt_new_parse(name,definition,&type));
- TRY(gras_ddt_register( type));
- *code = type->code;
- return no_error;
-}
-
-/**
- * gras_datadesc_parse:
- *
- * Parse a NWS type declaration, and declare locally the corresponding type description
- */
-gras_error_t
-gras_datadesc_from_nws(const char *name,
- const DataDescriptor *desc,
- size_t howmany,
- long int *code) {
-
- gras_error_t errcode;
- gras_datadesc_type_t *type;
- TRY(gras_ddt_new_from_nws(name,desc,howmany,&type));
- TRY(gras_ddt_register(type));
- *code = type->code;
- return no_error;
-}
/* $Id$ */
-/* ddt_use - use of datatypes structs (public) */
+/* ddt_exchange - send/recv data described */
/* Authors: Olivier Aumage, Martin Quinson */
/* Copyright (C) 2003, 2004 the GRAS posse. */
#include "DataDesc/datadesc_private.h"
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(use,DataDesc);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(exchange,DataDesc);
static const char *gras_datadesc_cat_names[9] = {
"undefined",
return no_error;
}
-/**
- * gras_datadesc_get_id_from_name:
- * Returns: -1 in case of error.
- *
- * Retrieve the ID of a previously declared datatype from its name.
- */
-long int
-gras_datadesc_get_id_from_name(const char *name) {
- gras_error_t errcode;
- gras_datadesc_type_t *type;
-
- errcode = gras_datadesc_by_name(name,&type);
- if (errcode != no_error)
- return -1;
- return type->code;
-}
-
/**
* gras_datadesc_type_cmp:
*
TRY(gras_dict_new(&refs));
TRY(gras_dd_cbps_new(&state));
+ if (!dst)
+ CRITICAL0("Cannot receive data into a NULL pointer!");
if (*dst)
VERB0("'*dst' not NULL in datadesc_recv. Data to be copied there without malloc");
# Core/dict_multi.c
# Common/gras.c Common/gras_datadesc.c Common/gras_msg.c
-# Messaging/messaging.c
# Messaging/datadesc_simple.c
# Transport/transport_sg.c
Transport/transport_plugin_tcp.c \
Transport/transport_plugin_sg.c \
\
- DataDesc/ddt_create.c DataDesc/ddt_declare.c \
- DataDesc/ddt_remote.c DataDesc/ddt_use.c \
- DataDesc/cbps.c DataDesc/datadesc.c \
- DataDesc/datadesc_interface.h DataDesc/datadesc_private.h
+ DataDesc/ddt_create.c \
+ DataDesc/ddt_convert.c DataDesc/ddt_exchange.c \
+ DataDesc/cbps.c DataDesc/datadesc.c \
+ DataDesc/datadesc_interface.h DataDesc/datadesc_private.h \
+ \
+ Msg/msg.c Msg/msg_interface.h Msg/msg_private.h \
+ \
+ Virtu/process.c
+# DataDesc/ddt_declare.c
# DataDesc/datadesc.c \
# DataDesc/tools.c \
--- /dev/null
+/* $Id$ */
+
+/* messaging - Function related to messaging (code shared between RL and SG)*/
+
+/* Authors: Martin Quinson */
+/* Copyright (C) 2003 the OURAGAN project. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "Msg/msg_private.h"
+
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(msg,GRAS);
+
+gras_set_t *_gras_msgtype_set = NULL;
+static char GRAS_header[6];
+static char *make_namev(const char *name, short int ver);
+
+/**
+ * gras_msg_init:
+ *
+ * Initialize this submodule.
+ */
+void gras_msg_init(void) {
+ gras_error_t errcode;
+
+ /* only initialize once */
+ if (_gras_msgtype_set != NULL)
+ return;
+
+ VERB0("Initializing Msg");
+
+ TRYFAIL(gras_set_new(&_gras_msgtype_set));
+
+ memcpy(GRAS_header,"GRAS", 4);
+ GRAS_header[4]=GRAS_PROTOCOL_VERSION;
+ GRAS_header[5]=(char)GRAS_THISARCH;
+}
+
+/**
+ * gras_msg_exit:
+ *
+ * Finalize the msg module
+ **/
+void
+gras_msg_exit(void) {
+ VERB0("Exiting Msg");
+ gras_set_free(&_gras_msgtype_set);
+ _gras_msgtype_set = NULL;
+}
+
+/**
+ * gras_msgtype_free:
+ *
+ * Reclamed memory
+ */
+void gras_msgtype_free(void *t) {
+ gras_msgtype_t *msgtype=(gras_msgtype_t *)t;
+ if (msgtype) {
+ free(msgtype->name);
+ free(msgtype);
+ }
+}
+
+/**
+ * make_namev:
+ *
+ * Returns the versionned name of the message. If the version is 0, that's
+ * the name unchanged. Pay attention to this before free'ing the result.
+ */
+static char *make_namev(const char *name, short int ver) {
+ char *namev=malloc(strlen(name)+2+3+1);
+
+ if (!ver)
+ return (char *)name;
+
+ if (namev) {
+ sprintf(namev,"%s_v%d",name,ver);
+ }
+ return namev;
+}
+
+/**
+ * gras_msgtype_declare:
+ * @name: name as it should be used for logging messages (must be uniq)
+ * @payload: datadescription of the payload
+ *
+ * Registers a message to the GRAS mecanism.
+ */
+gras_error_t
+gras_msgtype_declare(const char *name,
+ gras_datadesc_type_t *payload,
+ gras_msgtype_t **dst) {
+ return gras_msgtype_declare_v(name, 0, payload, dst);
+}
+
+/**
+ * gras_msgtype_declare_v:
+ * @name: name as it should be used for logging messages (must be uniq)
+ * @version: something like versionning symbol
+ * @payload: datadescription of the payload
+ *
+ * Registers a message to the GRAS mecanism. Use this version instead of
+ * gras_msgtype_declare when you change the semantic or syntax of a message and
+ * want your programs to be able to deal with both versions. Internally, each
+ * will be handled as an independent message type, so you can register
+ * differents for each of them.
+ */
+gras_error_t
+gras_msgtype_declare_v(const char *name,
+ short int version,
+ gras_datadesc_type_t *payload,
+ gras_msgtype_t **dst) {
+
+ gras_error_t errcode;
+ gras_msgtype_t *msgtype;
+ char *namev=make_namev(name,version);
+
+ if (!namev)
+ RAISE_MALLOC;
+
+ errcode = gras_set_get_by_name(_gras_msgtype_set,
+ namev,(gras_set_elm_t**)msgtype);
+ if (errcode == mismatch_error) {
+ /* create type */
+ if (! (msgtype = malloc(sizeof(gras_msgtype_t))) )
+ RAISE_MALLOC;
+
+ msgtype->name = (namev == name ? strdup(name) : namev);
+ msgtype->name_len = strlen(namev);
+ msgtype->version = version;
+ msgtype->ctn_type = payload;
+
+ TRY(gras_set_add(_gras_msgtype_set, (gras_set_elm_t*)msgtype,
+ &gras_msgtype_free));
+
+ DEBUG2("Register version %d of message '%s'.", version, name);
+ } else if (errcode == no_error) { /* found */
+ if (namev != name)
+ free(namev);
+
+ gras_assert1(!gras_datadesc_type_cmp(msgtype->ctn_type, payload),
+ "Message %s registred again with a different payload",
+ namev);
+ } else {
+ if (namev != name)
+ free(namev);
+ return errcode; /* Error is set lookup */
+ }
+
+ return no_error;
+}
+
+/**
+ * gras_msgtype_by_name:
+ *
+ * Retrieve a datatype description from its name
+ */
+gras_error_t
+gras_msgtype_by_name (const char *name,
+ gras_msgtype_t **dst) {
+ return gras_msgtype_by_namev(name,0,dst);
+}
+/**
+ * gras_msgtype_by_namev:
+ *
+ * Retrieve a datatype description from its name and version
+ */
+gras_error_t
+gras_msgtype_by_namev(const char *name,
+ short int version,
+ gras_msgtype_t **dst) {
+
+ gras_error_t errcode;
+ char *namev = make_namev(name,version);
+
+ TRY(gras_set_get_by_name(_gras_msgtype_set, namev,
+ (gras_set_elm_t**)dst));
+ if (name != namev)
+ free(namev);
+
+ return no_error;
+}
+
+/**
+ * gras_msg_send:
+ *
+ * Send the given message on the given socket
+ */
+gras_error_t
+gras_msg_send(gras_socket_t *sock,
+ gras_msgtype_t *msgtype,
+ void *payload) {
+
+ gras_error_t errcode;
+ static gras_datadesc_type_t *string_type=NULL;
+ if (!string_type)
+ TRY(gras_datadesc_by_name("string", &string_type));
+
+ TRY(gras_trp_chunk_send(sock, GRAS_header, 6));
+
+ TRY(gras_datadesc_send(sock, string_type, msgtype->name));
+ TRY(gras_datadesc_send(sock, msgtype->ctn_type, payload));
+
+ return no_error;
+}
+/**
+ * gras_msg_recv:
+ *
+ * receive the next message on the given socket (which should be dropped
+ * when the function returns an error)
+ */
+gras_error_t
+gras_msg_recv(gras_socket_t *sock,
+ gras_msgtype_t **msgtype,
+ void **payload) {
+
+ gras_error_t errcode;
+ static gras_datadesc_type_t *string_type=NULL;
+ char header[6];
+ int cpt;
+ int r_arch;
+ char *msg_name;
+
+ if (!string_type)
+ TRY(gras_datadesc_by_name("string", &string_type));
+
+ TRY(gras_trp_chunk_recv(sock, header, 6));
+ for (cpt=0; cpt<4; cpt++)
+ if (header[cpt] != GRAS_header[cpt])
+ RAISE0(mismatch_error,"Incoming bytes do not look like a GRAS message");
+ if (header[4] != GRAS_header[4])
+ RAISE2(mismatch_error,"GRAS protocol mismatch (got %d, use %d)",
+ (int)header[4], (int)GRAS_header[4]);
+ r_arch = (int)header[5];
+
+ TRY(gras_datadesc_recv(sock, string_type, r_arch,(void**) &msg_name));
+ TRY(gras_set_get_by_name(_gras_msgtype_set,
+ msg_name,(gras_set_elm_t**)msgtype));
+ TRY(gras_datadesc_recv(sock, (*msgtype)->ctn_type, r_arch, payload));
+
+ return no_error;
+}
+
+/**
+ * gras_msg_wait:
+ * @timeout: How long should we wait for this message.
+ * @id: id of awaited msg
+ * @Returns: the error code (or no_error).
+ *
+ * Waits for a message to come in over a given socket.
+ *
+ * Every message of another type received before the one waited will be queued
+ * and used by subsequent call to this function or MsgHandle().
+ */
+gras_error_t
+gras_msg_wait(double timeout,
+ gras_msgtype_t *msgt_want,
+ gras_socket_t **expeditor,
+ void **payload) {
+
+ gras_msgtype_t *msgt_got;
+ gras_error_t errcode;
+ double start, now;
+ gras_procdata_t *pd=gras_procdata_get();
+ int cpt;
+ gras_msg_t msg;
+
+ *expeditor = NULL;
+ *payload = NULL;
+
+ VERB1("Waiting for message %s",msgt_want->name);
+
+ start = now = gras_time();
+
+ gras_dynar_foreach(pd->msg_queue,cpt,msg){
+ if (msg.type->code == msgt_want->code) {
+ *expeditor = msg.expeditor;
+ *payload = msg.payload;
+ gras_dynar_cursor_rm(pd->msg_queue, &cpt);
+ VERB0("Waited message was queued");
+ return no_error;
+ }
+ }
+
+ while (1) {
+ TRY(gras_trp_select(timeout - now + start, expeditor));
+ TRY(gras_msg_recv(*expeditor, &msgt_got, payload));
+ if (msgt_got->code == msgt_want->code) {
+ VERB0("Got waited message");
+ return no_error;
+ }
+
+ /* not expected msg type. Queue it for later */
+ msg.expeditor = *expeditor;
+ msg.type = msgt_got;
+ msg.payload = *payload;
+ TRY(gras_dynar_push(pd->msg_queue,&msg));
+
+ now=gras_time();
+ if (now - start + 0.001 < timeout) {
+ RAISE1(timeout_error,"Timeout while waiting for msg %s",msgt_want->name);
+ }
+ }
+
+ RAISE_IMPOSSIBLE;
+}
+
+/**
+ * gras_msg_handle:
+ * @timeOut: How long to wait for incoming messages
+ * @Returns: the error code (or no_error).
+ *
+ * Waits up to #timeOut# seconds to see if a message comes in; if so, calls the
+ * registered listener for that message (see RegisterCallback()).
+ */
+gras_error_t
+gras_msg_handle(double timeOut) {
+
+ gras_error_t errcode;
+ int cpt;
+
+ gras_msg_t msg;
+ gras_socket_t *expeditor;
+ void *payload;
+ gras_msgtype_t *msgtype;
+
+ gras_procdata_t*pd=gras_procdata_get();
+ gras_cblist_t *list;
+ gras_cb_t cb;
+
+
+
+ VERB1("Handling message within the next %.2s",timeOut);
+
+ /* get a message (from the queue or from the net) */
+ if (gras_dynar_length(pd->msg_queue)) {
+ gras_dynar_shift(pd->msg_queue,&msg);
+ expeditor = msg.expeditor;
+ msgtype = msg.type;
+ payload = msg.payload;
+
+ } else {
+ TRY(gras_trp_select(timeOut, &expeditor));
+ TRY(gras_msg_recv(expeditor, &msgtype, &payload));
+ }
+
+ /* handle it */
+ gras_dynar_foreach(pd->cbl_list,cpt,list) {
+ if (list->id == msgtype->code) {
+ break;
+ } else {
+ list=NULL;
+ }
+ }
+ if (!list) {
+ INFO1("Unexpected message '%s' ignored", msgtype->name);
+ WARN0("FIXME: gras_datadesc_free not implemented => leaking the payload");
+ return no_error;
+ }
+
+ gras_dynar_foreach(list->cbs,cpt,cb) {
+ if (cb(expeditor,msgtype->ctn_type,payload)) {
+ /* cb handled the message */
+ return no_error;
+ }
+ }
+
+ INFO1("Message '%s' refused by all registered callbacks", msgtype->name);
+ WARN0("FIXME: gras_datadesc_free not implemented => leaking the payload");
+ return mismatch_error;
+}
+
+gras_error_t
+gras_cb_register(gras_msgtype_t *msgtype,
+ gras_cb_t cb) {
+ gras_error_t errcode;
+ gras_procdata_t *pd=gras_procdata_get();
+ gras_cblist_t *list;
+ int cpt;
+
+ /* search the list of cb for this message on this host (creating if NULL) */
+ gras_dynar_foreach(pd->cbl_list,cpt,list) {
+ if (list->id == msgtype->code) {
+ break;
+ } else {
+ list=NULL;
+ }
+ }
+ if (!list) {
+ /* First cb? Create room */
+ list = malloc(sizeof(gras_cblist_t));
+ if (!list)
+ RAISE_MALLOC;
+
+ list->id = msgtype->code;
+ TRY(gras_dynar_new(&(list->cbs), sizeof(gras_cb_t), NULL));
+ TRY(gras_dynar_push(pd->cbl_list,&list));
+ }
+
+ /* Insert the new one into the set */
+ TRY(gras_dynar_insert_at(list->cbs,0,cb));
+
+ return no_error;
+}
+
+void
+gras_cb_unregister(gras_msgtype_t *msgtype,
+ gras_cb_t cb) {
+
+ gras_procdata_t *pd=gras_procdata_get();
+ gras_cblist_t *list;
+ gras_cb_t cb_cpt;
+ int cpt;
+ int found = 0;
+
+ /* search the list of cb for this message on this host */
+ gras_dynar_foreach(pd->cbl_list,cpt,list) {
+ if (list->id == msgtype->code) {
+ break;
+ } else {
+ list=NULL;
+ }
+ }
+
+ /* Remove it from the set */
+ if (list) {
+ gras_dynar_foreach(list->cbs,cpt,cb_cpt) {
+ if (cb == cb_cpt) {
+ gras_dynar_cursor_rm(list->cbs, &cpt);
+ found = 1;
+ }
+ }
+ }
+ if (!found)
+ VERB1("Ignoring removal of unexisting callback to msg id %d",
+ msgtype->code);
+}
--- /dev/null
+/* $Id$ */
+
+/* messaging - high level communication (send/receive messages) */
+
+/* module's public interface exported within GRAS, but not to end user. */
+
+/* Authors: Martin Quinson */
+/* Copyright (C) 2003, 2004 Martin Quinson. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef GRAS_MSG_INTERFACE_H
+#define GRAS_MSG_INTERFACE_H
+
+void gras_msg_init(void);
+void gras_msg_exit(void);
+
+
+/* gras_msg_t is dereferenced to be stored in procdata, living in Virtu */
+typedef struct {
+ gras_socket_t *expeditor;
+ gras_msgtype_t *type;
+ void *payload;
+} gras_msg_t;
+
+gras_error_t gras_msg_send_namev(gras_socket_t *sock,
+ const char *namev,
+ void *payload);
+
+#define GRAS_PROTOCOL_VERSION '\0';
+
+typedef struct s_gras_cblist gras_cblist_t;
+
+#endif /* GRAS_MSG_INTERFACE_H */
--- /dev/null
+/* $Id$ */
+
+/* messaging - high level communication (send/receive messages) */
+
+/* module's private interface masked even to other parts of GRAS. */
+
+/* Authors: Martin Quinson */
+/* Copyright (C) 2003, 2004 Martin Quinson. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef GRAS_MESSAGE_PRIVATE_H
+#define GRAS_MESSAGE_PRIVATE_H
+
+#include "gras_private.h"
+#include "Msg/msg_interface.h"
+
+/**
+ * gras_msgtype_t:
+ *
+ * Message type descriptor. There one of these for each registered version.
+ */
+struct s_gras_msgtype {
+ /* headers for the data set */
+ unsigned int code;
+ char *name;
+ unsigned int name_len;
+
+ /* payload */
+ short int version;
+ gras_datadesc_type_t *ctn_type;
+};
+
+extern gras_set_t *_gras_msgtype_set; /* of gras_msgtype_t */
+void gras_msgtype_free(void *msgtype);
+
+
+gras_error_t gras_msg_recv(gras_socket_t *sock,
+ gras_msgtype_t **msgtype,
+ void **payload);
+
+
+/**
+ * gras_cblist_t:
+ *
+ * association between msg ID and cb list for a given process
+ */
+struct s_gras_cblist {
+ long int id;
+ gras_dynar_t *cbs; /* of gras_msg_cb_t */
+};
+
+void gras_cblist_free(void *cbl);
+
+#endif /* GRAS_MESSAGE_PRIVATE_H */
/* we cannot have more than FD_SETSIZE sockets */
if (++max_fds > FD_SETSIZE) {
- WARNING0("too many open sockets.");
+ WARN0("too many open sockets.");
done = 0;
break;
}
recvd = recv(sock_iter->sd, &lookahead, 1, MSG_PEEK);
if (recvd < 0) {
- WARNING2("socket %d failed: %s", sock_iter->sd, strerror(errno));
+ WARN2("socket %d failed: %s", sock_iter->sd, strerror(errno));
/* done with this socket */
gras_socket_close(&sock_iter);
cursor--;
under the terms of the license (GNU LGPL) which comes with this package. */
#include <time.h> /* time() */
-//#include <errno.h>
#include "Transport/transport_private.h"
return;
}
}
- WARNING0("Ignoring request to free an unknown socket");
+ WARN0("Ignoring request to free an unknown socket");
}
}
return gras_dict_retrieve(_gras_trp_plugins,name,(void**)dst);
}
+int gras_socket_my_port (gras_socket_t *sock) {
+ return sock->port;
+}
+int gras_socket_peer_port(gras_socket_t *sock) {
+ return sock->peer_port;
+}
+char *gras_socket_peer_name(gras_socket_t *sock) {
+ return sock->peer_name;
+}
/* close the socket */
if(close(sock->sd) < 0) {
- WARNING2("error while closing file %d: %s",
+ WARN2("error while closing file %d: %s",
sock->sd, strerror(errno));
}
}
if (setsockopt(sd, SOL_SOCKET, SO_KEEPALIVE, (char *)&i, s)
|| setsockopt(sd, TcpProtoNumber(), TCP_NODELAY, (char *)&i, s)) {
- WARNING0("setsockopt failed, cannot condition the accepted socket");
+ WARN0("setsockopt failed, cannot condition the accepted socket");
}
/* FIXME: bufSize removed until we can have optionsets
/* close the socket */
if(close(sock->sd) < 0) {
- WARNING3("error while closing tcp socket %d: %d (%s)\n",
+ WARN3("error while closing tcp socket %d: %d (%s)\n",
sock->sd, errno, strerror(errno));
}
}
--- /dev/null
+/* $Id$ */
+
+/* process - GRAS process handling (common code for RL and SG) */
+
+/* Authors: Martin Quinson */
+/* Copyright (C) 2003,2004 da GRAS posse. */
+
+/* This program is free software; you can redistribute it and/or modify it
+ under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "gras_private.h"
+#include "Virtu/virtu_interface.h"
+
+
+/* **************************************************************************
+ * Process data
+ * **************************************************************************/
+void *gras_userdata_get(void) {
+ gras_procdata_t *pd=gras_procdata_get();
+ return pd->userdata;
+}
+
+void *gras_userdata_set(void *ud) {
+ gras_procdata_t *pd=gras_procdata_get();
+
+ pd->userdata = ud;
+
+ return pd->userdata;
+}
+
+gras_error_t
+gras_procdata_init() {
+ gras_error_t errcode;
+ gras_procdata_t *pd=gras_procdata_get();
+ pd->userdata = NULL;
+ TRY(gras_dynar_new( &(pd->msg_queue), sizeof(gras_msg_t), NULL ));
+ TRY(gras_dynar_new( &(pd->cbl_list), sizeof(gras_cblist_t *), NULL ));
+ return no_error;
+}
GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(process,GRAS);
/* globals */
-static gras_process_data_t *_gras_process_data;
+static gras_procdata_t *_gras_procdata = NULL;
gras_error_t gras_process_init() {
- // gras_error_t errcode;
+ gras_error_t errcode;
- if (!(_gras_process_data=(gras_process_data_t *)malloc(sizeof(gras_process_data_t))))
+ if (!(_gras_procdata=(gras_procdata_t *)malloc(sizeof(gras_procdata_t))))
RAISE_MALLOC;
- WARNING0("Implement message queue");
- /*
- TRY(gras_dynar_new( &(_gras_process_data->msg_queue) ));
- TRY(gras_dynar_new( &(_gras_process_data->cbl_list) ));
- */
-
- _gras_process_data->userdata = NULL;
+ TRY(gras_procdata_init());
return no_error;
}
gras_error_t gras_process_exit() {
- WARNING0("FIXME: not implemented (=> leaking on exit :)");
+ WARN0("FIXME: not implemented (=> leaking on exit :)");
return no_error;
}
* Process data
* **************************************************************************/
-void *gras_userdata_get(void) {
- return _gras_process_data->userdata;
-}
+gras_procdata_t *gras_procdata_get(void) {
+ gras_assert0(_gras_procdata,"Run gras_process_init!");
-void *gras_userdata_set(void *ud) {
- _gras_process_data->userdata = ud;
- return ud;
+ return _gras_procdata;
}
gras_error_t
gras_process_init() {
+ gras_error_t errcode;
gras_hostdata_t *hd=(gras_hostdata_t *)MSG_host_get_data(MSG_host_self());
- gras_process_data_t *pd;
+ gras_procdata_t *pd;
int i;
- if (!(pd=(gras_process_data_t *)malloc(sizeof(gras_process_data_t))))
+ if (!(pd=(gras_procdata_t *)malloc(sizeof(gras_procdata_t))))
RAISE_MALLOC;
- WARNING0("Implement msg queue");
- /*
- pd->grasMsgQueueLen=0;
- pd->grasMsgQueue = NULL;
-
- pd->grasCblListLen = 0;
- pd->grasCblList = NULL;
- */
-
if (MSG_process_set_data(MSG_process_self(),(void*)pd) != MSG_OK) {
return unknown_error;
}
+ TRY(gras_procdata_init());
if (!hd) {
if (!(hd=(gras_hostdata_t *)malloc(sizeof(gras_hostdata_t))))
gras_error_t
gras_process_exit() {
gras_hostdata_t *hd=(gras_hostdata_t *)MSG_host_get_data(MSG_host_self());
- gras_process_data_t *pd=(gras_process_data_t *)MSG_process_get_data(MSG_process_self());
+ gras_procdata_t *pd=(gras_procdata_t *)MSG_process_get_data(MSG_process_self());
int myPID=MSG_process_self_PID();
int i;
INFO2("GRAS: Finalizing process '%s' (%d)",
MSG_process_get_name(MSG_process_self()),MSG_process_self_PID());
- WARNING0("Implement msg queue");
- /*
- if (pd->grasMsgQueueLen) {
- fprintf(stderr,"GRAS: Warning: process %d terminated, but some queued messages where not handled\n",MSG_process_self_PID());
- }
- */
+ if (gras_dynar_length(pd->msg_queue))
+ WARN1("process %d terminated, but some queued messages where not handled",MSG_process_self_PID());
for (i=0; i< GRAS_MAX_CHANNEL; i++)
if (myPID == hd->proc[i])
* Process data
* **************************************************************************/
-void *gras_userdata_get(void) {
- gras_process_data_t *pd=(gras_process_data_t *)MSG_process_get_data(MSG_process_self());
+gras_procdata_t *gras_procdata_get(void) {
+ gras_procdata_t *pd=(gras_procdata_t *)MSG_process_get_data(MSG_process_self());
gras_assert0(pd,"Run gras_process_init!");
- return pd->userdata;
+ return pd;
}
-void *gras_userdata_set(void *ud) {
- gras_process_data_t *pd=(gras_process_data_t *)MSG_process_get_data(MSG_process_self());
-
- gras_assert0(pd,"Run gras_process_init!");
-
- pd->userdata = ud;
-
- return pd->userdata;
-}
* Data for each process
*/
typedef struct {
- /* queue of messages which where received but not wanted in msgWait, and therefore
- temporarly queued until the next msgHandle */
+ /*queue of msgs storing the ones got while msg_wait'ing for something else */
gras_dynar_t *msg_queue; /* elm type: gras_msg_t */
/* registered callbacks for each message */
/* globals of the process */
void *userdata;
-} gras_process_data_t;
-
+} gras_procdata_t;
+/* FIXME: mv to _private? */
+gras_procdata_t *gras_procdata_get(void);
+gras_error_t gras_procdata_init(void);
#endif /* GRAS_VIRTU_INTERFACE_H */
#define TRUE 1
#define FALSE 0
+#define GRAS_MAX_CHANNEL 10 /* FIXME: killme */
+
#include "gras_config.h"
#include "gras/error.h"
#include "gras/datadesc.h"
#include "DataDesc/datadesc_interface.h"
#include "gras/messages.h"
-#include "Messaging/messaging_interface.h"
+#include "Msg/msg_interface.h"
#include "Virtu/virtu_interface.h"
TRYCATCH(mismatch_error,gras_dict_retrieve((gras_dict_t*)cfg,name,(void**)&res));
if (errcode != mismatch_error) {
- WARNING1("Config elem %s registered twice.",name);
+ WARN1("Config elem %s registered twice.",name);
/* Will be removed by the insertion of the new one */
}
TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_int,&cell));
if (gras_dynar_length(cell->content) > 1) {
- WARNING2("You asked for the first value of the config element '%s', but there is %d values\n",
+ WARN2("You asked for the first value of the config element '%s', but there is %d values\n",
name, gras_dynar_length(cell->content));
}
TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_double,&cell));
if (gras_dynar_length(cell->content) > 1) {
- WARNING2("You asked for the first value of the config element '%s', but there is %d values\n",
+ WARN2("You asked for the first value of the config element '%s', but there is %d values\n",
name, gras_dynar_length(cell->content));
}
TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_string,&cell));
if (gras_dynar_length(cell->content) > 1) {
- WARNING2("You asked for the first value of the config element '%s', but there is %d values\n",
+ WARN2("You asked for the first value of the config element '%s', but there is %d values\n",
name, gras_dynar_length(cell->content));
}
TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_host,&cell));
if (gras_dynar_length(cell->content) > 1) {
- WARNING2("You asked for the first value of the config element '%s', but there is %d values\n",
+ WARN2("You asked for the first value of the config element '%s', but there is %d values\n",
name, gras_dynar_length(cell->content));
}
};
void
-gras_init(int argc, char **argv) {
+gras_init(int *argc, char **argv) {
gras_init_defaultlog(argc, argv, NULL);
}
* Initialize the gras mecanisms.
*/
void
-gras_init_defaultlog(int argc,char **argv, const char *defaultlog) {
- int i;
+gras_init_defaultlog(int *argc,char **argv, const char *defaultlog) {
+ int i,j;
char *opt;
gras_error_t errcode;
int found=0;
INFO0("Initialize GRAS");
/** Set logs and init log submodule */
- for (i=1; i<argc; i++) {
+ for (i=1; i<*argc; i++) {
if (!strncmp(argv[i],"--gras-log=",strlen("--gras-log="))) {
found = 1;
opt=strchr(argv[i],'=');
opt++;
TRYFAIL(gras_log_control_set(opt));
+ /*remove this from argv*/
+ for (j=i+1; j<*argc; j++) {
+ argv[j-1] = argv[j];
+ }
+ argv[j-1] = NULL;
+ (*argc)--;
+ i--; /* compensate effect of next loop incrementation */
+ WARN1("argc %d",*argc);
}
}
if (!found && defaultlog) {
}
/** init other submodules */
+ gras_msg_init();
gras_trp_init();
gras_datadesc_init();
}
*/
void
gras_exit(){
+ gras_msg_exit();
gras_trp_exit();
gras_datadesc_exit();
gras_log_exit();
trp_tcp_client trp_tcp_server \
trp_file_client trp_file_server \
datadesc_usage
-# gs_example_send gs_example_receive
SG_tests =
noinst_PROGRAMS = $(core_tests) $(RL_tests) $(SG_tests)
-noinst_SCRIPTS = run_tests gs_example trp_tcp_usage
+noinst_SCRIPTS = run_tests trp_tcp_usage
TESTS=run_tests
test: $(noinst_PROGRAMS) $(noinst_SCRIPTS)
datadesc_usage_LDADD= $(LDADD_RL)
-#gs_example_send_LDADD= $(LDADD_UTILS)
-#gs_example_receive_LDADD= $(LDADD_UTILS)
-
gras_datadesc_type_t *my_type;
array i,*j;
- long int code;
int cpt;
INFO0("==== Test on fixed array ====");
j=NULL;
TRY(gras_datadesc_by_name("int", &int_type));
- TRY(gras_datadesc_declare_array("fixed array of int", int_type, 5, &code));
- TRY(gras_datadesc_by_code(code,&my_type));
+ TRY(gras_datadesc_declare_array_fixed("fixed int array",
+ int_type, 5, &my_type));
TRY(write_read(my_type, (void*)&i,(void**) &j));
for (cpt=0; cpt<SIZE; cpt++)
gras_datadesc_type_t *int_type;
gras_datadesc_type_t *my_type;
int *i,**j=NULL;
- long int code;
if (! (i=malloc(sizeof(int))) )
RAISE_MALLOC;
INFO1("==== Test on a reference to an integer (%p) ====",i);
TRY(gras_datadesc_by_name("int", &int_type));
- TRY(gras_datadesc_declare_ref("int*",int_type,&code));
- TRY(gras_datadesc_by_code(code,&my_type));
+ TRY(gras_datadesc_declare_ref("int*",int_type,&my_type));
TRY(write_read(my_type, (void*)&i,(void**) &j));
gras_assert(*i == **j);
gras_error_t test_string(void) {
gras_error_t errcode;
gras_datadesc_type_t *type;
- string i=strdup("Some data");
- string *j=NULL;
+ char *i=strdup("Some data");
+ char *j=NULL;
INFO0("==== Test on string (dynamic array) ====");
TRY(gras_datadesc_by_name("string", &type));
- TRY(write_read(type, (void*)&i,(void**) &j));
- gras_assert(!strcmp(i,*j));
- free(*j);
+ TRY(write_read(type, (void*)i,(void**) &j));
+ gras_assert(!strcmp(i,j));
+ free(j);
return no_error;
}
gras_error_t test_homostruct(void) {
gras_error_t errcode;
gras_datadesc_type_t *my_type;
- long int my_code;
homostruct *i, *j;
INFO0("==== Test on homogeneous structure ====");
/* create descriptor */
- TRY(gras_datadesc_declare_struct("homostruct",&my_code));
- TRY(gras_datadesc_declare_struct_add_name(my_code,"a","int"));
- TRY(gras_datadesc_declare_struct_add_name(my_code,"b","int"));
- TRY(gras_datadesc_declare_struct_add_name(my_code,"c","int"));
- TRY(gras_datadesc_declare_struct_add_name(my_code,"d","int"));
- TRY(gras_datadesc_by_code(my_code, &my_type));
+ TRY(gras_datadesc_declare_struct("homostruct",&my_type));
+ TRY(gras_datadesc_declare_struct_append_name(my_type,"a","signed int"));
+ TRY(gras_datadesc_declare_struct_append_name(my_type,"b","int"));
+ TRY(gras_datadesc_declare_struct_append_name(my_type,"c","int"));
+ TRY(gras_datadesc_declare_struct_append_name(my_type,"d","int"));
/* init a value, exchange it and check its validity*/
if (! (i=malloc(sizeof(homostruct))) )
gras_error_t test_hetestruct(void) {
gras_error_t errcode;
gras_datadesc_type_t *my_type;
- long int my_code;
hetestruct *i, *j;
INFO0("==== Test on heterogeneous structure ====");
/* create descriptor */
- TRY(gras_datadesc_declare_struct("hetestruct",&my_code));
- TRY(gras_datadesc_declare_struct_add_name(my_code,"c1","unsigned char"));
- TRY(gras_datadesc_declare_struct_add_name(my_code,"l1","unsigned long int"));
- TRY(gras_datadesc_declare_struct_add_name(my_code,"c2","unsigned char"));
- TRY(gras_datadesc_declare_struct_add_name(my_code,"l2","unsigned long int"));
- TRY(gras_datadesc_by_code(my_code, &my_type));
+ TRY(gras_datadesc_declare_struct("hetestruct",&my_type));
+ TRY(gras_datadesc_declare_struct_append_name(my_type,"c1","unsigned char"));
+ TRY(gras_datadesc_declare_struct_append_name(my_type,"l1","unsigned long int"));
+ TRY(gras_datadesc_declare_struct_append_name(my_type,"c2","unsigned char"));
+ TRY(gras_datadesc_declare_struct_append_name(my_type,"l2","unsigned long int"));
/* init a value, exchange it and check its validity*/
if (! (i=malloc(sizeof(hetestruct))) )
gras_error_t test_nestedstruct(void) {
gras_error_t errcode;
gras_datadesc_type_t *my_type;
- long int my_code;
nestedstruct *i, *j;
INFO0("==== Test on nested structures ====");
/* create descriptor */
- TRY(gras_datadesc_declare_struct("nestedstruct",&my_code));
- TRY(gras_datadesc_declare_struct_add_name(my_code,"hete","hetestruct"));
- TRY(gras_datadesc_declare_struct_add_name(my_code,"homo","homostruct"));
- TRY(gras_datadesc_by_code(my_code, &my_type));
+ TRY(gras_datadesc_declare_struct("nestedstruct",&my_type));
+ TRY(gras_datadesc_declare_struct_append_name(my_type,"hete","hetestruct"));
+ TRY(gras_datadesc_declare_struct_append_name(my_type,"homo","homostruct"));
/* init a value, exchange it and check its validity*/
if (! (i=malloc(sizeof(nestedstruct))) )
gras_error_t test_chain_list(void) {
gras_error_t errcode;
gras_datadesc_type_t *my_type,*ref_my_type;
- long int my_code;
- long int ref_my_code;
chained_list_t *i, *j;
INFO0("==== Test on chained list ====");
/* create descriptor */
- TRY(gras_datadesc_declare_struct("chained_list_t",&my_code));
- TRY(gras_datadesc_by_code(my_code, &my_type));
+ TRY(gras_datadesc_declare_struct("chained_list_t",&my_type));
+ TRY(gras_datadesc_declare_ref("chained_list_t*",my_type,&ref_my_type));
- TRY(gras_datadesc_declare_ref("chained_list_t*",my_type,&ref_my_code));
+ TRY(gras_datadesc_declare_struct_append_name(my_type,"v","int"));
+ TRY(gras_datadesc_declare_struct_append(my_type,"l",ref_my_type));
- TRY(gras_datadesc_declare_struct_add_name(my_code,"v","int"));
- TRY(gras_datadesc_declare_struct_add_code(my_code,"l",ref_my_code));
-
- TRY(gras_datadesc_by_code(ref_my_code, &ref_my_type));
-
/* init a value, exchange it and check its validity*/
i = cons( rand(), cons( rand() , cons( rand(), NULL)));
j = NULL;
int main(int argc,char *argv[]) {
gras_error_t errcode;
- gras_init_defaultlog(argc,argv,
+ gras_init_defaultlog(&argc,argv,
"DataDesc.thresh=verbose"
" test.thresh=debug"
// " set.thresh=debug"
);
- /*
+
TRYFAIL(test_int());
TRYFAIL(test_float());
TRYFAIL(test_array());
TRYFAIL(test_homostruct());
TRYFAIL(test_hetestruct());
TRYFAIL(test_nestedstruct());
- */
+
TRYFAIL(test_chain_list());
- TRYFAIL(test_graph());
+ CRITICAL0("Not even test graphs: it dies with awfully scaring messages");
+ gras_abort();
+ // TRYFAIL(test_graph());
+
+ gras_exit();
return 0;
}
+++ /dev/null
-#! @BASH@ -e
-
-./gs_example_send $@ | ./gs_example_receive $@
-
+++ /dev/null
-/* gs_example_receive.c */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <gras.h>
-
-/* structs */
-struct list {
- int v;
- struct list *l;
-};
-
-struct s_pair {
- int *pa;
- int *pb;
-};
-
-struct s_mixed {
- unsigned char c1;
- unsigned long int l1;
- unsigned char c2;
- unsigned long int l2;
-};
-
-/* prototypes */
-void disp_l(struct list *l);
-long int
-string_size_callback(void *vars,
- struct s_gs_type *p_type,
- void *data);
-
-/* local functions */
-void
-disp_l(struct list *l) {
- if (l) {
- printf("%d ", l->v);
- disp_l(l->l);
- }
-}
-
-long int
-string_size_callback(void *vars,
- struct s_gs_type *p_type,
- void *data) {
- return 1+(long int)strlen(data);
-}
-
-/* main */
-int
-main(int argc, char **argv) {
- struct list **pl = NULL;
- int *array = NULL;
- struct s_pair *p_pair = NULL;
- char *str = NULL;
- // struct s_mixed *mixed = NULL;
-
- struct s_gs_type_driver *t_driver = NULL;
- struct s_gs_net_driver *n_driver = NULL;
- struct s_gs_type_bag *bag = NULL;
- struct s_gs_connection *cnx = NULL;
-
- struct s_gs_type_bag_ops *bag_ops = NULL;
-
- struct s_gs_type *t_signed_int = NULL;
- struct s_gs_type *t_list = NULL;
- struct s_gs_type *t_ref_list = NULL;
-
- struct s_gs_type *t_array = NULL;
-
- struct s_gs_type *t_ref_sint = NULL;
- struct s_gs_type *t_pair = NULL;
-
- struct s_gs_type *t_char = NULL;
- struct s_gs_type *t_string = NULL;
-
- struct s_gs_type *t_u_char = NULL;
- struct s_gs_type *t_u_long_int = NULL;
- struct s_gs_type *t_mixed = NULL;
-
- struct s_gs_message_instance *mi = NULL;
-
- gs_init(argc, argv);
- gs_purge_cmd_line(&argc, argv);
-
- t_driver = gs_type_driver_init("rl");
- n_driver = gs_net_driver_init("fd");
-
- bag = gs_type_bag_alloc(t_driver);
- bag_ops = bag->bag_ops;
-
- {
- int fd = 0;
- cnx = gs_net_connection_accept(n_driver, &fd);
- }
-
- bag_ops->register_incoming_connection(bag, cnx);
-
- /* sequence 1 */
- t_signed_int = bag_ops->get_type_by_name(bag, NULL, "signed int");
- t_list = gs_type_new_struct(bag, NULL, "list");
- t_ref_list = gs_type_new_ref(bag, NULL, "p_list", t_list);
-
- gs_type_struct_append_field(t_list, "v", t_signed_int);
- gs_type_struct_append_field(t_list, "l", t_ref_list);
-
- /* sequence 2 */
- t_array = gs_type_new_array(bag, NULL, "array", 5, t_signed_int);
-
- /* sequence 3 */
- t_ref_sint = gs_type_new_ref(bag, NULL, "p_ref_sint", t_signed_int);
- t_pair = gs_type_new_struct(bag, NULL, "pair");
-
- gs_type_struct_append_field(t_pair, "pa", t_ref_sint);
- gs_type_struct_append_field(t_pair, "pb", t_ref_sint);
-
- /* sequence 4 */
- t_char = bag_ops->get_type_by_name(bag, NULL, "signed char");
- t_string = gs_type_new_array_with_callback(bag, NULL, "string", -1, t_char, string_size_callback, NULL);
-
- /* sequence 5 */
- t_u_char = bag_ops->get_type_by_name(bag, NULL, "unsigned char");
- t_u_long_int = bag_ops->get_type_by_name(bag, NULL, "unsigned long int");
- t_mixed = gs_type_new_struct(bag, NULL, "mixed");
-
- gs_type_struct_append_field(t_mixed, "c1", t_u_char);
- gs_type_struct_append_field(t_mixed, "l1", t_u_long_int);
- gs_type_struct_append_field(t_mixed, "c2", t_u_char);
- gs_type_struct_append_field(t_mixed, "l2", t_u_long_int);
-
- /* message receive */
- mi = gs_message_init_receive(bag, cnx);
- fprintf(stderr, "\nreceiving sequence 1\n----------------\n");
- pl = gs_message_receive_next_sequence(mi);
-
- printf("( ");
- disp_l(*pl);
- printf(")\n");
-
- fprintf(stderr, "\nreceiving sequence 2\n----------------\n");
- array = gs_message_receive_next_sequence(mi);
-
- {
- int i = 0;
- for (i = 0; i < 5; i++) {
- printf("array[%d] = %d\n", i, array[i]);
- }
- }
-
- fprintf(stderr, "\nreceiving sequence 3\n----------------\n");
- p_pair = gs_message_receive_next_sequence(mi);
- printf("pair.pa = %p, *pair.pa = %d\n", (*p_pair).pa, *((*p_pair).pa));
- printf("pair.pb = %p, *pair.pb = %d\n", (*p_pair).pb, *((*p_pair).pb));
-
- fprintf(stderr, "\nreceiving sequence 4\n----------------\n");
- str = gs_message_receive_next_sequence(mi);
- printf("str = %s\n", str);
-
- /*
- fprintf(stderr, "\nreceiving sequence 5\n----------------\n");
- mixed = gs_message_receive_next_sequence(mi);
- printf("c1=%c c2=%c; l1=%ld l2=%ld\n",
- mixed->c1, mixed->c2, mixed->l1, mixed->l2);
- */
- gs_exit();
-
- return 0;
-}
+++ /dev/null
-/* gs_example_send */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <gras.h>
-
-#undef PARSING
-
-/* structs */
-struct list {
- int v;
- struct list *l;
-};
-
-struct s_pair {
- int *pa;
- int *pb;
-};
-
-#ifdef PARSING
-GRAS_DEFINE_TYPE(struct_s_mixed,
- struct s_mixed {
- unsigned char c1;
- unsigned long int l1;
- unsigned char c2;
- unsigned long int l2;
- }
-);
-#else
- struct s_mixed {
- unsigned char c1;
- unsigned long int l1;
- unsigned char c2;
- unsigned long int l2;
- };
-#endif
-
-/* prototypes */
-struct list * cons(int v, struct list *l);
-long int
-string_size_callback(void *vars,
- struct s_gs_type *p_type,
- void *data);
-
-/* local functions */
-struct list *
-cons(int v, struct list *l) {
- struct list *nl = malloc(sizeof (struct list));
-
- nl->v = v;
- nl->l = l;
-
- return nl;
-}
-
-long int
-string_size_callback(void *vars,
- struct s_gs_type *p_type,
- void *data) {
- return 1+(long int)strlen(data);
-}
-
-void parse_log_opt(int argc, char **argv,const char *deft);
-
-/* main */
-int
-main(int argc, char **argv) {
- struct list *l = NULL;
-
- struct s_pair pair;
-
- int array[5] =
- {
- 11, 12, 13, 14, 15,
- };
- /*
- struct s_mixed mixed =
- {
- 'a',1.0,'b',2.0
- };
- */
- struct s_gs_type_driver *t_driver = NULL;
- struct s_gs_net_driver *n_driver = NULL;
- struct s_gs_type_bag *bag = NULL;
- struct s_gs_connection *cnx = NULL;
-
- struct s_gs_type_bag_ops *bag_ops = NULL;
-
- struct s_gs_type *t_signed_int = NULL;
- struct s_gs_type *t_list = NULL;
- struct s_gs_type *t_ref_list = NULL;
-
- struct s_gs_type *t_array = NULL;
-
- struct s_gs_type *t_ref_sint = NULL;
- struct s_gs_type *t_pair = NULL;
-
- struct s_gs_type *t_char = NULL;
- struct s_gs_type *t_string = NULL;
-
-#ifndef PARSING
- struct s_gs_type *t_u_char = NULL;
- struct s_gs_type *t_u_long_int = NULL;
-#endif
-
- struct s_gs_type *t_mixed = NULL;
-
- struct s_gs_message *m = NULL;
- struct s_gs_message_instance *mi = NULL;
-
-
- parse_log_opt(argc,argv,"datadesc.thresh=debug");
- gs_init(argc, argv);
- gs_purge_cmd_line(&argc, argv);
- gras_log_control_set("NDR.thresh=debug");
-
- t_driver = gs_type_driver_init("rl");
- n_driver = gs_net_driver_init("fd");
-
- bag = gs_type_bag_alloc(t_driver);
- bag_ops = bag->bag_ops;
-
- {
- int fd = 1;
- cnx = gs_net_connection_connect(n_driver, &fd);
- }
-
- bag_ops->register_outgoing_connection(bag, cnx);
-
- /* sequence 1 */
- t_signed_int = bag_ops->get_type_by_name(bag, NULL, "signed int");
- t_list = gs_type_new_struct(bag, NULL, "list");
- t_ref_list = gs_type_new_ref(bag, NULL, "p_list", t_list);
-
- gs_type_struct_append_field(t_list, "v", t_signed_int);
- gs_type_struct_append_field(t_list, "l", t_ref_list);
-
- /* sequence 2 */
- t_array = gs_type_new_array(bag, NULL, "array", 5, t_signed_int);
-
- /* sequence 3 */
- t_ref_sint = gs_type_new_ref(bag, NULL, "p_ref_sint", t_signed_int);
- t_pair = gs_type_new_struct(bag, NULL, "pair");
-
- gs_type_struct_append_field(t_pair, "pa", t_ref_sint);
- gs_type_struct_append_field(t_pair, "pb", t_ref_sint);
-
- /* sequence 4 */
- t_char = bag_ops->get_type_by_name(bag, NULL, "signed char");
- t_string = gs_type_new_array_with_callback(bag, NULL, "string", -1, t_char, string_size_callback, NULL);
-
- /* sequence 5 */
-#ifdef PARSING
- t_mixed = gs_type_get_by_symbol(bag,struct_s_mixed);
-#else
- t_u_char = bag_ops->get_type_by_name(bag, NULL, "unsigned char");
- t_u_long_int = bag_ops->get_type_by_name(bag, NULL, "unsigned long int");
- t_mixed = gs_type_new_struct(bag, NULL, "s_mixed");
-
- gs_type_struct_append_field(t_mixed, "c1", t_u_char);
- gs_type_struct_append_field(t_mixed, "l1", t_u_long_int);
- gs_type_struct_append_field(t_mixed, "c2", t_u_char);
- gs_type_struct_append_field(t_mixed, "l2", t_u_long_int);
-#endif
-
- /* message declaration */
- m = gs_message_new(bag, NULL, "my msg");
- gs_message_append_new_sequence(m, t_ref_list);
- gs_message_append_new_sequence(m, t_array);
- gs_message_append_new_sequence(m, t_pair);
- gs_message_append_new_sequence(m, t_string);
- gs_message_append_new_sequence(m, t_mixed);
-
- /* data setup */
- l = cons (1, l);
- l = cons (2, l);
- l = cons (3, l);
-
- pair.pa = malloc(sizeof(int));
- pair.pb = pair.pa;
- *(pair.pa) = 17;
-
- /* message send */
- mi = gs_message_init_send_by_name(bag, cnx, "my msg");
- fprintf(stderr, "\nsending sequence 1\n----------------\n");
- gs_message_send_next_sequence(mi, &l);
- fprintf(stderr, "\nsending sequence 2\n----------------\n");
- gs_message_send_next_sequence(mi, (void*)array);
- fprintf(stderr, "\nsending sequence 3\n----------------\n");
- gs_message_send_next_sequence(mi, &pair);
- fprintf(stderr, "\nsending sequence 4\n----------------\n");
- gs_message_send_next_sequence(mi, (void*)"Hello, World");
- /*
- fprintf(stderr, "\nsending sequence 5\n----------------\n");
- gs_message_send_next_sequence(mi, (void*)&mixed);
- */
- gs_exit();
-
- return 0;
-}
gras_error_t errcode;
char data_send[256];
- gras_init_defaultlog(argc,argv,"trp.thresh=debug");
+ gras_init_defaultlog(&argc,argv,"trp.thresh=debug");
fprintf(stderr,"===[CLIENT]=== Contact the server\n");
TRYFAIL(gras_socket_client_from_file("-",&sock));
fprintf(stderr,"===[CLIENT]=== Exiting successfully\n");
gras_socket_close(&sock);
+
+ gras_exit();
return 0;
}
gras_error_t errcode;
char data_recv[256];
- gras_init_defaultlog(argc,argv,"trp.thresh=debug");
+ gras_init_defaultlog(&argc,argv,"trp.thresh=debug");
fprintf(stderr,"===[SERVER]=== Create the socket\n");
TRYFAIL(gras_socket_server_from_file("-",&sock));
fprintf(stderr,"===[SERVER]=== Exiting successfully\n");
gras_socket_close(&sock);
+ gras_exit();
return 0;
}
char data_send[256];
char data_recv[256];
- gras_init_defaultlog(argc,argv,"trp.thresh=debug");
+ gras_init_defaultlog(&argc,argv,"trp.thresh=debug");
fprintf(stderr,"===[CLIENT]=== Contact the server\n");
TRYFAIL(gras_socket_client(NULL,55555,&sock));
fprintf(stderr,"===[CLIENT]=== Exiting successfully\n");
gras_socket_close(&sock);
+
+ gras_exit();
return 0;
}
gras_error_t errcode;
char data_recv[256];
- gras_init_defaultlog(argc,argv,"trp.thresh=debug");
+ gras_init_defaultlog(&argc,argv,"trp.thresh=debug");
fprintf(stderr,"===[SERVER]=== Create the socket\n");
TRYFAIL(gras_socket_server(55555,&sock));
fprintf(stderr,"===[SERVER]=== Exiting successfully\n");
gras_socket_close(&sock);
+ gras_exit();
return 0;
}
gras_cfg_t *set;
int ival;
- gras_init_defaultlog(argc,argv,"config.thresh=debug root.thresh=info");
+ gras_init_defaultlog(&argc,argv,"config.thresh=debug root.thresh=info");
fprintf(stderr,"==== Alloc and free a config set.\n");
set=make_set();
"Count: 3; Options:\\nmquinson\\necaron\\nfsuter");
test5();
+ gras_exit();
return 0;
}
char *key;
void *data;
- gras_init_defaultlog(argc,argv,"dict.thresh=verbose");
+ gras_init_defaultlog(&argc,argv,"dict.thresh=verbose");
srand((unsigned int)time(NULL));
printf("Dictionnary: CRASH test:\n");
printf("\n Free the structure (twice)\n");
gras_dict_free(&head);
gras_dict_free(&head);
+
+ gras_exit();
return 0;
}
gras_dict_t *head=NULL;
char *data;
- gras_init_defaultlog(argc,argv,"dict.thresh=verbose");
+ gras_init_defaultlog(&argc,argv,"dict.thresh=verbose");
printf("\nGeneric dictionnary: USAGE test:\n");
int cpt,cursor;
double d1,d2;
- gras_init_defaultlog(argc,argv,"dynar.thresh=debug");
+ gras_init_defaultlog(&argc,argv,"dynar.thresh=debug");
fprintf(stderr,"==== Traverse the empty dynar\n");
TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL));
gras_error_t errcode;
int i,cpt,cursor;
- gras_init_defaultlog(argc,argv,"dynar.thresh=debug");
+ gras_init_defaultlog(&argc,argv,"dynar.thresh=debug");
fprintf(stderr,"==== Traverse the empty dynar\n");
TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL));
}
gras_dynar_free(d);
+ gras_exit();
return 0;
}
char buf[1024];
char *s1,*s2;
- gras_init_defaultlog(argc,argv,"dynar.thresh=debug");
+ gras_init_defaultlog(&argc,argv,"dynar.thresh=debug");
fprintf(stderr,"==== Traverse the empty dynar\n");
TRYFAIL(gras_dynar_new(&d,sizeof(char *),&free_string));
}
gras_dynar_free(d);
+ gras_exit();
return 0;
}
GRAS_LOG_NEW_CATEGORY(Top);
int main(int argc, char **argv) {
- gras_init_defaultlog(argc,argv,"root.thresh=debug log.thresh=debug");
+ gras_init_defaultlog(&argc,argv,"root.thresh=debug log.thresh=debug");
DEBUG1("val=%d", 1);
- WARNING1("val=%d", 2);
+ WARN1("val=%d", 2);
CDEBUG2(Top, "val=%d%s", 3, "!");
CRITICAL6("false alarm%s%s%s%s%s%s", "","","","","","!");
return no_error;
}
-int main() {
+int main(int argc, char *argv[]) {
gras_error_t errcode;
- TRY(gras_log_control_set("root.thresh=debug"));
- /*
- //DirectDiagnostics(DIAGDEBUG, stdout);
- DirectDiagnostics(DIAGINFO, stdout);
- // DirectDiagnostics(DIAGLOG, stdout);
- DirectDiagnostics(DIAGWARN, stderr);
- DirectDiagnostics(DIAGERROR, stderr);
- DirectDiagnostics(DIAGFATAL, stderr);
- */
+ gras_init(argc,argv,"root.thresh=debug"));
TRYFAIL(test1());
+
+ gras_exit();
return 0;
}
gras_set_t *set=NULL;
my_elem_t *elm;
- gras_init_defaultlog(argc,argv,"set.thresh=verbose");
+ gras_init_defaultlog(&argc,argv,"set.thresh=verbose");
printf("\nData set: USAGE test:\n");
printf(" - Traverse the resulting data set\n");
TRYFAIL(traverse(set));
+ gras_exit();
return 0;
}