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 xbt_dict_cursor_t cursor;
40 if (sd_global->link_list == NULL) { /* this is the first time the function is called */
41 sd_global->link_list = xbt_new0(SD_link_t, sd_global->link_count);
44 xbt_dict_foreach(sd_global->links, cursor, key, data) {
45 sd_global->link_list[i++] = (SD_link_t) data;
48 return sd_global->link_list;
52 * \brief Returns the number of links
54 * \return the number of existing links
55 * \see SD_link_get_list()
57 int SD_link_get_number(void) {
59 return sd_global->link_count;
63 * \brief Returns the user data of a link
66 * \return the user data associated with this link (can be \c NULL)
67 * \see SD_link_set_data()
69 void* SD_link_get_data(SD_link_t link) {
71 xbt_assert0(link != NULL, "Invalid parameter");
76 * \brief Sets the user data of a link
78 * The new data can be \c NULL. The old data should have been freed first
79 * if it was not \c NULL.
82 * \param data the new data you want to associate with this link
83 * \see SD_link_get_data()
85 void SD_link_set_data(SD_link_t link, void *data) {
87 xbt_assert0(link != NULL, "Invalid parameter");
92 * \brief Returns the name of a link
95 * \return the name of this link (cannot be \c NULL)
97 const char* SD_link_get_name(SD_link_t link) {
99 xbt_assert0(link != NULL, "Invalid parameter");
100 return surf_workstation_resource->extension_public->get_link_name(link->surf_link);
104 * \brief Returns the current bandwidth of a link
107 * \return the current bandwidth of this link, in Flops
109 double SD_link_get_current_bandwidth(SD_link_t link) {
110 SD_CHECK_INIT_DONE();
111 xbt_assert0(link != NULL, "Invalid parameter");
112 return surf_workstation_resource->extension_public->get_link_bandwidth(link->surf_link);
116 * \brief Returns the current latency of a link
119 * \return the current latency of this link, in seconds
121 double SD_link_get_current_latency(SD_link_t link) {
122 SD_CHECK_INIT_DONE();
123 xbt_assert0(link != NULL, "Invalid parameter");
124 return surf_workstation_resource->extension_public->get_link_latency(link->surf_link);
129 void __SD_link_destroy(void *link) {
130 SD_CHECK_INIT_DONE();
131 xbt_assert0(link != NULL, "Invalid parameter");
132 /* link->surf_link is freed by surf_exit and link->data is freed by the user */