10 #ifndef WRENCH_SIM4U_DAEMON_H
11 #define WRENCH_SIM4U_DAEMON_H
15 #include <simgrid/s4u.hpp>
36 explicit LifeSaver(std::shared_ptr<S4U_Daemon> &reference) : reference(reference) {}
38 std::shared_ptr<S4U_Daemon> reference;
55 S4U_Daemon(std::string
hostname, std::string process_name_prefix, std::string mailbox_prefix);
62 void startDaemon(
bool daemonized,
bool auto_restart);
66 virtual void cleanup(
bool has_returned_from_main,
int return_value);
72 virtual int main() = 0;
80 std::pair<bool, int>
join();
128 simgrid::s4u::MutexPtr daemon_lock;
130 simgrid::s4u::ActorPtr s4u_actor;
132 bool has_returned_from_main =
false;
133 int return_value = 0;
138 #ifdef ACTOR_TRACKING_OUTPUT
139 std::string process_name_prefix;
150 #endif //WRENCH_SIM4U_DAEMONWITHMAILBOX_H
void createLifeSaver(std::shared_ptr< S4U_Daemon > reference)
Create a life saver for the daemon.
Definition: S4U_Daemon.cpp:340
bool hasReturnedFromMain()
Returns true if the daemon has returned from main() (i.e., not brutally killed)
Definition: S4U_Daemon.cpp:316
std::pair< bool, int > join()
Join (i.e., wait for) the daemon.
Definition: S4U_Daemon.cpp:301
void suspendActor()
Suspend the daemon/actor.
Definition: S4U_Daemon.cpp:280
void startDaemon(bool daemonized, bool auto_restart)
Start the daemon.
Definition: S4U_Daemon.cpp:140
@ DOWN
DOWN state: the daemon has been shutdown and/or has terminated.
Definition: S4U_Daemon.h:94
virtual ~S4U_Daemon()
Definition: S4U_Daemon.cpp:83
virtual void cleanup(bool has_returned_from_main, int return_value)
Cleanup function called when the daemon terminates (for whatever reason). The default behavior is to ...
Definition: S4U_Daemon.cpp:113
virtual int main()=0
The daemon's main method, to be overridden.
void setupOnExitFunction()
Sets up the on_exit functionf for the actor.
Definition: S4U_Daemon.cpp:206
std::string initial_mailbox_name
The initial name of the daemon's mailbox.
Definition: S4U_Daemon.h:47
bool isDaemonized()
Return the daemonized status of the daemon.
Definition: S4U_Daemon.cpp:240
@ SUSPENDED
SUSPENDED state: the daemon has been suspended (and hopefully will be resumed0.
Definition: S4U_Daemon.h:96
std::string process_name
The name of the daemon.
Definition: S4U_Daemon.h:45
unsigned int num_starts
The number of time that this daemon has started (i.e., 1 + number of restarts)
Definition: S4U_Daemon.h:121
LifeSaver * life_saver
The daemon's life saver.
Definition: S4U_Daemon.h:102
State state
The service's state.
Definition: S4U_Daemon.h:109
void acquireDaemonLock()
Lock the daemon's lock.
Definition: S4U_Daemon.cpp:350
void releaseDaemonLock()
Unlock the daemon's lock.
Definition: S4U_Daemon.cpp:357
A generic "running daemon" abstraction that serves as a basis for all simulated processes.
Definition: S4U_Daemon.h:32
bool isSetToAutoRestart()
Return the auto-restart status of the daemon.
Definition: S4U_Daemon.cpp:232
std::string hostname
The name of the host on which the daemon is running.
Definition: S4U_Daemon.h:51
A class that provides basic simulation methods. Once the simulation object has been explicitly or imp...
Definition: Simulation.h:45
S4U_Daemon::State getState()
Get the daemon's state.
Definition: S4U_Daemon.cpp:127
void resumeActor()
Resume the daemon/actor.
Definition: S4U_Daemon.cpp:289
void killActor()
Kill the daemon/actor (does nothing if already dead)
Definition: S4U_Daemon.cpp:264
The S4U actor that's the foundation for the S4U_Daemon abstraction.
Definition: S4U_DaemonActor.h:36
int getReturnValue()
Returns the value returned by main() (if the daemon has returned from main)
Definition: S4U_Daemon.cpp:324
void runMainMethod()
Method that run's the user-defined main method (that's called by the S4U actor class)
Definition: S4U_Daemon.cpp:247
State
Daemon states.
Definition: S4U_Daemon.h:90
std::string getName()
Retrieve the process name.
Definition: S4U_Daemon.cpp:332
S4U_Daemon(std::string hostname, std::string process_name_prefix, std::string mailbox_prefix)
Constructor (daemon with a mailbox)
Definition: S4U_Daemon.cpp:38
std::string mailbox_name
The current name of the daemon's mailbox.
Definition: S4U_Daemon.h:49
Simulation * simulation
a pointer to the simulation object
Definition: S4U_Daemon.h:105
@ UP
UP state: the daemon has been started and is still running.
Definition: S4U_Daemon.h:92