From 922482ff141f9ce5878f39a58bef3c7f7e19bffa Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Thu, 11 Jan 2018 15:14:33 +0100 Subject: [PATCH] use class and enum class in Actor parsing --- include/simgrid/forward.h | 5 ----- src/simix/smx_deployment.cpp | 20 ++++++++++---------- src/surf/sg_platf.cpp | 22 +++++++++++----------- src/surf/xml/platf_private.hpp | 10 ++++++---- src/surf/xml/surfxml_sax_cb.cpp | 6 +++--- 5 files changed, 30 insertions(+), 33 deletions(-) diff --git a/include/simgrid/forward.h b/include/simgrid/forward.h index 6b9d37f6ee..0a082a69d0 100644 --- a/include/simgrid/forward.h +++ b/include/simgrid/forward.h @@ -139,11 +139,6 @@ typedef enum { // FIXME: move this to s4u::Link; make it an enum class SURF_LINK_FATPIPE = 0 } e_surf_link_sharing_policy_t; -typedef enum { // FIXME: move this to s4u::Actor; make it an enum class - SURF_ACTOR_ON_FAILURE_DIE = 1, - SURF_ACTOR_ON_FAILURE_RESTART = 0 -} e_surf_process_on_failure_t; - /** @ingroup m_datatypes_management_details * @brief Type for any simgrid size */ diff --git a/src/simix/smx_deployment.cpp b/src/simix/smx_deployment.cpp index 18bf778ded..f59d64f6bd 100644 --- a/src/simix/smx_deployment.cpp +++ b/src/simix/smx_deployment.cpp @@ -117,30 +117,30 @@ simgrid::simix::ActorCodeFactory& SIMIX_get_actor_code_factory(const char *name) void SIMIX_process_set_function(const char* process_host, const char* process_function, xbt_dynar_t arguments, double process_start_time, double process_kill_time) { - s_sg_platf_process_cbarg_t process; + ActorCreationArgs actor; sg_host_t host = sg_host_by_name(process_host); if (not host) THROWF(arg_error, 0, "Host '%s' unknown", process_host); - process.host = process_host; - process.args.push_back(process_function); + actor.host = process_host; + actor.args.push_back(process_function); /* add arguments */ unsigned int i; char *arg; xbt_dynar_foreach(arguments, i, arg) { - process.args.push_back(arg); + actor.args.push_back(arg); } // Check we know how to handle this function name: simgrid::simix::ActorCodeFactory& parse_code = SIMIX_get_actor_code_factory(process_function); xbt_assert(parse_code, "Function '%s' unknown", process_function); - process.function = process_function; - process.host = process_host; - process.kill_time = process_kill_time; - process.start_time = process_start_time; - process.on_failure = SURF_ACTOR_ON_FAILURE_DIE; - sg_platf_new_process(&process); + actor.function = process_function; + actor.host = process_host; + actor.kill_time = process_kill_time; + actor.start_time = process_start_time; + actor.on_failure = ActorOnFailure::DIE; + sg_platf_new_process(&actor); } namespace simgrid { diff --git a/src/surf/sg_platf.cpp b/src/surf/sg_platf.cpp index 851a89cb13..9e51f91ad7 100644 --- a/src/surf/sg_platf.cpp +++ b/src/surf/sg_platf.cpp @@ -409,12 +409,12 @@ void sg_platf_new_bypassRoute(sg_platf_route_cbarg_t bypassRoute) bypassRoute->link_list, bypassRoute->symmetrical); } -void sg_platf_new_process(sg_platf_process_cbarg_t process) +void sg_platf_new_process(ActorCreationArgs* actor) { - sg_host_t host = sg_host_by_name(process->host); + sg_host_t host = sg_host_by_name(actor->host); if (not host) { // The requested host does not exist. Do a nice message to the user - std::string msg = std::string("Cannot create process '") + process->function + "': host '" + process->host + + std::string msg = std::string("Cannot create process '") + actor->function + "': host '" + actor->host + "' does not exist\nExisting hosts: '"; std::vector list; @@ -431,16 +431,16 @@ void sg_platf_new_process(sg_platf_process_cbarg_t process) } xbt_die("%s", msg.c_str()); } - simgrid::simix::ActorCodeFactory& factory = SIMIX_get_actor_code_factory(process->function); - xbt_assert(factory, "Function '%s' unknown", process->function); + simgrid::simix::ActorCodeFactory& factory = SIMIX_get_actor_code_factory(actor->function); + xbt_assert(factory, "Function '%s' unknown", actor->function); - double start_time = process->start_time; - double kill_time = process->kill_time; - int auto_restart = process->on_failure == SURF_ACTOR_ON_FAILURE_DIE ? 0 : 1; + double start_time = actor->start_time; + double kill_time = actor->kill_time; + int auto_restart = actor->on_failure == ActorOnFailure::DIE ? 0 : 1; - std::string process_name = process->args[0]; - std::function code = factory(std::move(process->args)); - std::shared_ptr> properties(process->properties); + std::string process_name = actor->args[0]; + std::function code = factory(std::move(actor->args)); + std::shared_ptr> properties(actor->properties); smx_process_arg_t arg = nullptr; diff --git a/src/surf/xml/platf_private.hpp b/src/surf/xml/platf_private.hpp index d6084a212b..8848ab2eec 100644 --- a/src/surf/xml/platf_private.hpp +++ b/src/surf/xml/platf_private.hpp @@ -175,16 +175,18 @@ public: std::string element; }; -struct s_sg_platf_process_cbarg_t { +enum class ActorOnFailure { DIE, RESTART }; + +class ActorCreationArgs { +public: std::vector args; std::map* properties = nullptr; const char* host = nullptr; const char* function = nullptr; double start_time = 0.0; double kill_time = 0.0; - e_surf_process_on_failure_t on_failure = {}; + ActorOnFailure on_failure; }; -typedef s_sg_platf_process_cbarg_t* sg_platf_process_cbarg_t; class ZoneCreationArgs { public: @@ -220,7 +222,7 @@ XBT_PUBLIC(void) sg_platf_new_storage(StorageCreationArgs* storage); // Add a st 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); +XBT_PUBLIC(void) sg_platf_new_process(ActorCreationArgs* actor); XBT_PRIVATE void sg_platf_trace_connect(TraceConnectCreationArgs* trace_connect); /* Prototypes of the functions offered by flex */ diff --git a/src/surf/xml/surfxml_sax_cb.cpp b/src/surf/xml/surfxml_sax_cb.cpp index 05fc0ed4e0..b94cbbf045 100644 --- a/src/surf/xml/surfxml_sax_cb.cpp +++ b/src/surf/xml/surfxml_sax_cb.cpp @@ -904,7 +904,7 @@ void ETag_surfxml_process() void ETag_surfxml_actor() { - s_sg_platf_process_cbarg_t actor; + ActorCreationArgs actor; actor.properties = current_property_set; current_property_set = nullptr; @@ -918,10 +918,10 @@ void ETag_surfxml_actor() switch (A_surfxml_actor_on___failure) { case AU_surfxml_actor_on___failure: case A_surfxml_actor_on___failure_DIE: - actor.on_failure = SURF_ACTOR_ON_FAILURE_DIE; + actor.on_failure = ActorOnFailure::DIE; break; case A_surfxml_actor_on___failure_RESTART: - actor.on_failure = SURF_ACTOR_ON_FAILURE_RESTART; + actor.on_failure = ActorOnFailure::RESTART; break; default: surf_parse_error("Invalid on failure behavior"); -- 2.20.1