Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Verify if elements src_gateway and dst_gateway are present in global_routing.
[simgrid.git] / src / surf / surf_model.c
1
2 /* Copyright (c) 2009, 2010. The SimGrid Team.
3  * All rights reserved.                                                     */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #include "surf_private.h"
9 #include "xbt/dict.h"
10
11 static void void_die_impossible_paction(surf_action_t action)
12 {
13   DIE_IMPOSSIBLE;
14 }
15
16 static int int_die_impossible_paction(surf_action_t action)
17 {
18   DIE_IMPOSSIBLE;
19 }
20
21 /** @brief initialize common datastructures to all models */
22 surf_model_t surf_model_init(void)
23 {
24   s_surf_action_t action;
25   surf_model_t model = xbt_new0(s_surf_model_t, 1);
26
27   model->model_private = xbt_new0(s_surf_model_private_t, 1);
28
29   model->states.ready_action_set =
30       xbt_swag_new(xbt_swag_offset(action, state_hookup));
31   model->states.running_action_set =
32       xbt_swag_new(xbt_swag_offset(action, state_hookup));
33   model->states.failed_action_set =
34       xbt_swag_new(xbt_swag_offset(action, state_hookup));
35   model->states.done_action_set =
36       xbt_swag_new(xbt_swag_offset(action, state_hookup));
37   model->resource_set = xbt_dict_new();
38
39   model->action_unref = int_die_impossible_paction;
40   model->action_cancel = void_die_impossible_paction;
41   model->action_recycle = void_die_impossible_paction;
42
43   model->action_state_get = surf_action_state_get;
44   model->action_state_set = surf_action_state_set;
45   model->action_get_start_time = surf_action_get_start_time;
46   model->action_get_finish_time = surf_action_get_finish_time;
47   model->action_data_set = surf_action_data_set;
48
49
50   return model;
51 }
52
53 /** @brief finalize common datastructures to all models */
54 void surf_model_exit(surf_model_t model)
55 {
56   xbt_swag_free(model->states.ready_action_set);
57   xbt_swag_free(model->states.running_action_set);
58   xbt_swag_free(model->states.failed_action_set);
59   xbt_swag_free(model->states.done_action_set);
60   xbt_dict_free(&model->resource_set);
61   free(model->model_private);
62   free(model);
63 }
64
65 void *surf_model_resource_by_name(surf_model_t model, const char *name)
66 {
67   return xbt_dict_get_or_null(model->resource_set, name);
68 }