Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move the Link signals to s4u
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 13 Feb 2017 22:01:28 +0000 (23:01 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 13 Feb 2017 22:11:24 +0000 (23:11 +0100)
include/simgrid/s4u/Link.hpp
src/s4u/s4u_link.cpp
src/surf/instr_routing.cpp
src/surf/network_cm02.cpp
src/surf/network_constant.cpp
src/surf/network_ib.cpp
src/surf/network_interface.cpp
src/surf/network_interface.hpp
src/surf/ptask_L07.cpp

index 05a3636..af44cb4 100644 (file)
@@ -10,8 +10,7 @@
 
 #include <unordered_map>
 
-#include "xbt/dict.h"
-#include "xbt/fifo.h"
+#include "xbt/signal.hpp"
 
 #include "simgrid/link.h"
 
  ***********/
 
 namespace simgrid {
+namespace surf {
+class NetworkAction;
+class Action;
+};
 namespace s4u {
 /** @brief A Link represents the network facilities between [hosts](\ref simgrid::s4u::Host) */
 class Link {
@@ -64,6 +67,22 @@ public:
                                                   external load). Trace must contain percentages (value between 0 and 1). */
   void setLatencyTrace(tmgr_trace_t trace); /*< setup the trace file with latency events (peak latency changes due to
                                                external load). Trace must contain absolute values */
+
+  /* The signals */
+  /** @brief Callback signal fired when a new Link is created */
+  static simgrid::xbt::signal<void(surf::LinkImpl*)> onCreation;
+
+  /** @brief Callback signal fired when a Link is destroyed */
+  static simgrid::xbt::signal<void(surf::LinkImpl*)> onDestruction;
+
+  /** @brief Callback signal fired when the state of a Link changes (when it is turned on or off) */
+  static simgrid::xbt::signal<void(surf::LinkImpl*)> onStateChange;
+
+  /** @brief Callback signal fired when a communication starts */
+  static simgrid::xbt::signal<void(surf::NetworkAction*, s4u::Host* src, s4u::Host* dst)> onCommunicate;
+
+  /** @brief Callback signal fired when a communication changes it state (ready/done/cancel) */
+  static simgrid::xbt::signal<void(surf::NetworkAction*)> onCommunicationStateChange;
 };
 }
 }
index f4b2d93..3f719e5 100644 (file)
@@ -148,5 +148,14 @@ void Link::setLatencyTrace(tmgr_trace_t trace)
     this->pimpl_->setLatencyTrace(trace);
   });
 }
+
+/*************
+ * Callbacks *
+ *************/
+simgrid::xbt::signal<void(surf::LinkImpl*)> Link::onCreation;
+simgrid::xbt::signal<void(surf::LinkImpl*)> Link::onDestruction;
+simgrid::xbt::signal<void(surf::LinkImpl*)> Link::onStateChange;
+simgrid::xbt::signal<void(surf::NetworkAction*, s4u::Host* src, s4u::Host* dst)> Link::onCommunicate;
+simgrid::xbt::signal<void(surf::NetworkAction*)> Link::onCommunicationStateChange;
 }
 }
index 89e9787..00b2555 100644 (file)
@@ -324,7 +324,7 @@ void instr_routing_define_callbacks ()
   //always need the call backs to ASes (we need only the root AS),
   //to create the rootContainer and the rootType properly
   if (!TRACE_needs_platform()) return;
-  simgrid::surf::LinkImpl::onCreation.connect(instr_routing_parse_start_link);
+  simgrid::s4u::Link::onCreation.connect(instr_routing_parse_start_link);
   simgrid::s4u::onPlatformCreated.connect(instr_routing_parse_end_platform);
 }
 
index 7f4e900..51b26da 100644 (file)
@@ -377,7 +377,7 @@ Action* NetworkCm02Model::communicate(s4u::Host* src, s4u::Host* dst, double siz
   delete back_route;
   XBT_OUT();
 
-  LinkImpl::onCommunicate(action, src, dst);
+  simgrid::s4u::Link::onCommunicate(action, src, dst);
   return action;
 }
 
@@ -401,11 +401,9 @@ NetworkCm02Link::NetworkCm02Link(NetworkCm02Model* model, const char* name, doub
   if (policy == SURF_LINK_FATPIPE)
     lmm_constraint_shared(constraint());
 
-  LinkImpl::onCreation(this);
+  simgrid::s4u::Link::onCreation(this);
 }
 
