Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
deport three other MSG examples
[simgrid.git] / teshsuite / msg / app-chainsend / messages.c
1 /* Copyright (c) 2012-2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #include "messages.h"
8
9 msg_task_t task_message_new(e_message_type type, unsigned int len)
10 {
11   message_t msg      = xbt_new(s_message_t, 1);
12   msg->type          = type;
13   msg->prev_hostname = NULL;
14   msg->next_hostname = NULL;
15   msg_task_t task    = MSG_task_create(NULL, 0, len, msg);
16
17   return task;
18 }
19
20 msg_task_t task_message_chain_new(const char* prev, const char* next, const unsigned int num_pieces)
21 {
22   msg_task_t task    = task_message_new(MESSAGE_BUILD_CHAIN, MESSAGE_BUILD_CHAIN_SIZE);
23   message_t msg      = MSG_task_get_data(task);
24   msg->prev_hostname = xbt_strdup(prev);
25   msg->next_hostname = xbt_strdup(next);
26   msg->num_pieces    = num_pieces;
27
28   return task;
29 }
30
31 msg_task_t task_message_data_new(const char* block, unsigned int len)
32 {
33   msg_task_t task  = task_message_new(MESSAGE_SEND_DATA, MESSAGE_SEND_DATA_HEADER_SIZE + len);
34   message_t msg    = MSG_task_get_data(task);
35   msg->data_block  = block;
36   msg->data_length = len;
37
38   return task;
39 }
40
41 void task_message_delete(void* task)
42 {
43   message_t msg = MSG_task_get_data(task);
44   xbt_free(msg);
45   MSG_task_destroy(task);
46 }