1 /* Copyright (c) 2006-2018. 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/forward.h>
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.
19 * They are somewhat linked but not identical to simgrid::kernel::resource::Action,
20 * that are stuff occurring on a resource:
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.
29 class XBT_PUBLIC Activity {
31 friend XBT_PUBLIC void intrusive_ptr_release(Comm * c);
32 friend XBT_PUBLIC void intrusive_ptr_add_ref(Comm * c);
34 friend XBT_PUBLIC void intrusive_ptr_release(Exec * e);
35 friend XBT_PUBLIC void intrusive_ptr_add_ref(Exec * e);
39 virtual ~Activity() = default;
42 Activity(Activity const&) = delete;
43 Activity& operator=(Activity const&) = delete;
45 enum class State { INITED = 0, STARTED, CANCELED, ERRORED, FINISHED };
47 /** Starts a previously created activity.
49 * This function is optional: you can call wait() even if you didn't call start()
51 virtual Activity* start() = 0;
52 /** Tests whether the given activity is terminated yet. This is a pure function. */
53 //virtual bool test()=0;
54 /** Blocks until the activity is terminated */
55 virtual Activity* wait() = 0;
56 /** Blocks until the activity is terminated, or until the timeout is elapsed
57 * Raises: timeout exception.*/
58 virtual Activity* wait(double timeout) = 0;
59 /** Cancel that activity */
60 //virtual void cancel();
61 /** Retrieve the current state of the activity */
62 Activity::State get_state() { return state_; }
64 /** Get the remaining amount of work that this Activity entails. When it's 0, it's done. */
65 virtual double get_remaining();
67 /** Set the [remaining] amount of work that this Activity will entail
69 * It is forbidden to change the amount of work once the Activity is started */
70 Activity* set_remaining(double remains);
72 /** Put some user data onto the Activity */
73 Activity* set_user_data(void* data)
78 /** Retrieve the user data of the Activity */
79 void* get_user_data() { return user_data_; }
81 XBT_ATTRIB_DEPRECATED_v323("Please use Activity::get_state()") Activity::State getState() { return state_; }
82 XBT_ATTRIB_DEPRECATED_v323("Please use Activity::get_remaining()") double getRemains() { return get_remaining(); }
83 XBT_ATTRIB_DEPRECATED_v323("Please use Activity::set_remaining()") Activity* setRemains(double remains)
85 return set_remaining(remains);
87 XBT_ATTRIB_DEPRECATED_v323("Please use Activity::set_user_data()") Activity* setUserData(void* data)
89 return set_user_data(data);
91 XBT_ATTRIB_DEPRECATED_v323("Please use Activity::get_user_data()") void* getUserData() { return user_data_; }
94 simgrid::kernel::activity::ActivityImplPtr pimpl_ = nullptr;
95 Activity::State state_ = Activity::State::INITED;
97 void* user_data_ = nullptr;
100 }}; // Namespace simgrid::s4u
102 #endif /* SIMGRID_S4U_ACTIVITY_HPP */