From 75ffa801579aeb214b8d95290b76c96a605a2422 Mon Sep 17 00:00:00 2001 From: mquinson Date: Tue, 3 Feb 2004 23:35:05 +0000 Subject: [PATCH] Reduce overengeneering around datadesc, put stubs in place so that the kernel compiles again (but examples still cannot be built) git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@26 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- configure | 2 +- cruft/doc/gras-sections.txt | 1 + cruft/doc/tmpl/core_dico.sgml | 9 +++ include/Makefile.am | 2 +- include/datadesc.h | 17 ++++++ include/datadesc_simple.h | 110 ++++++++++++++++++++++++++++++++++ include/error.h | 1 + include/gras.h | 4 +- include/messages.h | 2 +- include/transport.h | 33 ++++++++++ src/gras/Makefile.am | 13 +++- src/gras/SG/gras_sg.c | 97 ------------------------------ src/gras/gras_private.h | 7 ++- testsuite/xbt/dynar_string.c | 2 +- 14 files changed, 194 insertions(+), 106 deletions(-) create mode 100644 include/datadesc_simple.h create mode 100644 include/transport.h diff --git a/configure b/configure index 7121fe395f..b6429792c8 100755 --- a/configure +++ b/configure @@ -1,5 +1,5 @@ #! /bin/sh -# From configure.ac Revision: 1.1.1.1 . +# From configure.ac Revision: 1.2 . # Guess values for system-dependent variables and create Makefiles. # Generated by GNU Autoconf 2.59 for GRAS 0.0.040129. # diff --git a/cruft/doc/gras-sections.txt b/cruft/doc/gras-sections.txt index a82a2328f5..593b903563 100644 --- a/cruft/doc/gras-sections.txt +++ b/cruft/doc/gras-sections.txt @@ -160,6 +160,7 @@ gras_dynar_foreach
core_dico +gras_dict_new gras_dict_free gras_dict_insert gras_dict_retrieve diff --git a/cruft/doc/tmpl/core_dico.sgml b/cruft/doc/tmpl/core_dico.sgml index 5159d33294..43618d0d32 100644 --- a/cruft/doc/tmpl/core_dico.sgml +++ b/cruft/doc/tmpl/core_dico.sgml @@ -14,6 +14,15 @@ Data container associating data to a string key. + + + + + +@dict: +@Returns: + + diff --git a/include/Makefile.am b/include/Makefile.am index 84ea0dbcd2..8f2d145393 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -8,7 +8,7 @@ EXTRA_DIST= \ dict.h \ config.h \ \ - datadesc.h \ + datadesc_simple.h \ data_description.h dd_type_bag.h \ \ socket.h messages.h \ diff --git a/include/datadesc.h b/include/datadesc.h index 1948e24922..189dcc84da 100644 --- a/include/datadesc.h +++ b/include/datadesc.h @@ -77,6 +77,23 @@ typedef struct DataDescriptorStruct { sizeof(structType) - offsetof(structType, lastMember) - \ sizeof(memberType) * repetitions + +gras_error_t gras_datadesc_parse(const char *def, + gras_datadesc_t **dst); +gras_error_t gras_datadesc_from_nws(const DataDescriptor *desc, + size_t howmany, + gras_datadesc_t **dst); +gras_error_t gras_datadesc_eq(const gras_datadesc_t *d1, + const gras_datadesc_t *d2); +gras_error_t gras_datadesc_cpy(gras_datadesc_t *src, + gras_datadesc_t **dst); +gras_error_t gras_datadesc_sizeof_host(gras_datadesc_t *desc, + size_t *dst); +gras_error_t gras_datadesc_sizeof_network(gras_datadesc_t *desc, + size_t *dst); + + + END_DECL #endif /* GRAS_DATADESC_H */ diff --git a/include/datadesc_simple.h b/include/datadesc_simple.h new file mode 100644 index 0000000000..5b2b21115d --- /dev/null +++ b/include/datadesc_simple.h @@ -0,0 +1,110 @@ +/* $Id$ */ + +/* gras/datadesc.h - Describing the data you want to exchange */ + +/* 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. */ + +#ifndef GRAS_DATADESC_SIMPLE_H +#define GRAS_DATADESC_SIMPLE_H + +#include /* offsetof() */ +#include /* size_t */ +#include + + +/*! C++ users need love */ +#ifndef BEGIN_DECL +# ifdef __cplusplus +# define BEGIN_DECL extern "C" { +# else +# define BEGIN_DECL +# endif +#endif + +/*! C++ users need love */ +#ifndef END_DECL +# ifdef __cplusplus +# define END_DECL } +# else +# define END_DECL +# endif +#endif +/* End of cruft for C++ */ + +BEGIN_DECL + +/**** + **** The NWS type and constructors + ****/ + +typedef enum + {CHAR_TYPE, DOUBLE_TYPE, FLOAT_TYPE, INT_TYPE, LONG_TYPE, SHORT_TYPE, + UNSIGNED_INT_TYPE, UNSIGNED_LONG_TYPE, UNSIGNED_SHORT_TYPE, STRUCT_TYPE} + DataTypes; +#define SIMPLE_TYPE_COUNT 9 + +typedef struct DataDescriptorStruct { + DataTypes type; + size_t repetitions; + size_t offset; + struct DataDescriptorStruct *members; + size_t length; + size_t tailPadding; +} DataDescriptor; +#ifndef NULL +#define NULL 0 +#endif +#define SIMPLE_DATA(type,repetitions) {type, repetitions, 0, NULL, 0, 0} +#define SIMPLE_MEMBER(type,repetitions,offset) \ + {type, repetitions, offset, NULL, 0, 0} +#define PAD_BYTES(structType,lastMember,memberType,repetitions) \ + sizeof(structType) - offsetof(structType, lastMember) - \ + sizeof(memberType) * repetitions + +/**** + **** Gras (opaque) type, constructors and functions + ****/ + +typedef struct gras_datadesc_ gras_datadesc_t; + +/* constructors, memory management */ +gras_error_t gras_datadesc_parse(const char *def, + gras_datadesc_t **dst); +gras_error_t gras_datadesc_from_nws(const DataDescriptor *desc, + size_t howmany, + gras_datadesc_t **dst); + +gras_error_t gras_datadesc_cpy(gras_datadesc_t *src, + gras_datadesc_t **dst); +void gras_datadesc_free(gras_datadesc_t **dd); + +/* basic functionnalities */ +int gras_datadesc_cmp(const gras_datadesc_t *d1, + const gras_datadesc_t *d2); + +gras_error_t gras_datadesc_sizeof_host(gras_datadesc_t *desc, + size_t *dst); +gras_error_t gras_datadesc_sizeof_network(gras_datadesc_t *desc, + size_t *dst); + +/* high level function needed in SG */ +gras_error_t gras_datadesc_data_cpy(const gras_datadesc_t *dd, + const void *src, + void **dst); + +/* high level functions needed in RL */ +gras_error_t gras_datadesc_convert_recv(const gras_datadesc_t *dd, + gras_trp_plugin_t *trp, + void **dst); +gras_error_t gras_datadesc_convert_send(const gras_datadesc_t *dd, + gras_trp_plugin_t *trp, + void *src); + +END_DECL + +#endif /* GRAS_DATADESC_SIMPLE_H */ + diff --git a/include/error.h b/include/error.h index 4a45d910df..58c89adf37 100644 --- a/include/error.h +++ b/include/error.h @@ -125,6 +125,7 @@ typedef enum { #define RAISE_MALLOC RAISE0(malloc_error,"Malloc error") #define RAISE_IMPOSSIBLE RAISE0(unknown_error,"The Impossible did happen") +#define RAISE_UNIMPLEMENTED RAISE1(unknown_error,"Function %s unimplemented",__FUNCTION__) #define gras_abort abort diff --git a/include/gras.h b/include/gras.h index fb941a4c8f..5bb8012244 100644 --- a/include/gras.h +++ b/include/gras.h @@ -40,7 +40,9 @@ #include #include -#include + +#include +#include #include #include diff --git a/include/messages.h b/include/messages.h index e9d1aa6b34..5887aa5e3d 100644 --- a/include/messages.h +++ b/include/messages.h @@ -3,7 +3,7 @@ /* gras/messages.h - Public interface to GRAS messages */ /* Authors: Martin Quinson */ -/* Copyright (C) 2003 the OURAGAN project. */ +/* 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. */ diff --git a/include/transport.h b/include/transport.h new file mode 100644 index 0000000000..ffe6e6e4c7 --- /dev/null +++ b/include/transport.h @@ -0,0 +1,33 @@ +/* $Id$ */ + +/* trp (transport) - send/receive a bunch of bytes */ + +/* This file implements the public interface of this module, exported to the*/ +/* other modules of GRAS, but not to the end user. */ + +/* Authors: Martin Quinson */ +/* Copyright (C) 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_TRANSPORT_H +#define GRAS_TRANSPORT_H + +/* each plugin implements the socket the way it wants */ +typedef void gras_trp_sock_t; + +/* A plugin type */ +typedef struct gras_trp_plugin_ gras_trp_plugin_t; + +/* Module, and get plugin by name */ +gras_error_t gras_trp_init(void); + +void gras_trp_exit(void); + +gras_error_t gras_trp_plugin_get_by_name(const char *name, + gras_trp_plugin_t **dst); + + + +#endif /* GRAS_TRANSPORT_H */ diff --git a/src/gras/Makefile.am b/src/gras/Makefile.am index 37b8c2ef98..2341998753 100644 --- a/src/gras/Makefile.am +++ b/src/gras/Makefile.am @@ -15,6 +15,7 @@ noinst_LIBRARIES=libgrasutils.a # Core/dict_multi.c # Common/gras.c Common/gras_datadesc.c Common/gras_msg.c +# Messaging/messaging.c COMMON_S=\ \ @@ -25,6 +26,11 @@ COMMON_S=\ \ Core/config.c \ \ + Messaging/transport.c Messaging/transport.h \ + Messaging/transport_sg.c Messaging/transport_tcp.c \ + \ + Messaging/datadesc_simple.c \ + \ gs/datadesc.c \ gs/tools.c \ gs/categories.h \ @@ -51,7 +57,9 @@ libgrasutils_a_SOURCES = $(COMMON_S) Tests/gras_dummy.c libgrasutils_a_LIBADD = $(COMMON_L) -libgrasrl_a_SOURCES= $(COMMON_S) RL/gras_rl.c RL/gras_rl.h + +# RL/gras_rl.c RL/gras_rl.h FIXME +libgrasrl_a_SOURCES= $(COMMON_S) Messaging/messaging_rl.c libgrasrl_a_LIBADD= \ $(foreach file,\ exp_smooth forc median mse_forc protocol \ @@ -60,7 +68,8 @@ libgrasrl_a_LIBADD= \ $(COMMON_L) -libgrassg_a_SOURCES= $(COMMON_S) SG/gras_sg.c SG/gras_sg.h +# SG/gras_sg.c SG/gras_sg.h FIXME +libgrassg_a_SOURCES= $(COMMON_S) Messaging/messaging_sg.c libgrassg_a_LIBADD= \ $(COMMON_L) diff --git a/src/gras/SG/gras_sg.c b/src/gras/SG/gras_sg.c index 4159c9c3a8..cd24c8a725 100644 --- a/src/gras/SG/gras_sg.c +++ b/src/gras/SG/gras_sg.c @@ -15,103 +15,6 @@ GRAS_LOG_DEFAULT_CATEGORY(GRAS); -gras_error_t -gras_process_init() { - gras_hostdata_t *hd=(gras_hostdata_t *)MSG_host_get_data(MSG_host_self()); - grasProcessData_t *pd; - int i; - - if (!(pd=(grasProcessData_t *)malloc(sizeof(grasProcessData_t)))) { - fprintf(stderr,"grasInit: out of memory\n"); - return malloc_error; - } - 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; - } - - if (!hd) { - if (!(hd=(gras_hostdata_t *)malloc(sizeof(gras_hostdata_t)))) { - fprintf(stderr,"grasInit: out of memory\n"); - return malloc_error; - } - hd->portLen = 0; - hd->port=NULL; - hd->port2chan=NULL; - for (i=0; iproc[i]=0; - } - - if (MSG_host_set_data(MSG_host_self(),(void*)hd) != MSG_OK) { - return unknown_error; - } - } - - /* take a free channel for this process */ - for (i=0; iproc[i]; i++); - if (i == MAX_CHANNEL) { - fprintf(stderr, - "GRAS: Can't add a new process on %s, because all channel are already in use. Please increase MAX CHANNEL (which is %d for now) and recompile GRAS\n.", - MSG_host_get_name(MSG_host_self()),MAX_CHANNEL); - return system_error; - } - pd->chan = i; - hd->proc[ i ] = MSG_process_self_PID(); - - /* take a free channel for this process */ - for (i=0; iproc[i]; i++); - if (i == MAX_CHANNEL) { - fprintf(stderr, - "GRAS: Can't add a new process on %s, because all channel are already in use. Please increase MAX CHANNEL (which is %d for now) and recompile GRAS\n.", - MSG_host_get_name(MSG_host_self()),MAX_CHANNEL); - return system_error; - } - pd->rawChan = i; - hd->proc[ i ] = MSG_process_self_PID(); - - /* - fprintf(stderr,"GRAS: Creating process '%s' (%d)\n", - MSG_process_get_name(MSG_process_self()),MSG_process_self_PID()); - */ - return no_error; -} - -gras_error_t -gras_process_finalize() { - gras_hostdata_t *hd=(gras_hostdata_t *)MSG_host_get_data(MSG_host_self()); - grasProcessData_t *pd=(grasProcessData_t *)MSG_process_get_data(MSG_process_self()); - int myPID=MSG_process_self_PID(); - int i; - - gras_assert0(hd && pd,"Run gras_process_init!!\n"); - - - fprintf(stderr,"GRAS: Finalizing process '%s' (%d)\n", - MSG_process_get_name(MSG_process_self()),MSG_process_self_PID()); - if (pd->grasMsgQueueLen) { - fprintf(stderr,"GRAS: Warning: process %d terminated, but some queued messages where not handled\n",MSG_process_self_PID()); - } - - for (i=0; i< MAX_CHANNEL; i++) - if (myPID == hd->proc[i]) - hd->proc[i] = 0; - - for (i=0; iportLen; i++) { - if (hd->port2chan[ i ] == pd->chan) { - memmove(&(hd->port[i]), &(hd->port[i+1]), (hd->portLen -i -1) * sizeof(int)); - memmove(&(hd->port2chan[i]), &(hd->port2chan[i+1]), (hd->portLen -i -1) * sizeof(int)); - hd->portLen--; - i--; /* counter the effect of the i++ at the end of the iteration */ - } - } - - return no_error; -} /* ************************************************************************** * Openning/Maintaining/Closing connexions (private functions for both raw * and regular sockets) diff --git a/src/gras/gras_private.h b/src/gras/gras_private.h index f8d1962b17..81f9c5e73b 100644 --- a/src/gras/gras_private.h +++ b/src/gras/gras_private.h @@ -44,7 +44,8 @@ #include "gras/dd_type_bag.h" #include "gras/core.h" -#include "gras/datadesc.h" +#include "gras/transport.h" +#include "gras/datadesc_simple.h" #include "gras/socket.h" #include "gras/messages.h" @@ -250,6 +251,8 @@ void grasSockFree(gras_sock_t *s); /* ************************************************************************** * Handling DataDescriptors * **************************************************************************/ +#if 0 +FIXME: Kill it typedef enum {HOST_FORMAT, NETWORK_FORMAT} FormatTypes; size_t DataSize(const DataDescriptor *description, size_t length, @@ -258,5 +261,5 @@ void *gras_datadesc_copy_data(const DataDescriptor *dd, unsigned int c, void *da int gras_datadesc_cmp(/*@null@*/const DataDescriptor *dd1, unsigned int c1, /*@null@*/const DataDescriptor *dd2, unsigned int c2); void gras_datadesc_dump(/*@null@*/const DataDescriptor *dd, unsigned int c); - +#endif #endif /* GRAS_PRIVATE_H */ diff --git a/testsuite/xbt/dynar_string.c b/testsuite/xbt/dynar_string.c index 7fea46b9a7..5ce0dfbdc6 100644 --- a/testsuite/xbt/dynar_string.c +++ b/testsuite/xbt/dynar_string.c @@ -29,7 +29,7 @@ int main(int argc,char *argv[]) { parse_log_opt(argc,argv,"dynar.thresh=debug"); fprintf(stderr,"==== Traverse the empty dynar\n"); - TRYFAIL(gras_dynar_new(&d,sizeof(int),NULL)); + TRYFAIL(gras_dynar_new(&d,sizeof(char *),&free_string)); gras_dynar_foreach(d,cpt,i){ fprintf(stderr, "Damnit, there is something in the empty dynar\n"); -- 2.20.1