Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Gcc is *very* permissive with pointers to functions. If we declare them as function...
[simgrid.git] / src / gras / Msg / msg_private.h
1 /* $Id$ */
2
3 /* messaging - high level communication (send/receive messages)             */
4
5 /* module's private interface masked even to other parts of GRAS.           */
6
7 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved.            */
8
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. */
11
12 #ifndef GRAS_MESSAGE_PRIVATE_H
13 #define GRAS_MESSAGE_PRIVATE_H
14
15 #include "portable.h"
16
17 #include "xbt/sysdep.h"
18 #include "xbt/log.h"
19 #include "xbt/dynar.h"
20 #include "xbt/queue.h"
21 #include "xbt/set.h"
22 #include "gras/transport.h"
23 #include "gras/datadesc.h"
24 #include "gras/virtu.h"
25
26 #include "gras/messages.h"
27 #include "gras/timer.h"
28 #include "gras_modinter.h"
29
30 #include "gras/Msg/msg_interface.h"
31
32 extern char _GRAS_header[6];
33
34 extern int gras_msg_libdata_id; /* The identifier of our libdata */
35  
36 extern const char *e_gras_msg_kind_names[e_gras_msg_kind_count];
37
38 /* declare either regular messages or RPC or whatever */
39 void 
40 gras_msgtype_declare_ext(const char           *name,
41                          short int             version,
42                          e_gras_msg_kind_t     kind, 
43                          gras_datadesc_type_t  payload_request,
44                          gras_datadesc_type_t  payload_answer);
45
46 /**
47  * gras_msgtype_t:
48  *
49  * Message type descriptor. There one of these for each registered version.
50  */
51 typedef struct s_gras_msgtype {
52   /* headers for the data set */
53   unsigned int   code;
54   char          *name;
55   unsigned int   name_len;
56         
57   /* payload */
58   short int version;
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 */
62 } s_gras_msgtype_t;
63
64 extern xbt_set_t _gras_msgtype_set; /* of gras_msgtype_t */
65 void gras_msgtype_free(void *msgtype);
66
67
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,
70                    gras_msg_t      msg/*OUT*/);
71 void gras_msg_send_ext(gras_socket_t   sock,
72                      e_gras_msg_kind_t kind,
73                        unsigned long int ID,
74                        gras_msgtype_t  msgtype,
75                        void           *payload);
76
77 /* The thread in charge of receiving messages and queuing them */
78 typedef struct s_gras_msg_listener_ *gras_msg_listener_t;
79 gras_msg_listener_t
80 gras_msg_listener_launch(xbt_queue_t msg_exchange);
81 /* The caller has the responsability to cleanup the queues himself */
82 void gras_msg_listener_shutdown(gras_msg_listener_t);
83
84 /**
85  * gras_cblist_t:
86  *
87  * association between msg ID and cb list for a given process
88  */
89 struct s_gras_cblist {
90   long int id;
91   xbt_dynar_t cbs; /* of gras_msg_cb_t */
92 };
93
94 typedef struct s_gras_cblist gras_cblist_t;
95 void gras_cbl_free(void *); /* used to free the memory at the end */
96 void gras_cblist_free(void *cbl);
97
98 /**
99  * gras_msg_cb_ctx_t:
100  *
101  * Context associated to a given callback (to either regular message or RPC)
102  */
103 struct s_gras_msg_cb_ctx {
104   gras_socket_t expeditor;
105   gras_msgtype_t msgtype;
106   unsigned long int ID;
107   double timeout;
108   int answer_due; /* Whether the callback is expected to return a result (for sanity checks) */
109 };
110 typedef struct s_gras_msg_cb_ctx s_gras_msg_cb_ctx_t;
111
112 /* ********* *
113  * * TIMER * *
114  * ********* */
115 typedef struct {
116   double expiry;
117   double period;
118   void_f_void_t action;
119   int repeat;
120 } s_gras_timer_t, *gras_timer_t;
121
122 /* returns 0 if it handled a timer, or the delay until next timer, or -1 if no armed timer */
123 double gras_msg_timer_handle(void);
124
125 gras_msg_cb_ctx_t gras_msg_cb_ctx_new(gras_socket_t expe,
126                                                  gras_msgtype_t msgtype,
127                                                  unsigned long int ID,
128                                                  int answer_due,
129                                                  double timeout);
130
131
132
133 /* We deploy a mallocator on the RPC contextes */
134 #include "xbt/mallocator.h"
135 extern xbt_mallocator_t gras_msg_ctx_mallocator;
136 void* gras_msg_ctx_mallocator_new_f(void);
137 void gras_msg_ctx_mallocator_free_f(void* dict);
138 void gras_msg_ctx_mallocator_reset_f(void* dict);
139
140
141 #endif  /* GRAS_MESSAGE_PRIVATE_H */