From: Frederic Suter Date: Mon, 31 Jul 2017 13:07:46 +0000 (+0200) Subject: simplify storage_type mess X-Git-Tag: v3_17~304 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/832a679c3195a9d11796dd2918988362b0f4bc70 simplify storage_type mess --- diff --git a/include/simgrid/forward.h b/include/simgrid/forward.h index f62fa97a29..45a0af22d4 100644 --- a/include/simgrid/forward.h +++ b/include/simgrid/forward.h @@ -55,6 +55,7 @@ namespace surf { class LinkImpl; class HostImpl; class StorageImpl; + class StorageType; class FileImpl; } namespace trace_mgr { diff --git a/src/surf/StorageImpl.hpp b/src/surf/StorageImpl.hpp index 9f410d35cf..6f1f2b95b3 100644 --- a/src/surf/StorageImpl.hpp +++ b/src/surf/StorageImpl.hpp @@ -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* 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* model_properties, sg_size_t size) + : id(id), model(model), content(content), properties(properties), model_properties(model_properties), size(size) + { + } +}; +} +} #endif /* STORAGE_INTERFACE_HPP_ */ diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 632c8b9e2c..cd318395e1 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -48,7 +48,7 @@ extern std::map host_list; } static int surf_parse_models_setup_already_called = 0; -std::map storage_types; +std::map 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) diff --git a/src/surf/storage_n11.cpp b/src/surf/storage_n11.cpp index c05e8a5c33..5ae236e757 100644 --- a/src/surf/storage_n11.cpp +++ b/src/surf/storage_n11.cpp @@ -13,7 +13,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_storage); /************* * CallBacks * *************/ -extern std::map storage_types; +extern std::map 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()); diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 7d685bf8f5..b13c5ab98c 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -30,7 +30,7 @@ std::vector surf_path; std::vector host_that_restart; /** set of hosts for which one want to be notified if they ever restart. */ std::set watched_hosts; -extern std::map storage_types; +extern std::map 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; diff --git a/src/surf/xml/platf_private.hpp b/src/surf/xml/platf_private.hpp index 1989a471a9..cdfe6efb5e 100644 --- a/src/surf/xml/platf_private.hpp +++ b/src/surf/xml/platf_private.hpp @@ -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* 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); diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index c348cd5346..0d09857753 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -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); }