Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
improve doxygen comments in s4u
[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, activities are all the things that do take time to the actor in the simulated world.
18  *
19  * They are somewhat linked but not identical to simgrid::kernel::resource::Action,
20  * that are stuff occurring on a resource:
21  *
22  * - A sequential execution activity encompasses 2 actions: one for the exec itself,
23  *   and a time-limited sleep used as timeout detector.
24  * - A point-to-point communication activity encompasses 3 actions: one for the comm itself
25  *   (which spans on all links of the path), and one infinite sleep used as failure detector
26  *   on both sender and receiver hosts.
27  * - Synchronization activities may possibly be connected to no action.
28  */
29 class XBT_PUBLIC Activity {
30 #ifndef DOXYGEN
31   friend Comm;
32   friend XBT_PUBLIC void intrusive_ptr_release(Comm * c);
33   friend XBT_PUBLIC void intrusive_ptr_add_ref(Comm * c);
34   friend Exec;
35   friend XBT_PUBLIC void intrusive_ptr_release(Exec * e);
36   friend XBT_PUBLIC void intrusive_ptr_add_ref(Exec * e);
37   friend Io;
38   friend XBT_PUBLIC void intrusive_ptr_release(Io* i);
39   friend XBT_PUBLIC void intrusive_ptr_add_ref(Io* i);
40 #endif
41
42 protected:
43   Activity()  = default;
44   virtual ~Activity() = default;
45
46 public:
47   Activity(Activity const&) = delete;
48   Activity& operator=(Activity const&) = delete;
49
50   enum class State { INITED = 0, STARTED, CANCELED, ERRORED, FINISHED };
51
52   /** Starts a previously created activity.
53    *
54    * This function is optional: you can call wait() even if you didn't call start()
55    */
56   virtual Activity* start() = 0;
57   /** Tests whether the given activity is terminated yet. This is a pure function. */
58   //virtual bool test()=0;
59   /** Blocks until the activity is terminated */
60   virtual Activity* wait() = 0;
61   /** Blocks until the activity is terminated, or until the timeout is elapsed
62    *  Raises: timeout exception.*/
63   virtual Activity* wait(double timeout) = 0;
64   /** Cancel that activity */
65   virtual Activity* cancel() = 0;
66   /** Retrieve the current state of the activity */
67   Activity::State get_state() { return state_; }
68
69   /** Get the remaining amount of work that this Activity entails. When it's 0, it's done. */
70   virtual double get_remaining();
71
72   /** Set the [remaining] amount of work that this Activity will entail
73    *
74    * It is forbidden to change the amount of work once the Activity is started */
75   Activity* set_remaining(double remains);
76
77   /** Put some user data onto the Activity */
78   Activity* set_user_data(void* data)
79   {
80     user_data_ = data;
81     return this;
82   }
83   /** Retrieve the user data of the Activity */
84   void* get_user_data() { return user_data_; }
85
86   /** @deprecated See Activity::get_state()*/
87   XBT_ATTRIB_DEPRECATED_v323("Please use Activity::get_state()") Activity::State getState() { return state_; }
88   /** @deprecated See Activity::get_remaining() */
89   XBT_ATTRIB_DEPRECATED_v323("Please use Activity::get_remaining()") double getRemains() { return get_remaining(); }
90   /** @deprecated See Activity::set_remaining() */
91   XBT_ATTRIB_DEPRECATED_v323("Please use Activity::set_remaining()") Activity* setRemains(double remains)
92   {
93     return set_remaining(remains);
94   }
95   /** @deprecated See Activity::set_user_data() */
96   XBT_ATTRIB_DEPRECATED_v323("Please use Activity::set_user_data()") Activity* setUserData(void* data)
97   {
98     return set_user_data(data);
99   }
100   /** @deprecated See Activity::get_user_data() */
101   XBT_ATTRIB_DEPRECATED_v323("Please use Activity::get_user_data()") void* getUserData() { return user_data_; }
102
103 private:
104   simgrid::kernel::activity::ActivityImplPtr pimpl_ = nullptr;
105   Activity::State state_                            = Activity::State::INITED;
106   double remains_                                   = 0;
107   void* user_data_                                  = nullptr;
108 }; // class
109
110 }}; // Namespace simgrid::s4u
111
112 #endif /* SIMGRID_S4U_ACTIVITY_HPP */