Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove gras from the main documentation
[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) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
6  * All rights reserved.                                                     */
7
8 /* This program is free software; you can redistribute it and/or modify it
9  * under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #ifndef GRAS_MESSAGE_PRIVATE_H
12 #define GRAS_MESSAGE_PRIVATE_H
13
14 #include "portable.h"
15
16 #include "xbt/sysdep.h"
17 #include "xbt/log.h"
18 #include "xbt/dynar.h"
19 #include "xbt/queue.h"
20 #include "xbt/set.h"
21 #include "gras/transport.h"
22 #include "xbt/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/Msg/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                          xbt_datadesc_type_t payload_request,
43                          xbt_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   xbt_datadesc_type_t ctn_type;
60   xbt_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 gras_msg_t gras_msg_recv_any(void);     /* Get first message arriving */
69 void gras_msg_recv(xbt_socket_t sock, gras_msg_t msg /*OUT*/);
70 void gras_msg_send_ext(xbt_socket_t sock,
71                        e_gras_msg_kind_t kind,
72                        unsigned long int ID,
73                        gras_msgtype_t msgtype, void *payload);
74
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);
80
81 /**
82  * gras_cblist_t:
83  *
84  * association between msg ID and cb list for a given process
85  */
86 struct s_gras_cblist {
87   long int id;
88   xbt_dynar_t cbs;              /* of gras_msg_cb_t */
89 };
90
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);
94
95 /**
96  * gras_msg_cb_ctx_t:
97  *
98  * Context associated to a given callback (to either regular message or RPC)
99  */
100 struct s_gras_msg_cb_ctx {
101   xbt_socket_t expeditor;
102   gras_msgtype_t msgtype;
103   unsigned long int ID;
104   double timeout;
105   int answer_due;               /* Whether the callback is expected to return a result (for sanity checks) */
106 };
107 typedef struct s_gras_msg_cb_ctx s_gras_msg_cb_ctx_t;
108
109 /* ********* *
110  * * TIMER * *
111  * ********* */
112 typedef struct {
113   double expiry;
114   double period;
115   void_f_void_t action;
116   int repeat;
117 } s_gras_timer_t, *gras_timer_t;
118
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);
121
122 gras_msg_cb_ctx_t gras_msg_cb_ctx_new(xbt_socket_t expe,
123                                       gras_msgtype_t msgtype,
124                                       unsigned long int ID,
125                                       int answer_due, double timeout);
126
127
128
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 #define gras_msg_ctx_mallocator_free_f xbt_free_f
134 void gras_msg_ctx_mallocator_reset_f(void *dict);
135
136
137 #endif                          /* GRAS_MESSAGE_PRIVATE_H */