Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revert "remove a C-like pimple"
[simgrid.git] / src / surf / host_interface.hpp
index 978ed35..236ccdb 100644 (file)
@@ -8,6 +8,7 @@
 #include "storage_interface.hpp"
 #include "cpu_interface.hpp"
 #include "network_interface.hpp"
+#include "src/surf/PropertyHolder.hpp"
 
 #include <xbt/base.h>
 
  * Classes *
  ***********/
 
+namespace simgrid {
+namespace surf {
+
 class XBT_PRIVATE HostModel;
 class XBT_PRIVATE Host;
 class XBT_PRIVATE HostAction;
 
-/*************
- * Callbacks *
- *************/
-
-/** @ingroup SURF_callbacks
- * @brief Callbacks fired after Host creation. Signature: `void(Host*)`
- */
-XBT_PUBLIC_DATA(surf_callback(void, Host*)) hostCreatedCallbacks;
-
-/** @ingroup SURF_callbacks
- * @brief Callbacks fired Host destruction. Signature: `void(Host*)`
- */
-XBT_PUBLIC_DATA(surf_callback(void, Host*)) hostDestructedCallbacks;
 
-/** @ingroup SURF_callbacks
- * @brief Callbacks fired after Host State changed. Signature: `void(Host *, e_surf_resource_state_t old, e_surf_resource_state_t current)`
- */
-XBT_PUBLIC_DATA(surf_callback(void, Host*, e_surf_resource_state_t, e_surf_resource_state_t)) hostStateChangedCallbacks;
-
-/** @ingroup SURF_callbacks
- * @brief Callbacks fired HostAction State changed. Signature: `void(HostAction *, e_surf_action_state_t old, e_surf_action_state_t current)`
- */
-XBT_PUBLIC_DATA(surf_callback(void, HostAction*, e_surf_action_state_t, e_surf_action_state_t)) hostActionStateChangedCallbacks;
+}
+}
 
 /*********
  * Tools *
  *********/
-XBT_PUBLIC_DATA(HostModel*) surf_host_model;
+XBT_PUBLIC_DATA(simgrid::surf::HostModel*) surf_host_model;
 XBT_PUBLIC(void) host_add_traces();
 
 /*********
  * Model *
  *********/
