Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Factorize some code into the netcard constructor
authorMartin Quinson <martin.quinson@loria.fr>
Sat, 26 Mar 2016 14:42:33 +0000 (15:42 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Sat, 26 Mar 2016 14:50:43 +0000 (15:50 +0100)
src/surf/sg_platf.cpp
src/surf/surf_routing.hpp

index 9dfdc53..ea7814c 100644 (file)
@@ -82,10 +82,8 @@ void sg_platf_new_host(sg_platf_host_cbarg_t host)
   simgrid::surf::NetCard *netcard =
       new simgrid::surf::NetCardImpl(host->id, SURF_NETWORK_ELEMENT_HOST, current_routing);
 
-  netcard->setId(current_routing->addComponent(netcard));
   sg_host_t h = simgrid::s4u::Host::by_name_or_create(host->id);
   h->pimpl_netcard = netcard;
-  simgrid::surf::netcardCreatedCallbacks(netcard);
 
   if(mount_list){
     xbt_lib_set(storage_lib, host->id, ROUTING_STORAGE_HOST_LEVEL, (void *) mount_list);
@@ -142,10 +140,8 @@ void sg_platf_new_router(sg_platf_router_cbarg_t router)
 
   simgrid::surf::NetCard *netcard =
     new simgrid::surf::NetCardImpl(router->id, SURF_NETWORK_ELEMENT_ROUTER, current_routing);
-  netcard->setId(current_routing->addComponent(netcard));
   xbt_lib_set(as_router_lib, router->id, ROUTING_ASR_LEVEL, (void *) netcard);
   XBT_DEBUG("Having set name '%s' id '%d'", router->id, netcard->id());
-  simgrid::surf::netcardCreatedCallbacks(netcard);
 
   if (router->coord && strcmp(router->coord, "")) {
     unsigned int cursor;
@@ -925,10 +921,8 @@ void sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS)
   /* make a new routing component */
   simgrid::surf::NetCard *netcard = new simgrid::surf::NetCardImpl(new_as->name(), SURF_NETWORK_ELEMENT_AS, current_routing);
 
-  if (current_routing == NULL && routing_platf->root_ == NULL) {
-    /* it is the first one */
+  if (current_routing == NULL && routing_platf->root_ == NULL) { /* it is the first one */
     routing_platf->root_ = new_as;
-    netcard->setId(-1);
   } else if (current_routing != NULL && routing_platf->root_ != NULL) {
 
     xbt_assert(!xbt_dict_get_or_null(current_routing->children(), AS->id),
@@ -940,8 +934,6 @@ void sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS)
       current_routing->hierarchy_ = simgrid::surf::AsImpl::RoutingMode::recursive;
     /* add to the sons dictionary */
     xbt_dict_set(current_routing->children(), AS->id, (void *) new_as, NULL);
-    /* add to the father element list */
-    netcard->setId(current_routing->addComponent(netcard));
   } else {
     THROWF(arg_error, 0, "All defined components must belong to a AS");
   }
@@ -953,7 +945,6 @@ void sg_platf_new_AS_begin(sg_platf_AS_cbarg_t AS)
   current_routing = new_as;
   current_routing->netcard_ = netcard;
 
-  simgrid::surf::netcardCreatedCallbacks(netcard);
   simgrid::surf::asCreatedCallbacks(new_as);
   if (TRACE_is_enabled())
     sg_instr_AS_begin(AS);
index 2e04910..ccbb7d6 100644 (file)
@@ -27,6 +27,9 @@ SG_END_DECL()
 namespace simgrid {
 namespace surf {
 
+  XBT_PUBLIC_DATA(simgrid::xbt::signal<void(s4u::As*)>) asCreatedCallbacks;
+  XBT_PUBLIC_DATA(simgrid::xbt::signal<void(NetCard*)>) netcardCreatedCallbacks;
+
 /***********
  * Classes *
  ***********/
@@ -43,7 +46,6 @@ class NetCard {
 public:
   virtual ~NetCard(){};
   virtual int id()=0; // Our rank in the vertices_ array of our containing AS.
-  virtual void setId(int id)=0;
   virtual char *name()=0;
   virtual AsImpl *containingAS()=0; // This is the AS in which I am
   virtual bool isAS()=0;
@@ -53,15 +55,18 @@ public:
 
 struct XBT_PRIVATE NetCardImpl : public NetCard {
 public:
-  NetCardImpl(const char *name, e_surf_network_element_type_t componentType, AsImpl *as)
+  NetCardImpl(const char *name, e_surf_network_element_type_t componentType, AsImpl *containingAS)
   : name_(xbt_strdup(name)),
     componentType_(componentType),
-    containingAS_(as)
-  {}
+    containingAS_(containingAS)
+  {
+    if (containingAS != nullptr)
+      id_ = containingAS->addComponent(this);
+    simgrid::surf::netcardCreatedCallbacks(this);
+  }
   ~NetCardImpl() { xbt_free(name_);};
 
   int id()           override {return id_;}
-  void setId(int id) override {id_ = id;}
   char *name()       override {return name_;}
   AsImpl *containingAS() override {return containingAS_;}
 
@@ -101,13 +106,6 @@ public:
   void getRouteAndLatency(NetCard *src, NetCard *dst, std::vector<Link*> * links, double *latency);
 };
 
-/*************
- * Callbacks *
- *************/
-
-XBT_PUBLIC_DATA(simgrid::xbt::signal<void(NetCard*)>) netcardCreatedCallbacks;
-XBT_PUBLIC_DATA(simgrid::xbt::signal<void(s4u::As*)>) asCreatedCallbacks;
-
 }
 }