Logo AND Algorithmique Numérique Distribuée

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