Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
sonar don't want half-initialized enums
[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 { inited = 0, started, canceled, errored, finished } e_s4u_activity_state_t;
19
20 namespace simgrid {
21 namespace s4u {
22
23 /** @brief Activities
24  *
25  * 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.
26  */
27 XBT_PUBLIC_CLASS Activity {
28   friend Comm;
29   friend void intrusive_ptr_release(Comm * c);
30   friend void intrusive_ptr_add_ref(Comm * c);
31
32 protected:
33   Activity();
34   virtual ~Activity();
35
36 public:
37   Activity(Activity const&) = delete;
38   Activity& operator=(Activity const&) = delete;
39
40   /** Starts a previously created activity.
41    *
42    * This function is optional: you can call wait() even if you didn't call start()
43    */
44   virtual void start()=0;
45   /** Tests whether the given activity is terminated yet. This is a pure function. */
46   //virtual bool test()=0;
47   /** Blocks until the activity is terminated */
48   virtual void wait()=0;
49   /** Blocks until the activity is terminated, or until the timeout is elapsed
50    *  Raises: timeout exception.*/
51   virtual void wait(double timeout)=0;
52   /** Cancel that activity */
53   //virtual void cancel();
54   /** Retrieve the current state of the activity */
55   e_s4u_activity_state_t getState() {return state_;}
56
57   /** Get the remaining amount of work that this Activity entails. When it's 0, it's done. */
58   double getRemains();
59   /** Set the [remaining] amount of work that this Activity will entail
60    *
61    * It is forbidden to change the amount of work once the Activity is started */
62   void setRemains(double remains);
63
64   /** Put some user data onto the Activity */
65   void setUserData(void *data) {userData_=data;}
66   /** Retrieve the user data of the Activity */
67   void *getUserData() { return userData_; }
68
69 private:
70   simgrid::kernel::activity::ActivityImpl *pimpl_ = nullptr;
71   e_s4u_activity_state_t state_ = inited;
72   double remains_ = 0;
73   void *userData_ = nullptr;
74 }; // class
75
76 }}; // Namespace simgrid::s4u
77
78 #endif /* SIMGRID_S4U_ACTIVITY_HPP */