1 /* Copyright (c) 2012. 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. */
8 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_kademlia_task,
9 "Messages specific for this msg example");
11 * Creates a new "find node" task
12 * @param sender_id the id of the node who sends the task
13 * @param destination_id the id the sender is trying to find
14 * @param hostname the hostname of the node, for logging purposes
16 msg_task_t task_new_find_node(unsigned int sender_id,
17 unsigned int destination_id, char *mailbox,
21 task_data_t data = xbt_new(s_task_data_t, 1);
23 data->type = TASK_FIND_NODE;
24 data->sender_id = sender_id;
25 data->destination_id = destination_id;
27 data->answer_to = mailbox;
28 data->issuer_host_name = hostname;
31 msg_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, data);
37 * Creates a new "answer to find node" task
38 * @param sender_id the node who sent the task
39 * @param destination_id the node that should be found
40 * @param answer the answer to send
41 * @param mailbox The mailbox of the sender
42 * @param hostname sender hostname
44 msg_task_t task_new_find_node_answer(unsigned int sender_id,
45 unsigned int destination_id,
46 answer_t answer, char *mailbox,
50 task_data_t data = xbt_new(s_task_data_t, 1);
52 data->type = TASK_FIND_NODE_ANSWER;
53 data->sender_id = sender_id;
54 data->destination_id = destination_id;
55 data->answer = answer;
56 data->answer_to = mailbox;
57 data->issuer_host_name = hostname;
59 msg_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, data);
65 * Creates a new "ping" task
66 * @param sender_id : sender node identifier
67 * @param mailbox : mailbox where we should respond
68 * @param hostname : hostname of the sender, for debugging purposes
70 msg_task_t task_new_ping(unsigned int sender_id, char *mailbox,
74 task_data_t data = xbt_new(s_task_data_t, 1);
76 data->type = TASK_PING;
77 data->sender_id = sender_id;
78 data->destination_id = 0;
80 data->answer_to = mailbox;
81 data->issuer_host_name = hostname;
83 msg_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, data);
89 * Creates a new "ping answer" task
90 * @param sender_id : sender node identifier
91 * @param mailbox : mailbox of the sender
92 * @param hostname : hostname of the sender, for debugging purposes
94 msg_task_t task_new_ping_answer(unsigned int sender_id, char *mailbox,
98 task_data_t data = xbt_new(s_task_data_t, 1);
100 data->type = TASK_PING_ANSWER;
101 data->sender_id = sender_id;
102 data->destination_id = 0;
104 data->answer_to = mailbox;
105 data->issuer_host_name = hostname;
107 msg_task_t task = MSG_task_create(NULL, COMP_SIZE, COMM_SIZE, data);
113 * Destroys a task and its data
114 * @param task the task that'll be destroyed
116 void task_free(msg_task_t task)
118 xbt_assert((task != NULL), "Tried to free a NULL task");
120 task_data_t data = MSG_task_get_data(task);
123 answer_free(data->answer);
127 MSG_task_destroy(task);
132 * Destroys a task and its data (taking a void* pointer
133 * @param task The task that'll be destroyed
135 void task_free_v(void *task)