Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
simplify storage_type mess
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 31 Jul 2017 13:07:46 +0000 (15:07 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Mon, 31 Jul 2017 13:07:46 +0000 (15:07 +0200)
include/simgrid/forward.h
src/surf/StorageImpl.hpp
src/surf/sg_platf.cpp
src/surf/storage_n11.cpp
src/surf/surf_interface.cpp
src/surf/xml/platf_private.hpp
src/surf/xml/surfxml_sax_cb.cpp

index f62fa97..45a0af2 100644 (file)
@@ -55,6 +55,7 @@ namespace surf {
   class LinkImpl;
   class HostImpl;
   class StorageImpl;
+  class StorageType;
   class FileImpl;
 }
 namespace trace_mgr {
index 9f410d3..6f1f2b9 100644 (file)
@@ -207,17 +207,22 @@ public:
   StorageImpl* storage_;
   FileImpl* file_ = nullptr;
 };
-}
-}
 
-typedef struct s_storage_type {
-  char* model;
-  char* content;
-  char* type_id;
+class StorageType {
+public:
+  std::string id;
+  std::string model;
+  std::string content;
   xbt_dict_t properties;
   std::map<std::string, std::string>* model_properties;
   sg_size_t size;
-} s_storage_type_t;
-typedef s_storage_type_t* storage_type_t;
+  StorageType(std::string id, std::string model, std::string content, xbt_dict_t properties,
+              std::map<std::string, std::string>* model_properties, sg_size_t size)
+      : id(id), model(model), content(content), properties(properties), model_properties(model_properties), size(size)
+  {
+  }
+};
+}
+}
 
 #endif /* STORAGE_INTERFACE_HPP_ */
index 632c8b9..cd31839 100644 (file)
@@ -48,7 +48,7 @@ extern std::map<std::string, simgrid::s4u::Host*> host_list;
 }
 
 static int surf_parse_models_setup_already_called = 0;
-std::map<std::string, storage_type_t> storage_types;
+std::map<std::string, simgrid::surf::StorageType*> storage_types;
 
 /** The current AS in the parsing */
 static simgrid::kernel::routing::NetZoneImpl* current_routing = nullptr;
@@ -364,7 +364,7 @@ void sg_platf_new_storage(StorageCreationArgs* storage)
   xbt_assert(std::find(known_storages.begin(), known_storages.end(), storage->id) == known_storages.end(),
              "Refusing to add a second storage named \"%s\"", storage->id.c_str());
 
-  storage_type_t stype;
+  simgrid::surf::StorageType* stype;
   try {
     stype = storage_types.at(storage->type_id);
   } catch (std::out_of_range& unfound) {
@@ -377,17 +377,19 @@ void sg_platf_new_storage(StorageCreationArgs* storage)
   known_storages.push_back(storage->id);
 
   // if storage content is not specified use the content of storage_type if any
-  if (storage->content.empty() && strcmp(stype->content, "")) {
-    storage->content = std::string(stype->content);
-    XBT_DEBUG("For disk '%s' content is empty, inherit the content (of type %s)", storage->id.c_str(), stype->type_id);
+  if (storage->content.empty() && not stype->content.empty()) {
+    storage->content = stype->content;
+    XBT_DEBUG("For disk '%s' content is empty, inherit the content (of type %s)", storage->id.c_str(),
+              stype->id.c_str());
   }
 
   XBT_DEBUG("SURF storage create resource\n\t\tid '%s'\n\t\ttype '%s' "
             "\n\t\tmodel '%s' \n\t\tcontent '%s' "
             "\n\t\tproperties '%p''\n",
-            storage->id.c_str(), stype->model, stype->type_id, storage->content.c_str(), storage->properties);
+            storage->id.c_str(), stype->model.c_str(), stype->id.c_str(), storage->content.c_str(),
+            storage->properties);
 
-  auto s = surf_storage_model->createStorage(storage->id, stype->type_id, storage->content, storage->attach);
+  auto s = surf_storage_model->createStorage(storage->id, stype->id, storage->content, storage->attach);
 
   if (storage->properties) {
     xbt_dict_cursor_t cursor = nullptr;
@@ -399,23 +401,19 @@ void sg_platf_new_storage(StorageCreationArgs* storage)
   }
 }
 
-void sg_platf_new_storage_type(sg_platf_storage_type_cbarg_t storage_type)
+void sg_platf_new_storage_type(StorageTypeCreationArgs* storage_type)
 {
   xbt_assert(storage_types.find(storage_type->id) == storage_types.end(),
-             "Reading a storage type, processing unit \"%s\" already exists", storage_type->id);
+             "Reading a storage type, processing unit \"%s\" already exists", storage_type->id.c_str());
 
-  storage_type_t stype = xbt_new0(s_storage_type_t, 1);
-  stype->model = xbt_strdup(storage_type->model);
-  stype->properties = storage_type->properties;
-  stype->content = xbt_strdup(storage_type->content);
-  stype->type_id = xbt_strdup(storage_type->id);
-  stype->size = storage_type->size;
-  stype->model_properties = storage_type->model_properties;
+  simgrid::surf::StorageType* stype =
+      new simgrid::surf::StorageType(storage_type->id, storage_type->model, storage_type->content,
+                                     storage_type->properties, storage_type->model_properties, storage_type->size);
 
