1 /* Copyright (c) 2012, 2014. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
9 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia_task,
10 "Messages specific for this msg example");
12 * Creates a new "find node" task
13 * @param sender_id the id of the node who sends the task
14 * @param destination_id the id the sender is trying to find
15 * @param hostname the hostname of the node, for logging purposes
17 msg_task_t task_new_find_node(unsigned int sender_id,
18 unsigned int destination_id, char *mailbox,
22 task_data_t data = xbt_new(s_task_data_t, 1);
24 data->type = TASK_FIND_NODE;
25 data->sender_id = sender_id;
26 data->destination_id = destination_id;
28 data->answer_to = mailbox;
29 data->issuer_host_name = hostname;
32 msg_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, data);
38 * Creates a new "answer to find node" task
39 * @param sender_id the node who sent the task
40 * @param destination_id the node that should be found
41 * @param answer the answer to send
42 * @param mailbox The mailbox of the sender
43 * @param hostname sender hostname
45 msg_task_t task_new_find_node_answer(unsigned int sender_id,
46 unsigned int destination_id,
47 answer_t answer, char *mailbox,
51 task_data_t data = xbt_new(s_task_data_t, 1);
53 data->type = TASK_FIND_NODE_ANSWER;
54 data->sender_id = sender_id;
55 data->destination_id = destination_id;
56 data->answer = answer;
57 data->answer_to = mailbox;
58 data->issuer_host_name = hostname;
60 msg_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, data);
66 * Creates a new "ping" task
67 * @param sender_id : sender node identifier
68 * @param mailbox : mailbox where we should respond
69 * @param hostname : hostname of the sender, for debugging purposes
71 msg_task_t task_new_ping(unsigned int sender_id, char *mailbox,
75 task_data_t data = xbt_new(s_task_data_t, 1);
77 data->type = TASK_PING;
78 data->sender_id = sender_id;
79 data->destination_id = 0;
81 data->answer_to = mailbox;
82 data->issuer_host_name = hostname;
84 msg_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, data);
90 * Creates a new "ping answer" task
91 * @param sender_id : sender node identifier
92 * @param mailbox : mailbox of the sender
93 * @param hostname : hostname of the sender, for debugging purposes
95 msg_task_t task_new_ping_answer(unsigned int sender_id, char *mailbox,
99 task_data_t data = xbt_new(s_task_data_t, 1);
101 data->type = TASK_PING_ANSWER;
102 data->sender_id = sender_id;
103 data->destination_id = 0;
105 data->answer_to = mailbox;
106 data->issuer_host_name = hostname;
108 msg_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, data);
114 * Destroys a task and its data
115 * @param task the task that'll be destroyed
117 void task_free(msg_task_t task)
119 xbt_assert((task != NULL), "Tried to free a NULL task");
121 task_data_t data = MSG_task_get_data(task);
124 answer_free(data->answer);
128 MSG_task_destroy(task);
133 * Destroys a task and its data (taking a void* pointer
134 * @param task The task that'll be destroyed
136 void task_free_v(void *task)