1 /* Copyright (c) 2006-2017. The SimGrid Team. All rights reserved. */
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. */
6 #ifndef SIMGRID_S4U_ACTIVITY_HPP
7 #define SIMGRID_S4U_ACTIVITY_HPP
9 #include <simgrid/s4u/forward.hpp>
10 #include <simgrid/forward.h>
12 enum e_s4u_activity_state_t { inited = 0, started, canceled, errored, finished };
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.
21 XBT_PUBLIC_CLASS Activity {
23 friend void intrusive_ptr_release(Comm * c);
24 friend void intrusive_ptr_add_ref(Comm * c);
28 virtual ~Activity() = default;
31 Activity(Activity const&) = delete;
32 Activity& operator=(Activity const&) = delete;
34 /** Starts a previously created activity.
36 * This function is optional: you can call wait() even if you didn't call start()
38 virtual void start()=0;
39 /** Tests whether the given activity is terminated yet. This is a pure function. */
40 //virtual bool test()=0;
41 /** Blocks until the activity is terminated */
42 virtual void wait()=0;
43 /** Blocks until the activity is terminated, or until the timeout is elapsed
44 * Raises: timeout exception.*/
45 virtual void wait(double timeout)=0;
46 /** Cancel that activity */
47 //virtual void cancel();
48 /** Retrieve the current state of the activity */
49 e_s4u_activity_state_t getState() {return state_;}
51 /** Get the remaining amount of work that this Activity entails. When it's 0, it's done. */
53 /** Set the [remaining] amount of work that this Activity will entail
55 * It is forbidden to change the amount of work once the Activity is started */
56 void setRemains(double remains);
58 /** Put some user data onto the Activity */
59 void setUserData(void *data) {userData_=data;}
60 /** Retrieve the user data of the Activity */
61 void *getUserData() { return userData_; }
64 simgrid::kernel::activity::ActivityImplPtr pimpl_ = nullptr;
65 e_s4u_activity_state_t state_ = inited;
67 void *userData_ = nullptr;
70 }}; // Namespace simgrid::s4u
72 #endif /* SIMGRID_S4U_ACTIVITY_HPP */