X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/8750e7f378b5d48477e1b0b2796a437366a3ea2b..e33bfee8391fbf3a1a0b4cd5cd33f14a291c8052:/src/simdag/sd_link.c diff --git a/src/simdag/sd_link.c b/src/simdag/sd_link.c index 89eed1065f..80cf7cac85 100644 --- a/src/simdag/sd_link.c +++ b/src/simdag/sd_link.c @@ -1,97 +1,167 @@ #include "private.h" #include "simdag/simdag.h" +#include "xbt/dict.h" +#include "xbt/sysdep.h" #include "surf/surf.h" -#include "xbt/sysdep.h" /* xbt_new0 */ -/* Creates a link. +/* Creates a link and registers it in SD. */ -SD_link_t __SD_link_create(void *surf_link, char *name, void *data) { - CHECK_INIT_DONE(); - xbt_assert0(surf_link != NULL, "surf_link is NULL !"); - xbt_assert0(name != NULL, "name is NULL !"); +SD_link_t __SD_link_create(void *surf_link, void *data) { - SD_link_data_t sd_data = xbt_new0(s_SD_link_data_t, 1); /* link private data */ - sd_data->surf_link = surf_link; - sd_data->name = xbt_strdup(name); + SD_link_t link; + const char *name; - SD_link_t link = xbt_new0(s_SD_link_t, 1); - link->sd_data = sd_data; /* private data */ - link->data = data; /* user data */ + SD_CHECK_INIT_DONE(); + xbt_assert0(surf_link != NULL, "surf_link is NULL !"); - /*link->capacity = capacity;*/ - /* link->current_bandwidth = bandwidth; - link->current_latency = latency;*/ + link = xbt_new(s_SD_link_t, 1); + link->surf_link = surf_link; + link->data = data; /* user data */ - /*xbt_dynar_push(sd_global->links, link);*/ - xbt_dict_set(sd_global->links, name, link, __SD_link_destroy); /* add the workstation to the dictionary */ + name = SD_link_get_name(link); + xbt_dict_set(sd_global->links, name, link, __SD_link_destroy); /* add the link to the dictionary */ + sd_global->link_count++; return link; } +/** + * \brief Returns the link list + * + * Use SD_link_get_number() to know the array size. + * + * \return an array of \ref SD_link_t containing all links + * \see SD_link_get_number() + */ +const SD_link_t* SD_link_get_list(void) { + + xbt_dict_cursor_t cursor; + char *key; + void *data; + int i; + + SD_CHECK_INIT_DONE(); + xbt_assert0(SD_link_get_number() > 0, "There is no link!"); + + if (sd_global->link_list == NULL) { /* this is the first time the function is called */ + sd_global->link_list = xbt_new(SD_link_t, sd_global->link_count); + + i = 0; + xbt_dict_foreach(sd_global->links, cursor, key, data) { + sd_global->link_list[i++] = (SD_link_t) data; + } + } + return sd_global->link_list; +} + +/** + * \brief Returns the number of links + * + * \return the number of existing links + * \see SD_link_get_list() + */ +int SD_link_get_number(void) { + SD_CHECK_INIT_DONE(); + return sd_global->link_count; +} -/* Returns the user data of a link. The user data can be NULL. +/** + * \brief Returns the user data of a link + * + * \param link a link + * \return the user data associated with this link (can be \c NULL) + * \see SD_link_set_data() */ void* SD_link_get_data(SD_link_t link) { - CHECK_INIT_DONE(); + SD_CHECK_INIT_DONE(); xbt_assert0(link != NULL, "Invalid parameter"); return link->data; } -/* 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. +/** + * \brief Sets the user data of a link + * + * The new data can be \c NULL. The old data should have been freed first + * if it was not \c NULL. + * + * \param link a link + * \param data the new data you want to associate with this link + * \see SD_link_get_data() */ void SD_link_set_data(SD_link_t link, void *data) { - CHECK_INIT_DONE(); + SD_CHECK_INIT_DONE(); xbt_assert0(link != NULL, "Invalid parameter"); link->data = data; } -/* Returns the name of a link. The name can be NULL. +/** + * \brief Returns the name of a link + * + * \param link a link + * \return the name of this link (cannot be \c NULL) */ const char* SD_link_get_name(SD_link_t link) { - CHECK_INIT_DONE(); + SD_CHECK_INIT_DONE(); xbt_assert0(link != NULL, "Invalid parameter"); - return link->sd_data->name; + return surf_workstation_model->extension_public->get_link_name(link->surf_link); +} - /* return surf_network_resource->common_public->get_resource_name(link->sd_data->surf_link);*/ +/** + * \brief Returns the current bandwidth of a link + * + * \param link a link + * \return the current bandwidth of this link, in Flops + */ +double SD_link_get_current_bandwidth(SD_link_t link) { + SD_CHECK_INIT_DONE(); + xbt_assert0(link != NULL, "Invalid parameter"); + return surf_workstation_model->extension_public->get_link_bandwidth(link->surf_link); } -/* Returns the capacity of a link. +/** + * \brief Returns the value of a given link property + * + * \param link the inspected link + * \param name a property name + * \return value of a property (or NULL if property not set) */ -/* -double SD_link_get_capacity(SD_link_t link) { - xbt_assert0(link, "Invalid parameter"); - return link->capacity; -}*/ +const char* SD_link_get_property_value(SD_link_t link, const char* name) +{ + return xbt_dict_get_or_null(SD_link_get_properties(link), name); +} -/* Return the current bandwidth of a link. +/** + * \brief Returns a #xbt_dict_t consisting of the list of properties assigned to a link + * + * \param link a link + * \return the dictionary containing the properties associated with the link */ -double SD_link_get_current_bandwidth(SD_link_t link) { - CHECK_INIT_DONE(); - xbt_assert0(link != NULL, "Invalid parameter"); - return surf_workstation_resource->extension_public->get_link_bandwidth(link->sd_data->surf_link); +xbt_dict_t SD_link_get_properties(SD_link_t link) +{ + SD_CHECK_INIT_DONE(); + xbt_assert0((link != NULL), "Invalid parameters"); + + return (surf_workstation_model->common_public->get_properties(link->surf_link)); + } -/* Return the current latency of a link. +/** + * \brief Returns the current latency of a link + * + * \param link a link + * \return the current latency of this link, in seconds */ double SD_link_get_current_latency(SD_link_t link) { - CHECK_INIT_DONE(); + SD_CHECK_INIT_DONE(); xbt_assert0(link != NULL, "Invalid parameter"); - return surf_workstation_resource->extension_public->get_link_latency(link->sd_data->surf_link); + return surf_workstation_model->extension_public->get_link_latency(link->surf_link); } -/* Destroys a link. The user data (if any) should have been destroyed first. +/* Destroys a link. */ void __SD_link_destroy(void *link) { - CHECK_INIT_DONE(); + SD_CHECK_INIT_DONE(); xbt_assert0(link != NULL, "Invalid parameter"); - - SD_link_data_t sd_data = ((SD_link_t) link)->data; - if (sd_data != NULL) { - if (sd_data->name != NULL) - xbt_free(sd_data->name); - - xbt_free(sd_data); - } - + /* link->surf_link is freed by surf_exit and link->data is freed by the user */ xbt_free(link); }