Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
every setter in s4u::Activity return the activity
[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 enum e_s4u_activity_state_t { inited = 0, started, canceled, errored, finished };
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 XBT_PUBLIC(void) intrusive_ptr_release(Comm * c);
24   friend XBT_PUBLIC(void) intrusive_ptr_add_ref(Comm * c);
25   friend Exec;
26   friend XBT_PUBLIC(void) intrusive_ptr_release(Exec * e);
27   friend XBT_PUBLIC(void) intrusive_ptr_add_ref(Exec * e);
28
29 protected:
30   Activity()  = default;
31   virtual ~Activity() = default;
32
33 public:
34   Activity(Activity const&) = delete;
35   Activity& operator=(Activity const&) = delete;
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   e_s4u_activity_state_t getState() {return state_;}
53
54   /** Get the remaining amount of work that this Activity entails. When it's 0, it's done. */
55   virtual double getRemains();
56   /** Set the [remaining] amount of work that this Activity will entail
57    *
58    * It is forbidden to change the amount of work once the Activity is started */
59   Activity* setRemains(double remains);
60
61   /** Put some user data onto the Activity */
62   Activity* setUserData(void* data)
63   {
64     userData_ = data;
65     return this;
66   }
67   /** Retrieve the user data of the Activity */
68   void *getUserData() { return userData_; }
69
70 private:
71   simgrid::kernel::activity::ActivityImplPtr pimpl_ = nullptr;
72   e_s4u_activity_state_t state_ = inited;
73   double remains_ = 0;
74   void *userData_ = nullptr;
75 }; // class
76
77 }}; // Namespace simgrid::s4u
78
79 #endif /* SIMGRID_S4U_ACTIVITY_HPP */