Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[surf] new (abstract) class: PropertyHolder, with only one purpose
authorMartin Quinson <martin.quinson@loria.fr>
Thu, 17 Dec 2015 23:18:48 +0000 (00:18 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Thu, 17 Dec 2015 23:35:56 +0000 (00:35 +0100)
src/surf/PropertyHolder.cpp [new file with mode: 0644]
src/surf/PropertyHolder.hpp [new file with mode: 0644]
src/surf/host_interface.cpp
src/surf/host_interface.hpp
src/surf/network_interface.cpp
src/surf/network_interface.hpp
src/surf/storage_interface.cpp
src/surf/storage_interface.hpp
tools/cmake/DefinePackages.cmake

diff --git a/src/surf/PropertyHolder.cpp b/src/surf/PropertyHolder.cpp
new file mode 100644 (file)
index 0000000..cdd87be
--- /dev/null
@@ -0,0 +1,43 @@
+/* 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 */
diff --git a/src/surf/PropertyHolder.hpp b/src/surf/PropertyHolder.hpp
new file mode 100644 (file)
index 0000000..bd03e3c
--- /dev/null
@@ -0,0 +1,33 @@
+/* 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_ */
index 2d87c0d..134e106 100644 (file)
@@ -92,7 +92,8 @@ void Host::init()
 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;
 }
@@ -100,14 +101,14 @@ Host::Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
 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)
@@ -126,13 +127,6 @@ void Host::setState(e_surf_resource_state_t state){
   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;
index 090c2ed..2ae6d5d 100644 (file)
@@ -8,6 +8,7 @@
 #include "storage_interface.hpp"
 #include "cpu_interface.hpp"
 #include "network_interface.hpp"
+#include "src/surf/PropertyHolder.hpp"
 
 #include <xbt/base.h>
 
@@ -94,7 +95,7 @@ public:
  * @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();
@@ -132,13 +133,6 @@ public:
   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
    *
@@ -269,7 +263,6 @@ public:
   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();
index a6b7937..5ae5679 100644 (file)
@@ -195,7 +195,7 @@ double NetworkModel::shareResourcesFull(double now)
 
 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});
 
@@ -207,7 +207,7 @@ Link::Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t prop
                             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);
@@ -220,7 +220,6 @@ Link::Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t prop
 Link::~Link()
 {
   surf_callback_emit(networkLinkDestructedCallbacks, this);
-  xbt_dict_free(&p_properties);
 }
 
 bool Link::isUsed()
@@ -249,13 +248,6 @@ void Link::setState(e_surf_resource_state_t state){
   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 *
  **********/
index dcd3136..415d244 100644 (file)
@@ -15,6 +15,7 @@
 #include "xbt/dict.h"
 #include "surf_interface.hpp"
 #include "surf_routing.hpp"
+#include "src/surf/PropertyHolder.hpp"
 
 #include "simgrid/link.h"
 
@@ -187,7 +188,7 @@ public:
   * @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
@@ -252,11 +253,6 @@ public:
 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;
index 8b64c56..2bdecef 100644 (file)
@@ -59,11 +59,11 @@ Storage::Storage(Model *model, const char *name, xbt_dict_t props,
                  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);
@@ -73,12 +73,12 @@ Storage::Storage(Model *model, const char *name, xbt_dict_t props,
                  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);
@@ -91,7 +91,6 @@ Storage::Storage(Model *model, const char *name, xbt_dict_t props,
 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);
@@ -180,13 +179,6 @@ sg_size_t Storage::getUsedSize(){
   return m_usedSize;
 }
 
-xbt_dict_t Storage::getProperties()
-{
-       if (p_properties==NULL)
-               p_properties = xbt_dict_new();
-       return p_properties;
-}
-
 /**********
  * Action *
  **********/
index 3be52e9..8c7be43 100644 (file)
@@ -7,6 +7,7 @@
 #include <xbt/base.h>
 
 #include "surf_interface.hpp"
+#include "src/surf/PropertyHolder.hpp"
 
 #ifndef STORAGE_INTERFACE_HPP_
 #define STORAGE_INTERFACE_HPP_
@@ -101,7 +102,7 @@ public:
  * @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
@@ -241,12 +242,6 @@ public:
 
   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;
-
 };
 
 /**********
index 0a8819c..0bc0ae4 100644 (file)
@@ -84,6 +84,7 @@ set(EXTRA_DIST
   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
@@ -326,6 +327,7 @@ set(SURF_SRC
   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