SimGrid 3.6.2
Scalable simulation of distributed systems
Defines | Typedefs | Functions
Callback declaration and use
Messages

Defines

#define gras_cb_register(msgtype_name, cb)
 Bind the given callback to the given message type (described by its name)
#define gras_cb_unregister(msgtype_name, cb)
 Unbind the given callback to the given message type (described by its name)

Typedefs

typedef struct s_gras_msg_cb_ctxgras_msg_cb_ctx_t
 Context of callbacks (opaque structure, created by the middleware only, never by user)
typedef int(* gras_msg_cb_t )(gras_msg_cb_ctx_t ctx, void *payload)
 Type of message callback functions.

Functions

gras_socket_t gras_msg_cb_ctx_from (gras_msg_cb_ctx_t ctx)
 Retrieve the expeditor of the message.
void gras_cb_register_ (gras_msgtype_t msgtype, gras_msg_cb_t cb)
 Bind the given callback to the given message type.
void gras_cb_unregister_ (gras_msgtype_t msgtype, gras_msg_cb_t cb)
 Unbind the given callback from the given message type.

Detailed Description

This is how to register a given function so that it gets called when a given type of message arrives.

You can register several callbacks to the same kind of messages, and they will get stacked. The lastly added callback gets the message first. If it consumes the message, it should return a true value when done. If not, it should return 0, and the message will be passed to the second callback of the stack, if any.


Define Documentation

#define gras_cb_register (   msgtype_name,
  cb 
)

Bind the given callback to the given message type (described by its name)

Several callbacks can be attached to a given message type. The lastly added one will get the message first, and if it returns a non-null value, the message will be passed to the second one. And so on until one of the callbacks accepts the message.

Using gras_cb_register is a bit slower than using gras_cb_register_ since GRAS has to search for the given msgtype in the hash table, but you don't care in most case.

#define gras_cb_unregister (   msgtype_name,
  cb 
)

Unbind the given callback to the given message type (described by its name)

Using gras_cb_unregister is a bit slower than using gras_cb_unregister_ since GRAS has to search for the given msgtype in the hash table, but you don't care in most case.


Typedef Documentation

typedef int(* gras_msg_cb_t)(gras_msg_cb_ctx_t ctx, void *payload)

Type of message callback functions.

Parameters:
expeditor,:a socket to contact who sent this message
payload,:the message itself
Returns:
true if the message was consumed by the callback, false if the message was refused by the callback (and should be passed to the next callback of the stack for this message)

Once a such a function is registered to handle messages of a given type with gras_cb_register(), it will be called each time such a message arrives (unless a gras_msg_wait() intercepts it on arrival).

If the callback accepts the message, it should free it after use.


Function Documentation

void gras_cb_register_ ( gras_msgtype_t  msgtype,
gras_msg_cb_t  cb 
)

Bind the given callback to the given message type.

Several callbacks can be attached to a given message type. The lastly added one will get the message first, and if it returns a non-null value, the message will be passed to the second one. And so on until one of the callbacks accepts the message.


Back to the main Simgrid Documentation page The version of Simgrid documented here is v3.6.2.
Documentation of other versions can be found in their respective archive files (directory doc/html).
Generated for SimGridAPI by doxygen