Logo AND Algorithmique Numérique Distribuée

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