Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix copyright headers
[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 "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/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                          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, gras_msg_t msg /*OUT*/);
69 void gras_msg_send_ext(gras_socket_t sock,
70                        e_gras_msg_kind_t kind,
71                        unsigned long int ID,
72                        gras_msgtype_t msgtype, void *payload);
73
74 /* The thread in charge of receiving messages and queuing them */
75 typedef struct s_gras_msg_listener_ *gras_msg_listener_t;
76 gras_msg_listener_t gras_msg_listener_launch(xbt_queue_t msg_exchange);
77 /* The caller has the responsability to cleanup the queues himself */
78 void gras_msg_listener_shutdown(void);
79
80 /**
81  * gras_cblist_t:
82  *
83  * association between msg ID and cb list for a given process
84  */
85 struct s_gras_cblist {
86   long int id;
87   xbt_dynar_t cbs;              /* of gras_msg_cb_t */
88 };
89
90 typedef struct s_gras_cblist gras_cblist_t;
91 void gras_cbl_free(void *);     /* used to free the memory at the end */
92 void gras_cblist_free(void *cbl);
93
94 /**
95  * gras_msg_cb_ctx_t:
96  *
97  * Context associated to a given callback (to either regular message or RPC)
98  */
99 struct s_gras_msg_cb_ctx {
100   gras_socket_t expeditor;
101   gras_msgtype_t msgtype;
102   unsigned long int ID;
103   double timeout;
104   int answer_due;               /* Whether the callback is expected to return a result (for sanity checks) */
105 };
106 typedef struct s_gras_msg_cb_ctx s_gras_msg_cb_ctx_t;
107
108 /* ********* *
109  * * TIMER * *
110  * ********* */
111 typedef struct {
112   double expiry;
113   double period;
114   void_f_void_t action;
115   int repeat;
116 } s_gras_timer_t, *gras_timer_t;
117
118 /* returns 0 if it handled a timer, or the delay until next timer, or -1 if no armed timer */
119 double gras_msg_timer_handle(void);
120
121 gras_msg_cb_ctx_t gras_msg_cb_ctx_new(gras_socket_t expe,
122                                       gras_msgtype_t msgtype,
123                                       unsigned long int ID,
124                                       int answer_due, double timeout);
125
126
127
128 /* We deploy a mallocator on the RPC contextes */
129 #include "xbt/mallocator.h"
130 extern xbt_mallocator_t gras_msg_ctx_mallocator;
131 void *gras_msg_ctx_mallocator_new_f(void);
132 void gras_msg_ctx_mallocator_free_f(void *dict);
133 void gras_msg_ctx_mallocator_reset_f(void *dict);
134
135
136 #endif /* GRAS_MESSAGE_PRIVATE_H */