--- /dev/null
+/* Copyright (c) 2015. The SimGrid Team. All rights reserved. */
+
+/* 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 "xbt/sysdep.h"
+#include "PropertyHolder.hpp"
+
+namespace simgrid {
+namespace surf {
+
+PropertyHolder::PropertyHolder(xbt_dict_t props)
+: p_properties(props)
+{
+}
+
+PropertyHolder::~PropertyHolder() {
+ xbt_dict_free(&p_properties);
+}
+
+/** @brief Return the property associated to the provided key (or NULL if not existing) */
+const char *PropertyHolder::getProperty(const char*key) {
+ if (p_properties == NULL)
+ return NULL;
+ return (const char*) xbt_dict_get_or_null(p_properties,key);
+}
+
+/** @brief Change the value of a given key in the property set */
+void PropertyHolder::setProperty(const char*key, const char*value) {
+ if (!p_properties)
+ p_properties = xbt_dict_new();
+ xbt_dict_set(p_properties, key, xbt_strdup(value), &xbt_free_f);
+}
+
+/** @brief Return the whole set of properties. Don't mess with it, dude! */
+xbt_dict_t PropertyHolder::getProperties() {
+ if (!p_properties)
+ p_properties = xbt_dict_new();
+ return p_properties;
+}
+
+} /* namespace surf */
+} /* namespace simgrid */
--- /dev/null
+/* Copyright (c) 2015. The SimGrid Team. All rights reserved. */
+
+/* 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. */
+
+#ifndef SRC_SURF_PROPERTYHOLDER_HPP_
+#define SRC_SURF_PROPERTYHOLDER_HPP_
+#include <xbt/dict.h>
+
+namespace simgrid {
+namespace surf {
+
+/** @brief a PropertyHolder can be given a set of textual properties
+ *
+ * Common PropertyHolders are elements of the platform file, such as Host, Link or Storage.
+ */
+class PropertyHolder { // DO NOT DERIVE THIS CLASS, or the diamond inheritance mayhem will get you
+
+public:
+ PropertyHolder(xbt_dict_t props);
+ ~PropertyHolder();
+
+ const char *getProperty(const char*id);
+ void setProperty(const char*id, const char*value);
+ xbt_dict_t getProperties();
+private:
+ xbt_dict_t p_properties = NULL;
+};
+
+} /* namespace surf */
+} /* namespace simgrid */
+
+#endif /* SRC_SURF_PROPERTYHOLDER_HPP_ */
Host::Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu)
: Resource(model, name)
- , p_storage(storage), p_netElm(netElm), p_cpu(cpu), p_properties(props)
+ , PropertyHolder(props)
+ , p_storage(storage), p_netElm(netElm), p_cpu(cpu)
{
p_params.ramsize = 0;
}
Host::Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props, lmm_constraint_t constraint,
xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu)
: Resource(model, name, constraint)
- , p_storage(storage), p_netElm(netElm), p_cpu(cpu), p_properties(props)
+, PropertyHolder(props)
+ , p_storage(storage), p_netElm(netElm), p_cpu(cpu)
{
p_params.ramsize = 0;
}
Host::~Host(){
surf_callback_emit(hostDestructedCallbacks, this);
- xbt_dict_free(&p_properties);
}
void Host::attach(simgrid::Host* host)
p_cpu->setState(state);
}
-xbt_dict_t Host::getProperties()
-{
- if (p_properties==NULL)
- p_properties = xbt_dict_new();
- return p_properties;
-}
-
simgrid::surf::Storage *Host::findStorageOnMountList(const char* mount)
{
simgrid::surf::Storage *st = NULL;
#include "storage_interface.hpp"
#include "cpu_interface.hpp"
#include "network_interface.hpp"
+#include "src/surf/PropertyHolder.hpp"
#include <xbt/base.h>
* @brief SURF Host interface class
* @details An host represents a machine with a aggregation of a Cpu, a Link and a Storage
*/
-class Host : public simgrid::surf::Resource {
+class Host : public simgrid::surf::Resource, public simgrid::surf::PropertyHolder {
public:
static simgrid::xbt::FacetLevel<simgrid::Host, Host> LEVEL;
static void init();
void attach(simgrid::Host* host);
void setState(e_surf_resource_state_t state);
- /**
- * @brief Get the properties of the current Host
- *
- * @return The properties of the current Host
- */
- xbt_dict_t getProperties();
-
/**
* @brief Execute some quantity of computation
*
RoutingEdge *p_netElm;
Cpu *p_cpu;
simgrid::Host* p_host = nullptr;
- xbt_dict_t p_properties = NULL;
/** @brief Get the list of virtual machines on the current Host */
xbt_dynar_t getVms();
Link::Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t props)
: Resource(model, name),
- p_properties(props)
+ PropertyHolder(props)
{
links->insert({name, this});
tmgr_history_t history,
tmgr_trace_t state_trace)
: Resource(model, name, constraint),
- p_properties(props)
+ PropertyHolder(props)
{
if (state_trace)
p_stateEvent = tmgr_history_add_trace(history, state_trace, 0.0, 0, this);
Link::~Link()
{
surf_callback_emit(networkLinkDestructedCallbacks, this);
- xbt_dict_free(&p_properties);
}
bool Link::isUsed()
surf_callback_emit(networkLinkStateChangedCallbacks, this, old, state);
}
-xbt_dict_t Link::getProperties()
-{
- if (p_properties==NULL)
- p_properties = xbt_dict_new();
- return p_properties;
-}
-
/**********
* Action *
**********/
#include "xbt/dict.h"
#include "surf_interface.hpp"
#include "surf_routing.hpp"
+#include "src/surf/PropertyHolder.hpp"
#include "simgrid/link.h"
* @brief SURF network link interface class
* @details A Link represents the link between two [hosts](\ref Host)
*/
-class Link : public simgrid::surf::Resource {
+class Link : public simgrid::surf::Resource, public simgrid::surf::PropertyHolder {
public:
/**
* @brief Link constructor
private:
void *userData = NULL;
-public:
- xbt_dict_t getProperties();
-protected:
- xbt_dict_t p_properties = NULL;
-
/* List of all links */
private:
static boost::unordered_map<std::string, Link *> *links;
const char* type_id, char *content_name, char *content_type,
sg_size_t size)
: Resource(model, name)
+ , PropertyHolder(props)
, p_contentType(content_type)
, m_size(size), m_usedSize(0)
, p_typeId(xbt_strdup(type_id))
, p_writeActions(xbt_dynar_new(sizeof(Action*),NULL))
- , p_properties(props)
{
p_content = parseContent(content_name);
setState(SURF_RESOURCE_ON);
lmm_system_t maxminSystem, double bread, double bwrite,
double bconnection, const char* type_id, char *content_name,
char *content_type, sg_size_t size, char *attach)
- : Resource(model, name, lmm_constraint_new(maxminSystem, this, bconnection))
+ : Resource(model, name, lmm_constraint_new(maxminSystem, this, bconnection))
+ , PropertyHolder(props)
, p_contentType(content_type)
, m_size(size), m_usedSize(0)
, p_typeId(xbt_strdup(type_id))
, p_writeActions(xbt_dynar_new(sizeof(Action*),NULL))
- , p_properties(props)
{
p_content = parseContent(content_name);
p_attach = xbt_strdup(attach);
Storage::~Storage(){
surf_callback_emit(storageDestructedCallbacks, this);
xbt_dict_free(&p_content);
- xbt_dict_free(&p_properties);
xbt_dynar_free(&p_writeActions);
free(p_typeId);
free(p_contentType);
return m_usedSize;
}
-xbt_dict_t Storage::getProperties()
-{
- if (p_properties==NULL)
- p_properties = xbt_dict_new();
- return p_properties;
-}
-
/**********
* Action *
**********/
#include <xbt/base.h>
#include "surf_interface.hpp"
+#include "src/surf/PropertyHolder.hpp"
#ifndef STORAGE_INTERFACE_HPP_
#define STORAGE_INTERFACE_HPP_
* @brief SURF storage interface class
* @details A Storage represent a storage unit (e.g.: hard drive, usb key)
*/
-class Storage : public simgrid::surf::Resource {
+class Storage : public simgrid::surf::Resource, public simgrid::surf::PropertyHolder {
public:
/**
* @brief Storage constructor
lmm_constraint_t p_constraintWrite; /* Constraint for maximum write bandwidth*/
lmm_constraint_t p_constraintRead; /* Constraint for maximum write bandwidth*/
-
-public:
- xbt_dict_t getProperties();
-protected:
- xbt_dict_t p_properties = NULL;
-
};
/**********
src/surf/surfxml_parse.c
src/surf/trace_mgr_private.h
src/surf/vm_hl13.hpp
+ src/surf/PropertyHolder.hpp
src/surf/virtual_machine.hpp
src/surf/host_clm03.hpp
src/surf/host_interface.hpp
src/surf/network_ib.cpp
src/surf/platf_generator.c
src/surf/plugins/energy.cpp
+ src/surf/PropertyHolder.cpp
src/surf/random_mgr.c
src/surf/sg_platf.cpp
src/surf/storage_interface.cpp