Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add sets, continue mess with datadesc
[simgrid.git] / src / gras / gras_private.h
1 /* $Id$ */
2
3 /* gras_private.h - GRAS private definitions                                */
4
5 /* Authors: Martin Quinson                                                  */
6 /* Copyright (C) 2003 the OURAGAN project.                                  */
7
8 /* This program is free software; you can redistribute it and/or modify it
9    under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #ifndef GRAS_PRIVATE_H
12 #define GRAS_PRIVATE_H
13
14 #include <unistd.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
18
19 /* Oli's macro */
20 #ifndef GS_FAILURE_CONTEXT
21 #  define GS_FAILURE_CONTEXT
22 #endif /* FAILURE_CONTEXT */
23
24 #define GS_FAILURE(str) \
25      (fprintf(stderr, "FAILURE: %s(%s:%d)" GS_FAILURE_CONTEXT "%s\n", __func__, __FILE__, __LINE__, (str)), \
26       abort())
27
28 #define max(a, b) (((a) > (b))?(a):(b))
29 #define min(a, b) (((a) < (b))?(a):(b))
30
31 /* end of Oli's cruft */
32
33 #include "gras_config.h"
34
35 #include "gras/error.h"
36 #include "gras/log.h"
37 #include "gras/module.h"
38 #include "gras/dynar.h"
39 #include "gras/dict.h"
40 #include "gras/set.h"
41 #include "gras/config.h"
42
43 //#include "gras/data_description.h"
44 //#include "gras/dd_type_bag.h"
45
46 #include "gras/core.h"
47 #include "gras/transport.h"
48 //#include "gras/datadesc_simple.h"
49 #include "gras/datadesc.h"
50 #include "gras/socket.h"
51 #include "gras/messages.h"
52
53 #define TRUE  1
54 #define FALSE 0
55
56 #define ASSERT(cond,msg) do {if (!(cond)) { fprintf(stderr,msg); abort(); }} while(0)
57
58 /* **************************************************************************
59  * Locking system
60  ****************************************************************************/
61 /**
62  * gras_lock:
63  * @Returns: 1 if succesfull 0 otherwise.
64  *
65  * Get the GRAS lock.
66  */
67 int
68 gras_lock(void);
69
70 /**
71  * gras_unlock:
72  * @Returns: 1 if succesfull 0 otherwise.
73  *
74  * release the GRAS general lock.
75  */
76 int
77 gras_unlock(void);
78
79 /* **************************************************************************
80  * Messaging stuff
81  * **************************************************************************/
82
83 /**
84  * gras_cblist_t:
85  *
86  * The list of callbacks for a given message type on a given host
87  */
88 typedef struct {
89   gras_msgid_t id;     /** identificator of this message */
90   
91   int cbCount;         /** number of registered callbacks */
92   gras_cb_t *cb;       /** callbacks */
93   int *cbTTL;          /** TTL of each callback (in number of use)*/
94 } gras_cblist_t;
95
96 /**
97  * gras_msgentry_t:
98  *
99  * An entry in the registered message list.
100  */
101
102 struct gras_msgentry_s {
103   gras_msgid_t id;     /** identificator of this message */
104   char *name;               /** printable name of this message */
105
106   int seqCount;             /** number of sequence for this message */
107   DataDescriptor **dd;      /** list of datadescriptor for each sequence */
108   size_t *ddCount;          /** list of datadescriptor for each sequence */
109   unsigned int *networkSize;/** network size of one element in each sequence */
110   unsigned int *hostSize;   /** host size of one element in each sequence */
111 };
112 /* **************************************************************************
113  * GRAS globals
114  * **************************************************************************/
115
116 /** 
117  * gras_hostglobal_t:
118  * 
119  * Globals for a given host. 
120  */
121 typedef struct {
122   gras_cblist_t *grasCbList; /** callbacks for registered messages */
123   unsigned int grasCbListCount;      /** length of previous array */
124 } gras_hostglobal_t;
125
126 /**
127  * gras_msgheader_t:
128  *
129  * A header sent with messages.  #version# is the NWS version and is presently
130  * ignored, but it could be used for compatibility.  #message# is the actual
131  * message. #seqCount# is the number of sequence accompagning this message.
132  */
133 struct gras_msgheader_s {
134   char          version[10];
135   gras_msgid_t  message;
136   unsigned int  dataSize;
137   unsigned int  seqCount;
138 };
139
140 /**
141  * grasProcessData_t:
142  *
143  * Data for each process 
144  */
145 typedef struct {
146   /* queue of messages which where received but not wanted in msgWait, and therefore
147      temporarly queued until the next msgHandle */
148   int grasMsgQueueLen;
149   gras_msg_t **grasMsgQueue;
150
151   /* registered callbacks for each message */
152   int grasCblListLen;
153   gras_cblist_t *grasCblList;
154
155   /* The channel we are listening to in SG for formated messages */
156   int chan;
157   /* The channel we are listening to in SG for raw send/recv */
158   int rawChan; 
159
160   /* globals of the process */
161   void *userdata;               
162 } grasProcessData_t;
163
164
165 /*@unused@*/static const DataDescriptor headerDescriptor[] =
166   {SIMPLE_MEMBER(CHAR_TYPE, 10, offsetof(gras_msgheader_t, version)),
167    SIMPLE_MEMBER(UNSIGNED_INT_TYPE, 1, offsetof(gras_msgheader_t, message)),
168    SIMPLE_MEMBER(UNSIGNED_INT_TYPE, 1, offsetof(gras_msgheader_t, dataSize)),
169    SIMPLE_MEMBER(UNSIGNED_INT_TYPE, 1, offsetof(gras_msgheader_t, seqCount))};
170 #define headerDescriptorCount 4
171
172 /*@unused@*/static const DataDescriptor countDescriptor[] =
173   {SIMPLE_DATA(UNSIGNED_INT_TYPE,1)};
174 #define countDescriptorCount 1
175
176 /**
177  * GRASVERSION
178  *
179  * This string is sent in each message to identify the version of the 
180  * communication protocol used. This may be paranoid, but I feel so right now.
181  */
182 #define GRASVERSION "0.0.020504"
183
184 /**
185  * grasMsgEntryGet: 
186  * @id: msg id to look for
187  * @Returns: the entry if found, NULL otherwise
188  * 
189  * Get the entry corresponding to this message id;
190  */ /*@observer@*/
191 gras_msgentry_t * grasMsgEntryGet(gras_msgid_t id);
192
193 /**
194  * grasProcessDataGet: 
195  * 
196  * Get the GRAS globals for this host
197  */ /*@observer@*/
198 grasProcessData_t *grasProcessDataGet(void);
199
200 /**
201  * gras_cb_get: 
202  * @id: msg id to look for
203  * 
204  * Get the callback list corresponding to this message id;
205  */ /*@observer@*/
206 gras_cblist_t * gras_cb_get(gras_msgid_t id);
207
208 /**
209  * gras_cb_create:
210  * @id: the id of the new msg
211  *
212  * Create a new callback list for a new message id.
213  */
214 gras_error_t gras_cb_create(gras_msgid_t message);
215
216 /**
217  * grasMsgHeaderNew:
218  * @msgId: 
219  * @dataSize: total size in network format, including headers and seqcount
220  * @seqCount: Number of sequences in this message (to check that everything goes well)
221  * @Returns: the created header
222  *
223  * Create a new header containing the passed values.
224  */
225 gras_msgheader_t *grasMsgHeaderNew(gras_msgid_t msgId, 
226                                   unsigned int dataSize,
227                                   unsigned int seqCount);
228
229 /**
230  * grasMsgRecv:
231  *
232  * Receive the next message arriving within the given timeout
233  */
234 gras_error_t grasMsgRecv(gras_msg_t **msg, double timeout);
235
236 /**
237  * gras_sock_new:
238  *
239  * Create an empty socket
240  */
241 gras_sock_t *gras_sock_new(void);
242
243 /**
244  * grasSockFree:
245  *
246  * Frees an old socket
247  */
248 void grasSockFree(gras_sock_t *s);
249
250
251
252 /* **************************************************************************
253  * Handling DataDescriptors
254  * **************************************************************************/
255 #if 0
256 FIXME: Kill it
257 typedef enum {HOST_FORMAT, NETWORK_FORMAT} FormatTypes;
258 size_t DataSize(const DataDescriptor *description,
259                 size_t length,
260                 FormatTypes format);
261 void *gras_datadesc_copy_data(const DataDescriptor *dd, unsigned int c, void *data);
262 int gras_datadesc_cmp(/*@null@*/const DataDescriptor *dd1, unsigned int c1,
263                       /*@null@*/const DataDescriptor *dd2, unsigned int c2);
264 void gras_datadesc_dump(/*@null@*/const DataDescriptor *dd, unsigned int c);
265 #endif
266 #endif /* GRAS_PRIVATE_H */