Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / src / instr / jedule / jedule_events.cpp
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 void jed_event_add_info(jed_event_t event, char *key, char *value) {
41   char *val_cp;
42
43   xbt_assert(key != NULL);
44   xbt_assert(value != NULL);
45
46   val_cp = strdup(value);
47   xbt_dict_set(event->info_hash, key, val_cp, NULL);
48 }
49
50 void create_jed_event(jed_event_t *event, char *name, double start_time,
51     double end_time, const char *type) {
52
53   *event = xbt_new0(s_jed_event_t,1);
54   (*event)->name = xbt_strdup(name);
55
56   (*event)->start_time = start_time;
57   (*event)->end_time = end_time;
58
59   (*event)->type = xbt_strdup(type);
60
61   (*event)->resource_subsets = xbt_dynar_new(sizeof(jed_res_subset_t), xbt_free_ref);
62   (*event)->characteristics_list = xbt_dynar_new(sizeof(char*), NULL);
63   (*event)->info_hash = xbt_dict_new_homogeneous(NULL);
64 }
65
66 void jed_event_free(jed_event_t event) {
67   free(event->name);
68   free(event->type);
69
70   xbt_dynar_free(&event->resource_subsets);
71
72   xbt_dynar_free(&event->characteristics_list);
73   xbt_dict_free(&event->info_hash);
74
75   free(event);
76 }
77 #endif