Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill dead code in the C interface to surf
[simgrid.git] / src / surf / network_interface.cpp
index 34bf4fc..321c0d8 100644 (file)
@@ -43,8 +43,8 @@ void* sg_link_data(Link *link) {
 void sg_link_data_set(Link *link,void *data) {
        link->setData(data);
 }
-int sg_link_amount(void) {
-       return Link::linksAmount();
+int sg_link_count(void) {
+       return Link::linksCount();
 }
 Link** sg_link_list(void) {
        return Link::linksList();
@@ -72,7 +72,7 @@ Link *Link::byName(const char* name) {
          return res;
 }
 /** @brief Returns the amount of links in the platform */
-int Link::linksAmount() {
+int Link::linksCount() {
          return links->size();
 }
 /** @brief Returns a list of all existing links */
@@ -87,7 +87,7 @@ Link **Link::linksList() {
 /** @brief destructor of the static data */
 void Link::linksExit() {
        for (auto kv : *links)
-               delete (kv.second);
+               (kv.second)->destroy();
        delete links;
 }
 
@@ -95,11 +95,12 @@ void Link::linksExit() {
  * Callbacks *
  *************/
 
-simgrid::surf::signal<void(simgrid::surf::Link*)> networkLinkCreatedCallbacks;
-simgrid::surf::signal<void(simgrid::surf::Link*)> networkLinkDestructedCallbacks;
-simgrid::surf::signal<void(simgrid::surf::Link*, e_surf_resource_state_t, e_surf_resource_state_t)> networkLinkStateChangedCallbacks;
-simgrid::surf::signal<void(simgrid::surf::NetworkAction*, e_surf_action_state_t, e_surf_action_state_t)> networkActionStateChangedCallbacks;
-simgrid::surf::signal<void(simgrid::surf::NetworkAction*, simgrid::surf::RoutingEdge *src, simgrid::surf::RoutingEdge *dst, double size, double rate)> networkCommunicateCallbacks;
+simgrid::xbt::signal<void(simgrid::surf::Link*)> Link::onCreation;
+simgrid::xbt::signal<void(simgrid::surf::Link*)> Link::onDestruction;
+simgrid::xbt::signal<void(simgrid::surf::Link*, int, int)> Link::onStateChange; // signature: wasOn, currentlyOn
+
+simgrid::xbt::signal<void(simgrid::surf::NetworkAction*, e_surf_action_state_t, e_surf_action_state_t)> networkActionStateChangedCallbacks;
+simgrid::xbt::signal<void(simgrid::surf::NetworkAction*, simgrid::surf::NetCard *src, simgrid::surf::NetCard *dst, double size, double rate)> networkCommunicateCallbacks;
 
 }
 }
@@ -113,7 +114,7 @@ void netlink_parse_init(sg_platf_link_cbarg_t link){
                       link->bandwidth_trace,
                       link->latency,
                       link->latency_trace,
-                      link->state,
+                      link->initiallyOn,
                       link->state_trace, link->policy, link->properties);
     xbt_free(link_id);
     link_id = bprintf("%s_DOWN", link->id);
@@ -122,7 +123,7 @@ void netlink_parse_init(sg_platf_link_cbarg_t link){
                       link->bandwidth_trace,
                       link->latency,
                       link->latency_trace,
-                      link->state,
+                      link->initiallyOn,
                       link->state_trace, link->policy, link->properties);
     xbt_free(link_id);
   } else {
@@ -131,15 +132,11 @@ void netlink_parse_init(sg_platf_link_cbarg_t link){
                          link->bandwidth_trace,
                          link->latency,
                          link->latency_trace,
-                         link->state,
+                         link->initiallyOn,
                          link->state_trace, link->policy, link->properties);
   }
 }
 
-void net_add_traces(){
-  surf_network_model->addTraces();
-}
-
 /*********
  * Model *
  *********/
@@ -204,7 +201,7 @@ Link::Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t prop
 
 Link::Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t props,
                                 lmm_constraint_t constraint,
-                            tmgr_history_t history,
+                            tmgr_fes_t history,
                             tmgr_trace_t state_trace)
 : Resource(model, name, constraint),
   PropertyHolder(props)
@@ -217,9 +214,21 @@ Link::Link(simgrid::surf::NetworkModel *model, const char *name, xbt_dict_t prop
 
 }
 
-Link::~Link()
+/** @brief use destroy() instead of this destructor */
+Link::~Link() {
+       xbt_assert(currentlyDestroying_, "Don't delete Links directly. Call destroy() instead.");
+}
+/** @brief Fire the require callbacks and destroy the object
+ *
+ * Don't delete directly an Link, call l->destroy() instead.
+ */
+void Link::destroy()
 {
-  networkLinkDestructedCallbacks(this);
+       if (!currentlyDestroying_) {
+               currentlyDestroying_ = true;
+               onDestruction(this);
+               delete this;
+       }
 }
 
 bool Link::isUsed()
@@ -242,10 +251,17 @@ int Link::sharingPolicy()
   return lmm_constraint_sharing_policy(getConstraint());
 }
 
-void Link::setState(e_surf_resource_state_t state){
-  e_surf_resource_state_t old = Resource::getState();
-  Resource::setState(state);
-  networkLinkStateChangedCallbacks(this, old, state);
+void Link::turnOn(){
+  if (isOff()) {
+    Resource::turnOn();
+    onStateChange(this, 0, 1);
+  }
+}
+void Link::turnOff(){
+  if (isOn()) {
+    Resource::turnOff();
+    onStateChange(this, 1, 0);
+  }
 }
 
 /**********