Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
777eafef9aaf1679668d515666cf383943ebf83a
[simgrid.git] / src / gras / Msg / msg_private.h
1 /* messaging - high level communication (send/receive messages)             */
2
3 /* module's private interface masked even to other parts of GRAS.           */
4
5 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved.            */
6
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. */
9
10 #ifndef GRAS_MESSAGE_PRIVATE_H
11 #define GRAS_MESSAGE_PRIVATE_H
12
13 #include "portable.h"
14
15 #include "xbt/sysdep.h"
16 #include "xbt/log.h"
17 #include "xbt/dynar.h"
18 #include "xbt/queue.h"
19 #include "xbt/set.h"
20 #include "gras/transport.h"
21 #include "gras/datadesc.h"
22 #include "gras/virtu.h"
23
24 #include "gras/messages.h"
25 #include "gras/timer.h"
26 #include "gras_modinter.h"
27
28 #include "gras/Msg/msg_interface.h"
29
30 extern char _GRAS_header[6];
31
32 extern int gras_msg_libdata_id; /* The identifier of our libdata */
33
34 extern const char *e_gras_msg_kind_names[e_gras_msg_kind_count];
35
36 /* declare either regular messages or RPC or whatever */
37 void
38 gras_msgtype_declare_ext(const char *name,
39                          short int version,
40                          e_gras_msg_kind_t kind,
41                          gras_datadesc_type_t payload_request,
42                          gras_datadesc_type_t payload_answer);
43
44 /**
45  * gras_msgtype_t:
46  *
47  * Message type descriptor. There one of these for each registered version.
48  */
49 typedef struct s_gras_msgtype {
50   /* headers for the data set */
51   unsigned int code;
52   char *name;
53   unsigned int name_len;
54
55   /* payload */
56   short int version;
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 */
60 } s_gras_msgtype_t;
61
62 extern xbt_set_t _gras_msgtype_set;     /* of gras_msgtype_t */
63 void gras_msgtype_free(void *msgtype);
64
65
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,
70                        unsigned long int ID,
71                        gras_msgtype_t msgtype, void *payload);
72
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);
78
79 /**
80  * gras_cblist_t:
81  *
82  * association between msg ID and cb list for a given process
83  */
84 struct s_gras_cblist {
85   long int id;
86   xbt_dynar_t cbs;              /* of gras_msg_cb_t */
87 };
88
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);
92
93 /**
94  * gras_msg_cb_ctx_t:
95  *
96  * Context associated to a given callback (to either regular message or RPC)
97  */
98 struct s_gras_msg_cb_ctx {
99   gras_socket_t expeditor;
100   gras_msgtype_t msgtype;
101   unsigned long int ID;
102   double timeout;
103   int answer_due;               /* Whether the callback is expected to return a result (for sanity checks) */
104 };
105 typedef struct s_gras_msg_cb_ctx s_gras_msg_cb_ctx_t;
106
107 /* ********* *
108  * * TIMER * *
109  * ********* */
110 typedef struct {
111   double expiry;
112   double period;
113   void_f_void_t action;
114   int repeat;
115 } s_gras_timer_t, *gras_timer_t;
116
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);
119
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);
124
125
126
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);
133
134
135 #endif /* GRAS_MESSAGE_PRIVATE_H */