static void test_host(const std::string& hostname)
{
simgrid::s4u::Host* thehost = simgrid::s4u::Host::by_name(hostname);
- std::unordered_map<std::string, std::string>* props = thehost->get_properties();
+ const std::unordered_map<std::string, std::string>* props = thehost->get_properties();
const char* noexist = "Unknown";
const char* exist = "Hdd";
const char* value;
XBT_INFO(" Zone property: author -> %s", root->get_property("author"));
/* Get the property list of current bob process */
- std::unordered_map<std::string, std::string>* props = simgrid::s4u::Actor::self()->get_properties();
+ const std::unordered_map<std::string, std::string>* props = simgrid::s4u::Actor::self()->get_properties();
const char* noexist = "UnknownProcessProp";
XBT_ATTRIB_UNUSED const char* value;
/** @brief Make a host within that NetZone */
simgrid::s4u::Host* create_host(const char* name, const std::vector<double>& speed_per_pstate, int core_count,
- std::map<std::string, std::string>* props);
+ const std::map<std::string, std::string>* props);
/** @brief Creates a new route in this NetZone */
virtual void add_bypass_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst,
std::vector<resource::LinkImpl*>& link_list, bool symmetrical);
kernel::actor::ActorImpl* get_impl() const { return pimpl_; }
/** Retrieve the property value (or nullptr if not set) */
- std::unordered_map<std::string, std::string>*
+ const std::unordered_map<std::string, std::string>*
get_properties() const; // FIXME: do not export the map, but only the keys or something
const char* get_property(const std::string& key) const;
void set_property(const std::string& key, const std::string& value);
const char* get_property(const std::string& key) const;
void set_property(const std::string& key, const std::string& value);
- std::unordered_map<std::string, std::string>* get_properties();
+ const std::unordered_map<std::string, std::string>* get_properties() const;
void set_state_profile(kernel::profile::Profile* p);
void set_speed_profile(kernel::profile::Profile* p);
* The profile must contain absolute values */
void set_latency_profile(kernel::profile::Profile* profile);
- const char* get_property(const std::string& key);
+ const char* get_property(const std::string& key) const;
void set_property(const std::string& key, const std::string& value);
/* The signals */
public:
/** Get the properties assigned to a netzone */
- std::unordered_map<std::string, std::string>* get_properties();
+ const std::unordered_map<std::string, std::string>* get_properties() const;
std::vector<NetZone*> get_children();
/** Retrieve the property value (or nullptr if not set) */
- const char* get_property(const std::string& key);
+ const char* get_property(const std::string& key) const;
void set_property(const std::string& key, const std::string& value);
/* Add content to the netzone, at parsing time. It should be sealed afterward. */
Host* get_host() { return attached_to_; };
void set_host(Host* host) { attached_to_ = host; }
- std::unordered_map<std::string, std::string>* get_properties();
- const char* get_property(const std::string& key);
+ const std::unordered_map<std::string, std::string>* get_properties() const;
+ const char* get_property(const std::string& key) const;
void set_property(const std::string&, const std::string& value);
void set_data(void* data) { userdata_ = data; }
*/
ActorImplPtr ActorImpl::attach(const std::string& name, void* data, s4u::Host* host,
- std::unordered_map<std::string, std::string>* properties)
+ const std::unordered_map<std::string, std::string>* properties)
{
// This is mostly a copy/paste from create(), it'd be nice to share some code between those two functions.
}
ActorImplPtr ActorImpl::create(const std::string& name, const simix::ActorCode& code, void* data, s4u::Host* host,
- std::unordered_map<std::string, std::string>* properties, ActorImpl* parent_actor)
+ const std::unordered_map<std::string, std::string>* properties, ActorImpl* parent_actor)
{
XBT_DEBUG("Start actor %s@'%s'", name.c_str(), host->get_cname());
ActorImpl* start(const simix::ActorCode& code);
static ActorImplPtr create(const std::string& name, const simix::ActorCode& code, void* data, s4u::Host* host,
- std::unordered_map<std::string, std::string>* properties, ActorImpl* parent_actor);
+ const std::unordered_map<std::string, std::string>* properties, ActorImpl* parent_actor);
static ActorImplPtr attach(const std::string& name, void* data, s4u::Host* host,
- std::unordered_map<std::string, std::string>* properties);
+ const std::unordered_map<std::string, std::string>* properties);
static void detach();
void cleanup();
void exit();
void* data = nullptr;
s4u::Host* host = nullptr;
double kill_time = 0.0;
- std::shared_ptr<std::unordered_map<std::string, std::string>> properties = nullptr;
+ std::shared_ptr<const std::unordered_map<std::string, std::string>> properties = nullptr;
bool auto_restart = false;
bool daemon_ = false;
ProcessArg() = default;
}
simgrid::s4u::Host* NetZoneImpl::create_host(const char* name, const std::vector<double>& speed_per_pstate,
- int coreAmount, std::map<std::string, std::string>* props)
+ int coreAmount, const std::map<std::string, std::string>* props)
{
simgrid::s4u::Host* res = new simgrid::s4u::Host(name);
simix::simcall([self] { self->kill_all(); });
}
-std::unordered_map<std::string, std::string>* Actor::get_properties() const
+const std::unordered_map<std::string, std::string>* Actor::get_properties() const
{
return pimpl_->get_properties();
}
{
xbt_assert(actor != nullptr, "Invalid parameter: First argument must not be nullptr");
xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
- std::unordered_map<std::string, std::string>* props = actor->get_properties();
+ const std::unordered_map<std::string, std::string>* props = actor->get_properties();
if (props == nullptr)
return nullptr;
for (auto const& kv : *props) {
}
/** Get the properties assigned to a host */
-std::unordered_map<std::string, std::string>* Host::get_properties()
+const std::unordered_map<std::string, std::string>* Host::get_properties() const
{
- return simix::simcall([this] { return this->pimpl_->get_properties(); });
+ return this->pimpl_->get_properties();
}
/** Retrieve the property value (or nullptr if not set) */
xbt_dict_t sg_host_get_properties(sg_host_t host)
{
xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
- std::unordered_map<std::string, std::string>* props = host->get_properties();
+ const std::unordered_map<std::string, std::string>* props = host->get_properties();
if (props == nullptr)
return nullptr;
for (auto const& elm : *props) {
XBT_INFO("Displaying host %s", host->get_cname());
XBT_INFO(" - speed: %.0f", host->get_speed());
XBT_INFO(" - available speed: %.2f", sg_host_get_available_speed(host));
- std::unordered_map<std::string, std::string>* props = host->get_properties();
+ const std::unordered_map<std::string, std::string>* props = host->get_properties();
if (not props->empty()) {
XBT_INFO(" - properties:");
simgrid::simix::simcall([this, trace]() { this->pimpl_->set_latency_profile(trace); });
}
-const char* Link::get_property(const std::string& key)
+const char* Link::get_property(const std::string& key) const
{
return this->pimpl_->get_property(key);
}
{
}
-std::unordered_map<std::string, std::string>* NetZone::get_properties()
+const std::unordered_map<std::string, std::string>* NetZone::get_properties() const
{
- return simix::simcall([this] { return &properties_; });
+ return &properties_;
}
/** Retrieve the property value (or nullptr if not set) */
-const char* NetZone::get_property(const std::string& key)
+const char* NetZone::get_property(const std::string& key) const
{
- return properties_.at(key).c_str();
+ auto prop = properties_.find(key);
+ return prop == properties_.end() ? nullptr : prop->second.c_str();
}
+
void NetZone::set_property(const std::string& key, const std::string& value)
{
simix::simcall([this, &key, &value] { properties_[key] = value; });
return pimpl_->typeId_.c_str();
}
-std::unordered_map<std::string, std::string>* Storage::get_properties()
+const std::unordered_map<std::string, std::string>* Storage::get_properties() const
{
- return simix::simcall([this] { return pimpl_->get_properties(); });
+ return pimpl_->get_properties();
}
-const char* Storage::get_property(const std::string& key)
+const char* Storage::get_property(const std::string& key) const
{
return this->pimpl_->get_property(key);
}
{
xbt_assert((storage != nullptr), "Invalid parameters (storage is nullptr)");
xbt_dict_t as_dict = xbt_dict_new_homogeneous(xbt_free_f);
- std::unordered_map<std::string, std::string>* props = storage->get_properties();
+ const std::unordered_map<std::string, std::string>* props = storage->get_properties();
if (props == nullptr)
return nullptr;
for (auto const& elm : *props) {
}
/** @brief Return the whole set of properties. Don't mess with it, dude! */
-std::unordered_map<std::string, std::string>* PropertyHolder::get_properties()
+const std::unordered_map<std::string, std::string>* PropertyHolder::get_properties()
{
if (not properties_)
properties_.reset(new std::unordered_map<std::string, std::string>);
const char* get_property(const std::string& key) const;
void set_property(const std::string& id, const std::string& value);
- /* FIXME: This should not be exposed, as users may do bad things with the map they got (it's not a copy).
- * But some user API expose this call so removing it is not so easy.
- */
- std::unordered_map<std::string, std::string>* get_properties();
+ const std::unordered_map<std::string, std::string>* get_properties();
private:
std::unique_ptr<std::unordered_map<std::string, std::string>> properties_ = nullptr;
static void display_storage_properties(simgrid::s4u::Storage* storage)
{
- std::unordered_map<std::string, std::string>* props = storage->get_properties();
+ const std::unordered_map<std::string, std::string>* props = storage->get_properties();
if (not props->empty()) {
XBT_INFO("\tProperties of mounted storage: %s", storage->get_cname());
> [ 1.207952] (server@alice) Storage name: Disk2, mount name: c:
> [ 1.207952] (server@alice) Free size: 534479367024 bytes
> [ 1.207952] (server@alice) Used size: 2391544976 bytes
-> [ 1.207952] (client@bob) *** GET/SET DATA for storage element: Disk1 ***
-> [ 1.207952] (client@bob) Get data: 'No User Data'
-> [ 1.207952] (client@bob) Set and get data: 'Some data'
> [ 1.207952] (server@alice) No property attached.
> [ 1.207952] (server@alice) *** Dump a storage element ***
> [ 1.207952] (server@alice) Print the content of the storage element: Disk2
> [ 1.207952] (server@alice) \Windows\winhlp32.exe size: 10752 bytes
> [ 1.207952] (server@alice) \Windows\write.exe size: 10752 bytes
> [ 1.207952] (server@alice) Storage Disk1 is attached to bob
+> [ 1.207952] (client@bob) *** GET/SET DATA for storage element: Disk1 ***
+> [ 1.207952] (client@bob) Get data: 'No User Data'
+> [ 1.207952] (client@bob) Set and get data: 'Some data'
> [ 1.207952] (server@alice) Storage Disk2 is attached to alice
> [ 1.207952] (server@alice) Storage Disk3 is attached to carl
> [ 1.207952] (server@alice) Storage Disk4 is attached to denise
static void dump_hosts()
{
- std::unordered_map<std::string, std::string>* props = nullptr;
unsigned int totalHosts = sg_host_count();
sg_host_t* hosts = sg_host_list();
std::sort(hosts, hosts + totalHosts,
for (unsigned int i = 0; i < totalHosts; i++) {
std::printf(" <host id=\"%s\" speed=\"%.0f\"", hosts[i]->get_cname(), sg_host_speed(hosts[i]));
- props = hosts[i]->get_properties();
+ const std::unordered_map<std::string, std::string>* props = hosts[i]->get_properties();
if (hosts[i]->get_core_count() > 1) {
std::printf(" core=\"%d\"", hosts[i]->get_core_count());
}