Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add more callbacks
authorPaul Bédaride <paul.bedaride@gmail.com>
Wed, 22 Jan 2014 17:07:06 +0000 (18:07 +0100)
committerPaul Bédaride <paul.bedaride@gmail.com>
Wed, 22 Jan 2014 17:07:26 +0000 (18:07 +0100)
18 files changed:
src/surf/cpu_cas01.cpp
src/surf/cpu_interface.cpp
src/surf/cpu_interface.hpp
src/surf/cpu_ti.cpp
src/surf/network_cm02.cpp
src/surf/network_interface.cpp
src/surf/network_interface.hpp
src/surf/plugins/energy.cpp
src/surf/storage_interface.cpp
src/surf/storage_interface.hpp
src/surf/storage_n11.cpp
src/surf/surf_interface.hpp
src/surf/vm_workstation_interface.cpp
src/surf/vm_workstation_interface.hpp
src/surf/workstation_interface.cpp
src/surf/workstation_interface.hpp
src/surf/workstation_ptask_L07.cpp
src/surf/workstation_ptask_L07.hpp

index 1174ac2..8baff8b 100644 (file)
@@ -203,7 +203,7 @@ CpuCas01::CpuCas01(CpuCas01ModelPtr model, const char *name, xbt_dynar_t powerPe
   XBT_DEBUG("CPU create: peak=%f, pstate=%d", m_powerPeak, m_pstate);
 
   m_core = core;
-  m_stateCurrent = stateInitial;
+  setState(stateInitial);
   if (powerTrace)
     p_powerEvent = tmgr_history_add_trace(history, powerTrace, 0.0, 0, static_cast<ResourcePtr>(this));
 
@@ -253,13 +253,13 @@ void CpuCas01::updateState(tmgr_trace_event_t event_type, double value, double d
     xbt_assert(m_core == 1, "FIXME: add state change code also for constraint_core[i]");
 
     if (value > 0) {
-      if(m_stateCurrent == SURF_RESOURCE_OFF)
+      if(getState() == SURF_RESOURCE_OFF)
         xbt_dynar_push_as(host_that_restart, char*, (char *)getName());
-      m_stateCurrent = SURF_RESOURCE_ON;
+      setState(SURF_RESOURCE_ON);
     } else {
       lmm_constraint_t cnst = getConstraint();
 
-      m_stateCurrent = SURF_RESOURCE_OFF;
+      setState(SURF_RESOURCE_OFF);
 
       while ((var = lmm_get_var_from_cnst(surf_cpu_model_pm->getMaxminSystem(), cnst, &elem))) {
         ActionPtr action = static_cast<ActionPtr>(lmm_variable_id(var));
@@ -286,7 +286,7 @@ CpuActionPtr CpuCas01::execute(double size)
 {
 
   XBT_IN("(%s,%g)", getName(), size);
-  CpuCas01ActionPtr action = new CpuCas01Action(surf_cpu_model_pm, size, m_stateCurrent != SURF_RESOURCE_ON,
+  CpuCas01ActionPtr action = new CpuCas01Action(surf_cpu_model_pm, size, getState() != SURF_RESOURCE_ON,
                                                              m_powerScale * m_powerPeak, getConstraint());
 
   XBT_OUT();
@@ -299,7 +299,7 @@ CpuActionPtr CpuCas01::sleep(double duration)
     duration = MAX(duration, MAXMIN_PRECISION);
 
   XBT_IN("(%s,%g)", getName(), duration);
-  CpuCas01ActionPtr action = new CpuCas01Action(surf_cpu_model_pm, 1.0, m_stateCurrent != SURF_RESOURCE_ON,
+  CpuCas01ActionPtr action = new CpuCas01Action(surf_cpu_model_pm, 1.0, getState() != SURF_RESOURCE_ON,
                                                       m_powerScale * m_powerPeak, getConstraint());
 
 
index a55374b..cd3173e 100644 (file)
@@ -16,9 +16,11 @@ CpuPtr getActionCpu(CpuActionPtr action) {
                                         (action->getModel()->getMaxminSystem(),
                                         action->getVariable(), 0)));
 }
-surf_callback(void, CpuPtr) createCpuCallbacks;
-surf_callback(void, CpuPtr) deleteCpuCallbacks;
-surf_callback(void, CpuActionPtr) updateCpuActionCallbacks;
+
+surf_callback(void, CpuPtr) cpuCreatedCallbacks;
+surf_callback(void, CpuPtr) cpuDestructedCallbacks;
+surf_callback(void, CpuPtr) cpuStateChangedCallbacks;
+surf_callback(void, CpuActionPtr) cpuActionStateChangedCallbacks;
 
 /*********
  * Model *
@@ -44,8 +46,6 @@ void CpuModel::updateActionsStateLazy(double now, double /*delta*/)
     action->finish();
     XBT_CDEBUG(surf_kernel, "Action %p finished", action);
 
-    surf_callback_emit(updateCpuActionCallbacks, action);
-
     /* set the remains to 0 due to precision problems when updating the remaining amount */
     action->setRemains(0);
     action->setState(SURF_ACTION_DONE);
@@ -115,8 +115,6 @@ void CpuModel::updateActionsStateFull(double now, double delta)
       action->finish();
       action->setState(SURF_ACTION_DONE);
     }
-    surf_callback_emit(updateCpuActionCallbacks, action);
-    //action->updateEnergy();
   }
 
   return;
@@ -127,7 +125,7 @@ void CpuModel::updateActionsStateFull(double now, double delta)
  ************/
 
 Cpu::Cpu(){
-  surf_callback_emit(createCpuCallbacks, this);
+  surf_callback_emit(cpuCreatedCallbacks, this);
 }
 
 Cpu::Cpu(ModelPtr model, const char *name, xbt_dict_t props,
@@ -139,7 +137,7 @@ Cpu::Cpu(ModelPtr model, const char *name, xbt_dict_t props,
  , p_constraintCore(NULL)
  , p_constraintCoreId(NULL)
 {
-  surf_callback_emit(createCpuCallbacks, this);
+  surf_callback_emit(cpuCreatedCallbacks, this);
 }
 
 Cpu::Cpu(ModelPtr model, const char *name, xbt_dict_t props,
@@ -149,7 +147,7 @@ Cpu::Cpu(ModelPtr model, const char *name, xbt_dict_t props,
  , m_powerPeak(powerPeak)
  , m_powerScale(powerScale)
 {
-  surf_callback_emit(createCpuCallbacks, this);
+  surf_callback_emit(cpuCreatedCallbacks, this);
   /* At now, we assume that a VM does not have a multicore CPU. */
   if (core > 1)
     xbt_assert(model == surf_cpu_model_pm);
@@ -170,7 +168,7 @@ Cpu::Cpu(ModelPtr model, const char *name, xbt_dict_t props,
 }
 
 Cpu::~Cpu(){
-  surf_callback_emit(deleteCpuCallbacks, this);
+  surf_callback_emit(cpuDestructedCallbacks, this);
   if (p_constraintCoreId){
     for (int i = 0; i < m_core; i++) {
          xbt_free(p_constraintCoreId[i]);
@@ -197,6 +195,11 @@ int Cpu::getCore()
   return m_core;
 }
 
+void Cpu::setState(e_surf_resource_state_t state)
+{
+  Resource::setState(state);
+  surf_callback_emit(cpuStateChangedCallbacks, this);
+}
 /**********
  * Action *
  **********/
@@ -307,6 +310,10 @@ void CpuAction::setAffinity(CpuPtr cpu, unsigned long mask)
   if (cpu->getModel()->getUpdateMechanism() == UM_LAZY) {
     /* FIXME (hypervisor): Do we need to do something for the LAZY mode? */
   }
-
   XBT_OUT();
 }
+
+void CpuAction::setState(e_surf_action_state_t state){
+  Action::setState(state);
+  surf_callback_emit(cpuActionStateChangedCallbacks, this);
+}
index 7e2c9cd..1178388 100644 (file)
@@ -34,19 +34,25 @@ CpuPtr getActionCpu(CpuActionPtr action);
  * @brief Callbacks handler which emit the callbacks after Cpu creation * 
  * @detail Callback functions have the following signature: `void(CpuPtr)`
  */
-extern surf_callback(void, CpuPtr) createCpuCallbacks;
+extern surf_callback(void, CpuPtr) cpuCreatedCallbacks;
 
 /** @ingroup SURF_callbacks
  * @brief Callbacks handler which emit the callbacks after Cpu destruction * 
  * @detail Callback functions have the following signature: `void(CpuPtr)`
  */
-extern surf_callback(void, CpuPtr) deleteCpuCallbacks;
+extern surf_callback(void, CpuPtr) cpuDestructedCallbacks;
 
 /** @ingroup SURF_callbacks
- * @brief Callbacks handler which emit the callbacks after CpuAction update * 
+ * @brief Callbacks handler which emit the callbacks after Cpu State changed * 
  * @detail Callback functions have the following signature: `void(CpuActionPtr)`
  */
-extern surf_callback(void, CpuActionPtr) updateCpuActionCallbacks;
+extern surf_callback(void, CpuPtr) cpuStateChangedCallbacks;
+
+/** @ingroup SURF_callbacks
+ * @brief Callbacks handler which emit the callbacks after CpuAction State changed * 
+ * @detail Callback functions have the following signature: `void(CpuActionPtr)`
+ */
+extern surf_callback(void, CpuActionPtr) cpuActionStateChangedCallbacks;
 
 /*********
  * Model *
@@ -74,6 +80,7 @@ public:
    */
   CpuPtr createResource(string name);
 
+  void setState(e_surf_resource_state_t state);
 
   void updateActionsStateLazy(double now, double delta);
   void updateActionsStateFull(double now, double delta);
@@ -124,7 +131,7 @@ public:
          int core, double powerPeak, double powerScale);
 
   /**
-   * @brieaf Cpu destructor
+   * @brief Cpu destructor
    */
   ~Cpu();
 
@@ -183,6 +190,8 @@ public:
   
   virtual void setPowerPeakAt(int pstate_index)=0;
 
+  void setState(e_surf_resource_state_t state);
+
   void addTraces(void);
   int m_core;
   double m_powerPeak;            /*< CPU power peak */
@@ -247,6 +256,8 @@ public:
    */
   virtual void setBound(double bound);
 
+  void setState(e_surf_action_state_t state);
+
   void updateRemainingLazy(double now);
   double m_bound;
 };
index 1b3cec3..c1c35e5 100644 (file)
@@ -567,7 +567,7 @@ CpuTi::CpuTi(CpuTiModelPtr model, const char *name, xbt_dynar_t powerPeak,
 : Cpu(model, name, properties, core, 0, powerScale)
 {
   p_powerEvent = NULL;
-  m_stateCurrent = stateInitial;
+  setState(stateInitial);
   m_powerScale = powerScale;
   m_core = core;
   tmgr_trace_t empty_trace;            
@@ -643,11 +643,11 @@ void CpuTi::updateState(tmgr_trace_event_t event_type,
 
   } else if (event_type == p_stateEvent) {
     if (value > 0) {
-      if(m_stateCurrent == SURF_RESOURCE_OFF)
+      if(getState() == SURF_RESOURCE_OFF)
         xbt_dynar_push_as(host_that_restart, char*, (char *)getName());
-      m_stateCurrent = SURF_RESOURCE_ON;
+      setState(SURF_RESOURCE_ON);
     } else {
-      m_stateCurrent = SURF_RESOURCE_OFF;
+      setState(SURF_RESOURCE_OFF);
 
       /* put all action running on cpu to failed */
       xbt_swag_foreach(_action, p_actionSet) {
@@ -822,7 +822,7 @@ void CpuTi::updateRemainingAmount(double now)
 CpuActionPtr CpuTi::execute(double size)
 {
   XBT_IN("(%s,%g)", getName(), size);
-  CpuTiActionPtr action = new CpuTiAction(static_cast<CpuTiModelPtr>(getModel()), size, m_stateCurrent != SURF_RESOURCE_ON, this);
+  CpuTiActionPtr action = new CpuTiAction(static_cast<CpuTiModelPtr>(getModel()), size, getState() != SURF_RESOURCE_ON, this);
 
   xbt_swag_insert(action, p_actionSet);
 
@@ -837,7 +837,7 @@ CpuActionPtr CpuTi::sleep(double duration)
     duration = MAX(duration, MAXMIN_PRECISION);
 
   XBT_IN("(%s,%g)", getName(), duration);
-  CpuTiActionPtr action = new CpuTiAction(static_cast<CpuTiModelPtr>(getModel()), 1.0, m_stateCurrent != SURF_RESOURCE_ON, this);
+  CpuTiActionPtr action = new CpuTiAction(static_cast<CpuTiModelPtr>(getModel()), 1.0, getState() != SURF_RESOURCE_ON, this);
 
   action->m_maxDuration = duration;
   action->m_suspended = 2;
index 9479fd3..e34e829 100644 (file)
@@ -497,7 +497,7 @@ NetworkCm02Link::NetworkCm02Link(NetworkCm02ModelPtr model, const char *name, xb
                                   e_surf_link_sharing_policy_t policy)
 : NetworkLink(model, name, props, lmm_constraint_new(system, this, constraint_value), history, state_trace)
 {
-  m_stateCurrent = state_init;
+  setState(state_init);
 
   p_power.scale = 1.0;
   p_power.peak = metric_peak;
@@ -581,13 +581,13 @@ void NetworkCm02Link::updateState(tmgr_trace_event_t event_type,
       p_latEvent = NULL;
   } else if (event_type == p_stateEvent) {
     if (value > 0)
-      m_stateCurrent = SURF_RESOURCE_ON;
+      setState(SURF_RESOURCE_ON);
     else {
       lmm_constraint_t cnst = getConstraint();
       lmm_variable_t var = NULL;
       lmm_element_t elem = NULL;
 
-      m_stateCurrent = SURF_RESOURCE_OFF;
+      setState(SURF_RESOURCE_OFF);
       while ((var = lmm_get_var_from_cnst(getModel()->getMaxminSystem(), cnst, &elem))) {
         ActionPtr action = (ActionPtr) lmm_variable_id(var);
 
index bb53714..5bafd03 100644 (file)
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_network, surf,
                                 "Logging specific to the SURF network module");
 
+/*************
+ * Callbacks *
+ *************/
+
+surf_callback(void, NetworkLinkPtr) networkLinkCreatedCallbacks;
+surf_callback(void, NetworkLinkPtr) networkLinkDestructedCallbacks;
+surf_callback(void, NetworkLinkPtr) networkLinkStateChangedCallbacks;
+surf_callback(void, NetworkActionPtr) networkActionStateChangedCallbacks;
+
+/*********
+ * Model *
+ *********/
+
 NetworkModelPtr surf_network_model = NULL;
 
 xbt_dynar_t NetworkModel::getRoute(RoutingEdgePtr src, RoutingEdgePtr dst)
@@ -34,10 +47,16 @@ double NetworkModel::bandwidthConstraint(double rate, double /*bound*/, double /
   return rate;
 }
 
+/************
+ * Resource *
+ ************/
+
 NetworkLink::NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t props)
 : Resource(model, name, props)
 , p_latEvent(NULL)
-{}
+{
+  surf_callback_emit(networkLinkCreatedCallbacks, this);
+}
 
 NetworkLink::NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t props,
                                 lmm_constraint_t constraint,
@@ -46,10 +65,16 @@ NetworkLink::NetworkLink(NetworkModelPtr model, const char *name, xbt_dict_t pro
 : Resource(model, name, props, constraint),
   p_latEvent(NULL)
 {
+  surf_callback_emit(networkLinkCreatedCallbacks, this);
   if (state_trace)
     p_stateEvent = tmgr_history_add_trace(history, state_trace, 0.0, 0, static_cast<ResourcePtr>(this));
 }
 
+NetworkLink::~NetworkLink()
+{
+  surf_callback_emit(networkLinkDestructedCallbacks, this);
+}
+
 bool NetworkLink::isUsed()
 {
   return lmm_constraint_used(getModel()->getMaxminSystem(), getConstraint());
@@ -70,4 +95,18 @@ bool NetworkLink::isShared()
   return lmm_constraint_is_shared(getConstraint());
 }
 
+void NetworkLink::setState(e_surf_resource_state_t state){
+  Resource::setState(state);
+  surf_callback_emit(networkLinkStateChangedCallbacks, this);
+}
+
+/**********
+ * Action *
+ **********/
+
+void NetworkAction::setState(e_surf_action_state_t state){
+  Action::setState(state);
+  surf_callback_emit(networkActionStateChangedCallbacks, this);
+}
+
 #endif /* NETWORK_INTERFACE_CPP_ */
index b9425d2..9a68045 100644 (file)
@@ -22,6 +22,34 @@ typedef NetworkLink *NetworkLinkPtr;
 class NetworkAction;
 typedef NetworkAction *NetworkActionPtr;
 
+/*************
+ * Callbacks *
+ *************/
+
+/** @ingroup SURF_callbacks
+ * @brief Callbacks handler which emit the callbacks after NetworkLink creation *
+ * @detail Callback functions have the following signature: `void(NetworkLinkPtr)`
+ */
+extern surf_callback(void, NetworkLinkPtr) networkLinkCreatedCallbacks;
+
+/** @ingroup SURF_callbacks
+ * @brief Callbacks handler which emit the callbacks after NetworkLink destruction *
+ * @detail Callback functions have the following signature: `void(NetworkLinkPtr)`
+ */
+extern surf_callback(void, NetworkLinkPtr) networkLinkDestructedCallbacks;
+
+/** @ingroup SURF_callbacks
+ * @brief Callbacks handler which emit the callbacks after NetworkLink State changed *
+ * @detail Callback functions have the following signature: `void(NetworkLinkActionPtr)`
+ */
+extern surf_callback(void, NetworkLinkPtr) networkLinkStateChangedCallbacks;
+
+/** @ingroup SURF_callbacks
+ * @brief Callbacks handler which emit the callbacks after NetworkAction State changed *
+ * @detail Callback functions have the following signature: `void(NetworkActionPtr)`
+ */
+extern surf_callback(void, NetworkActionPtr) networkActionStateChangedCallbacks;
+
 /*********
  * Tools *
  *********/
@@ -187,6 +215,11 @@ public:
                  tmgr_history_t history,
                  tmgr_trace_t state_trace);
 
+  /**
+   * @brief NetworkLink destructor
+   */
+  ~NetworkLink();
+
   /**
    * @brief Get the bandwidth in bytes per second of current NetworkLink
    * 
@@ -216,6 +249,8 @@ public:
    */
   bool isUsed();
 
+  void setState(e_surf_resource_state_t state);
+
   /* Using this object with the public part of
     model does not make sense */
   double m_latCurrent;
@@ -256,6 +291,8 @@ public:
   NetworkAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
   : Action(model, cost, failed, var) {};
 
+  void setState(e_surf_action_state_t state);
+
   double m_latency;
   double m_latCurrent;
   double m_weight;
index 8719d9c..63d5ffb 100644 (file)
@@ -19,11 +19,11 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_energy, surf,
 
 std::map<CpuPtr, CpuEnergyPtr> *surf_energy=NULL;
 
-static void createCpuCallback(CpuPtr cpu){
+static void energyCpuCreatedCallback(CpuPtr cpu){
   (*surf_energy)[cpu] = new CpuEnergy(cpu);
 }
 
-static void deleteCpuCallback(CpuPtr cpu){
+static void energyCpuDestructedCallback(CpuPtr cpu){
   std::map<CpuPtr, CpuEnergyPtr>::iterator cpuIt = surf_energy->find(cpu);
   xbt_assert(cpuIt != surf_energy->end(), "The cpu is not in surf_energy.");
   XBT_INFO("Total energy (Joules) of host %s: %f", cpu->getName(), cpuIt->second->getConsumedEnergy());
@@ -31,7 +31,7 @@ static void deleteCpuCallback(CpuPtr cpu){
   surf_energy->erase(cpuIt);
 }
 
-static void updateActionEnergyCallback(CpuActionPtr action){
+static void energyCpuActionStateChangedCallback(CpuActionPtr action){
   CpuPtr cpu  = getActionCpu(action);
   CpuEnergyPtr cpu_energy = (*surf_energy)[cpu];
 
@@ -61,9 +61,10 @@ static void updateActionEnergyCallback(CpuActionPtr action){
 void sg_energy_plugin_init() {
   if (surf_energy == NULL) {
     surf_energy = new std::map<CpuPtr, CpuEnergyPtr>();
-    surf_callback_connect(createCpuCallbacks, createCpuCallback);
-    surf_callback_connect(deleteCpuCallbacks, deleteCpuCallback);
-    surf_callback_connect(updateCpuActionCallbacks, updateActionEnergyCallback);
+    surf_callback_connect(cpuCreatedCallbacks, energyCpuCreatedCallback);
+    surf_callback_connect(cpuDestructedCallbacks, energyCpuDestructedCallback);
+    surf_callback_connect(cpuActionStateChangedCallbacks, energyCpuActionStateChangedCallback);
+
   }
 }
 
index 4869a5c..a579a6b 100644 (file)
@@ -14,6 +14,15 @@ int ROUTING_STORAGE_TYPE_LEVEL; //Routing for storage_type level
 xbt_dynar_t mount_list = NULL;
 StorageModelPtr surf_storage_model = NULL;
 
+/*************
+ * Callbacks *
+ *************/
+
+surf_callback(void, StoragePtr) storageCreatedCallbacks;
+surf_callback(void, StoragePtr) storageDestructedCallbacks;
+surf_callback(void, StoragePtr) storageStateChangedCallbacks;
+surf_callback(void, StorageActionPtr) storageActionStateChangedCallbacks;
+
 /*********
  * Model *
  *********/
@@ -42,8 +51,9 @@ Storage::Storage(ModelPtr model, const char *name, xbt_dict_t props,
  , p_typeId(xbt_strdup(type_id))
  , p_writeActions(xbt_dynar_new(sizeof(ActionPtr),NULL))
 {
+  surf_callback_emit(storageCreatedCallbacks, this);
   p_content = parseContent(content_name);
-  m_stateCurrent = SURF_RESOURCE_ON;
+  setState(SURF_RESOURCE_ON);
 }
 
 Storage::Storage(ModelPtr model, const char *name, xbt_dict_t props,
@@ -54,14 +64,16 @@ Storage::Storage(ModelPtr model, const char *name, xbt_dict_t props,
  , m_size(size), m_usedSize(0)
  , p_typeId(xbt_strdup(type_id))
  , p_writeActions(xbt_dynar_new(sizeof(ActionPtr),NULL)) {
+  surf_callback_emit(storageCreatedCallbacks, this);
   p_content = parseContent(content_name);
-  m_stateCurrent = SURF_RESOURCE_ON;
+  setState(SURF_RESOURCE_ON);
   XBT_DEBUG("Create resource with Bconnection '%f' Bread '%f' Bwrite '%f' and Size '%llu'", bconnection, bread, bwrite, size);
   p_constraintRead  = lmm_constraint_new(maxminSystem, this, bread);
   p_constraintWrite = lmm_constraint_new(maxminSystem, this, bwrite);
 }
 
 Storage::~Storage(){
+  surf_callback_emit(storageDestructedCallbacks, this);
   xbt_dict_free(&p_content);
   xbt_dynar_free(&p_writeActions);
   free(p_typeId);
@@ -116,6 +128,12 @@ void Storage::updateState(tmgr_trace_event_t /*event_type*/, double /*value*/, d
   THROW_UNIMPLEMENTED;
 }
 
+void Storage::setState(e_surf_resource_state_t state)
+{
+  Resource::setState(state);
+  surf_callback_emit(storageStateChangedCallbacks, this);
+}
+
 xbt_dict_t Storage::getContent()
 {
   /* For the moment this action has no cost, but in the future we could take in account access latency of the disk */
@@ -136,8 +154,6 @@ sg_size_t Storage::getSize(){
   return m_size;
 }
 
-
-
 /**********
  * Action *
  **********/
@@ -154,3 +170,7 @@ StorageAction::StorageAction(ModelPtr model, double cost, bool failed, lmm_varia
   , m_type(type), p_storage(storage), p_file(NULL), p_lsDict(NULL) {
 }
 
+void StorageAction::setState(e_surf_action_state_t state){
+  Action::setState(state);
+  surf_callback_emit(storageActionStateChangedCallbacks, this);
+}
index c606e11..d8d4e18 100644 (file)
@@ -30,6 +30,34 @@ typedef StorageAction *StorageActionPtr;
 class StorageAction;
 typedef StorageAction *StorageActionPtr;
 
+/*************
+ * Callbacks *
+ *************/
+
+/** @ingroup SURF_callbacks
+ * @brief Callbacks handler which emit the callbacks after Storage creation *
+ * @detail Callback functions have the following signature: `void(StoragePtr)`
+ */
+extern surf_callback(void, StoragePtr) storageCreatedCallbacks;
+
+/** @ingroup SURF_callbacks
+ * @brief Callbacks handler which emit the callbacks after Storage destruction *
+ * @detail Callback functions have the following signature: `void(StoragePtr)`
+ */
+extern surf_callback(void, StoragePtr) storageDestructedCallbacks;
+
+/** @ingroup SURF_callbacks
+ * @brief Callbacks handler which emit the callbacks after Storage State changed *
+ * @detail Callback functions have the following signature: `void(StorageActionPtr)`
+ */
+extern surf_callback(void, StoragePtr) storageStateChangedCallbacks;
+
+/** @ingroup SURF_callbacks
+ * @brief Callbacks handler which emit the callbacks after StorageAction State changed *
+ * @detail Callback functions have the following signature: `void(StorageActionPtr)`
+ */
+extern surf_callback(void, StorageActionPtr) storageActionStateChangedCallbacks;
+
 /*********
  * Model *
  *********/
@@ -133,6 +161,8 @@ public:
    */
   void updateState(tmgr_trace_event_t event_type, double value, double date);
 
+  void setState(e_surf_resource_state_t state);
+
   xbt_dict_t p_content;
   char* p_contentType;
   sg_size_t m_size;
@@ -265,6 +295,8 @@ public:
   StorageAction(ModelPtr model, double cost, bool failed, lmm_variable_t var,
                            StoragePtr storage, e_surf_action_storage_type_t type);
 
+  void setState(e_surf_action_state_t state);
+
   e_surf_action_storage_type_t m_type;
   StoragePtr p_storage;
   surf_file_t p_file;
index aed2695..5173ed8 100644 (file)
@@ -357,7 +357,7 @@ StorageN11::StorageN11(StorageModelPtr model, const char* name, xbt_dict_t prope
 
 StorageActionPtr StorageN11::ls(const char* path)
 {
-  StorageActionPtr action = new StorageN11Action(getModel(), 0, m_stateCurrent != SURF_RESOURCE_ON, this, LS);
+  StorageActionPtr action = new StorageN11Action(getModel(), 0, getState() != SURF_RESOURCE_ON, this, LS);
 
   action->p_lsDict = NULL;
   xbt_dict_t ls_dict = xbt_dict_new_homogeneous(xbt_free);
@@ -421,7 +421,7 @@ StorageActionPtr StorageN11::open(const char* mount, const char* path)
   file->mount = xbt_strdup(mount);
   file->current_position = 0;
 
-  StorageActionPtr action = new StorageN11Action(getModel(), 0, m_stateCurrent != SURF_RESOURCE_ON, this, OPEN);
+  StorageActionPtr action = new StorageN11Action(getModel(), 0, getState() != SURF_RESOURCE_ON, this, OPEN);
   action->p_file = file;
   return action;
 }
@@ -444,7 +444,7 @@ StorageActionPtr StorageN11::close(surf_file_t fd)
   free(fd->name);
   free(fd->mount);
   xbt_free(fd);
-  StorageActionPtr action = new StorageN11Action(getModel(), 0, m_stateCurrent != SURF_RESOURCE_ON, this, CLOSE);
+  StorageActionPtr action = new StorageN11Action(getModel(), 0, getState() != SURF_RESOURCE_ON, this, CLOSE);
   return action;
 }
 
@@ -457,7 +457,7 @@ StorageActionPtr StorageN11::read(surf_file_t fd, sg_size_t size)
   else
        fd->current_position += size;
 
-  StorageActionPtr action = new StorageN11Action(getModel(), size, m_stateCurrent != SURF_RESOURCE_ON, this, READ);
+  StorageActionPtr action = new StorageN11Action(getModel(), size, getState() != SURF_RESOURCE_ON, this, READ);
   return action;
 }
 
@@ -466,7 +466,7 @@ StorageActionPtr StorageN11::write(surf_file_t fd, sg_size_t size)
   char *filename = fd->name;
   XBT_DEBUG("\tWrite file '%s' size '%llu/%llu'",filename,size,fd->size);
 
-  StorageActionPtr action = new StorageN11Action(getModel(), size, m_stateCurrent != SURF_RESOURCE_ON, this, WRITE);
+  StorageActionPtr action = new StorageN11Action(getModel(), size, getState() != SURF_RESOURCE_ON, this, WRITE);
   action->p_file = fd;
   fd->current_position += size;
   // If the storage is full
index 06ae981..ffceddc 100644 (file)
@@ -360,15 +360,13 @@ public:
    */
   virtual void setState(e_surf_resource_state_t state);
 
-protected:
-  e_surf_resource_state_t m_stateCurrent;
-
 private:
   const char *p_name;
   xbt_dict_t p_properties;
   ModelPtr p_model;
   void *p_resource;
   bool m_running;
+  e_surf_resource_state_t m_stateCurrent;
 
   /* LMM */
 public:
@@ -439,7 +437,7 @@ public:
    * 
    * @param state The new state of the current Action
    */
-  virtual void setState(e_surf_action_state_t state); /**< Change state*/
+  virtual void setState(e_surf_action_state_t state);
 
   /**
    * @brief Get the bound of the current Action
index 7a24d2d..f331ea2 100644 (file)
@@ -12,6 +12,14 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm_workstation, surf,
 
 WorkstationVMModelPtr surf_vm_workstation_model = NULL;
 
+/*************
+ * Callbacks *
+ *************/
+
+surf_callback(void, WorkstationVMPtr) workstationVMCreatedCallbacks;
+surf_callback(void, WorkstationVMPtr) workstationVMDestructedCallbacks;
+surf_callback(void, WorkstationVMPtr) workstationVMStateChangedCallbacks;
+
 /*********
  * Model *
  *********/
@@ -24,12 +32,25 @@ WorkstationVMModel::WorkstationVMModel() : WorkstationModel("Virtual Workstation
  * Resource *
  ************/
 
+WorkstationVM::WorkstationVM(ModelPtr model, const char *name, xbt_dict_t props,
+                       RoutingEdgePtr netElm, CpuPtr cpu)
+: Workstation(model, name, props, NULL, netElm, cpu)
+{
+  surf_callback_emit(workstationVMCreatedCallbacks, this);
+}
+
 /*
  * A physical host does not disapper in the current SimGrid code, but a VM may
  * disapper during a simulation.
  */
 WorkstationVM::~WorkstationVM()
 {
+  surf_callback_emit(workstationVMDestructedCallbacks, this);
+}
+
+void WorkstationVM::setState(e_surf_resource_state_t state){
+  Resource::setState(state);
+  surf_callback_emit(workstationVMStateChangedCallbacks, this);
 }
 
 /*
index ec334ac..20b1700 100644 (file)
@@ -27,6 +27,28 @@ typedef WorkstationVM *WorkstationVMPtr;
 class WorkstationVMLmm;
 typedef WorkstationVMLmm *WorkstationVMLmmPtr;
 
+/*************
+ * Callbacks *
+ *************/
+
+/** @ingroup SURF_callbacks
+ * @brief Callbacks handler which emit the callbacks after WorkstationVM creation *
+ * @detail Callback functions have the following signature: `void(WorkstationVMPtr)`
+ */
+extern surf_callback(void, WorkstationVMPtr) workstationVMCreatedCallbacks;
+
+/** @ingroup SURF_callbacks
+ * @brief Callbacks handler which emit the callbacks after WorkstationVM destruction *
+ * @detail Callback functions have the following signature: `void(WorkstationVMPtr)`
+ */
+extern surf_callback(void, WorkstationVMPtr) workstationVMDestructedCallbacks;
+
+/** @ingroup SURF_callbacks
+ * @brief Callbacks handler which emit the callbacks after WorkstationVM State changed *
+ * @detail Callback functions have the following signature: `void(WorkstationVMActionPtr)`
+ */
+extern surf_callback(void, WorkstationVMPtr) workstationVMStateChangedCallbacks;
+
 /*********
  * Model *
  *********/
@@ -55,7 +77,6 @@ public:
    */
   virtual void createResource(const char *name, void *ind_phys_workstation)=0;
 
-
   void adjustWeightOfDummyCpuActions() {};
 };
 
@@ -79,14 +100,15 @@ public:
    * @param cpu The Cpu associated to this Workstation
    */
   WorkstationVM(ModelPtr model, const char *name, xbt_dict_t props,
-                       RoutingEdgePtr netElm, CpuPtr cpu)
-  : Workstation(model, name, props, NULL, netElm, cpu) {}
+                       RoutingEdgePtr netElm, CpuPtr cpu);
 
   /**
-   * @brief WdorkstationVM estructor
+   * @brief WdorkstationVM destructor
    */
   ~WorkstationVM();
 
+  void setState(e_surf_resource_state_t state);
+
   /**
    * @brief Suspend the VM
    */
index 9af820b..d43fd4a 100644 (file)
@@ -8,6 +8,15 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
 
 WorkstationModelPtr surf_workstation_model = NULL;
 
+/*************
+ * Callbacks *
+ *************/
+
+surf_callback(void, WorkstationPtr) workstationCreatedCallbacks;
+surf_callback(void, WorkstationPtr) workstationDestructedCallbacks;
+surf_callback(void, WorkstationPtr) workstationStateChangedCallbacks;
+surf_callback(void, WorkstationActionPtr) workstationActionStateChangedCallbacks;
+
 /*********
  * Model *
  *********/
@@ -25,8 +34,6 @@ WorkstationModel::WorkstationModel()
 WorkstationModel::~WorkstationModel() {
 }
 
-
-
 /* Each VM has a dummy CPU action on the PM layer. This CPU action works as the
  * constraint (capacity) of the VM in the PM layer. If the VM does not have any
  * active task, the dummy CPU action must be deactivated, so that the VM does
@@ -79,17 +86,35 @@ void WorkstationModel::adjustWeightOfDummyCpuActions()
 /************
  * Resource *
  ************/
+Workstation::Workstation()
+{
+  surf_callback_emit(workstationCreatedCallbacks, this);
+}
+
 Workstation::Workstation(ModelPtr model, const char *name, xbt_dict_t props,
                                 xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu)
  : Resource(model, name, props)
  , p_storage(storage), p_netElm(netElm), p_cpu(cpu)
-{}
+{
+  surf_callback_emit(workstationCreatedCallbacks, this);
+}
 
 Workstation::Workstation(ModelPtr model, const char *name, xbt_dict_t props, lmm_constraint_t constraint,
                                         xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu)
  : Resource(model, name, props, constraint)
  , p_storage(storage), p_netElm(netElm), p_cpu(cpu)
-{}
+{
+  surf_callback_emit(workstationCreatedCallbacks, this);
+}
+
+Workstation::~Workstation(){
+  surf_callback_emit(workstationDestructedCallbacks, this);
+}
+
+void Workstation::setState(e_surf_resource_state_t state){
+  Resource::setState(state);
+  surf_callback_emit(workstationStateChangedCallbacks, this);
+}
 
 int Workstation::getCore(){
   return p_cpu->getCore();
@@ -311,3 +336,8 @@ void Workstation::setParams(ws_params_t params)
 /**********
  * Action *
  **********/
+
+void WorkstationAction::setState(e_surf_action_state_t state){
+  Action::setState(state);
+  surf_callback_emit(workstationActionStateChangedCallbacks, this);
+}
index 5045cec..297cf8f 100644 (file)
@@ -25,6 +25,34 @@ typedef Workstation *WorkstationPtr;
 class WorkstationAction;
 typedef WorkstationAction *WorkstationActionPtr;
 
+/*************
+ * Callbacks *
+ *************/
+
+/** @ingroup SURF_callbacks
+ * @brief Callbacks handler which emit the callbacks after Workstation creation *
+ * @detail Callback functions have the following signature: `void(WorkstationPtr)`
+ */
+extern surf_callback(void, WorkstationPtr) workstationCreatedCallbacks;
+
+/** @ingroup SURF_callbacks
+ * @brief Callbacks handler which emit the callbacks after Workstation destruction *
+ * @detail Callback functions have the following signature: `void(WorkstationPtr)`
+ */
+extern surf_callback(void, WorkstationPtr) workstationDestructedCallbacks;
+
+/** @ingroup SURF_callbacks
+ * @brief Callbacks handler which emit the callbacks after Workstation State changed *
+ * @detail Callback functions have the following signature: `void(WorkstationActionPtr)`
+ */
+extern surf_callback(void, WorkstationPtr) workstationStateChangedCallbacks;
+
+/** @ingroup SURF_callbacks
+ * @brief Callbacks handler which emit the callbacks after WorkstationAction State changed *
+ * @detail Callback functions have the following signature: `void(WorkstationActionPtr)`
+ */
+extern surf_callback(void, WorkstationActionPtr) workstationActionStateChangedCallbacks;
+
 /*********
  * Tools *
  *********/
@@ -116,9 +144,8 @@ class Workstation : public Resource {
 public:
   /**
    * @brief Workstation consrtuctor
-   * @details [long description]
    */
-  Workstation(){};
+  Workstation();
 
   /**
    * @brief Workstation constructor
@@ -147,6 +174,13 @@ public:
   Workstation(ModelPtr model, const char *name, xbt_dict_t props, lmm_constraint_t constraint,
                      xbt_dynar_t storage, RoutingEdgePtr netElm, CpuPtr cpu);
 
+  /**
+   * @brief Workstation destructor
+   */
+  ~ Workstation();
+
+  void setState(e_surf_resource_state_t state);
+
   /**
    * @brief Get the properties of the currenrt Workstation
    *
@@ -399,6 +433,7 @@ public:
   WorkstationAction(ModelPtr model, double cost, bool failed, lmm_variable_t var)
   : Action(model, cost, failed, var) {}
 
+  void setState(e_surf_action_state_t state);
 };
 
 
index 1e26a52..1898fe7 100644 (file)
@@ -438,7 +438,7 @@ CpuL07::CpuL07(CpuL07ModelPtr model, const char* name, xbt_dict_t props,
   if (power_trace)
        p_power.event = tmgr_history_add_trace(history, power_trace, 0.0, 0, static_cast<ResourcePtr>(this));
 
-  m_stateCurrent = state_initial;
+  setState(state_initial);
   if (state_trace)
        p_stateEvent = tmgr_history_add_trace(history, state_trace, 0.0, 0, static_cast<ResourcePtr>(this));
 }
@@ -457,7 +457,7 @@ LinkL07::LinkL07(NetworkL07ModelPtr model, const char* name, xbt_dict_t props,
   if (bw_trace)
     p_bwEvent = tmgr_history_add_trace(history, bw_trace, 0.0, 0, static_cast<ResourcePtr>(this));
 
-  m_stateCurrent = state_initial;
+  setState(state_initial);
   m_latCurrent = lat_initial;
 
   if (lat_trace)
@@ -484,9 +484,9 @@ void CpuL07::updateState(tmgr_trace_event_t event_type, double value, double /*d
       p_power.event = NULL;
   } else if (event_type == p_stateEvent) {
     if (value > 0)
-      m_stateCurrent = SURF_RESOURCE_ON;
+      setState(SURF_RESOURCE_ON);
     else
-      m_stateCurrent = SURF_RESOURCE_OFF;
+      setState(SURF_RESOURCE_OFF);
     if (tmgr_trace_event_free(event_type))
       p_stateEvent = NULL;
   } else {
@@ -517,9 +517,9 @@ void LinkL07::updateState(tmgr_trace_event_t event_type, double value, double da
       p_latEvent = NULL;
   } else if (event_type == p_stateEvent) {
     if (value > 0)
-      m_stateCurrent = SURF_RESOURCE_ON;
+      setState(SURF_RESOURCE_ON);
     else
-      m_stateCurrent = SURF_RESOURCE_OFF;
+      setState(SURF_RESOURCE_OFF);
     if (tmgr_trace_event_free(event_type))
       p_stateEvent = NULL;
   } else {
@@ -534,11 +534,6 @@ e_surf_resource_state_t WorkstationL07::getState()
   return p_cpu->getState();
 }
 
-e_surf_resource_state_t CpuL07::getState()
-{
-  return m_stateCurrent;
-}
-
 double CpuL07::getSpeed(double load)
 {
   return load * p_power.scale;
index 0dcf31e..20dd0b8 100644 (file)
@@ -126,7 +126,6 @@ public:
   bool isUsed();
   //bool isUsed() {DIE_IMPOSSIBLE;};
   void updateState(tmgr_trace_event_t event_type, double value, double date);
-  e_surf_resource_state_t getState();
   double getSpeed(double load);
   double getAvailableSpeed();
   CpuActionPtr execute(double /*size*/) {DIE_IMPOSSIBLE;};