Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
b794e142c36138e153f4fe1c9e53bf7b821515f6
[simgrid.git] / include / gras / messages.h
1 /* $Id$ */
2
3 /* messaging - high level communication (send/receive messages)             */
4
5 /* module's public interface exported to end user.                          */
6
7 /* Authors: Martin Quinson                                                  */
8 /* Copyright (C) 2003, 2004 Martin Quinson.                                 */
9
10 /* This program is free software; you can redistribute it and/or modify it
11    under the terms of the license (GNU LGPL) which comes with this package. */
12
13
14 #ifndef GRAS_MESSAGES_H
15 #define GRAS_MESSAGES_H
16
17 /*! C++ users need love */
18 #ifndef BEGIN_DECL
19 # ifdef __cplusplus
20 #  define BEGIN_DECL extern "C" {
21 # else
22 #  define BEGIN_DECL 
23 # endif
24 #endif
25
26 /*! C++ users need love */
27 #ifndef END_DECL
28 # ifdef __cplusplus
29 #  define END_DECL }
30 # else
31 #  define END_DECL 
32 # endif
33 #endif
34 /* End of cruft for C++ */
35
36 BEGIN_DECL
37
38 /* msgtype declaration and retrival */
39 typedef struct s_gras_msgtype gras_msgtype_t;
40
41 void gras_msgtype_declare  (const char            *name,
42                             gras_datadesc_type_t  *payload);
43 void gras_msgtype_declare_v(const char            *name,
44                             short int              version,
45                             gras_datadesc_type_t  *payload);
46
47 gras_msgtype_t *gras_msgtype_by_name (const char     *name);
48 gras_msgtype_t *gras_msgtype_by_namev(const char      *name,
49                                       short int        version);
50
51 /**
52  * gras_cb_t:
53  * @msg: The message itself
54  * @Returns: true if the message was consumed by the callback.
55  *
56  * Type of message callback functions. Once a such a function is registered to 
57  * handle messages of a given type with RegisterCallback(), it will be called 
58  * each time such a message incomes.
59  *
60  * If the callback accepts the message, it should free it after use.
61  */
62 typedef int (*gras_cb_t)(gras_socket_t        *expeditor,
63                          void                 *payload);
64 void gras_cb_register  (gras_msgtype_t *msgtype,
65                         gras_cb_t       cb);
66 void gras_cb_unregister(gras_msgtype_t *msgtype,
67                         gras_cb_t     cb);
68
69 gras_error_t gras_msg_send(gras_socket_t  *sock,
70                            gras_msgtype_t *msgtype,
71                            void           *payload);
72 gras_error_t gras_msg_wait(double                 timeout,    
73                            gras_msgtype_t        *msgt_want,
74                            gras_socket_t        **expeditor,
75                            void                  *payload);
76 gras_error_t gras_msg_handle(double timeOut);
77
78
79 END_DECL
80
81 #endif /* GRAS_MSG_H */
82