Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce code duplication.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 2 Mar 2021 14:26:06 +0000 (15:26 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 2 Mar 2021 15:48:51 +0000 (16:48 +0100)
src/mc/ModelChecker.cpp
src/mc/ModelChecker.hpp

index 4906532..141400a 100644 (file)
@@ -339,13 +339,14 @@ bool ModelChecker::simcall_is_visible(int aid)
   this->remote_simulation_->clear_cache();
   return answer.value;
 }
-std::string ModelChecker::simcall_to_string(int aid, int times_considered)
+
+std::string ModelChecker::simcall_to_string(MessageType type, int aid, int times_considered)
 {
   xbt_assert(mc_model_checker != nullptr, "This should be called from the checker side");
 
   s_mc_message_simcall_to_string_t m;
   memset(&m, 0, sizeof(m));
-  m.type            = MessageType::SIMCALL_TO_STRING;
+  m.type            = type;
   m.aid             = aid;
   m.time_considered = times_considered;
   checker_side_.get_channel().send(m);
@@ -359,33 +360,21 @@ std::string ModelChecker::simcall_to_string(int aid, int times_considered)
              to_c_str(answer.type), (int)answer.type, (int)s, (int)MessageType::SIMCALL_TO_STRING_ANSWER,
              (int)sizeof(answer));
 
-  XBT_DEBUG("to_string(%d) is returning %s", aid, answer.value);
-
   return std::string(answer.value);
 }
-std::string ModelChecker::simcall_dot_label(int aid, int times_considered)
-{
-  xbt_assert(mc_model_checker != nullptr, "This should be called from the checker side");
-
-  s_mc_message_simcall_to_string_t m;
-  memset(&m, 0, sizeof(m));
-  m.type            = MessageType::SIMCALL_DOT_LABEL;
-  m.aid             = aid;
-  m.time_considered = times_considered;
-  checker_side_.get_channel().send(m);
 
-  s_mc_message_simcall_to_string_answer_t answer;
-  ssize_t s = checker_side_.get_channel().receive(answer);
-  xbt_assert(s != -1, "Could not receive message");
-  xbt_assert(s == sizeof(answer) && answer.type == MessageType::SIMCALL_TO_STRING_ANSWER,
-             "Received unexpected message %s (%i, size=%i) "
-             "expected MessageType::SIMCALL_TO_STRING_ANSWER (%i, size=%i)",
-             to_c_str(answer.type), (int)answer.type, (int)s, (int)MessageType::SIMCALL_TO_STRING_ANSWER,
-             (int)sizeof(answer));
-
-  XBT_DEBUG("dot_label(%d) is returning %s", aid, answer.value);
+std::string ModelChecker::simcall_to_string(int aid, int times_considered)
+{
+  std::string answer = simcall_to_string(MessageType::SIMCALL_TO_STRING, aid, times_considered);
+  XBT_DEBUG("to_string(%d) is returning %s", aid, answer.c_str());
+  return answer;
+}
 
-  return std::string(answer.value);
+std::string ModelChecker::simcall_dot_label(int aid, int times_considered)
+{
+  std::string answer = simcall_to_string(MessageType::SIMCALL_DOT_LABEL, aid, times_considered);
+  XBT_DEBUG("dot_label(%d) is returning %s", aid, answer.c_str());
+  return answer;
 }
 
 bool ModelChecker::checkDeadlock()
index 0647ada..99aa60d 100644 (file)
@@ -28,6 +28,9 @@ class ModelChecker {
   std::unique_ptr<RemoteSimulation> remote_simulation_;
   Checker* checker_ = nullptr;
 
+  // Expect MessageType::SIMCALL_TO_STRING or MessageType::SIMCALL_DOT_LABEL
+  std::string simcall_to_string(MessageType type, int aid, int times_considered);
+
 public:
   ModelChecker(ModelChecker const&) = delete;
   ModelChecker& operator=(ModelChecker const&) = delete;