-  XBT_DEBUG("Create a storage type id '%s' with model '%s', content '%s'", stype->type_id, stype->model,
-            storage_type->content);
+  XBT_DEBUG("Create a storage type id '%s' with model '%s', content '%s'", storage_type->id.c_str(),
+            storage_type->model.c_str(), storage_type->content.c_str());
 
-  storage_types.insert({std::string(stype->type_id), stype});
+  storage_types[storage_type->id] = stype;
 }
 
 void sg_platf_new_mount(MountCreationArgs* mount)
index c05e8a5..5ae236e 100644 (file)
@@ -13,7 +13,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_storage);
 /*************
  * CallBacks *
  *************/
-extern std::map<std::string, storage_type_t> storage_types;
+extern std::map<std::string, simgrid::surf::StorageType*> storage_types;
 
 static void check_disk_attachment()
 {
@@ -49,7 +49,7 @@ namespace surf {
 StorageImpl* StorageN11Model::createStorage(std::string id, std::string type_id, std::string content_name,
                                             std::string attach)
 {
-  storage_type_t storage_type = storage_types.at(type_id);
+  StorageType* storage_type = storage_types.at(type_id);
 
   double Bread = surf_parse_get_bandwidth(storage_type->model_properties->at("Bread").c_str(),
                                           "property Bread, storage", type_id.c_str());
index 7d685bf..b13c5ab 100644 (file)
@@ -30,7 +30,7 @@ std::vector<std::string> surf_path;
 std::vector<simgrid::s4u::Host*> host_that_restart;
 /**  set of hosts for which one want to be notified if they ever restart. */
 std::set<std::string> watched_hosts;
-extern std::map<std::string, storage_type_t> storage_types;
+extern std::map<std::string, simgrid::surf::StorageType*> storage_types;
 
 namespace simgrid {
 namespace surf {
@@ -368,13 +368,10 @@ void surf_exit()
   sg_host_exit();
   sg_link_exit();
   for (auto e : storage_types) {
-    storage_type_t stype = e.second;
-    free(stype->model);
-    free(stype->type_id);
-    free(stype->content);
+    simgrid::surf::StorageType* stype = e.second;
     xbt_dict_free(&(stype->properties));
     delete stype->model_properties;
-    free(stype);
+    delete stype;
   }
   for (auto s : *simgrid::surf::StorageImpl::storagesMap())
     delete s.second;
index 1989a47..cdfe6ef 100644 (file)
@@ -136,15 +136,15 @@ public:
   std::string attach;
 };
 
-typedef struct s_sg_platf_storage_type_cbarg* sg_platf_storage_type_cbarg_t;
-typedef struct s_sg_platf_storage_type_cbarg {
-  const char* id;
-  const char* model;
-  const char* content;
+class StorageTypeCreationArgs {
+public:
+  std::string id;
+  std::string model;
+  std::string content;
   xbt_dict_t properties;
   std::map<std::string, std::string>* model_properties;
   sg_size_t size;
-} s_sg_platf_storage_type_cbarg_t;
+};
 
 class MountCreationArgs {
 public:
@@ -218,7 +218,7 @@ XBT_PUBLIC(void) sg_platf_new_bypassRoute (sg_platf_route_cbarg_t bypassroute);
 XBT_PUBLIC(void) sg_platf_new_trace(sg_platf_trace_cbarg_t trace);
 
 XBT_PUBLIC(void) sg_platf_new_storage(StorageCreationArgs* storage); // Add a storage to the currently described AS
-XBT_PUBLIC(void) sg_platf_new_storage_type(sg_platf_storage_type_cbarg_t storage_type);
+XBT_PUBLIC(void) sg_platf_new_storage_type(StorageTypeCreationArgs* storage_type);
 XBT_PUBLIC(void) sg_platf_new_mount(MountCreationArgs* mount);
 
 XBT_PUBLIC(void) sg_platf_new_process(sg_platf_process_cbarg_t process);
index c348cd5..0d09857 100644 (file)
@@ -360,8 +360,7 @@ void STag_surfxml_storage___type()
 }
 void ETag_surfxml_storage___type()
 {
-  s_sg_platf_storage_type_cbarg_t storage_type;
-  memset(&storage_type,0,sizeof(storage_type));
+  StorageTypeCreationArgs storage_type;
 
   storage_type.properties = current_property_set;
   current_property_set    = nullptr;
@@ -369,11 +368,11 @@ void ETag_surfxml_storage___type()
   storage_type.model_properties = current_model_property_set;
   current_model_property_set    = nullptr;
 
-  storage_type.content          = A_surfxml_storage___type_content;
-  storage_type.id               = A_surfxml_storage___type_id;
-  storage_type.model            = A_surfxml_storage___type_model;
-  storage_type.size             = surf_parse_get_size(A_surfxml_storage___type_size,
-        "size of storage type", storage_type.id);
+  storage_type.content = A_surfxml_storage___type_content;
+  storage_type.id      = A_surfxml_storage___type_id;
+  storage_type.model   = A_surfxml_storage___type_model;
+  storage_type.size =
+      surf_parse_get_size(A_surfxml_storage___type_size, "size of storage type", storage_type.id.c_str());
   sg_platf_new_storage_type(&storage_type);
 }