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) {
15 xbt_assert0(surf_link != NULL, "surf_link is NULL !");
17 link = xbt_new(s_SD_link_t, 1);
18 link->surf_link = surf_link;
19 link->data = data; /* user data */
21 name = SD_link_get_name(link);
22 xbt_dict_set(sd_global->links, name, link, __SD_link_destroy); /* add the link to the dictionary */
23 sd_global->link_count++;
28 * \brief Returns the link list
30 * Use SD_link_get_number() to know the array size.
32 * \return an array of \ref SD_link_t containing all links
33 * \see SD_link_get_number()
35 const SD_link_t* SD_link_get_list(void) {
37 xbt_dict_cursor_t cursor;
43 xbt_assert0(SD_link_get_number() > 0, "There is no link!");
45 if (sd_global->link_list == NULL) { /* this is the first time the function is called */
46 sd_global->link_list = xbt_new(SD_link_t, sd_global->link_count);
49 xbt_dict_foreach(sd_global->links, cursor, key, data) {
50 sd_global->link_list[i++] = (SD_link_t) data;
53 return sd_global->link_list;
57 * \brief Returns the number of links
59 * \return the number of existing links
60 * \see SD_link_get_list()
62 int SD_link_get_number(void) {
64 return sd_global->link_count;
68 * \brief Returns the user data of a link
71 * \return the user data associated with this link (can be \c NULL)
72 * \see SD_link_set_data()
74 void* SD_link_get_data(SD_link_t link) {
76 xbt_assert0(link != NULL, "Invalid parameter");
81 * \brief Sets the user data of a link
83 * The new data can be \c NULL. The old data should have been freed first
84 * if it was not \c NULL.
87 * \param data the new data you want to associate with this link
88 * \see SD_link_get_data()
90 void SD_link_set_data(SD_link_t link, void *data) {
92 xbt_assert0(link != NULL, "Invalid parameter");
97 * \brief Returns the name of a link
100 * \return the name of this link (cannot be \c NULL)
102 const char* SD_link_get_name(SD_link_t link) {
103 SD_CHECK_INIT_DONE();
104 xbt_assert0(link != NULL, "Invalid parameter");
105 return surf_workstation_model->extension_public->get_link_name(link->surf_link);
109 * \brief Returns the current bandwidth of a link
112 * \return the current bandwidth of this link, in Flops
114 double SD_link_get_current_bandwidth(SD_link_t link) {
115 SD_CHECK_INIT_DONE();
116 xbt_assert0(link != NULL, "Invalid parameter");
117 return surf_workstation_model->extension_public->get_link_bandwidth(link->surf_link);
121 * \brief Returns the value of a given link property
123 * \param workstation a workstation
124 * \param name a property name
125 * \return value of a property (or NULL if property not set)
127 const char* SD_link_get_property_value(SD_link_t link, const char* name)
129 return xbt_dict_get_or_null(SD_link_get_properties(link), name);
133 * \brief Returns a #xbt_dict_t consisting of the list of properties assigned to a link
136 * \return the dictionary containing the properties associated with the link
138 xbt_dict_t SD_link_get_properties(SD_link_t link)
140 SD_CHECK_INIT_DONE();
141 xbt_assert0((link != NULL), "Invalid parameters");
143 return (surf_workstation_model->common_public->get_properties(link->surf_link));
148 * \brief Returns the current latency of a link
151 * \return the current latency of this link, in seconds
153 double SD_link_get_current_latency(SD_link_t link) {
154 SD_CHECK_INIT_DONE();
155 xbt_assert0(link != NULL, "Invalid parameter");
156 return surf_workstation_model->extension_public->get_link_latency(link->surf_link);
161 void __SD_link_destroy(void *link) {
162 SD_CHECK_INIT_DONE();
163 xbt_assert0(link != NULL, "Invalid parameter");
164 /* link->surf_link is freed by surf_exit and link->data is freed by the user */