Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
use class and enum class in Actor parsing
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 11 Jan 2018 14:14:33 +0000 (15:14 +0100)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Thu, 11 Jan 2018 14:14:33 +0000 (15:14 +0100)
include/simgrid/forward.h
src/simix/smx_deployment.cpp
src/surf/sg_platf.cpp
src/surf/xml/platf_private.hpp
src/surf/xml/surfxml_sax_cb.cpp

index 6b9d37f..0a082a6 100644 (file)
@@ -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
  */
index 18bf778..f59d64f 100644 (file)
@@ -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 {
index 851a89c..9e51f91 100644 (file)
@@ -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<simgrid::s4u::Host*> 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<void()> code = factory(std::move(process->args));
-  std::shared_ptr<std::map<std::string, std::string>> properties(process->properties);
+  std::string process_name   = actor->args[0];
+  std::function<void()> code = factory(std::move(actor->args));
+  std::shared_ptr<std::map<std::string, std::string>> properties(actor->properties);
 
   smx_process_arg_t arg = nullptr;
 
index d6084a2..8848ab2 100644 (file)
@@ -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<std::string> args;
   std::map<std::string, std::string>* 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 */
index 05fc0ed..b94cbbf 100644 (file)
@@ -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");