Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix windows build
[simgrid.git] / include / simgrid / s4u / Actor.hpp
index 1eb18d1..72a5c6e 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <boost/intrusive_ptr.hpp>
 
+#include <xbt/Extendable.hpp>
 #include <xbt/base.h>
 #include <xbt/functional.hpp>
 #include <xbt/string.hpp>
@@ -131,9 +132,12 @@ namespace s4u {
  */
 
 /** @brief Simulation Agent */
-XBT_PUBLIC_CLASS Actor {
+XBT_PUBLIC_CLASS Actor : public simgrid::xbt::Extendable<Actor>
+{
+
   friend Mailbox;
   friend simgrid::simix::ActorImpl;
+  friend simgrid::kernel::activity::MailboxImpl;
   simix::ActorImpl* pimpl_ = nullptr;
 
   /** Wrap a (possibly non-copyable) single-use task into a `std::function` */
@@ -151,12 +155,10 @@ XBT_PUBLIC_CLASS Actor {
 public:
 
   // ***** No copy *****
-
   Actor(Actor const&) = delete;
   Actor& operator=(Actor const&) = delete;
 
   // ***** Reference count (delegated to pimpl_) *****
-
   friend void intrusive_ptr_add_ref(Actor* actor)
   {
     xbt_assert(actor != nullptr);
@@ -176,12 +178,7 @@ public:
    *
    *  If the actor is restarted, the actor has a fresh copy of the function.
    */
-  static ActorPtr createActor(const char* name, s4u::Host *host, double killTime, std::function<void()> code);
-
-  static ActorPtr createActor(const char* name, s4u::Host *host, std::function<void()> code)
-  {
-    return createActor(name, host, -1.0, std::move(code));
-  }
+  static ActorPtr createActor(const char* name, s4u::Host* host, std::function<void()> code);
 
   /** Create an actor using code
    *
@@ -201,50 +198,45 @@ public:
 
   // Create actor from function name:
 
-  static ActorPtr createActor(const char* name, s4u::Host *host, double killTime,
-    const char* function, std::vector<std::string> args);
-
-  static ActorPtr createActor(const char* name, s4u::Host *host, const char* function,
-      std::vector<std::string> args)
-  {
-    return createActor(name, host, -1.0, function, std::move(args));
-  }
+  static ActorPtr createActor(const char* name, s4u::Host* host, const char* function, std::vector<std::string> args);
 
   // ***** Methods *****
 
-  /** Retrieves the actor that have the given PID (or NULL if not existing) */
-  //static Actor *byPid(int pid); not implemented
-
-  /** Retrieves the name of that actor */
-  simgrid::xbt::string getName();
+  /** Retrieves the name of that actor as a C string */
+  const char* cname();
+  /** Retrieves the name of that actor as a C++ string */
+  simgrid::xbt::string name();
   /** Retrieves the host on which that actor is running */
-  s4u::Host *getHost();
+  s4u::Host* host();
   /** Retrieves the PID of that actor */
-  int getPid();
+  int pid();
   /** Retrieves the PPID of that actor */
-  int getPpid();
+  int ppid();
 
   /** If set to true, the actor will automatically restart when its host reboots */
   void setAutoRestart(bool autorestart);
   /** Sets the time at which that actor should be killed */
   void setKillTime(double time);
   /** Retrieves the time at which that actor will be killed (or -1 if not set) */
-  double getKillTime();
+  double killTime();
 
   /** Ask the actor to die.
    *
    * It will only notice your request when doing a simcall next time (a communication or similar).
    * SimGrid sometimes have issues when you kill actors that are currently communicating and such.
-   * We are working on it to fix the issues.
+   * Still. Please report any bug that you may encounter with a minimal working example.
    */
   void kill();
 
   static void kill(int pid);
-  static ActorPtr forPid(int pid);
-  
-  /**
-   * Wait for the actor to finish.
-   */ 
+
+  /** Retrieves the actor that have the given PID (or nullptr if not existing) */
+  static ActorPtr byPid(int pid);
+
+  /** @brief Wait for the actor to finish.
+   *
+   * This blocks the calling actor until the actor on which we call join() is terminated
+   */
   void join();
   
   // Static methods on all actors:
@@ -252,9 +244,8 @@ public:
   /** Ask kindly to all actors to die. Only the issuer will survive. */
   static void killAll();
 
-protected:
   /** Returns the internal implementation of this actor */
-  smx_actor_t getImpl();
+  simix::ActorImpl* getImpl();
 };
 
 /** @ingroup s4u_api
@@ -298,17 +289,15 @@ namespace this_actor {
    * See \ref Comm for the full communication API (including non blocking communications).
   */
   XBT_PUBLIC(void) send(MailboxPtr chan, void*payload, size_t simulatedSize);
-  
-  /**
-   * Return the PID of the current actor.
-   */
-  XBT_PUBLIC(int) getPid();
-  
-  /**
-   * Return the PPID of the current actor.
-   */
-  int getPpid();
 
+  /** @brief Returns the PID of the current actor. */
+  XBT_PUBLIC(int) pid();
+
+  /** @brief Returns the PPID of the current actor. */
+  XBT_PUBLIC(int) ppid();
+
+  /** @brief Returns the name of the current actor. */
+  XBT_PUBLIC(std::string) name();
 };
 
 /** @} */