3 /* gras_private.h - GRAS private definitions */
5 /* Authors: Martin Quinson */
6 /* Copyright (C) 2003 the OURAGAN project. */
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. */
11 #ifndef GRAS_PRIVATE_H
12 #define GRAS_PRIVATE_H
20 #ifndef GS_FAILURE_CONTEXT
21 # define GS_FAILURE_CONTEXT
22 #endif /* FAILURE_CONTEXT */
24 #define GS_FAILURE(str) \
25 (fprintf(stderr, "FAILURE: %s(%s:%d)" GS_FAILURE_CONTEXT "%s\n", __func__, __FILE__, __LINE__, (str)), \
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))
32 /* end of Oli's cruft */
34 #include "gras_config.h"
36 #include "gras/error.h"
38 #include "gras/module.h"
39 #include "gras/dynar.h"
40 #include "gras/dict.h"
41 #include "gras/config.h"
43 #include "gras/data_description.h"
44 #include "gras/dd_type_bag.h"
46 #include "gras/core.h"
47 #include "gras/datadesc.h"
48 #include "gras/socket.h"
49 #include "gras/messages.h"
54 #define ASSERT(cond,msg) do {if (!(cond)) { fprintf(stderr,msg); abort(); }} while(0)
56 /* **************************************************************************
58 ****************************************************************************/
61 * @Returns: 1 if succesfull 0 otherwise.
70 * @Returns: 1 if succesfull 0 otherwise.
72 * release the GRAS general lock.
77 /* **************************************************************************
79 * **************************************************************************/
84 * The list of callbacks for a given message type on a given host
87 gras_msgid_t id; /** identificator of this message */
89 int cbCount; /** number of registered callbacks */
90 gras_cb_t *cb; /** callbacks */
91 int *cbTTL; /** TTL of each callback (in number of use)*/
97 * An entry in the registered message list.
100 struct gras_msgentry_s {
101 gras_msgid_t id; /** identificator of this message */
102 char *name; /** printable name of this message */
104 int seqCount; /** number of sequence for this message */
105 DataDescriptor **dd; /** list of datadescriptor for each sequence */
106 size_t *ddCount; /** list of datadescriptor for each sequence */
107 unsigned int *networkSize;/** network size of one element in each sequence */
108 unsigned int *hostSize; /** host size of one element in each sequence */
110 /* **************************************************************************
112 * **************************************************************************/
117 * Globals for a given host.
120 gras_cblist_t *grasCbList; /** callbacks for registered messages */
121 unsigned int grasCbListCount; /** length of previous array */
127 * A header sent with messages. #version# is the NWS version and is presently
128 * ignored, but it could be used for compatibility. #message# is the actual
129 * message. #seqCount# is the number of sequence accompagning this message.
131 struct gras_msgheader_s {
133 gras_msgid_t message;
134 unsigned int dataSize;
135 unsigned int seqCount;
141 * Data for each process
144 /* queue of messages which where received but not wanted in msgWait, and therefore
145 temporarly queued until the next msgHandle */
147 gras_msg_t **grasMsgQueue;
149 /* registered callbacks for each message */
151 gras_cblist_t *grasCblList;
153 /* The channel we are listening to in SG for formated messages */
155 /* The channel we are listening to in SG for raw send/recv */
158 /* globals of the process */
163 /*@unused@*/static const DataDescriptor headerDescriptor[] =
164 {SIMPLE_MEMBER(CHAR_TYPE, 10, offsetof(gras_msgheader_t, version)),
165 SIMPLE_MEMBER(UNSIGNED_INT_TYPE, 1, offsetof(gras_msgheader_t, message)),
166 SIMPLE_MEMBER(UNSIGNED_INT_TYPE, 1, offsetof(gras_msgheader_t, dataSize)),
167 SIMPLE_MEMBER(UNSIGNED_INT_TYPE, 1, offsetof(gras_msgheader_t, seqCount))};
168 #define headerDescriptorCount 4
170 /*@unused@*/static const DataDescriptor countDescriptor[] =
171 {SIMPLE_DATA(UNSIGNED_INT_TYPE,1)};
172 #define countDescriptorCount 1
177 * This string is sent in each message to identify the version of the
178 * communication protocol used. This may be paranoid, but I feel so right now.
180 #define GRASVERSION "0.0.020504"
184 * @id: msg id to look for
185 * @Returns: the entry if found, NULL otherwise
187 * Get the entry corresponding to this message id;
189 gras_msgentry_t * grasMsgEntryGet(gras_msgid_t id);
192 * grasProcessDataGet:
194 * Get the GRAS globals for this host
196 grasProcessData_t *grasProcessDataGet(void);
200 * @id: msg id to look for
202 * Get the callback list corresponding to this message id;
204 gras_cblist_t * gras_cb_get(gras_msgid_t id);
208 * @id: the id of the new msg
210 * Create a new callback list for a new message id.
212 gras_error_t gras_cb_create(gras_msgid_t message);
217 * @dataSize: total size in network format, including headers and seqcount
218 * @seqCount: Number of sequences in this message (to check that everything goes well)
219 * @Returns: the created header
221 * Create a new header containing the passed values.
223 gras_msgheader_t *grasMsgHeaderNew(gras_msgid_t msgId,
224 unsigned int dataSize,
225 unsigned int seqCount);
230 * Receive the next message arriving within the given timeout
232 gras_error_t grasMsgRecv(gras_msg_t **msg, double timeout);
237 * Create an empty socket
239 gras_sock_t *gras_sock_new(void);
244 * Frees an old socket
246 void grasSockFree(gras_sock_t *s);
250 /* **************************************************************************
251 * Handling DataDescriptors
252 * **************************************************************************/
253 typedef enum {HOST_FORMAT, NETWORK_FORMAT} FormatTypes;
254 size_t DataSize(const DataDescriptor *description,
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);
262 #endif /* GRAS_PRIVATE_H */