Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add instance signals for all Disk signals
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Mon, 22 May 2023 15:13:14 +0000 (17:13 +0200)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Mon, 22 May 2023 15:13:14 +0000 (17:13 +0200)
docs/source/Plugins.rst
docs/source/app_s4u.rst
include/simgrid/s4u/Disk.hpp
src/kernel/resource/DiskImpl.cpp

index a173215..b3678c4 100644 (file)
@@ -90,7 +90,9 @@ Partial list of existing signals in s4u:
   :cpp:func:`CommImpl::on_completion <simgrid::s4u::Comm::on_completion_cb>`
 - :cpp:func:`Disk::on_creation <simgrid::s4u::Disk::on_creation_cb>`
   :cpp:func:`Disk::on_destruction <simgrid::s4u::Disk::on_destruction_cb>`
+  :cpp:func:`Disk::on_this_destruction <simgrid::s4u::Disk::on_this_destruction_cb>`
   :cpp:func:`Disk::on_state_change <simgrid::s4u::Disk::on_state_change_cb>`
+  :cpp:func:`Disk::on_this_state_change <simgrid::s4u::Disk::on_this_state_change_cb>`
 - :cpp:func:`Engine::on_platform_creation <simgrid::s4u::Engine::on_platform_creation_cb>`
   :cpp:func:`Engine::on_platform_created <simgrid::s4u::Engine::on_platform_created_cb>`
   :cpp:func:`Engine::on_time_advance <simgrid::s4u::Engine::on_time_advance_cb>`
index b768946..b5b7d66 100644 (file)
@@ -1212,7 +1212,9 @@ Signals
 
       .. doxygenfunction:: simgrid::s4u::Disk::on_creation_cb
       .. doxygenfunction:: simgrid::s4u::Disk::on_destruction_cb
+      .. doxygenfunction:: simgrid::s4u::Disk::on_this_destruction_cb
       .. doxygenfunction:: simgrid::s4u::Disk::on_state_change_cb
+      .. doxygenfunction:: simgrid::s4u::Disk::on_this_state_change_cb
 
 
 .. _API_s4u_Host:
index fcba914..46fc2f7 100644 (file)
@@ -135,15 +135,21 @@ public:
   /* The signals */
   /** @brief Add a callback fired when a new Disk is created */
   static void on_creation_cb(const std::function<void(Disk&)>& cb) { on_creation.connect(cb); }
-  /** @brief Add a callback fired when a Disk is destroyed */
+  /** @brief Add a callback fired when any Disk is destroyed */
   static void on_destruction_cb(const std::function<void(Disk const&)>& cb) { on_destruction.connect(cb); }
-  /** @brief Add a callback fired when a Disk's state changes */
+  /** @brief Add a callback fired when this specific Disk is destroyed */
+  void on_this_destruction_cb(const std::function<void(Disk const&)>& cb) { on_this_destruction.connect(cb); }
+  /** @brief Add a callback fired when the state of any Disk changes */
   static void on_state_change_cb(const std::function<void(Disk const&)>& cb) { on_state_change.connect(cb); }
+  /** @brief Add a callback fired when the state of this specific Disk changes */
+  void on_this_state_change_cb(const std::function<void(Disk const&)>& cb) { on_this_state_change.connect(cb); }
 
 private:
   static xbt::signal<void(Disk&)> on_creation;
   static xbt::signal<void(Disk const&)> on_destruction;
+  xbt::signal<void(Disk const&)> on_this_destruction;
   static xbt::signal<void(Disk const&)> on_state_change;
+  xbt::signal<void(Disk const&)> on_this_state_change;
 };
 
 } // namespace s4u
index 1903b81..bad9435 100644 (file)
@@ -53,6 +53,7 @@ DiskImpl* DiskImpl::set_write_constraint(lmm::Constraint* constraint_write)
 void DiskImpl::destroy()
 {
   s4u::Disk::on_destruction(piface_);
+  piface_.on_this_destruction(piface_);
   delete this;
 }
 
@@ -61,6 +62,7 @@ void DiskImpl::turn_on()
   if (not is_on()) {
     Resource::turn_on();
     s4u::Disk::on_state_change(piface_);
+    piface_.on_this_state_change(piface_);
   }
 }
 void DiskImpl::turn_off()
@@ -68,6 +70,7 @@ void DiskImpl::turn_off()
   if (is_on()) {
     Resource::turn_off();
     s4u::Disk::on_state_change(piface_);
+    piface_.on_this_state_change(piface_);
 
     const kernel::lmm::Element* elem = nullptr;
     double now                       = EngineImpl::get_clock();