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