Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
12572e325a2360af6dd6e5cf91178b21759a2d8c
[simgrid.git] / src / instr / jedule / jedule_events.c
1 /* Copyright (c) 2010-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 <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10
11 #include "xbt/dict.h"
12 #include "xbt/dynar.h"
13 #include "xbt/asserts.h"
14
15 #include "simgrid/jedule/jedule_events.h"
16 #include "simgrid/jedule/jedule_platform.h"
17
18 #ifdef HAVE_JEDULE
19
20 void jed_event_add_resources(jed_event_t event, xbt_dynar_t host_selection) {
21   xbt_dynar_t resource_subset_list;
22   jed_res_subset_t res_set;
23   unsigned int i;
24
25   resource_subset_list = xbt_dynar_new(sizeof(jed_res_subset_t), NULL);
26
27   jed_simgrid_get_resource_selection_by_hosts(resource_subset_list, host_selection);
28   xbt_dynar_foreach(resource_subset_list, i, res_set)  {
29     xbt_dynar_push(event->resource_subsets, &res_set);
30   }
31
32   xbt_dynar_free(&resource_subset_list);
33 }
34
35 void jed_event_add_characteristic(jed_event_t event, char *characteristic) {
36   xbt_assert( characteristic != NULL );
37   xbt_dynar_push(event->characteristics_list, &characteristic);
38 }
39
40
41 void jed_event_add_info(jed_event_t event, char *key, char *value) {
42   char *val_cp;
43
44   xbt_assert(key != NULL);
45   xbt_assert(value != NULL);
46
47   val_cp = strdup(value);
48   xbt_dict_set(event->info_hash, key, val_cp, NULL);
49 }
50
51
52 void create_jed_event(jed_event_t *event, char *name, double start_time,
53     double end_time, const char *type) {
54
55   *event = xbt_new0(s_jed_event_t,1);
56   (*event)->name = xbt_strdup(name);
57
58   (*event)->start_time = start_time;
59   (*event)->end_time = end_time;
60
61   (*event)->type = xbt_strdup(type);
62
63   (*event)->resource_subsets = xbt_dynar_new(sizeof(jed_res_subset_t), xbt_free_ref);
64   (*event)->characteristics_list = xbt_dynar_new(sizeof(char*), NULL);
65   (*event)->info_hash = xbt_dict_new_homogeneous(NULL);
66
67 }
68
69
70 void jed_event_free(jed_event_t event) {
71
72   free(event->name);
73   free(event->type);
74
75   xbt_dynar_free(&event->resource_subsets);
76
77   xbt_dynar_free(&event->characteristics_list);
78   xbt_dict_free(&event->info_hash);
79
80   free(event);
81 }
82
83 #endif