1 //using namespace generic;
10 #include <boost/smart_ptr.hpp>
11 #include <boost/function.hpp>
12 #include <boost/functional/factory.hpp>
13 #include <boost/bind.hpp>
14 #include "surf/trace_mgr.h"
16 extern tmgr_history_t history;
24 typedef Model* ModelPtr;
27 typedef Resource* ResourcePtr;
28 typedef boost::function<void (ResourcePtr r)> ResourceCallback;
31 typedef Action* ActionPtr;
32 typedef boost::function<void (ActionPtr a)> ActionCallback;
41 m_resOnCB = m_resOffCB= 0;
42 m_actSuspendCB = m_actCancelCB = m_actResumeCB = 0;
45 ResourcePtr createResource(string name);
46 ActionPtr createAction(double _cost, bool _failed);
48 string getName() {return m_name;};
50 void addTurnedOnCallback(ResourceCallback rc);
51 void notifyResourceTurnedOn(ResourcePtr r);
53 void addTurnedOffCallback(ResourceCallback rc);
54 void notifyResourceTurnedOff(ResourcePtr r);
56 void addActionCancelCallback(ActionCallback ac);
57 void notifyActionCancel(ActionPtr a);
58 void addActionResumeCallback(ActionCallback ac);
59 void notifyActionResume(ActionPtr a);
60 void addActionSuspendCallback(ActionCallback ac);
61 void notifyActionSuspend(ActionPtr a);
63 xbt_swag_t p_readyActionSet; /**< Actions in state SURF_ACTION_READY */
64 xbt_swag_t runningActionSet; /**< Actions in state SURF_ACTION_RUNNING */
65 xbt_swag_t failedActionSet; /**< Actions in state SURF_ACTION_FAILED */
66 xbt_swag_t doneActionSet; /**< Actions in state SURF_ACTION_DONE */
69 std::vector<ActionPtr> m_failedActions, m_runningActions;
73 ResourceCallback m_resOnCB, m_resOffCB;
74 ActionCallback m_actCancelCB, m_actSuspendCB, m_actResumeCB;
82 Resource(ModelPtr model, string name, xbt_dict_t properties):
83 m_name(name),m_running(true),p_model(model),m_properties(properties) {};
84 virtual ~Resource() {};
89 void setName(string name);
91 ModelPtr getModel() {return p_model;};
92 void printModel() { std::cout << p_model->getName() << "<<plop"<<std::endl;};
97 xbt_dict_t m_properties;
107 /** \ingroup SURF_actions
108 * \brief Action states
112 * \see surf_action_t, surf_action_state_t
115 SURF_ACTION_READY = 0, /**< Ready */
116 SURF_ACTION_RUNNING, /**< Running */
117 SURF_ACTION_FAILED, /**< Task Failure */
118 SURF_ACTION_DONE, /**< Completed */
119 SURF_ACTION_TO_FREE, /**< Action to free in next cleanup */
120 SURF_ACTION_NOT_IN_THE_SYSTEM
121 /**< Not in the system anymore. Why did you ask ? */
122 } e_surf_action_state_t;
132 Action(ModelPtr model, double cost, bool failed):
133 m_cost(cost),p_model(model),m_failed(failed)
135 m_priority = m_start = m_finish = m_maxDuration = -1.0;
136 m_start = 10;//surf_get_clock();
139 virtual ~Action() {};
141 virtual e_surf_action_state_t getState()=0; /**< Return the state of an action */
142 virtual void setState(e_surf_action_state_t state)=0; /**< Change an action state*/
143 virtual double getStartTime()=0; /**< Return the start time of an action */
144 virtual double getFinishTime()=0; /**< Return the finish time of an action */
145 virtual int unref()=0; /**< Specify that we don't use that action anymore. Returns true if the action was destroyed and false if someone still has references on it. */
146 virtual void cancel()=0; /**< Cancel a running action */
147 virtual void recycle()=0; /**< Recycle an action */
148 void suspend(); /**< Suspend an action */
149 void resume(); /**< Resume a suspended action */
150 bool isSuspended(); /**< Return whether an action is suspended */
151 void setMaxDuration(double duration); /**< Set the max duration of an action*/
152 void setPriority(double priority); /**< Set the priority of an action */
154 void setCategory(const char *category); /**< Set the category of an action */
156 double getRemains(); /**< Get the remains of an action */
157 #ifdef HAVE_LATENCY_BOUND_TRACKING
158 int getLatencyLimited(); /**< Return 1 if action is limited by latency, 0 otherwise */
165 bool m_failed, m_suspended;
167 double m_maxDuration;
168 double m_start, m_finish;
171 int resourceUsed(void *resource_id);
172 /* Share the resources to the actions and return in how much time
173 the next action may terminate */
174 double shareResources(double now);
175 /* Update the actions' state */
176 void updateActionsState(double now, double delta);
177 void updateResourceState(void *id, tmgr_trace_event_t event_type,
178 double value, double time);
181 lmm_system_t p_maxminSystem;
182 e_UM_t p_updateMechanism;
183 xbt_swag_t p_modifiedSet;
184 xbt_heap_t p_actionHeap;
185 int m_selectiveUpdate;
188 #endif /* SURF_MODEL_H_ */