#define SIMGRID_HOST_H_
#include <xbt/dict.h>
+#include <xbt/dynar.h>
SG_BEGIN_DECL()
typedef xbt_dictelm_t sg_host_t;
static XBT_INLINE char *sg_host_get_name(sg_host_t host){
return host->key;
}
+XBT_PUBLIC(xbt_dynar_t) sg_hosts_as_dynar(void);
#ifdef __cplusplus
#define DEFINE_EXTERNAL_CLASS(klass) class klass;
* \remark The host order in the returned array is generally different from the host creation/declaration order in the XML platform (we use a hash table internally)
*/
xbt_dynar_t MSG_hosts_as_dynar(void) {
- xbt_lib_cursor_t cursor;
- char *key;
- void **data;
- xbt_dynar_t res = xbt_dynar_new(sizeof(msg_host_t),NULL);
-
- xbt_lib_foreach(host_lib, cursor, key, data) {
- if(routing_get_network_element_type(key) == SURF_NETWORK_ELEMENT_HOST) {
- xbt_dictelm_t elm = xbt_dict_cursor_get_elm(cursor);
- xbt_dynar_push(res, &elm);
- }
- }
- return res;
+ return sg_hosts_as_dynar();
}
/** \ingroup m_host_management
* \remark The workstation order in the returned array is generally different from the workstation creation/declaration order in the XML platform (we use a hash table internally).
* \see SD_workstation_get_number()
*/
-const SD_workstation_t *SD_workstation_get_list(void)
-{
-
- xbt_lib_cursor_t cursor;
- char *key;
- void **data;
- int i;
-
+const SD_workstation_t *SD_workstation_get_list(void) {
xbt_assert(SD_workstation_get_number() > 0, "There is no workstation!");
- if (sd_global->workstation_list == NULL) { /* this is the first time the function is called */
- sd_global->workstation_list =
- xbt_new(SD_workstation_t, xbt_lib_length(host_lib));
+ if (sd_global->workstation_list == NULL) /* this is the first time the function is called */
+ sd_global->workstation_list = xbt_dynar_to_array(sg_hosts_as_dynar());
- i = 0;
- xbt_lib_foreach(host_lib, cursor, key, data) {
- if(data[SD_HOST_LEVEL])
- sd_global->workstation_list[i++] = xbt_dict_cursor_get_elm(cursor);
- }
- }
return sd_global->workstation_list;
}
#include "xbt/dict.h"
#include "simgrid/host.h"
#include "surf/surf_routing.h" // SIMIX_HOST_LEVEL and friends FIXME: make private here
+#include "surf/surf.h" // routing_get_network_element_type FIXME:killme
sg_host_t sg_host_by_name(const char *name){
return xbt_lib_get_elm_or_null(host_lib, name);
}
return res;
}
+xbt_dynar_t sg_hosts_as_dynar(void) {
+ xbt_lib_cursor_t cursor;
+ char *key;
+ void **data;
+ xbt_dynar_t res = xbt_dynar_new(sizeof(sg_host_t),NULL);
+
+ xbt_lib_foreach(host_lib, cursor, key, data) {
+ if(routing_get_network_element_type(key) == SURF_NETWORK_ELEMENT_HOST) {
+ xbt_dictelm_t elm = xbt_dict_cursor_get_elm(cursor);
+ xbt_dynar_push(res, &elm);
+ }
+ }
+ return res;
+}
// ========= Layering madness ==============