-
-
 void NetworkCm02Link::apply_event(tmgr_trace_iterator_t triggered, double value)
 {
 
index 7dc5c25..e2675fc 100644 (file)
@@ -78,7 +78,7 @@ namespace simgrid {
     {
       NetworkConstantAction *action = new NetworkConstantAction(this, size, sg_latency_factor);
 
-      LinkImpl::onCommunicate(action, src, dst);
+      simgrid::s4u::Link::onCommunicate(action, src, dst);
       return action;
     }
 
index 64e9649..41fa93c 100644 (file)
@@ -29,14 +29,12 @@ static void IB_create_host_callback(simgrid::s4u::Host& host){
   xbt_dict_set(((NetworkIBModel*)surf_network_model)->active_nodes, host.cname(), act, nullptr);
 }
 
-static void IB_action_state_changed_callback(
-    simgrid::surf::NetworkAction *action,
-    simgrid::surf::Action::State statein, simgrid::surf::Action::State stateout)
+static void IB_action_state_changed_callback(simgrid::surf::NetworkAction* action)
 {
   using simgrid::surf::NetworkIBModel;
   using simgrid::surf::IBNode;
 
-  if(statein!=simgrid::surf::Action::State::running || stateout!=simgrid::surf::Action::State::done)
+  if (action->getState() != simgrid::surf::Action::State::done)
     return;
   std::pair<IBNode*,IBNode*> pair = ((NetworkIBModel*)surf_network_model)->active_comms[action];
   XBT_DEBUG("IB callback - action %p finished", action);
@@ -79,15 +77,13 @@ static void IB_action_init_callback(simgrid::surf::NetworkAction* action, simgri
 /*  } */
 void surf_network_model_init_IB()
 {
-  using simgrid::surf::networkActionStateChangedCallbacks;
-
   if (surf_network_model)
     return;
 
   surf_network_model = new simgrid::surf::NetworkIBModel();
   all_existing_models->push_back(surf_network_model);
-  networkActionStateChangedCallbacks.connect(IB_action_state_changed_callback);
-  simgrid::surf::LinkImpl::onCommunicate.connect(IB_action_init_callback);
+  simgrid::s4u::Link::onCommunicationStateChange.connect(IB_action_state_changed_callback);
+  simgrid::s4u::Link::onCommunicate.connect(IB_action_init_callback);
   simgrid::s4u::Host::onCreation.connect(IB_create_host_callback);
   xbt_cfg_setdefault_double("network/weight-S", 8775);
 
index f88f52b..7f1e590 100644 (file)
@@ -48,17 +48,6 @@ namespace simgrid {
         (kv.second)->destroy();
       delete links;
     }
-
-    /*************
-     * Callbacks *
-     *************/
-
-    simgrid::xbt::signal<void(LinkImpl*)> LinkImpl::onCreation;
-    simgrid::xbt::signal<void(LinkImpl*)> LinkImpl::onDestruction;
-    simgrid::xbt::signal<void(LinkImpl*)> LinkImpl::onStateChange;
-
-    simgrid::xbt::signal<void(NetworkAction*, Action::State, Action::State)> networkActionStateChangedCallbacks;
-    simgrid::xbt::signal<void(NetworkAction*, s4u::Host* src, s4u::Host* dst)> LinkImpl::onCommunicate;
   }
 }
 
@@ -137,7 +126,7 @@ namespace simgrid {
     {
       if (!currentlyDestroying_) {
         currentlyDestroying_ = true;
-        onDestruction(this);
+        s4u::Link::onDestruction(this);
         delete this;
       }
     }
@@ -166,14 +155,14 @@ namespace simgrid {
     {
       if (isOff()) {
         Resource::turnOn();
-        onStateChange(this);
+        s4u::Link::onStateChange(this);
       }
     }
     void LinkImpl::turnOff()
     {
       if (isOn()) {
         Resource::turnOff();
-        onStateChange(this);
+        s4u::Link::onStateChange(this);
       }
     }
     void LinkImpl::setStateTrace(tmgr_trace_t trace)
@@ -198,9 +187,8 @@ namespace simgrid {
      **********/
 
     void NetworkAction::setState(Action::State state){
-      Action::State old = getState();
       Action::setState(state);
-      networkActionStateChangedCallbacks(this, old, state);
+      s4u::Link::onCommunicationStateChange(this);
     }
 
   }
index 25c3d61..6c1d47d 100644 (file)
@@ -28,10 +28,6 @@ namespace simgrid {
 
     class NetworkAction;
 
-    /** @brief Callback signal fired when the state of a NetworkAction changes
-     *  Signature: `void(NetworkAction *action, simgrid::surf::Action::State old, simgrid::surf::Action::State current)` */
-    XBT_PUBLIC_DATA(simgrid::xbt::signal<void(simgrid::surf::NetworkAction*, simgrid::surf::Action::State, simgrid::surf::Action::State)>) networkActionStateChangedCallbacks;
-
     /*********
      * Model *
      *********/
@@ -137,17 +133,6 @@ namespace simgrid {
     public:
       /** @brief Public interface */
       s4u::Link piface_;
-      /** @brief Callback signal fired when a new Link is created */
-      static simgrid::xbt::signal<void(surf::LinkImpl*)> onCreation;
-
-      /** @brief Callback signal fired when a Link is destroyed */
-      static simgrid::xbt::signal<void(surf::LinkImpl*)> onDestruction;
-
-      /** @brief Callback signal fired when the state of a Link changes (when it is turned on or off) */
-      static simgrid::xbt::signal<void(surf::LinkImpl*)> onStateChange;
-
-      /** @brief Callback signal fired when a communication starts */
-      static simgrid::xbt::signal<void(surf::NetworkAction*, s4u::Host* src, s4u::Host* dst)> onCommunicate;
 
       /** @brief Get the bandwidth in bytes per second of current Link */
       virtual double bandwidth();
index 2f0ccdc..8e90e06 100644 (file)
@@ -273,7 +273,7 @@ LinkL07::LinkL07(NetworkL07Model* model, const char* name, double bandwidth, dou
   if (policy == SURF_LINK_FATPIPE)
     lmm_constraint_shared(constraint());
 
-  LinkImpl::onCreation(this);
+  s4u::Link::onCreation(this);
 }
 
 Action *CpuL07::execution_start(double size)