Logo AND Algorithmique Numérique Distribuée

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