Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[Messaging]
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 26 Apr 2004 10:11:28 +0000 (10:11 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Mon, 26 Apr 2004 10:11:28 +0000 (10:11 +0000)
   - Porting to new standards.
 [Data description]
   - interface cleanup.
     There is no bag anymore, no need to take extra provision to mask the
       pointers behind "ID".
     Better splitup of functions between files create/exchange/convert.
       This is still a bit artificial since convert and receive are so
       interleaved, but anyway.
 [Virtu(process)]
   - add a queued message list to procdata (the ones not matching criteria
     in msg_wait)
   - factorize some more code between SG and RL wrt procdata
 [Tests]
   - use gras_exit in example to track memleaks
   - get rid of gs_example now that GS is properly integrated into gras
   - update run_test to integrate the lastest tests (datadesc)
 [Logging]
   - rename WARNINGn macros to WARNn since it prooved error-prone

git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@83 48e7efb5-ca39-0410-a469-dd3cf9ba447f

49 files changed:
include/datadesc.h
include/gras.h
include/log.h
include/messages.h
include/module.h
include/modules/base.h
include/transport.h
src/gras/Common/gras.c [deleted file]
src/gras/Common/gras_datadesc.c [deleted file]
src/gras/DataDesc/datadesc.c
src/gras/DataDesc/datadesc_interface.h
src/gras/DataDesc/datadesc_private.h
src/gras/DataDesc/ddt_convert.c [moved from src/gras/DataDesc/ddt_remote.c with 54% similarity]
src/gras/DataDesc/ddt_create.c
src/gras/DataDesc/ddt_declare.c [deleted file]
src/gras/DataDesc/ddt_exchange.c [moved from src/gras/DataDesc/ddt_use.c with 97% similarity]
src/gras/Makefile.am
src/gras/Msg/msg.c [new file with mode: 0644]
src/gras/Msg/msg_interface.h [new file with mode: 0644]
src/gras/Msg/msg_private.h [new file with mode: 0644]
src/gras/Transport/rl_transport.c
src/gras/Transport/transport.c
src/gras/Transport/transport_plugin_file.c
src/gras/Transport/transport_plugin_tcp.c
src/gras/Virtu/process.c [new file with mode: 0644]
src/gras/Virtu/rl_process.c
src/gras/Virtu/sg_process.c
src/gras/Virtu/virtu_interface.h
src/gras/gras_private.h
src/xbt/config.c
src/xbt/module.c
testsuite/Makefile.am
testsuite/gras/datadesc_usage.c
testsuite/gras/gs_example.in [deleted file]
testsuite/gras/gs_example_receive.c [deleted file]
testsuite/gras/gs_example_send.c [deleted file]
testsuite/gras/trp_file_client.c
testsuite/gras/trp_file_server.c
testsuite/gras/trp_tcp_client.c
testsuite/gras/trp_tcp_server.c
testsuite/xbt/config_usage.c
testsuite/xbt/dict_crash.c
testsuite/xbt/dict_usage.c
testsuite/xbt/dynar_double.c
testsuite/xbt/dynar_int.c
testsuite/xbt/dynar_string.c
testsuite/xbt/log_usage.c
testsuite/xbt/multidict_crash.c
testsuite/xbt/set_usage.c

index f50c9c4..3a904be 100644 (file)
 BEGIN_DECL
 
 
+/* datadesc */
 typedef struct s_gras_datadesc_type gras_datadesc_type_t;
 
+/* callbacks prototypes */
+typedef void (*gras_datadesc_type_cb_void_t)(void                 *vars,
+                                            gras_datadesc_type_t *p_type,
+                                            void                 *data);
+typedef int (*gras_datadesc_type_cb_int_t)(void                 *vars,
+                                          gras_datadesc_type_t *p_type,
+                                          void                 *data);
+
 /***********************************************
  **** Search and retrieve declared datatype ****
  ***********************************************/
-long int gras_datadesc_get_id_from_name(const char *name);
-
 gras_error_t gras_datadesc_by_name(const char *name,
                                   gras_datadesc_type_t **type);
-gras_error_t gras_datadesc_by_id  (long int code,
-                                  gras_datadesc_type_t **type);
-#define gras_datadesc_by_code(a,b) gras_datadesc_by_id(a,b)
 
-/*********************************************
- **** DataDesc callback persistent states ****
- *********************************************/
+/******************************************
+ **** Declare datadescription yourself ****
+ ******************************************/
+
+gras_error_t 
+gras_datadesc_declare_struct(const char            *name,
+                            gras_datadesc_type_t **dst);
+gras_error_t 
+gras_datadesc_declare_struct_append(gras_datadesc_type_t          *struct_type,
+                                   const char                    *name,
+                                   gras_datadesc_type_t          *field_type);
+gras_error_t 
+gras_datadesc_declare_struct_append_name(gras_datadesc_type_t *struct_type,
+                                        const char           *name,
+                                        const char          *field_type_name);
+gras_error_t 
+gras_datadesc_declare_union(const char                      *name,
+                           gras_datadesc_type_cb_int_t      selector,
+                           gras_datadesc_type_t           **dst);
+gras_error_t 
+gras_datadesc_declare_union_append(gras_datadesc_type_t          *union_type,
+                                  const char                    *name,
+                                  gras_datadesc_type_t          *field_type);
+gras_error_t 
+gras_datadesc_declare_union_append_name(gras_datadesc_type_t *union_type,
+                                       const char           *name,
+                                       const char           *field_type_name);
+gras_error_t 
+gras_datadesc_declare_ref(const char                      *name,
+                         gras_datadesc_type_t            *referenced_type,
+                         gras_datadesc_type_t           **dst);
+gras_error_t
+gras_datadesc_declare_ref_generic(const char                   *name,
+                                 gras_datadesc_type_cb_int_t   discriminant,
+                                 gras_datadesc_type_t        **dst);
+gras_error_t 
+gras_datadesc_declare_array_fixed(const char                    *name,
+                                 gras_datadesc_type_t          *element_type,
+                                 long int                       fixed_size,
+                                 gras_datadesc_type_t         **dst);
+gras_error_t 
+gras_datadesc_declare_array_dyn(const char                      *name,
+                               gras_datadesc_type_t            *element_type,
+                               gras_datadesc_type_cb_int_t      dynamic_size,
+                               gras_datadesc_type_t           **dst);
+
+/*********************************
+ * Change stuff within datadescs *
+ *********************************/
+
 typedef struct s_gras_dd_cbps gras_dd_cbps_t;
+void gras_datadesc_cb_set_pre (gras_datadesc_type_t    *type,
+                              gras_datadesc_type_cb_void_t  pre);
+void gras_datadesc_cb_set_post(gras_datadesc_type_t    *type,
+                              gras_datadesc_type_cb_void_t  post);
+
+/********************************************************
+ * Advanced data describing: callback persistent states *
+ ********************************************************/
 
 void *
 gras_dd_cbps_pop (gras_dd_cbps_t        *ps, 
@@ -82,100 +141,8 @@ void
 gras_dd_cbps_block_end(gras_dd_cbps_t *ps);
 
 
-/******************************************
- **** Declare datadescription manually ****
- ******************************************/
-
-typedef void (*gras_datadesc_type_cb_void_t)(void                 *vars,
-                                            gras_datadesc_type_t *p_type,
-                                            void                 *data);
-typedef int (*gras_datadesc_type_cb_int_t)(void                 *vars,
-                                          gras_datadesc_type_t *p_type,
-                                          void                 *data);
-
 
 
-/* Create a new type and register it on the local machine */
-#define gras_datadesc_declare_struct(   name,             code) \
-        gras_datadesc_declare_struct_cb(name, NULL, NULL, code)
-
-#define gras_datadesc_declare_struct_add_name(   struct_code,field_name,field_type_name) \
-        gras_datadesc_declare_struct_add_name_cb(struct_code,field_name,field_type_name, NULL, NULL)
-
-#define gras_datadesc_declare_struct_add_code(   struct_code,field_name,field_type_code) \
-        gras_datadesc_declare_struct_add_code_cb(struct_code,field_name,field_type_code, NULL, NULL)
-
-gras_error_t 
-gras_datadesc_declare_struct_cb(const char                   *name,
-                               gras_datadesc_type_cb_void_t  pre_cb,
-                               gras_datadesc_type_cb_void_t  post_cb,
-                               long int                     *code);
-gras_error_t 
-gras_datadesc_declare_struct_add_name_cb(long int                      struct_code,
-                                        const char                   *field_name,
-                                        const char                   *field_type_name,
-                                        gras_datadesc_type_cb_void_t  pre_cb,
-                                        gras_datadesc_type_cb_void_t  post_cb);
-
-gras_error_t 
-gras_datadesc_declare_struct_add_code_cb(long int                      struct_code,
-                                        const char                   *field_name,
-                                        long int                      field_code,
-                                        gras_datadesc_type_cb_void_t  pre_cb,
-                                        gras_datadesc_type_cb_void_t  post_cb);
-/* union */
-#define gras_datadesc_declare_union(   name,             code) \
-        gras_datadesc_declare_union_cb(name, NULL, NULL, code)
-
-#define gras_datadesc_declare_union_add_name(   union_code,field_name,field_type_name) \
-        gras_datadesc_declare_union_add_name_cb(union_code,field_name,field_type_name, NULL, NULL)
-
-#define gras_datadesc_declare_union_add_code(   union_code,field_name,field_type_code) \
-        gras_datadesc_declare_union_add_code_cb(union_code,field_name,field_type_code, NULL, NULL)
-
-gras_error_t 
-gras_datadesc_declare_union_cb(const char                   *name,
-                              gras_datadesc_type_cb_int_t   field_count,
-                              gras_datadesc_type_cb_void_t  post,
-                              long int                     *code);
-gras_error_t 
-gras_datadesc_declare_union_add_name_cb(long int                      union_code,
-                                       const char                   *field_name,
-                                       const char                   *field_type_name,
-                                       gras_datadesc_type_cb_void_t  pre_cb,
-                                       gras_datadesc_type_cb_void_t  post_cb);
-gras_error_t 
-gras_datadesc_declare_union_add_code_cb(long int                      union_code,
-                                       const char                   *field_name,
-                                       long int                      field_code,
-                                       gras_datadesc_type_cb_void_t  pre_cb,
-                                       gras_datadesc_type_cb_void_t  post_cb);
-/* ref */
-#define gras_datadesc_declare_ref(name,ref_type, code) \
-        gras_datadesc_declare_ref_cb(name, ref_type, NULL, NULL, code)
-#define gras_datadesc_declare_ref_disc(name,discriminant, code) \
-        gras_datadesc_declare_ref_cb(name, NULL, discriminant,  NULL, code)
-
-gras_error_t
-gras_datadesc_declare_ref_cb(const char                      *name,
-                            gras_datadesc_type_t            *referenced_type,
-                            gras_datadesc_type_cb_int_t      discriminant,
-                            gras_datadesc_type_cb_void_t     post,
-                            long int                        *code);
-/* array */
-#define gras_datadesc_declare_array(name,elm_type, size, code) \
-        gras_datadesc_declare_array_cb(name, elm_type, size, NULL,         NULL, code)
-#define gras_datadesc_declare_array_dyn(name,elm_type, dynamic_size, code) \
-        gras_datadesc_declare_array_cb(name, elm_type, -1,   dynamic_size, NULL, code)
-
-gras_error_t 
-gras_datadesc_declare_array_cb(const char                      *name,
-                              gras_datadesc_type_t            *element_type,
-                              long int                         fixed_size,
-                              gras_datadesc_type_cb_int_t      dynamic_size,
-                              gras_datadesc_type_cb_void_t     post,
-                              long int                        *code);
-
 /*******************************
  **** About data convertion ****
  *******************************/
@@ -187,17 +154,17 @@ int gras_arch_selfid(void); /* ID of this arch */
 gras_error_t
 gras_datadesc_parse(const char *name,
                    const char *Cdefinition,
-                   long int   *code);
+                   gras_datadesc_type_t **dst);
 #define GRAS_DEFINE_TYPE(name,def) \
   static const char * _gras_this_type_symbol_does_not_exist__##name=#def; def
  
-#define gras_type_symbol_parse(bag,name)                                  \
- _gs_type_parse(bag, _gs_this_type_symbol_does_not_exist__##name)
-#define gs_type_get_by_symbol(bag,name)                  \
+/*#define gras_type_symbol_parse(name)                                  \
+ _gras_datadesc_parse(_gras_this_datadesc_type_symbol_does_not_exist__##name)
+*/ 
+#define gras_datadesc_by_symbol(name)                    \
   (bag->bag_ops->get_type_by_name(bag, NULL, #name) ?    \
      bag->bag_ops->get_type_by_name(bag, NULL, #name) :  \
-     gras_type_symbol_parse(bag, name)                   \
+     gras_datadesc_parse(name)                           \
   )
 
 /*****************************
@@ -245,11 +212,10 @@ typedef struct DataDescriptorStruct {
   sizeof(memberType) * repetitions
 
 gras_error_t
-gras_datadesc_from_nws(const char           *name,
-                      const DataDescriptor *desc,
-                      size_t                howmany,
-                      long int             *code);
-
+gras_datadesc_import_nws(const char           *name,
+                        const DataDescriptor *desc,
+                        size_t                howmany,
+                        gras_datadesc_type_t **dst);
 
 END_DECL
 
index 1b0d843..ce3f387 100644 (file)
@@ -17,6 +17,8 @@
 #define TRUE  1
 #define FALSE 0
 
+#define GRAS_MAX_CHANNEL 10 /* FIXME: killme */
+
 #include <gras/error.h>
 #include <gras/log.h>
 
@@ -33,7 +35,6 @@
 #include <gras/virtu.h>
 #include <gras/cond.h>
 
-
 #include <gras/transport.h>
 #include <gras/datadesc.h>
 #include <gras/messages.h>
index bcd6a0a..716e10c 100644 (file)
@@ -310,13 +310,13 @@ extern gras_log_appender_t *gras_log_default_appender;
 #define CINFO5(c, f,a1,a2,a3,a4,a5)    CLOG5(c, gras_log_priority_info, f,a1,a2,a3,a4,a5)
 #define CINFO6(c, f,a1,a2,a3,a4,a5,a6) CLOG6(c, gras_log_priority_info, f,a1,a2,a3,a4,a5,a6)
 
-#define CWARNING0(c, f)                   CLOG0(c, gras_log_priority_warning, f)
-#define CWARNING1(c, f,a1)                CLOG1(c, gras_log_priority_warning, f,a1)
-#define CWARNING2(c, f,a1,a2)             CLOG2(c, gras_log_priority_warning, f,a1,a2)
-#define CWARNING3(c, f,a1,a2,a3)          CLOG3(c, gras_log_priority_warning, f,a1,a2,a3)
-#define CWARNING4(c, f,a1,a2,a3,a4)       CLOG4(c, gras_log_priority_warning, f,a1,a2,a3,a4)
-#define CWARNING5(c, f,a1,a2,a3,a4,a5)    CLOG5(c, gras_log_priority_warning, f,a1,a2,a3,a4,a5)
-#define CWARNING6(c, f,a1,a2,a3,a4,a5,a6) CLOG6(c, gras_log_priority_warning, f,a1,a2,a3,a4,a5,a6)
+#define CWARN0(c, f)                   CLOG0(c, gras_log_priority_warning, f)
+#define CWARN1(c, f,a1)                CLOG1(c, gras_log_priority_warning, f,a1)
+#define CWARN2(c, f,a1,a2)             CLOG2(c, gras_log_priority_warning, f,a1,a2)
+#define CWARN3(c, f,a1,a2,a3)          CLOG3(c, gras_log_priority_warning, f,a1,a2,a3)
+#define CWARN4(c, f,a1,a2,a3,a4)       CLOG4(c, gras_log_priority_warning, f,a1,a2,a3,a4)
+#define CWARN5(c, f,a1,a2,a3,a4,a5)    CLOG5(c, gras_log_priority_warning, f,a1,a2,a3,a4,a5)
+#define CWARN6(c, f,a1,a2,a3,a4,a5,a6) CLOG6(c, gras_log_priority_warning, f,a1,a2,a3,a4,a5,a6)
 
 #define CERROR0(c, f)                   CLOG0(c, gras_log_priority_error, f)
 #define CERROR1(c, f,a1)                CLOG1(c, gras_log_priority_error, f,a1)
@@ -446,7 +446,7 @@ extern gras_log_appender_t *gras_log_default_appender;
 #define INFO6(f,a1,a2,a3,a4,a5,a6) LOG6(gras_log_priority_info, f,a1,a2,a3,a4,a5,a6)
 
 /**
- * WARNING6:
+ * WARN6:
  * @f: the format string
  * @a1: first argument of the format
  * @a2: second argument of the format
@@ -457,18 +457,18 @@ extern gras_log_appender_t *gras_log_default_appender;
  *
  * Log something to the current default category under the warning priority.
  *
- * The macros WARNING0 ... WARNING5 naturally also exist, but are not listed here 
+ * The macros WARN0 ... WARN5 naturally also exist, but are not listed here 
  * for sake of clarity. They just differ in the number of arguments passed
  * along with the format string.
  */
 
-#define WARNING0(f)                   LOG0(gras_log_priority_warning, f)
-#define WARNING1(f,a1)                LOG1(gras_log_priority_warning, f,a1)
-#define WARNING2(f,a1,a2)             LOG2(gras_log_priority_warning, f,a1,a2)
-#define WARNING3(f,a1,a2,a3)          LOG3(gras_log_priority_warning, f,a1,a2,a3)
-#define WARNING4(f,a1,a2,a3,a4)       LOG4(gras_log_priority_warning, f,a1,a2,a3,a4)
-#define WARNING5(f,a1,a2,a3,a4,a5)    LOG5(gras_log_priority_warning, f,a1,a2,a3,a4,a5)
-#define WARNING6(f,a1,a2,a3,a4,a5,a6) LOG6(gras_log_priority_warning, f,a1,a2,a3,a4,a5,a6)
+#define WARN0(f)                   LOG0(gras_log_priority_warning, f)
+#define WARN1(f,a1)                LOG1(gras_log_priority_warning, f,a1)
+#define WARN2(f,a1,a2)             LOG2(gras_log_priority_warning, f,a1,a2)
+#define WARN3(f,a1,a2,a3)          LOG3(gras_log_priority_warning, f,a1,a2,a3)
+#define WARN4(f,a1,a2,a3,a4)       LOG4(gras_log_priority_warning, f,a1,a2,a3,a4)
+#define WARN5(f,a1,a2,a3,a4,a5)    LOG5(gras_log_priority_warning, f,a1,a2,a3,a4,a5)
+#define WARN6(f,a1,a2,a3,a4,a5,a6) LOG6(gras_log_priority_warning, f,a1,a2,a3,a4,a5,a6)
 
 /**
  * ERROR6:
index 598886d..9f62356 100644 (file)
@@ -1,21 +1,18 @@
 /* $Id$ */
 
-/* gras/messages.h - Public interface to GRAS messages                      */
+/* messaging - high level communication (send/receive messages)             */
+
+/* module's public interface exported to end user.                          */
 
 /* Authors: Martin Quinson                                                  */
-/* Copyright (C) 2003,2004 Martin Quinson.                                  */
+/* Copyright (C) 2003, 2004 Martin Quinson.                                 */
 
 /* This program is free software; you can redistribute it and/or modify it
    under the terms of the license (GNU LGPL) which comes with this package. */
 
 
-#ifndef GRAS_MSG_H
-#define GRAS_MSG_H
-
-#include <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 
@@ -167,71 +64,24 @@ void gras_msg_free(gras_msg_t *msg);
  *
  * If the callback accepts the message, it should free it after use.
  */
-
-typedef int (*gras_cb_t)(gras_msg_t *msg);
-
-/**
- * gras_cb_register:
- * @message: id of the concerned messages
- * @TTL: How many time should this callback be used
- * @cb: The callback.
- * @Returns: the error code (or no_error).
- *
- * Indicates a desire that the function #cb# be called whenever a
- * #message# message comes in.  
- * #TTL# is how many time this callback should be used. After that, this 
- * callback will be unregistred. If <0, the callback will never be unregistered.
- * (ie, it will be permanent)
- */
-gras_error_t
-gras_cb_register(gras_msgid_t message,
-                int TTL,
-                gras_cb_t cb);
-
-/**
- * gras_msg_handle:
- * @timeOut: How long to wait for incoming messages
- * @Returns: the error code (or no_error).
- *
- * Waits up to #timeOut# seconds to see if a message comes in; if so, calls the
- * registered listener for that message (see RegisterCallback()).
- */
+typedef int (*gras_cb_t)(gras_socket_t        *expeditor,
+                        gras_datadesc_type_t *payload_type,
+                        void                 *payload_data);
+gras_error_t gras_cb_register  (gras_msgtype_t *msgtype,
+                               gras_cb_t     cb);
+void         gras_cb_unregister(gras_msgtype_t *msgtype,
+                              gras_cb_t     cb);
+
+gras_error_t gras_msg_send(gras_socket_t  *sock,
+                          gras_msgtype_t *msgtype,
+                          void           *payload);
+gras_error_t gras_msg_wait(double                 timeout,    
+                          gras_msgtype_t        *msgt_want,
+                          gras_socket_t        **expeditor,
+                          void                 **payload);
 gras_error_t gras_msg_handle(double timeOut);
 
 
-/**
- * gras_msg_send:
- * @sd: Socket to write on
- * @msg: to send (build it with @gras_msg_new())
- * @freeDirective: if the msg passed as argument should be gras_msg_free'ed after sending.
- * @Returns: the error code (or no_error).
- *
- * Sends the message on the socket sd using an automatic and adaptative timeout.
- */
-
-gras_error_t
-gras_msg_send(gras_socket_t *sd,
-             gras_msg_t *msg,
-             e_gras_free_directive_t freeDirective);
-
-/**
- * gras_msg_wait:
- * @timeout: How long should we wait for this message.
- * @id: id of awaited msg
- * @message: where to store the message when it comes.
- * @Returns: the error code (or no_error).
- *
- * Waits for a message to come in over a given socket.
- *
- * Every message of another type received before the one waited will be queued
- * and used by subsequent call to this function or MsgHandle().
- */
-gras_error_t
-gras_msg_wait(double timeout,
-             gras_msgid_t id,
-             gras_msg_t **message);
-
-
 END_DECL
 
 #endif /* GRAS_MSG_H */
index d97da11..0dfb6fa 100644 (file)
@@ -16,7 +16,7 @@ typedef struct gras_module_ gras_module_t;
 typedef gras_module_t (*gras_module_new_fct_t)(int argc, char **argv);
 typedef int (*gras_module_finalize_fct_t)(void);
 
-void gras_init(int argc,char **argv);
-void gras_init_defaultlog(int argc,char **argv, const char *defaultlog);
+void gras_init(int *argc,char **argv);
+void gras_init_defaultlog(int *argc,char **argv, const char *defaultlog);
 void gras_exit(void);
 #endif /* _GRAS_MODULE_H */
index 856cd0f..0f300f5 100644 (file)
@@ -83,7 +83,7 @@ static const DataDescriptor msgResultDesc[] =
  * on localhost's stderr.
  */
 void
-grasRepportError (gras_socket_t *sock, gras_msgid_t id, int SeqCount,
+grasRepportError (gras_socket_t *sock, int id, int SeqCount,
                  const char *severeError,
                  gras_error_t errcode, const char* format,...);
 
index ad0a1bd..0a67d63 100644 (file)
@@ -22,6 +22,10 @@ gras_error_t gras_socket_server(unsigned short port,
                                /* OUT */ gras_socket_t **dst);
 void         gras_socket_close(gras_socket_t **sd);
 
+/* get information about socket */
+int   gras_socket_my_port  (gras_socket_t *sock);
+int   gras_socket_peer_port(gras_socket_t *sock);
+char *gras_socket_peer_name(gras_socket_t *sock);
 
 /* debuging functions */
 gras_error_t gras_socket_client_from_file(const char*path,
diff --git a/src/gras/Common/gras.c b/src/gras/Common/gras.c
deleted file mode 100644 (file)
index cfa9d34..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/* $Id$ */
-
-/* gras.c - common parts for the Grid Reality And Simulation                */
-
-/* Authors: Martin Quinson                                                  */
-/* Copyright (C) 2003 the OURAGAN project.                                  */
-
-/* This program is free software; you can redistribute it and/or modify it
-   under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "gras_private.h"
-
-/**************************************************************************/
-/**************************************************************************/
-/* Lock handling                                                          */
-/**************************************************************************/
-/**************************************************************************/
-
-#ifdef HAVE_LIBPTHREAD
-#include <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;
-}
-
diff --git a/src/gras/Common/gras_datadesc.c b/src/gras/Common/gras_datadesc.c
deleted file mode 100644 (file)
index 18e13a8..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/* $Id$ */
-
-/* gras_datadesc.c - manipulating datadescriptors                           */
-
-/* Authors: Martin Quinson                                                  */
-/* Copyright (C) 2003 the OURAGAN project.                                  */
-
-/* This program is free software; you can redistribute it and/or modify it
-   under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "gras_private.h"
-
-void *gras_datadesc_copy_data(const DataDescriptor *dd, unsigned int c, 
-                             void *data) {
-  size_t s=DataSize(dd,c,HOST_FORMAT);
-  void *res=malloc(s);
-  
-  if (!res) {
-    fprintf(stderr,"grasDataDescCpyData: malloc of %d bytes failed.\n",s);
-    return NULL;
-  }
-
-  memcpy(res,data,s);
-
-  return data; 
-}
-
-int gras_datadesc_cmp(const DataDescriptor *dd1, unsigned int c1,
-                     const DataDescriptor *dd2, unsigned int c2) {
-  unsigned int i;
-  int subcmp;
-
-  if (c1 != c2) 
-    return c1 < c2;
-
-  if (!dd1 && !dd2) return 0;
-  if (!dd1 || !dd2) return 1;
-
-  for (i=0;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);
-    }
-  }
-}
-
-
index 1154629..82a0391 100644 (file)
@@ -41,127 +41,99 @@ gras_datadesc_init(void) {
   /* 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));
 }
 
 /**
index 2c81d88..921d707 100644 (file)
 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 */
index 8eef386..00cdf32 100644 (file)
@@ -224,65 +224,14 @@ struct s_gras_datadesc_type {
  * 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 *
similarity index 54%
rename from src/gras/DataDesc/ddt_remote.c
rename to src/gras/DataDesc/ddt_convert.c
index b3c72cb..877d34f 100644 (file)
@@ -19,52 +19,6 @@ const gras_arch_sizes_t gras_arch_sizes[gras_arch_count] = {
   {"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:
index 1d871ce..61b371b 100644 (file)
 
 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;
@@ -114,15 +151,13 @@ void gras_dd_cat_field_free(void *f) {
 }
 
 /**
- * gras_ddt_new_struct:
+ * gras_datadesc_declare_struct:
  *
  * Create a new struct and give a pointer to it 
  */
 gras_error_t 
-gras_ddt_new_struct(const char                      *name,
-                   gras_datadesc_type_cb_void_t     pre,
-                   gras_datadesc_type_cb_void_t     post,
-                   gras_datadesc_type_t           **dst) {
+gras_datadesc_declare_struct(const char                      *name,
+                       gras_datadesc_type_t           **dst) {
 
   gras_error_t errcode;
   gras_datadesc_type_t *res;
@@ -140,23 +175,34 @@ gras_ddt_new_struct(const char                      *name,
   TRY(gras_dynar_new(&(res->category.struct_data.fields),
                     sizeof(gras_dd_cat_field_t*),
                     &gras_dd_cat_field_free));
-  res->pre                     = pre;
-  res->post                    = post;
 
   return no_error;
 }
 
+gras_error_t 
+gras_datadesc_declare_struct_append_name(gras_datadesc_type_t *struct_type,
+                                        const char           *name,
+                                        const char          *field_type_name){
+  gras_error_t errcode;
+  gras_datadesc_type_t *field_type;
+
+  errcode = gras_datadesc_by_name(field_type_name, &field_type);
+  if (errcode != no_error) {
+    WARN2("Got error '%s' while looking for '%s'",
+         gras_error_name(errcode), field_type_name);
+    return errcode;
+  }
+  return gras_datadesc_declare_struct_append(struct_type,name,field_type);
+}
 /**
- * gras_ddt_new_struct_append:
+ * gras_datadesc_declare_struct_append:
  *
  * Append a field to the struct
  */
 gras_error_t 
-gras_ddt_new_struct_append(gras_datadesc_type_t            *struct_type,
-                          const char                      *name,
-                          gras_datadesc_type_t            *field_type,
-                          gras_datadesc_type_cb_void_t     pre,
-                          gras_datadesc_type_cb_void_t     post) {
+gras_datadesc_declare_struct_append(gras_datadesc_type_t            *struct_type,
+                              const char                      *name,
+                              gras_datadesc_type_t            *field_type) {
 
   gras_error_t errcode;
   gras_dd_cat_field_t *field;
@@ -175,8 +221,8 @@ gras_ddt_new_struct_append(gras_datadesc_type_t            *struct_type,
     field->offset[arch] = aligned(struct_type->size[arch], field_type->alignment[arch]);
   }
   field->code   = field_type->code;
-  field->pre    = pre;
-  field->post   = post;
+  field->pre    = NULL;
+  field->post   = NULL;
   
   TRY(gras_dynar_push(struct_type->category.struct_data.fields, &field));
 
@@ -190,14 +236,13 @@ gras_ddt_new_struct_append(gras_datadesc_type_t            *struct_type,
 }
 
 /**
- * gras_ddt_new_union:
+ * gras_datadesc_declare_union:
  *
  * Create a new union and give a pointer to it 
  */
 gras_error_t 
-gras_ddt_new_union(const char                      *name,
+gras_datadesc_declare_union(const char                      *name,
                   gras_datadesc_type_cb_int_t      selector,
-                  gras_datadesc_type_cb_void_t     post,
                   gras_datadesc_type_t           **dst) {
 
   gras_error_t errcode;
@@ -220,23 +265,19 @@ gras_ddt_new_union(const char                      *name,
                     sizeof(gras_dd_cat_field_t*),
                     &gras_dd_cat_field_free));
   res->category.union_data.selector = selector;
-  res->pre                     = NULL;
-  res->post                    = post;
 
   return no_error;
 }
 
 /**
- * gras_ddt_new_union_append:
+ * gras_datadesc_declare_union_append:
  *
  * Append a field to the union
  */
 gras_error_t 
-gras_ddt_new_union_append(gras_datadesc_type_t            *union_type,
+gras_datadesc_declare_union_append(gras_datadesc_type_t            *union_type,
                          const char                      *name,
-                         gras_datadesc_type_t            *field_type,
-                         gras_datadesc_type_cb_void_t     pre,
-                         gras_datadesc_type_cb_void_t     post) {
+                         gras_datadesc_type_t            *field_type) {
 
   gras_error_t errcode;
   gras_dd_cat_field_t *field;
@@ -254,8 +295,8 @@ gras_ddt_new_union_append(gras_datadesc_type_t            *union_type,
     field->offset[arch] = 0; /* that's the purpose of union ;) */
   }
   field->code   = field_type->code;
-  field->pre    = pre;
-  field->post   = post;
+  field->pre    = NULL;
+  field->post   = NULL;
   
   TRY(gras_dynar_push(union_type->category.union_data.fields, &field));
 
@@ -269,24 +310,52 @@ gras_ddt_new_union_append(gras_datadesc_type_t            *union_type,
 }
 
 /**
- * gras_ddt_new_ref:
+ * gras_datadesc_declare_ref:
  *
- * Create a new ref and give a pointer to it 
+ * Create a new ref to a fixed type and give a pointer to it 
  */
 gras_error_t 
-gras_ddt_new_ref(const char                      *name,
-                gras_datadesc_type_t            *referenced_type,
-                gras_datadesc_type_cb_int_t      selector,
-                gras_datadesc_type_cb_void_t     post,
-                gras_datadesc_type_t           **dst) {
+gras_datadesc_declare_ref(const char             *name,
+                         gras_datadesc_type_t   *referenced_type,
+                         gras_datadesc_type_t  **dst) {
 
   gras_error_t errcode;
   gras_datadesc_type_t *res;
   gras_datadesc_type_t *pointer_type;
   int arch;
 
-  gras_assert0(selector || referenced_type,
-              "Attempt to create a generic reference without selector");
+  TRY(gras_ddt_new(name,dst));
+  res=*dst;
+
+  TRY(gras_datadesc_by_name("data pointer", &pointer_type));
+      
+  for (arch=0; 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;
@@ -301,43 +370,33 @@ gras_ddt_new_ref(const char                      *name,
 
   res->category_code           = e_gras_datadesc_type_cat_ref;
 
-  res->category.ref_data.code         = referenced_type ? referenced_type->code : -1;
+  res->category.ref_data.code     = -1;
   res->category.ref_data.selector = selector;
-  res->pre                     = NULL;
-  res->post                    = post;
 
   return no_error;
 }
 
 /**
- * gras_ddt_new_array:
+ * gras_datadesc_declare_array_fixed:
  *
  * Create a new array and give a pointer to it 
  */
 gras_error_t 
-gras_ddt_new_array(const char                      *name,
-                  gras_datadesc_type_t            *element_type,
-                  long int                         fixed_size,
-                  gras_datadesc_type_cb_int_t      dynamic_size,
-                  gras_datadesc_type_cb_void_t     post,
-                  gras_datadesc_type_t           **dst) {
+gras_datadesc_declare_array_fixed(const char                      *name,
+                        gras_datadesc_type_t            *element_type,
+                        long int                         fixed_size,
+                        gras_datadesc_type_t           **dst) {
 
   gras_error_t errcode;
   gras_datadesc_type_t *res;
   int arch;
 
-  gras_assert0(dynamic_size || fixed_size>0,
-              "Attempt to create a dynamic array without size discriminant");
-
   TRY(gras_ddt_new(name,dst));
   res=*dst;
 
+  gras_assert1(fixed_size > 0, "'%s' is a array of negative fixed size",name);
   for (arch=0; 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*/
   }
@@ -345,84 +404,64 @@ gras_ddt_new_array(const char                      *name,
 
   res->category.array_data.code         = element_type->code;
   res->category.array_data.fixed_size   = fixed_size;
-  res->category.array_data.dynamic_size = dynamic_size;
-
-  res->pre                     = NULL;
-  res->post                    = post;
+  res->category.array_data.dynamic_size = NULL;
 
   return no_error;
 }
-
 /**
- * gras_ddt_new_ignored:
- *
- * Create a new ignored field and give a pointer to it. 
+ * gras_datadesc_declare_array_dyn:
  *
- * If you give a default value, it will be copied away so that you can free your copy.
+ * Create a new array and give a pointer to it 
  */
 gras_error_t 
-gras_ddt_new_ignored(const char *name,
-                    void *default_value,
-                    void_f_pvoid_t   *free_func,
-                    long int                       size,
-                    long int                       alignment,
-                    gras_datadesc_type_cb_void_t     post,
-                    gras_datadesc_type_t           **dst) {
-  RAISE_UNIMPLEMENTED;
-  /*
+gras_datadesc_declare_array_dyn(const char                      *name,
+                      gras_datadesc_type_t            *element_type,
+                      gras_datadesc_type_cb_int_t      dynamic_size,
+                      gras_datadesc_type_t           **dst) {
+
   gras_error_t errcode;
   gras_datadesc_type_t *res;
+  int arch;
+
+  gras_assert1(dynamic_size,
+              "'%s' is a dynamic array without size discriminant",
+              name);
 
   TRY(gras_ddt_new(name,dst));
   res=*dst;
 
-  res->size            = size > 0?size:0;
-  res->alignment       = alignment;
-
-  if (size > 0) {
-    res->aligned_size  = aligned(size, alignment);
-  } else {
-    res->aligned_size  = 0;
-  }
-
-  if (default_value && res->size) {
-    res->category.ignored_data.default_value = malloc((size_t)size);
-    if (! (res->category.ignored_data.default_value) ) 
-      RAISE_MALLOC;
-    memcpy(res->category.ignored_data.default_value,
-          default_value, (size_t)size);
+  for (arch=0; 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;
 }
 
@@ -465,3 +504,22 @@ void gras_ddt_free(gras_datadesc_type_t **type) {
     }
   }
 }
+
+/**
+ * gras_datadesc_cb_set_pre:
+ *
+ * Add a pre-send callback to this datadexc
+ */
+void gras_datadesc_cb_set_pre (gras_datadesc_type_t         *type,
+                              gras_datadesc_type_cb_void_t  pre) {
+  type->pre = pre;
+}
+/**
+ * gras_datadesc_cb_set_post:
+ *
+ * Add a post-send callback to this datadexc
+ */
+void gras_datadesc_cb_set_post(gras_datadesc_type_t         *type,
+                              gras_datadesc_type_cb_void_t  post) {
+  type->post = post;
+}
diff --git a/src/gras/DataDesc/ddt_declare.c b/src/gras/DataDesc/ddt_declare.c
deleted file mode 100644 (file)
index 4001167..0000000
+++ /dev/null
@@ -1,181 +0,0 @@
-/* $Id$ */
-
-/* ddt_declare - user functions to create datatypes on locale machine       */
-
-/* Authors: Olivier Aumage, Martin Quinson                                  */
-/* Copyright (C) 2003, 2004 the GRAS posse.                                 */
-
-/* This program is free software; you can redistribute it and/or modify it
-   under the terms of the license (GNU LGPL) which comes with this package. */
-
-#include "DataDesc/datadesc_private.h"
-
-gras_error_t 
-gras_datadesc_declare_struct_cb(const char                   *name,
-                               gras_datadesc_type_cb_void_t  pre,
-                               gras_datadesc_type_cb_void_t  post,
-                               long int                     *code) {
-  gras_error_t errcode;
-  gras_datadesc_type_t *type;
-  TRY(gras_ddt_new_struct(name, pre, post, &type));
-  TRY(gras_ddt_register(type));
-  *code = type->code;
-  return no_error;
-}
-
-gras_error_t 
-gras_datadesc_declare_struct_add_name_cb(long int    struct_code,
-                                        const char *field_name,
-                                        const char *field_type_name,
-                                        gras_datadesc_type_cb_void_t     pre_cb,
-                                        gras_datadesc_type_cb_void_t     post_cb) {
-
-  gras_error_t errcode;
-  gras_datadesc_type_t *struct_type;
-  gras_datadesc_type_t *field_type;
-  
-  TRY(gras_datadesc_by_id(struct_code,&struct_type));
-  TRY(gras_datadesc_by_name(field_type_name,&field_type));
-
-  TRY(gras_ddt_new_struct_append(struct_type,
-                                field_name,  field_type,
-                                pre_cb,      post_cb));
-  
-  return no_error;
-}
-gras_error_t 
-gras_datadesc_declare_struct_add_code_cb(long int    struct_code,
-                                        const char *field_name,
-                                        long int    field_code,
-                                        gras_datadesc_type_cb_void_t     pre_cb,
-                                        gras_datadesc_type_cb_void_t     post_cb) {
-  gras_error_t errcode;
-  gras_datadesc_type_t *struct_type;
-  gras_datadesc_type_t *field_type;
-  
-  TRY(gras_datadesc_by_id(struct_code,&struct_type));
-  TRY(gras_datadesc_by_id(field_code, &field_type));
-
-  TRY(gras_ddt_new_struct_append(struct_type,
-                                field_name,  field_type,
-                                pre_cb,      post_cb));
-  
-  return no_error;
-}
-
-gras_error_t 
-gras_datadesc_declare_union_cb(const char                   *name,
-                              gras_datadesc_type_cb_int_t   field_count,
-                              gras_datadesc_type_cb_void_t  post,
-                              long int                     *code) {
-  gras_error_t errcode;
-  gras_datadesc_type_t *type;
-  TRY(gras_ddt_new_union(name, field_count, post, &type));
-  TRY(gras_ddt_register(type));
-  *code = type->code;
-  return no_error;
-}
-
-gras_error_t 
-gras_datadesc_declare_union_add_name_cb(long int                      union_code,
-                                       const char                   *field_name,
-                                       const char                   *field_type_name,
-                                       gras_datadesc_type_cb_void_t  pre_cb,
-                                       gras_datadesc_type_cb_void_t  post_cb) {
-  gras_error_t errcode;
-  gras_datadesc_type_t *union_type;
-  gras_datadesc_type_t *field_type;
-  
-  TRY(gras_datadesc_by_id  (union_code,      &union_type));
-  TRY(gras_datadesc_by_name(field_type_name, &field_type));
-
-  TRY(gras_ddt_new_union_append(union_type,
-                               field_name,  field_type,
-                               pre_cb,      post_cb));
-  
-  return no_error;
-}
-gras_error_t 
-gras_datadesc_declare_union_add_code_cb(long int                      union_code,
-                                       const char                   *field_name,
-                                       long int                      field_code,
-                                       gras_datadesc_type_cb_void_t  pre_cb,
-                                       gras_datadesc_type_cb_void_t  post_cb) {
-  gras_error_t errcode;
-  gras_datadesc_type_t *union_type;
-  gras_datadesc_type_t *field_type;
-  
-  TRY(gras_datadesc_by_id(union_code, &union_type));
-  TRY(gras_datadesc_by_id(field_code, &field_type));
-
-  TRY(gras_ddt_new_union_append(union_type,
-                               field_name,  field_type,
-                               pre_cb,      post_cb));
-  
-  return no_error;
-}
-
-gras_error_t
-gras_datadesc_declare_ref_cb(const char                      *name,
-                            gras_datadesc_type_t            *referenced_type,
-                            gras_datadesc_type_cb_int_t      discriminant,
-                            gras_datadesc_type_cb_void_t     post,
-                            long int                        *code){
-  gras_error_t errcode;
-  gras_datadesc_type_t *type;
-  TRY(gras_ddt_new_ref(name, referenced_type,discriminant,post, &type));
-  TRY(gras_ddt_register(type));
-  *code = type->code;
-  return no_error;
-}
-
-gras_error_t 
-gras_datadesc_declare_array_cb(const char                      *name,
-                              gras_datadesc_type_t            *element_type,
-                              long int                         fixed_size,
-                              gras_datadesc_type_cb_int_t      dynamic_size,
-                              gras_datadesc_type_cb_void_t     post,
-                              long int                        *code){
-  gras_error_t errcode;
-  gras_datadesc_type_t *type;
-  TRY(gras_ddt_new_array(name, element_type, fixed_size, dynamic_size, post, &type));
-  TRY(gras_ddt_register(type));
-  *code = type->code;
-  return no_error;
-}
-
-/**
- * gras_datadesc_parse:
- *
- * Parse a C type declaration, and declare locally the corresponding type description
- */
-gras_error_t
-gras_datadesc_parse(const char *name,
-                   const char *definition,
-                   long int   *code) {
-  gras_error_t errcode;
-  gras_datadesc_type_t *type;
-  TRY(gras_ddt_new_parse(name,definition,&type));
-  TRY(gras_ddt_register( type));
-  *code = type->code;
-  return no_error;
-}
-
-/**
- * gras_datadesc_parse:
- *
- * Parse a NWS type declaration, and declare locally the corresponding type description
- */
-gras_error_t
-gras_datadesc_from_nws(const char           *name,
-                      const DataDescriptor *desc,
-                      size_t                howmany,
-                      long int             *code) {
-
-  gras_error_t errcode;
-  gras_datadesc_type_t *type;
-  TRY(gras_ddt_new_from_nws(name,desc,howmany,&type));
-  TRY(gras_ddt_register(type));
-  *code = type->code;
-  return no_error;
-}
similarity index 97%
rename from src/gras/DataDesc/ddt_use.c
rename to src/gras/DataDesc/ddt_exchange.c
index ebad127..41b3ac0 100644 (file)
@@ -1,6 +1,6 @@
 /* $Id$ */
 
-/* ddt_use - use of datatypes structs (public)                              */
+/* ddt_exchange - send/recv data described                                  */
 
 /* Authors: Olivier Aumage, Martin Quinson                                  */
 /* Copyright (C) 2003, 2004 the GRAS posse.                                 */
@@ -10,7 +10,7 @@
 
 #include "DataDesc/datadesc_private.h"
 
-GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(use,DataDesc);
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(exchange,DataDesc);
 
 static const char *gras_datadesc_cat_names[9] = { 
   "undefined", 
@@ -129,23 +129,6 @@ gras_dd_alloc_ref(gras_dict_t *refs,
   return no_error;
 }
 
-/**
- * gras_datadesc_get_id_from_name:
- * Returns: -1 in case of error.
- *
- * Retrieve the ID of a previously declared datatype from its name.
- */
-long int
-gras_datadesc_get_id_from_name(const char *name) {
-  gras_error_t errcode;
-  gras_datadesc_type_t *type;
-
-  errcode = gras_datadesc_by_name(name,&type);
-  if (errcode != no_error)
-    return -1;
-  return type->code;
-}
-
 /**
  * gras_datadesc_type_cmp:
  *
@@ -685,6 +668,8 @@ gras_datadesc_recv(gras_socket_t *sock,
 
   TRY(gras_dict_new(&refs));
   TRY(gras_dd_cbps_new(&state));
+  if (!dst)
+    CRITICAL0("Cannot receive data into a NULL pointer!");
   if (*dst) 
     VERB0("'*dst' not NULL in datadesc_recv. Data to be copied there without malloc");
 
index edc7ff4..270ac05 100644 (file)
@@ -12,7 +12,6 @@ lib_LIBRARIES= libgrasrl.a libgrassg.a
 
 #                     Core/dict_multi.c
 #  Common/gras.c      Common/gras_datadesc.c        Common/gras_msg.c            
-#   Messaging/messaging.c                       
 #   Messaging/datadesc_simple.c                 
 #   Transport/transport_sg.c 
 
@@ -31,11 +30,16 @@ COMMON_S=\
   Transport/transport_plugin_tcp.c            \
   Transport/transport_plugin_sg.c             \
   \
-  DataDesc/ddt_create.c          DataDesc/ddt_declare.c \
-  DataDesc/ddt_remote.c          DataDesc/ddt_use.c     \
-  DataDesc/cbps.c                DataDesc/datadesc.c    \
-  DataDesc/datadesc_interface.h  DataDesc/datadesc_private.h 
+  DataDesc/ddt_create.c          \
+  DataDesc/ddt_convert.c         DataDesc/ddt_exchange.c     \
+  DataDesc/cbps.c                DataDesc/datadesc.c         \
+  DataDesc/datadesc_interface.h  DataDesc/datadesc_private.h \
+  \
+  Msg/msg.c   Msg/msg_interface.h   Msg/msg_private.h \
+  \
+  Virtu/process.c
 
+# DataDesc/ddt_declare.c 
 
 #  DataDesc/datadesc.c                               \
 #  DataDesc/tools.c                                  \
diff --git a/src/gras/Msg/msg.c b/src/gras/Msg/msg.c
new file mode 100644 (file)
index 0000000..4cb483b
--- /dev/null
@@ -0,0 +1,438 @@
+/* $Id$ */
+
+/* messaging - Function related to messaging (code shared between RL and SG)*/
+
+/* Authors: Martin Quinson                                                  */
+/* Copyright (C) 2003 the OURAGAN project.                                  */
+
+/* This program is free software; you can redistribute it and/or modify it
+   under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "Msg/msg_private.h"
+
+GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(msg,GRAS);
+
+gras_set_t *_gras_msgtype_set = NULL;
+static char GRAS_header[6];
+static char *make_namev(const char *name, short int ver);
+
+/**
+ * gras_msg_init:
+ *
+ * Initialize this submodule.
+ */
+void gras_msg_init(void) {
+  gras_error_t errcode;
+  
+  /* only initialize once */
+  if (_gras_msgtype_set != NULL)
+    return;
+
+  VERB0("Initializing Msg");
+  
+  TRYFAIL(gras_set_new(&_gras_msgtype_set));
+
+  memcpy(GRAS_header,"GRAS", 4);
+  GRAS_header[4]=GRAS_PROTOCOL_VERSION;
+  GRAS_header[5]=(char)GRAS_THISARCH;
+}
+
+/**
+ * gras_msg_exit:
+ *
+ * Finalize the msg module
+ **/
+void
+gras_msg_exit(void) {
+  VERB0("Exiting Msg");
+  gras_set_free(&_gras_msgtype_set);
+  _gras_msgtype_set = NULL;
+}
+
+/**
+ * gras_msgtype_free:
+ *
+ * Reclamed memory
+ */
+void gras_msgtype_free(void *t) {
+  gras_msgtype_t *msgtype=(gras_msgtype_t *)t;
+  if (msgtype) {
+    free(msgtype->name);
+    free(msgtype);
+  }
+}
+
+/**
+ * make_namev:
+ *
+ * Returns the versionned name of the message. If the version is 0, that's 
+ * the name unchanged. Pay attention to this before free'ing the result.
+ */
+static char *make_namev(const char *name, short int ver) {
+  char *namev=malloc(strlen(name)+2+3+1);
+
+  if (!ver)
+    return (char *)name;
+
+  if (namev) {
+      sprintf(namev,"%s_v%d",name,ver);
+  }
+  return namev;
+}
+
+/**
+ * gras_msgtype_declare:
+ * @name: name as it should be used for logging messages (must be uniq)
+ * @payload: datadescription of the payload
+ *
+ * Registers a message to the GRAS mecanism.
+ */
+gras_error_t
+gras_msgtype_declare(const char            *name,
+                    gras_datadesc_type_t  *payload,
+                    gras_msgtype_t       **dst) {
+  return gras_msgtype_declare_v(name, 0, payload, dst);
+}
+
+/**
+ * gras_msgtype_declare_v:
+ * @name: name as it should be used for logging messages (must be uniq)
+ * @version: something like versionning symbol
+ * @payload: datadescription of the payload
+ *
+ * Registers a message to the GRAS mecanism. Use this version instead of 
+ * gras_msgtype_declare when you change the semantic or syntax of a message and
+ * want your programs to be able to deal with both versions. Internally, each
+ * will be handled as an independent message type, so you can register 
+ * differents for each of them.
+ */
+gras_error_t
+gras_msgtype_declare_v(const char            *name,
+                      short int              version,
+                      gras_datadesc_type_t  *payload,
+                      gras_msgtype_t       **dst) {
+  gras_error_t    errcode;
+  gras_msgtype_t *msgtype;
+  char *namev=make_namev(name,version);
+  
+  if (!namev)
+    RAISE_MALLOC;
+
+  errcode = gras_set_get_by_name(_gras_msgtype_set,
+                                namev,(gras_set_elm_t**)msgtype);
+  if (errcode == mismatch_error) {
+    /* create type */
+    if (! (msgtype = malloc(sizeof(gras_msgtype_t))) ) 
+      RAISE_MALLOC;
+
+    msgtype->name = (namev == name ? strdup(name) : namev);
+    msgtype->name_len = strlen(namev);
+    msgtype->version = version;
+    msgtype->ctn_type = payload;
+
+    TRY(gras_set_add(_gras_msgtype_set, (gras_set_elm_t*)msgtype,
+                    &gras_msgtype_free));
+
+    DEBUG2("Register version %d of message '%s'.", version, name);
+  } else if (errcode == no_error) { /* found */ 
+    if (namev != name)
+      free(namev);
+
+    gras_assert1(!gras_datadesc_type_cmp(msgtype->ctn_type, payload),
+                "Message %s registred again with a different payload",
+                namev);
+  } else {
+    if (namev != name)
+      free(namev);
+    return errcode; /* Error is set lookup */
+  }
+
+  return no_error;
+}
+
+/**
+ * gras_msgtype_by_name:
+ *
+ * Retrieve a datatype description from its name
+ */
+gras_error_t 
+gras_msgtype_by_name (const char     *name,
+                     gras_msgtype_t **dst) {
+  return gras_msgtype_by_namev(name,0,dst);
+}
+/**
+ * gras_msgtype_by_namev:
+ *
+ * Retrieve a datatype description from its name and version
+ */
+gras_error_t
+gras_msgtype_by_namev(const char      *name,
+                     short int        version,
+                     gras_msgtype_t **dst) {
+
+  gras_error_t errcode;
+  char *namev = make_namev(name,version); 
+
+  TRY(gras_set_get_by_name(_gras_msgtype_set, namev,
+                          (gras_set_elm_t**)dst));
+  if (name != namev) 
+    free(namev);
+
+  return no_error;
+}
+
+/**
+ * gras_msg_send:
+ *
+ * Send the given message on the given socket 
+ */
+gras_error_t
+gras_msg_send(gras_socket_t  *sock,
+             gras_msgtype_t *msgtype,
+             void           *payload) {
+
+  gras_error_t errcode;
+  static gras_datadesc_type_t *string_type=NULL;
+  if (!string_type)
+    TRY(gras_datadesc_by_name("string", &string_type));
+  
+  TRY(gras_trp_chunk_send(sock, GRAS_header, 6));
+
+  TRY(gras_datadesc_send(sock, string_type,       msgtype->name));
+  TRY(gras_datadesc_send(sock, msgtype->ctn_type, payload));
+
+  return no_error;
+}
+/**
+ * gras_msg_recv:
+ *
+ * receive the next message on the given socket (which should be dropped 
+ * when the function returns an error)
+ */
+gras_error_t
+gras_msg_recv(gras_socket_t   *sock,
+             gras_msgtype_t **msgtype,
+             void           **payload) {
+  
+  gras_error_t errcode;
+  static gras_datadesc_type_t *string_type=NULL;
+  char header[6];
+  int cpt;
+  int r_arch;
+  char *msg_name;
+
+  if (!string_type)
+    TRY(gras_datadesc_by_name("string", &string_type));
+  
+  TRY(gras_trp_chunk_recv(sock, header, 6));
+  for (cpt=0; cpt<4; cpt++)
+    if (header[cpt] != GRAS_header[cpt])
+      RAISE0(mismatch_error,"Incoming bytes do not look like a GRAS message");
+  if (header[4] != GRAS_header[4]) 
+    RAISE2(mismatch_error,"GRAS protocol mismatch (got %d, use %d)",
+          (int)header[4], (int)GRAS_header[4]);
+  r_arch = (int)header[5];
+
+  TRY(gras_datadesc_recv(sock, string_type, r_arch,(void**) &msg_name));
+  TRY(gras_set_get_by_name(_gras_msgtype_set,
+                          msg_name,(gras_set_elm_t**)msgtype));
+  TRY(gras_datadesc_recv(sock, (*msgtype)->ctn_type, r_arch, payload));
+
+  return no_error;
+}
+
+/**
+ * gras_msg_wait:
+ * @timeout: How long should we wait for this message.
+ * @id: id of awaited msg
+ * @Returns: the error code (or no_error).
+ *
+ * Waits for a message to come in over a given socket.
+ *
+ * Every message of another type received before the one waited will be queued
+ * and used by subsequent call to this function or MsgHandle().
+ */
+gras_error_t
+gras_msg_wait(double                 timeout,    
+             gras_msgtype_t        *msgt_want,
+             gras_socket_t        **expeditor,
+             void                 **payload) {
+
+  gras_msgtype_t *msgt_got;
+  gras_error_t errcode;
+  double start, now;
+  gras_procdata_t *pd=gras_procdata_get();
+  int cpt;
+  gras_msg_t msg;
+  
+  *expeditor = NULL;
+  *payload   = NULL;
+
+  VERB1("Waiting for message %s",msgt_want->name);
+
+  start = now = gras_time();
+
+  gras_dynar_foreach(pd->msg_queue,cpt,msg){
+    if (msg.type->code == msgt_want->code) {
+      *expeditor = msg.expeditor;
+      *payload   = msg.payload;
+      gras_dynar_cursor_rm(pd->msg_queue, &cpt);
+      VERB0("Waited message was queued");
+      return no_error;
+    }
+  }
+
+  while (1) {
+    TRY(gras_trp_select(timeout - now + start, expeditor));
+    TRY(gras_msg_recv(*expeditor, &msgt_got, payload));
+    if (msgt_got->code == msgt_want->code) {
+      VERB0("Got waited message");
+      return no_error;
+    }
+
+    /* not expected msg type. Queue it for later */
+    msg.expeditor = *expeditor;
+    msg.type      =  msgt_got;
+    msg.payload   = *payload;
+    TRY(gras_dynar_push(pd->msg_queue,&msg));
+    
+    now=gras_time();
+    if (now - start + 0.001 < timeout) {
+      RAISE1(timeout_error,"Timeout while waiting for msg %s",msgt_want->name);
+    }
+  }
+
+  RAISE_IMPOSSIBLE;
+}
+
+/**
+ * gras_msg_handle:
+ * @timeOut: How long to wait for incoming messages
+ * @Returns: the error code (or no_error).
+ *
+ * Waits up to #timeOut# seconds to see if a message comes in; if so, calls the
+ * registered listener for that message (see RegisterCallback()).
+ */
+gras_error_t 
+gras_msg_handle(double timeOut) {
+  
+  gras_error_t    errcode;
+  int             cpt;
+
+  gras_msg_t      msg;
+  gras_socket_t  *expeditor;
+  void           *payload;
+  gras_msgtype_t *msgtype;
+
+  gras_procdata_t*pd=gras_procdata_get();
+  gras_cblist_t  *list;
+  gras_cb_t       cb;
+
+
+
+  VERB1("Handling message within the next %.2s",timeOut);
+  
+  /* get a message (from the queue or from the net) */
+  if (gras_dynar_length(pd->msg_queue)) {
+    gras_dynar_shift(pd->msg_queue,&msg);
+    expeditor = msg.expeditor;
+    msgtype   = msg.type;
+    payload   = msg.payload;
+    
+  } else {
+    TRY(gras_trp_select(timeOut, &expeditor));
+    TRY(gras_msg_recv(expeditor, &msgtype, &payload));
+  }
+      
+  /* handle it */
+  gras_dynar_foreach(pd->cbl_list,cpt,list) {
+    if (list->id == msgtype->code) {
+      break;
+    } else {
+      list=NULL;
+    }
+  }
+  if (!list) {
+    INFO1("Unexpected message '%s' ignored", msgtype->name);
+    WARN0("FIXME: gras_datadesc_free not implemented => leaking the payload");
+    return no_error;
+  }
+  
+  gras_dynar_foreach(list->cbs,cpt,cb) { 
+    if (cb(expeditor,msgtype->ctn_type,payload)) {
+      /* cb handled the message */
+      return no_error;
+    }
+  }
+
+  INFO1("Message '%s' refused by all registered callbacks", msgtype->name);
+  WARN0("FIXME: gras_datadesc_free not implemented => leaking the payload");
+  return mismatch_error;
+}
+
+gras_error_t
+gras_cb_register(gras_msgtype_t *msgtype,
+                gras_cb_t cb) {
+  gras_error_t errcode;
+  gras_procdata_t *pd=gras_procdata_get();
+  gras_cblist_t *list;
+  int cpt;
+
+  /* search the list of cb for this message on this host (creating if NULL) */
+  gras_dynar_foreach(pd->cbl_list,cpt,list) {
+    if (list->id == msgtype->code) {
+      break;
+    } else {
+      list=NULL;
+    }
+  }
+  if (!list) {
+    /* First cb? Create room */
+    list = malloc(sizeof(gras_cblist_t));
+    if (!list)
+      RAISE_MALLOC;
+
+    list->id = msgtype->code;
+    TRY(gras_dynar_new(&(list->cbs), sizeof(gras_cb_t), NULL));
+    TRY(gras_dynar_push(pd->cbl_list,&list));
+  }
+
+  /* Insert the new one into the set */
+  TRY(gras_dynar_insert_at(list->cbs,0,cb));
+
+  return no_error;
+}
+
+void
+gras_cb_unregister(gras_msgtype_t *msgtype,
+                  gras_cb_t cb) {
+
+  gras_procdata_t *pd=gras_procdata_get();
+  gras_cblist_t *list;
+  gras_cb_t cb_cpt;
+  int cpt;
+  int found = 0;
+
+  /* search the list of cb for this message on this host */
+  gras_dynar_foreach(pd->cbl_list,cpt,list) {
+    if (list->id == msgtype->code) {
+      break;
+    } else {
+      list=NULL;
+    }
+  }
+
+  /* Remove it from the set */
+  if (list) {
+    gras_dynar_foreach(list->cbs,cpt,cb_cpt) {
+      if (cb == cb_cpt) {
+       gras_dynar_cursor_rm(list->cbs, &cpt);
+       found = 1;
+      }
+    }
+  }
+  if (!found)
+    VERB1("Ignoring removal of unexisting callback to msg id %d",
+         msgtype->code);
+}
diff --git a/src/gras/Msg/msg_interface.h b/src/gras/Msg/msg_interface.h
new file mode 100644 (file)
index 0000000..c04cb16
--- /dev/null
@@ -0,0 +1,35 @@
+/* $Id$ */
+
+/* messaging - high level communication (send/receive messages)             */
+
+/* module's public interface exported within GRAS, but not to end user.     */
+
+/* Authors: Martin Quinson                                                  */
+/* Copyright (C) 2003, 2004 Martin Quinson.                                 */
+
+/* This program is free software; you can redistribute it and/or modify it
+   under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef GRAS_MSG_INTERFACE_H
+#define GRAS_MSG_INTERFACE_H
+
+void gras_msg_init(void);
+void gras_msg_exit(void);
+
+
+/* gras_msg_t is dereferenced to be stored in procdata, living in Virtu */
+typedef struct {
+  gras_socket_t  *expeditor;
+  gras_msgtype_t *type;
+  void           *payload;
+} gras_msg_t;
+
+gras_error_t gras_msg_send_namev(gras_socket_t *sock, 
+                                const char    *namev, 
+                                void          *payload);
+
+#define GRAS_PROTOCOL_VERSION '\0';
+
+typedef struct s_gras_cblist gras_cblist_t;
+
+#endif  /* GRAS_MSG_INTERFACE_H */
diff --git a/src/gras/Msg/msg_private.h b/src/gras/Msg/msg_private.h
new file mode 100644 (file)
index 0000000..b233e1c
--- /dev/null
@@ -0,0 +1,56 @@
+/* $Id$ */
+
+/* messaging - high level communication (send/receive messages)             */
+
+/* module's private interface masked even to other parts of GRAS.           */
+
+/* Authors: Martin Quinson                                                  */
+/* Copyright (C) 2003, 2004 Martin Quinson.                                 */
+
+/* This program is free software; you can redistribute it and/or modify it
+   under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef GRAS_MESSAGE_PRIVATE_H
+#define GRAS_MESSAGE_PRIVATE_H
+
+#include "gras_private.h"
+#include "Msg/msg_interface.h"
+
+/**
+ * gras_msgtype_t:
+ *
+ * Message type descriptor. There one of these for each registered version.
+ */
+struct s_gras_msgtype {
+  /* headers for the data set */
+  unsigned int   code;
+  char          *name;
+  unsigned int   name_len;
+        
+  /* payload */
+  short int version;
+  gras_datadesc_type_t *ctn_type;
+};
+
+extern gras_set_t *_gras_msgtype_set; /* of gras_msgtype_t */
+void gras_msgtype_free(void *msgtype);
+
+
+gras_error_t gras_msg_recv(gras_socket_t   *sock,
+                          gras_msgtype_t **msgtype,
+                          void           **payload);
+
+
+/**
+ * gras_cblist_t:
+ *
+ * association between msg ID and cb list for a given process
+ */
+struct s_gras_cblist {
+  long int id;
+  gras_dynar_t *cbs; /* of gras_msg_cb_t */
+};
+
+void gras_cblist_free(void *cbl);
+
+#endif  /* GRAS_MESSAGE_PRIVATE_H */
index 5069c42..279e4b3 100644 (file)
@@ -72,7 +72,7 @@ gras_trp_select(double timeout,
 
     /* we cannot have more than FD_SETSIZE sockets */
     if (++max_fds > FD_SETSIZE) {
-      WARNING0("too many open sockets.");
+      WARN0("too many open sockets.");
       done = 0;
       break;
     }
@@ -139,7 +139,7 @@ gras_trp_select(double timeout,
 
         recvd = recv(sock_iter->sd, &lookahead, 1, MSG_PEEK);
         if (recvd < 0) {
-          WARNING2("socket %d failed: %s", sock_iter->sd, strerror(errno));
+          WARN2("socket %d failed: %s", sock_iter->sd, strerror(errno));
           /* done with this socket */
           gras_socket_close(&sock_iter);
           cursor--;
index 4b5d45a..45c0531 100644 (file)
@@ -9,7 +9,6 @@
    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"
 
@@ -213,7 +212,7 @@ void gras_socket_close(gras_socket_t **sock) {
        return;
       }
     }
-    WARNING0("Ignoring request to free an unknown socket");
+    WARN0("Ignoring request to free an unknown socket");
   }
 }
 
@@ -259,3 +258,12 @@ gras_trp_plugin_get_by_name(const char *name,
   return gras_dict_retrieve(_gras_trp_plugins,name,(void**)dst);
 }
 
+int   gras_socket_my_port  (gras_socket_t *sock) {
+  return sock->port;
+}
+int   gras_socket_peer_port(gras_socket_t *sock) {
+  return sock->peer_port;
+}
+char *gras_socket_peer_name(gras_socket_t *sock) {
+  return sock->peer_name;
+}
index bb3a4c3..8bbb942 100644 (file)
@@ -203,7 +203,7 @@ void gras_trp_file_close(gras_socket_t *sock){
 
     /* close the socket */
     if(close(sock->sd) < 0) {
-      WARNING2("error while closing file %d: %s", 
+      WARN2("error while closing file %d: %s", 
               sock->sd, strerror(errno));
     }
   }
index 3d0cd16..8700947 100644 (file)
@@ -221,7 +221,7 @@ gras_trp_tcp_socket_accept(gras_socket_t  *sock,
   
     if (setsockopt(sd, SOL_SOCKET, SO_KEEPALIVE, (char *)&i, s) 
        || setsockopt(sd, TcpProtoNumber(), TCP_NODELAY, (char *)&i, s)) {
-      WARNING0("setsockopt failed, cannot condition the accepted socket");
+      WARN0("setsockopt failed, cannot condition the accepted socket");
     }
  
      /* FIXME: bufSize removed until we can have optionsets 
@@ -292,7 +292,7 @@ void gras_trp_tcp_socket_close(gras_socket_t *sock){
 
   /* close the socket */
   if(close(sock->sd) < 0) {
-    WARNING3("error while closing tcp socket %d: %d (%s)\n", 
+    WARN3("error while closing tcp socket %d: %d (%s)\n", 
             sock->sd, errno, strerror(errno));
   }
 }
diff --git a/src/gras/Virtu/process.c b/src/gras/Virtu/process.c
new file mode 100644 (file)
index 0000000..93475bf
--- /dev/null
@@ -0,0 +1,39 @@
+/* $Id$ */
+
+/* process - GRAS process handling (common code for RL and SG)              */
+
+/* Authors: Martin Quinson                                                  */
+/* Copyright (C) 2003,2004 da GRAS posse.                                   */
+
+/* This program is free software; you can redistribute it and/or modify it
+   under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "gras_private.h"
+#include "Virtu/virtu_interface.h"
+
+
+/* **************************************************************************
+ * Process data
+ * **************************************************************************/
+void *gras_userdata_get(void) {
+  gras_procdata_t *pd=gras_procdata_get();
+  return pd->userdata;
+}
+
+void *gras_userdata_set(void *ud) {
+  gras_procdata_t *pd=gras_procdata_get();
+
+  pd->userdata = ud;
+
+  return pd->userdata;
+}
+
+gras_error_t
+gras_procdata_init() {
+  gras_error_t errcode;
+  gras_procdata_t *pd=gras_procdata_get();
+  pd->userdata = NULL;
+  TRY(gras_dynar_new(  &(pd->msg_queue), sizeof(gras_msg_t),      NULL  ));
+  TRY(gras_dynar_new(  &(pd->cbl_list),  sizeof(gras_cblist_t *), NULL  ));
+  return no_error;
+}
index 10066a6..359c220 100644 (file)
 GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(process,GRAS);
                              
 /* globals */
-static gras_process_data_t *_gras_process_data;
+static gras_procdata_t *_gras_procdata = NULL;
 
 gras_error_t gras_process_init() {
-  //  gras_error_t errcode;
+  gras_error_t errcode;
 
-  if (!(_gras_process_data=(gras_process_data_t *)malloc(sizeof(gras_process_data_t))))
+  if (!(_gras_procdata=(gras_procdata_t *)malloc(sizeof(gras_procdata_t))))
     RAISE_MALLOC;
 
-  WARNING0("Implement message queue");
-  /*
-  TRY(gras_dynar_new(  &(_gras_process_data->msg_queue)  ));
-  TRY(gras_dynar_new(  &(_gras_process_data->cbl_list)  ));
-  */
-
-  _gras_process_data->userdata = NULL;
+  TRY(gras_procdata_init());
   return no_error;
 }
 gras_error_t gras_process_exit() {
-  WARNING0("FIXME: not implemented (=> leaking on exit :)");
+  WARN0("FIXME: not implemented (=> leaking on exit :)");
   return no_error;
 }
 
@@ -39,11 +33,8 @@ gras_error_t gras_process_exit() {
  * Process data
  * **************************************************************************/
 
-void *gras_userdata_get(void) {
-  return _gras_process_data->userdata;
-}
+gras_procdata_t *gras_procdata_get(void) {
+  gras_assert0(_gras_procdata,"Run gras_process_init!");
 
-void *gras_userdata_set(void *ud) {
-  _gras_process_data->userdata = ud;
-  return ud;
+  return _gras_procdata;
 }
index 243093b..ae0056d 100644 (file)
@@ -14,25 +14,18 @@ GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(process,GRAS);
 
 gras_error_t
 gras_process_init() {
+  gras_error_t errcode;
   gras_hostdata_t *hd=(gras_hostdata_t *)MSG_host_get_data(MSG_host_self());
-  gras_process_data_t *pd;
+  gras_procdata_t *pd;
   int i;
   
-  if (!(pd=(gras_process_data_t *)malloc(sizeof(gras_process_data_t)))) 
+  if (!(pd=(gras_procdata_t *)malloc(sizeof(gras_procdata_t)))) 
     RAISE_MALLOC;
 
-  WARNING0("Implement msg queue");
-  /*
-  pd->grasMsgQueueLen=0;
-  pd->grasMsgQueue = NULL;
-
-  pd->grasCblListLen = 0;
-  pd->grasCblList = NULL;
-  */
-
   if (MSG_process_set_data(MSG_process_self(),(void*)pd) != MSG_OK) {
     return unknown_error;
   }
+  TRY(gras_procdata_init());
 
   if (!hd) {
     if (!(hd=(gras_hostdata_t *)malloc(sizeof(gras_hostdata_t)))) 
@@ -79,7 +72,7 @@ gras_process_init() {
 gras_error_t
 gras_process_exit() {
   gras_hostdata_t *hd=(gras_hostdata_t *)MSG_host_get_data(MSG_host_self());
-  gras_process_data_t *pd=(gras_process_data_t *)MSG_process_get_data(MSG_process_self());
+  gras_procdata_t *pd=(gras_procdata_t *)MSG_process_get_data(MSG_process_self());
   int myPID=MSG_process_self_PID();
   int i;
 
@@ -88,12 +81,8 @@ gras_process_exit() {
   INFO2("GRAS: Finalizing process '%s' (%d)",
        MSG_process_get_name(MSG_process_self()),MSG_process_self_PID());
 
-  WARNING0("Implement msg queue");
-  /*
-  if (pd->grasMsgQueueLen) {
-    fprintf(stderr,"GRAS: Warning: process %d terminated, but some queued messages where not handled\n",MSG_process_self_PID());
-  }
-  */
+  if (gras_dynar_length(pd->msg_queue))
+    WARN1("process %d terminated, but some queued messages where not handled",MSG_process_self_PID());
 
   for (i=0; i< GRAS_MAX_CHANNEL; i++)
     if (myPID == hd->proc[i])
@@ -115,20 +104,11 @@ gras_process_exit() {
  * Process data
  * **************************************************************************/
 
-void *gras_userdata_get(void) {
-  gras_process_data_t *pd=(gras_process_data_t *)MSG_process_get_data(MSG_process_self());
+gras_procdata_t *gras_procdata_get(void) {
+  gras_procdata_t *pd=(gras_procdata_t *)MSG_process_get_data(MSG_process_self());
 
   gras_assert0(pd,"Run gras_process_init!");
 
-  return pd->userdata;
+  return pd;
 }
 
-void *gras_userdata_set(void *ud) {
-  gras_process_data_t *pd=(gras_process_data_t *)MSG_process_get_data(MSG_process_self());
-
-  gras_assert0(pd,"Run gras_process_init!");
-
-  pd->userdata = ud;
-
-  return pd->userdata;
-}
index f4fd3f9..170e999 100644 (file)
@@ -19,8 +19,7 @@
  * Data for each process 
  */
 typedef struct {
-  /* queue of messages which where received but not wanted in msgWait, and therefore
-     temporarly queued until the next msgHandle */
+  /*queue of msgs storing the ones got while msg_wait'ing for something else */
   gras_dynar_t *msg_queue; /* elm type: gras_msg_t */
 
   /* registered callbacks for each message */
@@ -34,7 +33,9 @@ typedef struct {
 
   /* globals of the process */
   void *userdata;               
-} gras_process_data_t;
-
+} gras_procdata_t;
 
+/* FIXME: mv to _private? */
+gras_procdata_t *gras_procdata_get(void);
+gras_error_t gras_procdata_init(void);
 #endif  /* GRAS_VIRTU_INTERFACE_H */
index 23b88e1..7b691a7 100644 (file)
@@ -22,6 +22,8 @@
 #define TRUE  1
 #define FALSE 0
 
+#define GRAS_MAX_CHANNEL 10 /* FIXME: killme */
+
 #include "gras_config.h"
 
 #include "gras/error.h"
@@ -42,7 +44,7 @@
 #include "gras/datadesc.h"
 #include "DataDesc/datadesc_interface.h"
 #include "gras/messages.h"
-#include "Messaging/messaging_interface.h"
+#include "Msg/msg_interface.h"
 
 #include "Virtu/virtu_interface.h"
 
index f74b848..b10cd74 100644 (file)
@@ -221,7 +221,7 @@ gras_cfg_register(gras_cfg_t *cfg,
   TRYCATCH(mismatch_error,gras_dict_retrieve((gras_dict_t*)cfg,name,(void**)&res));
 
   if (errcode != mismatch_error) {
-    WARNING1("Config elem %s registered twice.",name);
+    WARN1("Config elem %s registered twice.",name);
     /* Will be removed by the insertion of the new one */
   } 
 
@@ -956,7 +956,7 @@ gras_cfg_get_int   (gras_cfg_t  *cfg,
   TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_int,&cell));
 
   if (gras_dynar_length(cell->content) > 1) {
-    WARNING2("You asked for the first value of the config element '%s', but there is %d values\n",
+    WARN2("You asked for the first value of the config element '%s', but there is %d values\n",
             name, gras_dynar_length(cell->content));
   }
 
@@ -987,7 +987,7 @@ gras_cfg_get_double(gras_cfg_t *cfg,
   TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_double,&cell));
 
   if (gras_dynar_length(cell->content) > 1) {
-    WARNING2("You asked for the first value of the config element '%s', but there is %d values\n",
+    WARN2("You asked for the first value of the config element '%s', but there is %d values\n",
             name, gras_dynar_length(cell->content));
   }
 
@@ -1020,7 +1020,7 @@ gras_error_t gras_cfg_get_string(gras_cfg_t *cfg,
   TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_string,&cell));
 
   if (gras_dynar_length(cell->content) > 1) {
-    WARNING2("You asked for the first value of the config element '%s', but there is %d values\n",
+    WARN2("You asked for the first value of the config element '%s', but there is %d values\n",
             name, gras_dynar_length(cell->content));
   }
 
@@ -1054,7 +1054,7 @@ gras_error_t gras_cfg_get_host  (gras_cfg_t *cfg,
   TRY (gras_cfgelm_get(cfg,name,gras_cfgelm_host,&cell));
 
   if (gras_dynar_length(cell->content) > 1) {
-    WARNING2("You asked for the first value of the config element '%s', but there is %d values\n",
+    WARN2("You asked for the first value of the config element '%s', but there is %d values\n",
             name, gras_dynar_length(cell->content));
   }
 
index 290488e..5391c31 100644 (file)
@@ -23,7 +23,7 @@ struct gras_module_ {
 };
 
 void 
-gras_init(int argc, char **argv) {
+gras_init(int *argc, char **argv) {
    gras_init_defaultlog(argc, argv, NULL);
 }
 
@@ -35,8 +35,8 @@ gras_init(int argc, char **argv) {
  * Initialize the gras mecanisms.
  */
 void
-gras_init_defaultlog(int argc,char **argv, const char *defaultlog) {
-  int i;
+gras_init_defaultlog(int *argc,char **argv, const char *defaultlog) {
+  int i,j;
   char *opt;
   gras_error_t errcode;
   int found=0;
@@ -44,12 +44,20 @@ gras_init_defaultlog(int argc,char **argv, const char *defaultlog) {
   INFO0("Initialize GRAS");
   
   /** Set logs and init log submodule */
-  for (i=1; i<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) {
@@ -57,6 +65,7 @@ gras_init_defaultlog(int argc,char **argv, const char *defaultlog) {
   }
    
   /** init other submodules */
+  gras_msg_init();
   gras_trp_init();
   gras_datadesc_init();
 }
@@ -68,6 +77,7 @@ gras_init_defaultlog(int argc,char **argv, const char *defaultlog) {
  */
 void 
 gras_exit(){
+  gras_msg_exit();
   gras_trp_exit();
   gras_datadesc_exit();
   gras_log_exit();
index edd33a8..096b5af 100644 (file)
@@ -19,12 +19,11 @@ RL_tests =                                    \
        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)
@@ -56,6 +55,3 @@ trp_file_server_LDADD=    $(LDADD_RL)
 
 datadesc_usage_LDADD=     $(LDADD_RL)
 
-#gs_example_send_LDADD=    $(LDADD_UTILS)
-#gs_example_receive_LDADD= $(LDADD_UTILS)
-
index 2a6507b..8acb2d0 100644 (file)
@@ -80,7 +80,6 @@ gras_error_t test_array(void) {
   gras_datadesc_type_t *my_type;
   
   array i,*j;
-  long int code;
   int cpt;
 
   INFO0("==== Test on fixed array ====");
@@ -90,8 +89,8 @@ gras_error_t test_array(void) {
   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++)
@@ -104,7 +103,6 @@ gras_error_t test_intref(void) {
   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;
@@ -112,8 +110,7 @@ gras_error_t test_intref(void) {
   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);
@@ -128,14 +125,14 @@ typedef char *string;
 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;
 }
 
@@ -149,17 +146,15 @@ typedef struct {
 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))) )
@@ -191,17 +186,15 @@ typedef struct {
 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))) )
@@ -231,15 +224,13 @@ typedef struct {
 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))) )
@@ -299,22 +290,16 @@ int list_eq(chained_list_t*i,chained_list_t*j) {
 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;
@@ -376,13 +361,13 @@ typedef struct { /* structure presented in the IEEE article */
 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());  
@@ -392,9 +377,13 @@ int main(int argc,char *argv[]) {
   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;
 }
diff --git a/testsuite/gras/gs_example.in b/testsuite/gras/gs_example.in
deleted file mode 100644 (file)
index 014cb96..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#! @BASH@ -e
-
-./gs_example_send $@ | ./gs_example_receive $@
-
diff --git a/testsuite/gras/gs_example_receive.c b/testsuite/gras/gs_example_receive.c
deleted file mode 100644 (file)
index 64d2bd1..0000000
+++ /dev/null
@@ -1,168 +0,0 @@
-/* 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;
-}
diff --git a/testsuite/gras/gs_example_send.c b/testsuite/gras/gs_example_send.c
deleted file mode 100644 (file)
index 9ec9bfe..0000000
+++ /dev/null
@@ -1,201 +0,0 @@
-/* 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;
-}
index 2504954..e458aa7 100644 (file)
@@ -19,7 +19,7 @@ int main(int argc,char *argv[]) {
   gras_error_t errcode;
   char data_send[256];
 
-  gras_init_defaultlog(argc,argv,"trp.thresh=debug");
+  gras_init_defaultlog(&argc,argv,"trp.thresh=debug");
 
   fprintf(stderr,"===[CLIENT]=== Contact the server\n");
   TRYFAIL(gras_socket_client_from_file("-",&sock));
@@ -30,5 +30,7 @@ int main(int argc,char *argv[]) {
   
   fprintf(stderr,"===[CLIENT]=== Exiting successfully\n");
   gras_socket_close(&sock);
+   
+  gras_exit();
   return 0;
 }
index e1bfb99..3ac4e0c 100644 (file)
@@ -19,7 +19,7 @@ int main(int argc,char *argv[]) {
   gras_error_t errcode;
   char data_recv[256];
 
-  gras_init_defaultlog(argc,argv,"trp.thresh=debug");
+  gras_init_defaultlog(&argc,argv,"trp.thresh=debug");
 
   fprintf(stderr,"===[SERVER]=== Create the socket\n");
   TRYFAIL(gras_socket_server_from_file("-",&sock));
@@ -34,5 +34,6 @@ int main(int argc,char *argv[]) {
   fprintf(stderr,"===[SERVER]=== Exiting successfully\n");
   gras_socket_close(&sock);
 
+  gras_exit();
   return 0;
 }
index 671e283..bddff1a 100644 (file)
@@ -20,7 +20,7 @@ int main(int argc,char *argv[]) {
   char data_send[256];
   char data_recv[256];
 
-  gras_init_defaultlog(argc,argv,"trp.thresh=debug");
+  gras_init_defaultlog(&argc,argv,"trp.thresh=debug");
 
   fprintf(stderr,"===[CLIENT]=== Contact the server\n");
   TRYFAIL(gras_socket_client(NULL,55555,&sock));
@@ -39,5 +39,7 @@ int main(int argc,char *argv[]) {
   
   fprintf(stderr,"===[CLIENT]=== Exiting successfully\n");
   gras_socket_close(&sock);
+   
+  gras_exit();
   return 0;
 }
index 7c33b47..a67bb45 100644 (file)
@@ -19,7 +19,7 @@ int main(int argc,char *argv[]) {
   gras_error_t errcode;
   char data_recv[256];
 
-  gras_init_defaultlog(argc,argv,"trp.thresh=debug");
+  gras_init_defaultlog(&argc,argv,"trp.thresh=debug");
 
   fprintf(stderr,"===[SERVER]=== Create the socket\n");
   TRYFAIL(gras_socket_server(55555,&sock));
@@ -36,5 +36,6 @@ int main(int argc,char *argv[]) {
   fprintf(stderr,"===[SERVER]=== Exiting successfully\n");
   gras_socket_close(&sock);
 
+  gras_exit();
   return 0;
 }
index ab6f278..793afd2 100644 (file)
@@ -53,7 +53,7 @@ int main(int argc, char **argv) {
   gras_cfg_t *set;
   int ival;
   
-  gras_init_defaultlog(argc,argv,"config.thresh=debug root.thresh=info");
+  gras_init_defaultlog(&argc,argv,"config.thresh=debug root.thresh=info");
 
   fprintf(stderr,"==== Alloc and free a config set.\n");
   set=make_set();
@@ -87,6 +87,7 @@ int main(int argc, char **argv) {
         "Count: 3; Options:\\nmquinson\\necaron\\nfsuter");
   test5();
 
+  gras_exit();
   return 0;
 }
 
index 0139085..82ddc2e 100644 (file)
@@ -55,7 +55,7 @@ int main(int argc,char **argv) {
   char *key;
   void *data;
 
-  gras_init_defaultlog(argc,argv,"dict.thresh=verbose");
+  gras_init_defaultlog(&argc,argv,"dict.thresh=verbose");
   srand((unsigned int)time(NULL));
 
   printf("Dictionnary: CRASH test:\n");
@@ -149,5 +149,7 @@ int main(int argc,char **argv) {
   printf("\n Free the structure (twice)\n");
   gras_dict_free(&head);
   gras_dict_free(&head);
+  
+  gras_exit();
   return 0;
 }
index 72542d6..1c7a11d 100644 (file)
@@ -101,7 +101,7 @@ int main(int argc,char **argv) {
   gras_dict_t *head=NULL;
   char *data;
 
-  gras_init_defaultlog(argc,argv,"dict.thresh=verbose");
+  gras_init_defaultlog(&argc,argv,"dict.thresh=verbose");
    
   printf("\nGeneric dictionnary: USAGE test:\n");
 
index 1acaeb0..e5005fe 100644 (file)
@@ -17,7 +17,7 @@ int main(int argc,char *argv[]) {
    int cpt,cursor;
    double d1,d2;
    
-   gras_init_defaultlog(argc,argv,"dynar.thresh=debug");
+   gras_init_defaultlog(&argc,argv,"dynar.thresh=debug");
 
    fprintf(stderr,"==== Traverse the empty dynar\n");
    TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL));
index 70d3529..aa8b8fe 100644 (file)
@@ -19,7 +19,7 @@ int main(int argc,char *argv[]) {
    gras_error_t errcode;
    int i,cpt,cursor;
    
-   gras_init_defaultlog(argc,argv,"dynar.thresh=debug");
+   gras_init_defaultlog(&argc,argv,"dynar.thresh=debug");
 
    fprintf(stderr,"==== Traverse the empty dynar\n");
    TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL));
@@ -167,5 +167,6 @@ int main(int argc,char *argv[]) {
    }
    gras_dynar_free(d);
 
+   gras_exit();
    return 0;
 }
index 48522cb..6651a46 100644 (file)
@@ -27,7 +27,7 @@ int main(int argc,char *argv[]) {
    char buf[1024];
    char *s1,*s2;
    
-   gras_init_defaultlog(argc,argv,"dynar.thresh=debug");
+   gras_init_defaultlog(&argc,argv,"dynar.thresh=debug");
    
    fprintf(stderr,"==== Traverse the empty dynar\n");
    TRYFAIL(gras_dynar_new(&d,sizeof(char *),&free_string));
@@ -174,5 +174,6 @@ int main(int argc,char *argv[]) {
    }
    gras_dynar_free(d);
 
+   gras_exit();
    return 0;
 }
index e2a277a..26679d4 100644 (file)
@@ -41,10 +41,10 @@ GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(Test, Top);
 GRAS_LOG_NEW_CATEGORY(Top);
 
 int main(int argc, char **argv) {
-  gras_init_defaultlog(argc,argv,"root.thresh=debug log.thresh=debug");
+  gras_init_defaultlog(&argc,argv,"root.thresh=debug log.thresh=debug");
 
   DEBUG1("val=%d", 1);
-  WARNING1("val=%d", 2);
+  WARN1("val=%d", 2);
   CDEBUG2(Top, "val=%d%s", 3, "!");
   CRITICAL6("false alarm%s%s%s%s%s%s", "","","","","","!");
   
index 0f7e5f0..5aec582 100644 (file)
@@ -80,18 +80,12 @@ static gras_error_t test1() {
   return no_error;
 }
 
-int main() {
+int main(int argc, char *argv[]) {
   gras_error_t errcode;
 
-  TRY(gras_log_control_set("root.thresh=debug"));
-  /*
-  //DirectDiagnostics(DIAGDEBUG, stdout);
-  DirectDiagnostics(DIAGINFO, stdout);
-  //  DirectDiagnostics(DIAGLOG, stdout);
-  DirectDiagnostics(DIAGWARN, stderr);
-  DirectDiagnostics(DIAGERROR, stderr);
-  DirectDiagnostics(DIAGFATAL, stderr);
-  */
+  gras_init(argc,argv,"root.thresh=debug"));
   TRYFAIL(test1());
+   
+  gras_exit();
   return 0;
 }
index e9eecdd..6eed1e7 100644 (file)
@@ -166,7 +166,7 @@ int main(int argc,char **argv) {
   gras_set_t *set=NULL;
   my_elem_t *elm;
 
-  gras_init_defaultlog(argc,argv,"set.thresh=verbose");
+  gras_init_defaultlog(&argc,argv,"set.thresh=verbose");
    
   printf("\nData set: USAGE test:\n");
 
@@ -235,5 +235,6 @@ int main(int argc,char **argv) {
   printf(" - Traverse the resulting data set\n");
   TRYFAIL(traverse(set));
 
+  gras_exit();
   return 0;
 }