Logo AND Algorithmique Numérique Distribuée

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