Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
make sure that simgrid/s4u/forward.hpp is loaded from only one file
[simgrid.git] / include / simgrid / s4u / Activity.hpp
1 /* Copyright (c) 2006-2018. 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/forward.h>
10
11 namespace simgrid {
12 namespace s4u {
13
14 /** @brief Activities
15  *
16  * This class is the ancestor of every activities that an actor can undertake.
17  * That is, of the actions that do take time in the simulated world.
18  */
19 class XBT_PUBLIC Activity {
20   friend Comm;
21   friend XBT_PUBLIC void intrusive_ptr_release(Comm * c);
22   friend XBT_PUBLIC void intrusive_ptr_add_ref(Comm * c);
23   friend Exec;
24   friend XBT_PUBLIC void intrusive_ptr_release(Exec * e);
25   friend XBT_PUBLIC void intrusive_ptr_add_ref(Exec * e);
26
27 protected:
28   Activity()  = default;
29   virtual ~Activity() = default;
30
31 public:
32   Activity(Activity const&) = delete;
33   Activity& operator=(Activity const&) = delete;
34
35   enum class State { inited = 0, started, canceled, errored, finished };
36
37   /** Starts a previously created activity.
38    *
39    * This function is optional: you can call wait() even if you didn't call start()
40    */
41   virtual Activity* start() = 0;
42   /** Tests whether the given activity is terminated yet. This is a pure function. */
43   //virtual bool test()=0;
44   /** Blocks until the activity is terminated */
45   virtual Activity* wait() = 0;
46   /** Blocks until the activity is terminated, or until the timeout is elapsed
47    *  Raises: timeout exception.*/
48   virtual Activity* wait(double timeout) = 0;
49   /** Cancel that activity */
50   //virtual void cancel();
51   /** Retrieve the current state of the activity */
52   Activity::State get_state() { return state_; }
53
54   /** Get the remaining amount of work that this Activity entails. When it's 0, it's done. */
55   virtual double get_remaining();
56
57   /** Set the [remaining] amount of work that this Activity will entail
58    *
59    * It is forbidden to change the amount of work once the Activity is started */
60   Activity* set_remaining(double remains);
61
62   /** Put some user data onto the Activity */
63   Activity* set_user_data(void* data)
64   {
65     user_data_ = data;
66     return this;
67   }
68   /** Retrieve the user data of the Activity */
69   void* get_user_data() { return user_data_; }
70
71   XBT_ATTRIB_DEPRECATED_v323("Please use Activity::get_state()") Activity::State getState() { return state_; }
72   XBT_ATTRIB_DEPRECATED_v323("Please use Activity::get_remaining()") double getRemains() { return get_remaining(); }
73   XBT_ATTRIB_DEPRECATED_v323("Please use Activity::set_remaining()") Activity* setRemains(double remains)
74   {
75     return set_remaining(remains);
76   }
77   XBT_ATTRIB_DEPRECATED_v323("Please use Activity::set_user_data()") Activity* setUserData(void* data)
78   {
79     return set_user_data(data);
80   }
81   XBT_ATTRIB_DEPRECATED_v323("Please use Activity::get_user_data()") void* getUserData() { return user_data_; }
82
83 private:
84   simgrid::kernel::activity::ActivityImplPtr pimpl_ = nullptr;
85   Activity::State state_                            = Activity::State::inited;
86   double remains_ = 0;
87   void* user_data_                                  = nullptr;
88 }; // class
89
90 }}; // Namespace simgrid::s4u
91
92 #endif /* SIMGRID_S4U_ACTIVITY_HPP */