Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
2773ad10e713e9d81ee2186d091e602b74c3f6b4
[simgrid.git] / src / gras_simix / Msg / gras_simix_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/set.h"
21 #include "gras/transport.h"
22 #include "gras/datadesc.h"
23 #include "gras/virtu.h"
24
25 #include "gras/messages.h"
26 #include "gras/timer.h"
27 #include "gras_modinter.h"
28
29 #include "gras_simix/Msg/gras_simix_msg_interface.h"
30
31 extern char _GRAS_header[6];
32
33 extern int gras_msg_libdata_id; /* The identifier of our libdata */
34  
35 extern const char *e_gras_msg_kind_names[e_gras_msg_kind_count];
36
37 /* declare either regular messages or RPC or whatever */
38 void 
39 gras_msgtype_declare_ext(const char           *name,
40                          short int             version,
41                          e_gras_msg_kind_t     kind, 
42                          gras_datadesc_type_t  payload_request,
43                          gras_datadesc_type_t  payload_answer);
44
45 /**
46  * gras_msgtype_t:
47  *
48  * Message type descriptor. There one of these for each registered version.
49  */
50 typedef struct s_gras_msgtype {
51   /* headers for the data set */
52   unsigned int   code;
53   char          *name;
54   unsigned int   name_len;
55         
56   /* payload */
57   short int version;
58   e_gras_msg_kind_t kind;
59   gras_datadesc_type_t ctn_type;
60   gras_datadesc_type_t answer_type; /* only used for RPC */
61 } s_gras_msgtype_t;
62
63 extern xbt_set_t _gras_msgtype_set; /* of gras_msgtype_t */
64 void gras_msgtype_free(void *msgtype);
65
66
67 /* functions to extract msg from socket or put it on wire (depend RL vs SG) */
68 void gras_msg_recv(gras_socket_t   sock,
69                    gras_msg_t      msg/*OUT*/);
70 void gras_msg_send_ext(gras_socket_t   sock,
71                      e_gras_msg_kind_t kind,
72                        unsigned long int ID,
73                        gras_msgtype_t  msgtype,
74                        void           *payload);
75
76 /**
77  * gras_cblist_t:
78  *
79  * association between msg ID and cb list for a given process
80  */
81 struct s_gras_cblist {
82   long int id;
83   xbt_dynar_t cbs; /* of gras_msg_cb_t */
84 };
85
86 typedef struct s_gras_cblist gras_cblist_t;
87 void gras_cbl_free(void *); /* used to free the memory at the end */
88 void gras_cblist_free(void *cbl);
89
90 /**
91  * gras_msg_cb_ctx_t:
92  *
93  * Context associated to a given callback (to either regular message or RPC)
94  */
95 struct s_gras_msg_cb_ctx {
96   gras_socket_t expeditor;
97   gras_msgtype_t msgtype;
98   unsigned long int ID;
99   double timeout;
100   int answer_due; /* Whether the callback is expected to return a result (for sanity checks) */
101 };
102 typedef struct s_gras_msg_cb_ctx s_gras_msg_cb_ctx_t;
103
104 /* ********* *
105  * * TIMER * *
106  * ********* */
107 typedef struct {
108   double expiry;
109   double period;
110   void_f_void_t *action;
111   int repeat;
112 } s_gras_timer_t, *gras_timer_t;
113
114 /* returns 0 if it handled a timer, or the delay until next timer, or -1 if no armed timer */
115 double gras_msg_timer_handle(void);
116
117 gras_msg_cb_ctx_t gras_msg_cb_ctx_new(gras_socket_t expe,
118                                                  gras_msgtype_t msgtype,
119                                                  unsigned long int ID,
120                                                  int answer_due,
121                                                  double timeout);
122
123
124 /* We deploy a mallocator on the RPC contextes */
125 #include "xbt/mallocator.h"
126 extern xbt_mallocator_t gras_msg_ctx_mallocator;
127 void* gras_msg_ctx_mallocator_new_f(void);
128 void gras_msg_ctx_mallocator_free_f(void* dict);
129 void gras_msg_ctx_mallocator_reset_f(void* dict);
130
131
132 #endif  /* GRAS_MESSAGE_PRIVATE_H */