+ revise a bit an ugly simdag example
14 files changed:
const char *name1 = sg_host_get_name(h1);
const char *name2 = sg_host_get_name(h2);
const char *name1 = sg_host_get_name(h1);
const char *name2 = sg_host_get_name(h2);
- /* Get the property list of 'host1' */
+ /* Trying to set a new property */
+ sg_host_set_property_value(h1, "NewProp", "newValue");
+
+ /* Get the property list of 'host1'. This is only a copy of the internal data structure.*/
XBT_INFO("Property list for host %s", name1);
xbt_dict_t props = sg_host_get_properties(h1);
XBT_INFO("Property list for host %s", name1);
xbt_dict_t props = sg_host_get_properties(h1);
- /* Trying to set a new property */
- xbt_dict_set(props, "NewProp", strdup("newValue"), NULL);
/* Print the properties of 'host1' */
xbt_dict_foreach(props, cursor, key, data) {
/* Print the properties of 'host1' */
xbt_dict_foreach(props, cursor, key, data) {
XBT_INFO("\tProperty: %s is undefined", exist);
else {
XBT_INFO("\tProperty: %s old value: %s", exist, value);
XBT_INFO("\tProperty: %s is undefined", exist);
else {
XBT_INFO("\tProperty: %s old value: %s", exist, value);
- xbt_dict_set(props, exist, strdup("250"), NULL);
+ sg_host_set_property_value(h2, exist, "250");
}
/* Test if we have changed the value */
}
/* Test if we have changed the value */
XBT_PUBLIC(void) sg_host_set_pstate(sg_host_t host,int pstate);
XBT_PUBLIC(xbt_dict_t) sg_host_get_properties(sg_host_t host);
XBT_PUBLIC(const char*) sg_host_get_property_value(sg_host_t host, const char* name);
XBT_PUBLIC(void) sg_host_set_pstate(sg_host_t host,int pstate);
XBT_PUBLIC(xbt_dict_t) sg_host_get_properties(sg_host_t host);
XBT_PUBLIC(const char*) sg_host_get_property_value(sg_host_t host, const char* name);
+XBT_PUBLIC(void) sg_host_set_property_value(sg_host_t host, const char* name, const char* value);
XBT_PUBLIC(void) sg_host_route(sg_host_t from, sg_host_t to, xbt_dynar_t links);
XBT_PUBLIC(double) sg_host_route_latency(sg_host_t from, sg_host_t to);
XBT_PUBLIC(double) sg_host_route_bandwidth(sg_host_t from, sg_host_t to);
XBT_PUBLIC(void) sg_host_route(sg_host_t from, sg_host_t to, xbt_dynar_t links);
XBT_PUBLIC(double) sg_host_route_latency(sg_host_t from, sg_host_t to);
XBT_PUBLIC(double) sg_host_route_bandwidth(sg_host_t from, sg_host_t to);
double getSpeed();
int getCoreCount();
double getSpeed();
int getCoreCount();
- xbt_dict_t getProperties();
+ std::unordered_map<std::string, std::string>* getProperties();
const char* getProperty(const char* key);
void setProperty(const char* key, const char* value);
void getProcesses(std::vector<ActorPtr> * list);
const char* getProperty(const char* key);
void setProperty(const char* key, const char* value);
void getProcesses(std::vector<ActorPtr> * list);
sg_size_t getSizeFree();
sg_size_t getSizeUsed();
sg_size_t getSizeFree();
sg_size_t getSizeUsed();
- xbt_dict_t getProperties();
+ std::unordered_map<std::string, std::string>* getProperties();
const char* getProperty(const char* key);
void setProperty(const char* key, const char* value);
std::map<std::string, sg_size_t>* getContent();
const char* getProperty(const char* key);
void setProperty(const char* key, const char* value);
std::map<std::string, sg_size_t>* getContent();
xbt_dict_t MSG_host_get_properties(msg_host_t host)
{
xbt_assert((host != nullptr), "Invalid parameters (host is nullptr)");
xbt_dict_t MSG_host_get_properties(msg_host_t host)
{
xbt_assert((host != nullptr), "Invalid parameters (host is nullptr)");
- return host->getProperties();
+ xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
+ std::unordered_map<std::string, std::string>* props = host->getProperties();
+ if (props == nullptr)
+ return nullptr;
+ for (auto elm : *props) {
+ xbt_dict_set(as_dict, elm.first.c_str(), xbt_strdup(elm.second.c_str()), nullptr);
+ }
+ return as_dict;
}
/** \ingroup m_host_management
}
/** \ingroup m_host_management
xbt_dict_t MSG_storage_get_properties(msg_storage_t storage)
{
xbt_assert((storage != nullptr), "Invalid parameters (storage is nullptr)");
xbt_dict_t MSG_storage_get_properties(msg_storage_t storage)
{
xbt_assert((storage != nullptr), "Invalid parameters (storage is nullptr)");
- return storage->getProperties();
+ xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
+ std::unordered_map<std::string, std::string>* props = storage->getProperties();
+ if (props == nullptr)
+ return nullptr;
+ for (auto elm : *props) {
+ xbt_dict_set(as_dict, elm.first.c_str(), xbt_strdup(elm.second.c_str()), nullptr);
+ }
+ return as_dict;
}
/** \ingroup msg_storage_management
}
/** \ingroup msg_storage_management
xbt_dict_t MSG_storage_get_content(msg_storage_t storage)
{
std::map<std::string, sg_size_t>* content = storage->getContent();
xbt_dict_t MSG_storage_get_content(msg_storage_t storage)
{
std::map<std::string, sg_size_t>* content = storage->getContent();
- xbt_dict_t content_dict = xbt_dict_new_homogeneous(&free);
+ xbt_dict_t content_as_dict = xbt_dict_new_homogeneous(xbt_free_f);
for (auto entry : *content) {
sg_size_t* psize = static_cast<sg_size_t*>(malloc(sizeof(sg_size_t)));
*psize = entry.second;
for (auto entry : *content) {
sg_size_t* psize = static_cast<sg_size_t*>(malloc(sizeof(sg_size_t)));
*psize = entry.second;
- xbt_dict_set(content_dict, entry.first.c_str(), psize, nullptr);
+ xbt_dict_set(content_as_dict, entry.first.c_str(), psize, nullptr);
+ return content_as_dict;
}
/** \ingroup msg_storage_management
}
/** \ingroup msg_storage_management
}
/** Get the properties assigned to a host */
}
/** Get the properties assigned to a host */
-xbt_dict_t Host::getProperties()
+std::unordered_map<std::string, std::string>* Host::getProperties()
{
return simgrid::simix::kernelImmediate([this] {
return this->pimpl_->getProperties();
{
return simgrid::simix::kernelImmediate([this] {
return this->pimpl_->getProperties();
return pimpl_->getSize();
}
return pimpl_->getSize();
}
-xbt_dict_t Storage::getProperties()
+std::unordered_map<std::string, std::string>* Storage::getProperties()
{
return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); });
}
{
return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); });
}
/** @brief Get the properties of an host */
xbt_dict_t sg_host_get_properties(sg_host_t host) {
/** @brief Get the properties of an host */
xbt_dict_t sg_host_get_properties(sg_host_t host) {
- return host->getProperties();
+ xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
+ std::unordered_map<std::string, std::string>* props = host->getProperties();
+ if (props == nullptr)
+ return nullptr;
+ for (auto elm : *props) {
+ xbt_dict_set(as_dict, elm.first.c_str(), xbt_strdup(elm.second.c_str()), nullptr);
+ }
+ return as_dict;
}
/** \ingroup m_host_management
}
/** \ingroup m_host_management
*/
const char *sg_host_get_property_value(sg_host_t host, const char *name)
{
*/
const char *sg_host_get_property_value(sg_host_t host, const char *name)
{
- return (const char*) xbt_dict_get_or_null(sg_host_get_properties(host), name);
+ return host->getProperty(name);
+}
+
+void sg_host_set_property_value(sg_host_t host, const char* name, const char* value)
+{
+ host->setProperty(name, value);
/**
* \brief Find a route between two hosts
*
/**
* \brief Find a route between two hosts
*
/** @brief Displays debugging information about a host */
void sg_host_dump(sg_host_t host)
{
/** @brief Displays debugging information about a host */
void sg_host_dump(sg_host_t host)
{
XBT_INFO("Displaying host %s", host->getCname());
XBT_INFO(" - speed: %.0f", host->getSpeed());
XBT_INFO(" - available speed: %.2f", sg_host_get_available_speed(host));
XBT_INFO("Displaying host %s", host->getCname());
XBT_INFO(" - speed: %.0f", host->getSpeed());
XBT_INFO(" - available speed: %.2f", sg_host_get_available_speed(host));
- props = host->getProperties();
+ std::unordered_map<std::string, std::string>* props = host->getProperties();
- if (not xbt_dict_is_empty(props)) {
+ if (not props->empty()) {
XBT_INFO(" - properties:");
XBT_INFO(" - properties:");
- xbt_dict_cursor_t cursor = nullptr;
- char* key;
- char* data;
-
- xbt_dict_foreach(props,cursor,key,data) {
- XBT_INFO(" %s->%s",key,data);
+ for (auto elm : *props) {
+ XBT_INFO(" %s->%s", elm.first.c_str(), elm.second.c_str());
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "PropertyHolder.hpp"
namespace simgrid {
#include "PropertyHolder.hpp"
namespace simgrid {
PropertyHolder::PropertyHolder() = default;
PropertyHolder::~PropertyHolder() {
PropertyHolder::PropertyHolder() = default;
PropertyHolder::~PropertyHolder() {
- xbt_dict_free(&properties_);
}
/** @brief Return the property associated to the provided key (or nullptr if not existing) */
const char *PropertyHolder::getProperty(const char*key) {
if (properties_ == nullptr)
return nullptr;
}
/** @brief Return the property associated to the provided key (or nullptr if not existing) */
const char *PropertyHolder::getProperty(const char*key) {
if (properties_ == nullptr)
return nullptr;
- return static_cast<const char*>(xbt_dict_get_or_null(properties_,key));
+ try {
+ return properties_->at(key).c_str();
+ } catch (std::out_of_range& unfound) {
+ return nullptr;
+ }
}
/** @brief Change the value of a given key in the property set */
void PropertyHolder::setProperty(const char*key, const char*value) {
if (not properties_)
}
/** @brief Change the value of a given key in the property set */
void PropertyHolder::setProperty(const char*key, const char*value) {
if (not properties_)
- properties_ = xbt_dict_new_homogeneous(xbt_free_f);
- xbt_dict_set(properties_, key, xbt_strdup(value), nullptr);
+ properties_ = new std::unordered_map<std::string, std::string>;
+ (*properties_)[key] = value;
}
/** @brief Return the whole set of properties. Don't mess with it, dude! */
}
/** @brief Return the whole set of properties. Don't mess with it, dude! */
-xbt_dict_t PropertyHolder::getProperties() {
+std::unordered_map<std::string, std::string>* PropertyHolder::getProperties()
+{
- properties_ = xbt_dict_new_homogeneous(xbt_free_f);
+ properties_ = new std::unordered_map<std::string, std::string>;
#ifndef SRC_SURF_PROPERTYHOLDER_HPP_
#define SRC_SURF_PROPERTYHOLDER_HPP_
#ifndef SRC_SURF_PROPERTYHOLDER_HPP_
#define SRC_SURF_PROPERTYHOLDER_HPP_
+#include <unordered_map>
namespace simgrid {
namespace surf {
namespace simgrid {
namespace surf {
/* FIXME: This should not be exposed, as users may do bad things with the dict they got (it's not a copy).
* But some user API expose this call so removing it is not so easy.
*/
/* FIXME: This should not be exposed, as users may do bad things with the dict they got (it's not a copy).
* But some user API expose this call so removing it is not so easy.
*/
- xbt_dict_t getProperties();
+ std::unordered_map<std::string, std::string>* getProperties();
+
- xbt_dict_t properties_ = nullptr;
+ std::unordered_map<std::string, std::string>* properties_ = nullptr;
};
} /* namespace surf */
};
} /* namespace surf */
host->pimpl_cpu->setPState(args->pstate);
if (args->coord && strcmp(args->coord, ""))
new simgrid::kernel::routing::vivaldi::Coords(host->pimpl_netpoint, args->coord);
host->pimpl_cpu->setPState(args->pstate);
if (args->coord && strcmp(args->coord, ""))
new simgrid::kernel::routing::vivaldi::Coords(host->pimpl_netpoint, args->coord);
}
/** @brief Add a "router" to the network element list */
}
/** @brief Add a "router" to the network element list */
static void display_storage_properties(simgrid::s4u::Storage* storage)
{
static void display_storage_properties(simgrid::s4u::Storage* storage)
{
- xbt_dict_t props = storage->getProperties();
- if (xbt_dict_length(props) > 0) {
+ std::unordered_map<std::string, std::string>* props = storage->getProperties();
+ if (not props->empty()) {
XBT_INFO("\tProperties of mounted storage: %s", storage->getName());
XBT_INFO("\tProperties of mounted storage: %s", storage->getName());
- xbt_dict_cursor_t cursor = NULL;
- char* key;
- char* data;
- xbt_dict_foreach (props, cursor, key, data)
- XBT_INFO("\t\t'%s' -> '%s'", key, data);
+ for (auto elm : *props) {
+ XBT_INFO(" %s->%s", elm.first.c_str(), elm.second.c_str());
+ }
} else {
XBT_INFO("\tNo property attached.");
}
} else {
XBT_INFO("\tNo property attached.");
}
} else {
std::printf("/>\n");
}
} else {
std::printf("/>\n");
}