Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[surf] simgrid::surf::Host, add backlink and attach() method
[simgrid.git] / src / surf / host_interface.cpp
index 737583b..e2eb602 100644 (file)
@@ -6,6 +6,8 @@
 
 #include "host_interface.hpp"
 
+#include <simgrid/Host.hpp>
+
 #include "src/simix/smx_private.h"
 #include "cpu_cas01.hpp"
 #include "simgrid/sg_config.h"
@@ -28,7 +30,9 @@ void host_add_traces(){
 
 namespace simgrid {
 namespace surf {
-  
+
+simgrid::xbt::FacetLevel<simgrid::Host, Host> Host::LEVEL;
+
 surf_callback(void, simgrid::surf::Host*) hostCreatedCallbacks;
 surf_callback(void, simgrid::surf::Host*) hostDestructedCallbacks;
 surf_callback(void, simgrid::surf::Host*, e_surf_resource_state_t, e_surf_resource_state_t) hostStateChangedCallbacks;
@@ -76,6 +80,15 @@ void HostModel::adjustWeightOfDummyCpuActions()
 /************
  * Resource *
  ************/
+
+void Host::init()
+{
+  if (!LEVEL.valid()) {
+    LEVEL = simgrid::Host::add_level<simgrid::surf::Host>();
+    SURF_HOST_LEVEL = LEVEL.id();
+  }
+}
+
 Host::Host(simgrid::surf::Model *model, const char *name, xbt_dict_t props,
                                 xbt_dynar_t storage, RoutingEdge *netElm, Cpu *cpu)
  : Resource(model, name, props)
@@ -96,6 +109,15 @@ Host::~Host(){
   surf_callback_emit(hostDestructedCallbacks, this);
 }
 
+void Host::attach(simgrid::Host* host)
+{
+  if (p_host != nullptr)
+    xbt_die("Already attached to host %s", host->id().c_str());
+  host->set_facet(this);
+  p_host = host;
+  surf_callback_emit(hostCreatedCallbacks, this);
+}
+
 void Host::setState(e_surf_resource_state_t state){
   e_surf_resource_state_t old = Resource::getState();
   Resource::setState(state);