+
+namespace simgrid {
+namespace surf {
+
 /** @ingroup SURF_host_interface
  * @brief SURF Host model interface class
  * @details A model is an object which handle the interactions between its Resources and its Actions
  */
-class HostModel : public Model {
+class HostModel : public Model{
 public:
   HostModel() : Model() {}
   ~HostModel() {}
 
-  virtual Host *createHost(const char *name, RoutingEdge *net, Cpu *cpu)=0;
-  void addTraces(){DIE_IMPOSSIBLE;}
+  Host *createHost(const char *name, NetCard *net, Cpu *cpu, xbt_dict_t props);
+  void addTraces() override {DIE_IMPOSSIBLE;}
 
   virtual void adjustWeightOfDummyCpuActions();
   virtual Action *executeParallelTask(int host_nb,
@@ -74,7 +62,7 @@ public:
                                                                          double *bytes_amount,
                                                                          double rate)=0;
 
-  bool shareResourcesIsIdempotent() {return true;}
+  bool shareResourcesIsIdempotent() override {return true;}
 };
 
 /************
@@ -82,10 +70,21 @@ public:
  ************/
 /** @ingroup SURF_host_interface
  * @brief SURF Host interface class
- * @details An host represents a machine with a aggregation of a Cpu, a Link and a Storage
+ * @details An host represents a machine with a aggregation of a Cpu, a RoutingEdge and a Storage
  */
-class Host : public Resource {
+class Host :
+        public simgrid::surf::Resource,
+        public simgrid::surf::PropertyHolder {
+public:
+  static simgrid::xbt::Extension<simgrid::Host, Host> EXTENSION_ID;
+
+  /* callbacks */
+  static simgrid::surf::signal<void(Host*)> onCreation;    /** Called on each newly created object */
+  static simgrid::surf::signal<void(Host*)> onDestruction; /** Called just before destructing an object */
+  static simgrid::surf::signal<void(Host*)> onStateChange; /** Called when the machine is turned on or off */
+
 public:
+  static void classInit(); // must be called before the first use of that class
   /**
    * @brief Host constructor
    *
@@ -93,11 +92,10 @@ public:
    * @param name The name of the Host
    * @param props Dictionary of properties associated to this Host
    * @param storage The Storage associated to this Host
-   * @param netElm The RoutingEdge associated to this Host
    * @param cpu The Cpu associated to this Host
    */
-  Host(Model *model, const char *name, xbt_dict_t props,
-                     xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu);
+  Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
+                     xbt_dynar_t storage, Cpu *cpu);
 
   /**
    * @brief Host constructor
@@ -107,45 +105,31 @@ public:
    * @param props Dictionary of properties associated to this Host
    * @param constraint The lmm constraint associated to this Host if it is part of a LMM component
    * @param storage The Storage associated to this Host
-   * @param netElm The RoutingEdge associated to this Host
    * @param cpu The Cpu associated to this Host
    */
-  Host(Model *model, const char *name, xbt_dict_t props,
-      lmm_constraint_t constraint, xbt_dynar_t storage, RoutingEdge *netElm,
-      Cpu *cpu);
+  Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
+      lmm_constraint_t constraint, xbt_dynar_t storage, Cpu *cpu);
 
-  /** @brief Host destructor */
-  ~ Host();
+  /* Host destruction logic */
+  /**************************/
+protected:
+  ~Host();
+public:
+       void destroy(); // Must be called instead of the destructor
+private:
+       bool currentlyDestroying_ = false;
 
-  void setState(e_surf_resource_state_t state);
 
-  /**
-   * @brief Get the properties of the current Host
-   *
-   * @return The properties of the current Host
-   */
-  xbt_dict_t getProperties();
-
-  /**
-   * @brief Execute some quantity of computation
-   *
-   * @param flops_amount The value of the processing amount (in flop) needed to process
-   * @return The CpuAction corresponding to the processing
-   * @see Cpu
-   */
-  virtual Action *execute(double flops_amount)=0;
+public:
+  void attach(simgrid::Host* host);
 
-  /**
-   * @brief Make a process sleep for duration seconds
-   *
-   * @param duration The number of seconds to sleep
-   * @return The CpuAction corresponding to the sleeping
-   * @see Cpu
-   */
-  virtual Action *sleep(double duration)=0;
+  bool isOn() override;
+  bool isOff() override;
+  void turnOn() override;
+  void turnOff() override;
 
   /** @brief Return the storage of corresponding mount point */
-  virtual Storage *findStorageOnMountList(const char* storage);
+  virtual simgrid::surf::Storage *findStorageOnMountList(const char* storage);
 
   /** @brief Get the xbt_dict_t of mount_point: Storage */
   virtual xbt_dict_t getMountedStorageList();
@@ -157,7 +141,6 @@ public:
    * @brief Open a file
    *
    * @param fullpath The full path to the file
-   *
    * @return The StorageAction corresponding to the opening
    */
   virtual Action *open(const char* fullpath);
@@ -252,9 +235,14 @@ public:
    */
   virtual int fileMove(surf_file_t fd, const char* fullpath);
 
+  bool isUsed() override {DIE_IMPOSSIBLE;} // FIXME: Host should not be a Resource
+  void updateState(tmgr_trace_event_t event_type, double value, double date) override
+    {THROW_IMPOSSIBLE;} // FIXME: Host should not be a Resource
+
+public:
   xbt_dynar_t p_storage;
-  RoutingEdge *p_netElm;
   Cpu *p_cpu;
+  simgrid::Host* p_host = nullptr;
 
   /** @brief Get the list of virtual machines on the current Host */
   xbt_dynar_t getVms();
@@ -265,42 +253,12 @@ public:
   void getParams(vm_params_t params);
   /** @brief Sets the params of that VM/PM */
   void setParams(vm_params_t params);
+  simgrid::Host* getHost() { return p_host; }
 private:
   s_vm_params_t p_params;
 };
 
-/**********
- * Action *
- **********/
-
-/** @ingroup SURF_host_interface
- * @brief SURF host action interface class
- */
-class HostAction : public Action {
-public:
-  /**
-   * @brief HostAction constructor
-   *
-   * @param model The HostModel associated to this HostAction
-   * @param cost The cost of this HostAction in [TODO]
-   * @param failed [description]
-   */
-  HostAction(Model *model, double cost, bool failed)
-  : Action(model, cost, failed) {}
-
-  /**
-   * @brief HostAction constructor
-   *
-   * @param model The HostModel associated to this HostAction
-   * @param cost The cost of this HostAction in [TODO]
-   * @param failed [description]
-   * @param var The lmm variable associated to this StorageAction if it is part of a LMM component
-   */
-  HostAction(Model *model, double cost, bool failed, lmm_variable_t var)
-  : Action(model, cost, failed, var) {}
-
-  void setState(e_surf_action_state_t state);
-};
-
+}
+}
 
 #endif /* SURF_Host_INTERFACE_HPP_ */