2 #include "simdag/simdag.h"
4 #include "xbt/sysdep.h"
7 /* Creates a link and registers it in SD.
9 SD_link_t __SD_link_create(void *surf_link, void *data) {
11 xbt_assert0(surf_link != NULL, "surf_link is NULL !");
13 SD_link_t link = xbt_new0(s_SD_link_t, 1);
14 link->surf_link = surf_link;
15 link->data = data; /* user data */
17 const char *name = SD_link_get_name(link);
18 xbt_dict_set(sd_global->links, name, link, __SD_link_destroy); /* add the link to the dictionary */
19 sd_global->link_count++;
24 * \brief Returns the link list
26 * Use SD_link_get_number() to know the array size.
28 * \return an array of \ref SD_link_t containing all links
29 * \see SD_link_get_number()
31 const SD_link_t* SD_link_get_list(void) {
33 xbt_assert0(SD_link_get_number() > 0, "There is no link!");
35 SD_link_t *array = sd_global->link_list;
36 xbt_dict_cursor_t cursor;
41 if (array == NULL) { /* this is the first time the function is called */
42 array = xbt_new0(SD_link_t, sd_global->link_count);
45 xbt_dict_foreach(sd_global->links, cursor, key, data) {
46 array[i++] = (SD_link_t) data;
53 * \brief Returns the number of links
55 * \return the number of existing links
56 * \see SD_link_get_list()
58 int SD_link_get_number(void) {
60 return sd_global->link_count;
64 * \brief Returns the user data of a link
67 * \return the user data associated with this link (can be \c NULL)
68 * \see SD_link_set_data()
70 void* SD_link_get_data(SD_link_t link) {
72 xbt_assert0(link != NULL, "Invalid parameter");
77 * \brief Sets the user data of a link
79 * The new data can be \c NULL. The old data should have been freed first
80 * if it was not \c NULL.
83 * \param data the new data you want to associate with this link
84 * \see SD_link_get_data()
86 void SD_link_set_data(SD_link_t link, void *data) {
88 xbt_assert0(link != NULL, "Invalid parameter");
93 * \brief Returns the name of a link
96 * \return the name of this link (cannot be \c NULL)
98 const char* SD_link_get_name(SD_link_t link) {
100 xbt_assert0(link != NULL, "Invalid parameter");
101 return surf_workstation_resource->extension_public->get_link_name(link->surf_link);
105 * \brief Returns the current bandwidth of a link
108 * \return the current bandwidth of this link, in Flops
110 double SD_link_get_current_bandwidth(SD_link_t link) {
111 SD_CHECK_INIT_DONE();
112 xbt_assert0(link != NULL, "Invalid parameter");
113 return surf_workstation_resource->extension_public->get_link_bandwidth(link->surf_link);
117 * \brief Returns the current latency of a link
120 * \return the current latency of this link, in seconds
122 double SD_link_get_current_latency(SD_link_t link) {
123 SD_CHECK_INIT_DONE();
124 xbt_assert0(link != NULL, "Invalid parameter");
125 return surf_workstation_resource->extension_public->get_link_latency(link->surf_link);
130 void __SD_link_destroy(void *link) {
131 SD_CHECK_INIT_DONE();
132 xbt_assert0(link != NULL, "Invalid parameter");
133 /* link->surf_link is freed by surf_exit and link->data is freed by the user */