Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
637a6e28eb57590f924128123677568e6302f942
[simgrid.git] / src / simdag / sd_link.c
1 #include "private.h"
2 #include "simdag/simdag.h"
3 #include "xbt/dict.h"
4 #include "xbt/sysdep.h"
5 #include "surf/surf.h"
6
7 /* Creates a link.
8  */
9 SD_link_t __SD_link_create(void *surf_link, void *data) {
10   SD_CHECK_INIT_DONE();
11   xbt_assert0(surf_link != NULL, "surf_link is NULL !");
12
13
14   SD_link_t link = xbt_new0(s_SD_link_t, 1);
15   link->surf_link = surf_link;
16   link->data = data; /* user data */
17
18   const char *name = SD_link_get_name(link);
19   xbt_dict_set(sd_global->links, name, link, __SD_link_destroy); /* add the workstation to the dictionary */
20
21   return link;
22 }
23
24 /* Returns the user data of a link. The user data can be NULL.
25  */
26 void* SD_link_get_data(SD_link_t link) {
27   SD_CHECK_INIT_DONE();
28   xbt_assert0(link != NULL, "Invalid parameter");
29   return link->data;
30 }
31
32 /* Sets the user data of a link. The new data can be NULL. The old data should have been freed first if it was not NULL.
33  */
34 void SD_link_set_data(SD_link_t link, void *data) {
35   SD_CHECK_INIT_DONE();
36   xbt_assert0(link != NULL, "Invalid parameter");
37   link->data = data;
38 }
39
40 /* Returns the name of a link. The name cannot be NULL.
41  */
42 const char* SD_link_get_name(SD_link_t link) {
43   SD_CHECK_INIT_DONE();
44   xbt_assert0(link != NULL, "Invalid parameter");
45   return surf_workstation_resource->extension_public->get_link_name(link->surf_link);
46 }
47
48 /* Returns the capacity of a link.
49  */
50 /*
51 double SD_link_get_capacity(SD_link_t link) {
52   xbt_assert0(link, "Invalid parameter");
53   return link->capacity;
54 }*/
55
56 /* Return the current bandwidth of a link.
57  */
58 double SD_link_get_current_bandwidth(SD_link_t link) {
59   SD_CHECK_INIT_DONE();
60   xbt_assert0(link != NULL, "Invalid parameter");
61   return surf_workstation_resource->extension_public->get_link_bandwidth(link->surf_link);
62 }
63
64 /* Return the current latency of a link.
65  */
66 double SD_link_get_current_latency(SD_link_t link) {
67   SD_CHECK_INIT_DONE();
68   xbt_assert0(link != NULL, "Invalid parameter");
69   return surf_workstation_resource->extension_public->get_link_latency(link->surf_link);
70 }
71
72 /* Destroys a link. The user data (if any) should have been destroyed first.
73  */
74 void __SD_link_destroy(void *link) {
75   SD_CHECK_INIT_DONE();
76   xbt_assert0(link != NULL, "Invalid parameter");
77   /* link->surf_link is freed by surf_exit and link->data is freed by the user */
78   xbt_free(link);
79 }
80