X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/e37f2c1f29ad0e2f8615269dee59bd7f01f96c34..51f8d73fe7373b7b04bc2727ff9ef61272dce9a9:/src/surf/surf.hpp diff --git a/src/surf/surf.hpp b/src/surf/surf.hpp new file mode 100644 index 0000000000..d6c462e5f7 --- /dev/null +++ b/src/surf/surf.hpp @@ -0,0 +1,188 @@ +//using namespace generic; + +#ifndef SURF_MODEL_H_ +#define SURF_MODEL_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "surf/trace_mgr.h" + +extern tmgr_history_t history; + +using namespace std; + +/*********** + * Classes * + ***********/ +class Model; +typedef Model* ModelPtr; + +class Resource; +typedef Resource* ResourcePtr; +typedef boost::function ResourceCallback; + +class Action; +typedef Action* ActionPtr; +typedef boost::function ActionCallback; + +/********* + * Model * + *********/ +class Model { +public: + Model(string name) { + m_name = name; + m_resOnCB = m_resOffCB= 0; + m_actSuspendCB = m_actCancelCB = m_actResumeCB = 0; + } + virtual ~Model() {} + ResourcePtr createResource(string name); + ActionPtr createAction(double _cost, bool _failed); + + string getName() {return m_name;}; + + void addTurnedOnCallback(ResourceCallback rc); + void notifyResourceTurnedOn(ResourcePtr r); + + void addTurnedOffCallback(ResourceCallback rc); + void notifyResourceTurnedOff(ResourcePtr r); + + void addActionCancelCallback(ActionCallback ac); + void notifyActionCancel(ActionPtr a); + void addActionResumeCallback(ActionCallback ac); + void notifyActionResume(ActionPtr a); + void addActionSuspendCallback(ActionCallback ac); + void notifyActionSuspend(ActionPtr a); + + xbt_swag_t p_readyActionSet; /**< Actions in state SURF_ACTION_READY */ + xbt_swag_t runningActionSet; /**< Actions in state SURF_ACTION_RUNNING */ + xbt_swag_t failedActionSet; /**< Actions in state SURF_ACTION_FAILED */ + xbt_swag_t doneActionSet; /**< Actions in state SURF_ACTION_DONE */ + +protected: + std::vector m_failedActions, m_runningActions; + +private: + string m_name; + ResourceCallback m_resOnCB, m_resOffCB; + ActionCallback m_actCancelCB, m_actSuspendCB, m_actResumeCB; +}; + +/************ + * Resource * + ************/ +class Resource { +public: + Resource(ModelPtr model, string name, xbt_dict_t properties): + m_name(name),m_running(true),p_model(model),m_properties(properties) {}; + virtual ~Resource() {}; + + bool isOn(); + void turnOn(); + void turnOff(); + void setName(string name); + string getName(); + ModelPtr getModel() {return p_model;}; + void printModel() { std::cout << p_model->getName() << "<