Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Rename some model methods to stick to getters/setters naming standards; further facto...
[simgrid.git] / src / surf / surf_action.c
1 /* Copyright (c) 2009 The SimGrid Team. All rights reserved.                */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "surf_private.h"
7
8 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel);
9
10 const char *surf_action_state_names[6] = {
11   "SURF_ACTION_READY",
12   "SURF_ACTION_RUNNING",
13   "SURF_ACTION_FAILED",
14   "SURF_ACTION_DONE",
15   "SURF_ACTION_TO_FREE",
16   "SURF_ACTION_NOT_IN_THE_SYSTEM"
17 };
18
19 e_surf_action_state_t surf_action_state_get(surf_action_t action)
20 {
21   surf_action_state_t action_state = &(action->model_type->states);
22
23   if (action->state_set == action_state->ready_action_set)
24     return SURF_ACTION_READY;
25   if (action->state_set == action_state->running_action_set)
26     return SURF_ACTION_RUNNING;
27   if (action->state_set == action_state->failed_action_set)
28     return SURF_ACTION_FAILED;
29   if (action->state_set == action_state->done_action_set)
30     return SURF_ACTION_DONE;
31   return SURF_ACTION_NOT_IN_THE_SYSTEM;
32 }
33
34 double surf_action_get_start_time(surf_action_t action)
35 {
36   return action->start;
37 }
38
39 double surf_action_get_finish_time(surf_action_t action)
40 {
41   return action->finish;
42 }
43
44 void surf_action_free(surf_action_t * action)
45 {
46   (*action)->model_type->action_cancel(*action);
47   free(*action);
48   *action = NULL;
49 }
50
51 void surf_action_state_set(surf_action_t action,
52                               e_surf_action_state_t state)
53 {
54   surf_action_state_t action_state = &(action->model_type->states);
55   XBT_IN2("(%p,%s)", action, surf_action_state_names[state]);
56   xbt_swag_remove(action, action->state_set);
57
58   if (state == SURF_ACTION_READY)
59     action->state_set = action_state->ready_action_set;
60   else if (state == SURF_ACTION_RUNNING)
61     action->state_set = action_state->running_action_set;
62   else if (state == SURF_ACTION_FAILED)
63     action->state_set = action_state->failed_action_set;
64   else if (state == SURF_ACTION_DONE)
65     action->state_set = action_state->done_action_set;
66   else
67     action->state_set = NULL;
68
69   if (action->state_set)
70     xbt_swag_insert(action, action->state_set);
71   XBT_OUT;
72 }
73
74 void surf_action_data_set(surf_action_t action, void *data)
75 {
76   action->data = data;
77 }