Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #188 from Takishipp/clean_events
[simgrid.git] / include / simgrid / s4u / Activity.hpp
1 /* Copyright (c) 2006-2017. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SIMGRID_S4U_ACTIVITY_HPP
7 #define SIMGRID_S4U_ACTIVITY_HPP
8
9 #include <simgrid/s4u/forward.hpp>
10 #include <simgrid/forward.h>
11
12 typedef enum { inited = 0, started, canceled, errored, finished } e_s4u_activity_state_t;
13
14 namespace simgrid {
15 namespace s4u {
16
17 /** @brief Activities
18  *
19  * This class is the ancestor of every activities that an actor can undertake, that is, of the actions that do take time in the simulated world.
20  */
21 XBT_PUBLIC_CLASS Activity {
22   friend Comm;
23   friend void intrusive_ptr_release(Comm * c);
24   friend void intrusive_ptr_add_ref(Comm * c);
25
26 protected:
27   Activity()  = default;
28   ~Activity() = default;
29
30 public:
31   Activity(Activity const&) = delete;
32   Activity& operator=(Activity const&) = delete;
33
34   /** Starts a previously created activity.
35    *
36    * This function is optional: you can call wait() even if you didn't call start()
37    */
38   virtual void start()=0;
39   /** Tests whether the given activity is terminated yet. This is a pure function. */
40   //virtual bool test()=0;
41   /** Blocks until the activity is terminated */
42   virtual void wait()=0;
43   /** Blocks until the activity is terminated, or until the timeout is elapsed
44    *  Raises: timeout exception.*/
45   virtual void wait(double timeout)=0;
46   /** Cancel that activity */
47   //virtual void cancel();
48   /** Retrieve the current state of the activity */
49   e_s4u_activity_state_t getState() {return state_;}
50
51   /** Get the remaining amount of work that this Activity entails. When it's 0, it's done. */
52   double getRemains();
53   /** Set the [remaining] amount of work that this Activity will entail
54    *
55    * It is forbidden to change the amount of work once the Activity is started */
56   void setRemains(double remains);
57
58   /** Put some user data onto the Activity */
59   void setUserData(void *data) {userData_=data;}
60   /** Retrieve the user data of the Activity */
61   void *getUserData() { return userData_; }
62
63 private:
64   simgrid::kernel::activity::ActivityImplPtr pimpl_ = nullptr;
65   e_s4u_activity_state_t state_ = inited;
66   double remains_ = 0;
67   void *userData_ = nullptr;
68 }; // class
69
70 }}; // Namespace simgrid::s4u
71
72 #endif /* SIMGRID_S4U_ACTIVITY_HPP */