Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / include / simgrid / s4u / Activity.hpp
index efba3e2..0e0b72a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2006-2022. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2006-2023. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -32,10 +32,11 @@ namespace s4u {
  * That is, activities are all the things that do take time to the actor in the simulated world.
  */
 class XBT_PUBLIC Activity : public xbt::Extendable<Activity> {
+#ifndef DOXYGEN
   friend Comm;
   friend Exec;
   friend Io;
-#ifndef DOXYGEN
+  friend kernel::activity::ActivityImpl;
   friend std::vector<ActivityPtr> create_DAG_from_dot(const std::string& filename);
   friend std::vector<ActivityPtr> create_DAG_from_DAX(const std::string& filename);
 #endif
@@ -62,7 +63,7 @@ protected:
       XBT_CVERB(s4u_activity, "Remove a dependency from '%s' on '%s'", get_cname(), b->get_cname());
       b->dependencies_.erase(this);
       if (b->dependencies_solved()) {
-        b->vetoable_start();
+        b->start();
       }
       successors_.pop_back();
     }
@@ -95,9 +96,16 @@ protected:
 
   static std::set<Activity*>* vetoed_activities_;
 
+  /** Set the [remaining] amount of work that this Activity will entail
+   *
+   * It is forbidden to change the amount of work once the Activity is started */
+  Activity* set_remaining(double remains);
+
 private:
   static xbt::signal<void(Activity&)> on_veto;
-  static xbt::signal<void(Activity&)> on_completion;
+  static xbt::signal<void(Activity const&)> on_completion;
+  static xbt::signal<void(Activity const&)> on_suspended;
+  static xbt::signal<void(Activity const&)> on_resumed;
 
 public:
   /*! Add a callback fired each time that the activity fails to start because of a veto (e.g., unsolved dependency or no
@@ -105,13 +113,21 @@ public:
   static void on_veto_cb(const std::function<void(Activity&)>& cb) { on_veto.connect(cb); }
   /*! Add a callback fired when the activity completes (either normally, cancelled or failed) */
   static void on_completion_cb(const std::function<void(Activity const&)>& cb) { on_completion.connect(cb); }
+  /*! Add a callback fired when the activity is suspended */
+  static void on_suspended_cb(const std::function<void(Activity const&)>& cb) { on_suspended.connect(cb); }
+  /*! Add a callback fired when the activity is resumed after being suspended */
+  static void on_resumed_cb(const std::function<void(Activity const&)>& cb) { on_resumed.connect(cb); }
 
-  void vetoable_start()
+  XBT_ATTRIB_DEPRECATED_v334("All start() are vetoable now. Please use start() ") void vetoable_start()
+  {
+    start();
+  }
+  void start()
   {
     state_ = State::STARTING;
     if (dependencies_solved() && is_assigned()) {
       XBT_CVERB(s4u_activity, "'%s' is assigned to a resource and all dependencies are solved. Let's start", get_cname());
-      start();
+      do_start();
     } else {
       if (vetoed_activities_ != nullptr)
         vetoed_activities_->insert(this);
@@ -139,13 +155,13 @@ public:
    *
    * This function is optional: you can call wait() even if you didn't call start()
    */
-  virtual Activity* start() = 0;
-  /** Blocks the current actor until the activity is terminated */
+  virtual Activity* do_start() = 0;
   /** Tests whether the given activity is terminated yet. */
   virtual bool test();
   /*! take a vector s4u::ActivityPtr and return the rank of the first finished one (or -1 if none is done). */
   static ssize_t test_any(const std::vector<ActivityPtr>& activities);
 
+  /** Blocks the current actor until the activity is terminated */
   Activity* wait() { return wait_for(-1.0); }
   /** Blocks the current actor until the activity is terminated, or until the timeout is elapsed\n
    *  Raises: timeout exception.*/
@@ -179,10 +195,6 @@ public:
 
   /** Get the remaining amount of work that this Activity entails. When it's 0, it's done. */
   virtual double get_remaining() const;
-  /** Set the [remaining] amount of work that this Activity will entail
-   *
-   * It is forbidden to change the amount of work once the Activity is started */
-  Activity* set_remaining(double remains);
 
   double get_start_time() const;
   double get_finish_time() const;
@@ -237,7 +249,6 @@ public:
   }
   AnyActivity* set_name(const std::string& name)
   {
-    xbt_assert(get_state() == State::INITED, "Cannot change the name of an activity after its start");
     name_ = name;
     return static_cast<AnyActivity*>(this);
   }
@@ -262,10 +273,13 @@ public:
   {
     return get_data<void>();
   }
-
-  AnyActivity* vetoable_start()
+  XBT_ATTRIB_DEPRECATED_v334("All start() are vetoable now. Please use start() ") AnyActivity* vetoable_start()
+  {
+    return start();
+  }
+  AnyActivity* start()
   {
-    Activity::vetoable_start();
+    Activity::start();
     return static_cast<AnyActivity*>(this);
   }