3 /* messaging - high level communication (send/receive messages) */
5 /* module's private interface masked even to other parts of GRAS. */
7 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved. */
9 /* This program is free software; you can redistribute it and/or modify it
10 * under the terms of the license (GNU LGPL) which comes with this package. */
12 #ifndef GRAS_MESSAGE_PRIVATE_H
13 #define GRAS_MESSAGE_PRIVATE_H
17 #include "xbt/sysdep.h"
19 #include "xbt/dynar.h"
20 #include "xbt/queue.h"
22 #include "gras/transport.h"
23 #include "gras/datadesc.h"
24 #include "gras/virtu.h"
26 #include "gras/messages.h"
27 #include "gras/timer.h"
28 #include "gras_modinter.h"
30 #include "gras/Msg/msg_interface.h"
32 extern char _GRAS_header[6];
34 extern int gras_msg_libdata_id; /* The identifier of our libdata */
36 extern const char *e_gras_msg_kind_names[e_gras_msg_kind_count];
38 /* declare either regular messages or RPC or whatever */
40 gras_msgtype_declare_ext(const char *name,
42 e_gras_msg_kind_t kind,
43 gras_datadesc_type_t payload_request,
44 gras_datadesc_type_t payload_answer);
49 * Message type descriptor. There one of these for each registered version.
51 typedef struct s_gras_msgtype {
52 /* headers for the data set */
55 unsigned int name_len;
59 e_gras_msg_kind_t kind;
60 gras_datadesc_type_t ctn_type;
61 gras_datadesc_type_t answer_type; /* only used for RPC */
64 extern xbt_set_t _gras_msgtype_set; /* of gras_msgtype_t */
65 void gras_msgtype_free(void *msgtype);
68 /* functions to extract msg from socket or put it on wire (depend RL vs SG) */
69 void gras_msg_recv(gras_socket_t sock, gras_msg_t msg /*OUT*/);
70 void gras_msg_send_ext(gras_socket_t sock,
71 e_gras_msg_kind_t kind,
73 gras_msgtype_t msgtype, void *payload);
75 /* The thread in charge of receiving messages and queuing them */
76 typedef struct s_gras_msg_listener_ *gras_msg_listener_t;
77 gras_msg_listener_t gras_msg_listener_launch(xbt_queue_t msg_exchange);
78 /* The caller has the responsability to cleanup the queues himself */
79 void gras_msg_listener_shutdown(void);
84 * association between msg ID and cb list for a given process
86 struct s_gras_cblist {
88 xbt_dynar_t cbs; /* of gras_msg_cb_t */
91 typedef struct s_gras_cblist gras_cblist_t;
92 void gras_cbl_free(void *); /* used to free the memory at the end */
93 void gras_cblist_free(void *cbl);
98 * Context associated to a given callback (to either regular message or RPC)
100 struct s_gras_msg_cb_ctx {
101 gras_socket_t expeditor;
102 gras_msgtype_t msgtype;
103 unsigned long int ID;
105 int answer_due; /* Whether the callback is expected to return a result (for sanity checks) */
107 typedef struct s_gras_msg_cb_ctx s_gras_msg_cb_ctx_t;
115 void_f_void_t action;
117 } s_gras_timer_t, *gras_timer_t;
119 /* returns 0 if it handled a timer, or the delay until next timer, or -1 if no armed timer */
120 double gras_msg_timer_handle(void);
122 gras_msg_cb_ctx_t gras_msg_cb_ctx_new(gras_socket_t expe,
123 gras_msgtype_t msgtype,
124 unsigned long int ID,
125 int answer_due, double timeout);
129 /* We deploy a mallocator on the RPC contextes */
130 #include "xbt/mallocator.h"
131 extern xbt_mallocator_t gras_msg_ctx_mallocator;
132 void *gras_msg_ctx_mallocator_new_f(void);
133 void gras_msg_ctx_mallocator_free_f(void *dict);
134 void gras_msg_ctx_mallocator_reset_f(void *dict);
137 #endif /* GRAS_MESSAGE_PRIVATE_H */