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;
45 static std::unordered_map<aid_t , simgrid::s4u::Mailbox*> map_actor_to_recv_mailbox;
71 void startDaemon(
bool _daemonized,
bool _auto_restart);
75 virtual void cleanup(
bool has_returned_from_main,
int return_value);
81 virtual int main() = 0;
89 std::pair<bool, int>
join();
146 simgrid::s4u::MutexPtr daemon_lock;
148 simgrid::s4u::ActorPtr s4u_actor;
150 bool has_returned_from_main =
false;
151 int return_value = 0;
156 #ifdef ACTOR_TRACKING_OUTPUT
157 std::string process_name_prefix;
168 #endif //WRENCH_SIM4U_DAEMONWITHMAILBOX_H
void createLifeSaver(std::shared_ptr< S4U_Daemon > reference)
Create a life saver for the daemon.
Definition: S4U_Daemon.cpp:344
void startDaemon(bool _daemonized, bool _auto_restart)
Start the daemon.
Definition: S4U_Daemon.cpp:131
bool hasReturnedFromMain()
Returns true if the daemon has returned from main() (i.e., not brutally killed)
Definition: S4U_Daemon.cpp:320
bool killActor()
Kill the daemon/actor (does nothing if already dead)
Definition: S4U_Daemon.cpp:263
std::pair< bool, int > join()
Join (i.e., wait for) the daemon.
Definition: S4U_Daemon.cpp:305
void suspendActor()
Suspend the daemon/actor.
Definition: S4U_Daemon.cpp:284
@ DOWN
DOWN state: the daemon has been shutdown and/or has terminated.
Definition: S4U_Daemon.h:103
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:104
virtual int main()=0
The daemon's main method, to be overridden.
void setupOnExitFunction()
Sets up the on_exit function for the actor.
Definition: S4U_Daemon.cpp:198
bool isDaemonized()
Return the daemonized status of the daemon.
Definition: S4U_Daemon.cpp:232
simgrid::s4u::Mailbox * recv_mailbox
The daemon's receive mailbox (to send to another daemon so that that daemon can reply)
Definition: S4U_Daemon.h:57
@ SUSPENDED
SUSPENDED state: the daemon has been suspended (and hopefully will be resumed0.
Definition: S4U_Daemon.h:105
std::string process_name
The name of the daemon.
Definition: S4U_Daemon.h:48
unsigned int num_starts
The number of time that this daemon has started (i.e., 1 + number of restarts)
Definition: S4U_Daemon.h:139
Definition: Action.cpp:28
LifeSaver * life_saver
The daemon's life saver.
Definition: S4U_Daemon.h:111
State state
The service's state.
Definition: S4U_Daemon.h:129
S4U_Daemon(std::string hostname, std::string process_name_prefix)
Constructor (daemon with a mailbox)
Definition: S4U_Daemon.cpp:39
void acquireDaemonLock()
Method to acquire the daemon's lock.
Definition: S4U_Daemon.cpp:354
Simulation * getSimulation()
Get the service's simulation.
Definition: S4U_Daemon.cpp:369
void releaseDaemonLock()
Method to release the daemon's lock.
Definition: S4U_Daemon.cpp:361
A generic "running daemon" abstraction that serves as a basis for all simulated processes.
Definition: S4U_Daemon.h:32
static simgrid::s4u::Mailbox * getRunningActorRecvMailbox()
Return the running actor's recv mailbox.
Definition: S4U_Daemon.cpp:385
bool isSetToAutoRestart()
Return the auto-restart status of the daemon.
Definition: S4U_Daemon.cpp:224
std::string hostname
The name of the host on which the daemon is running.
Definition: S4U_Daemon.h:60
A class that provides basic simulation methods. Once the simulation object has been explicitly or imp...
Definition: Simulation.h:48
S4U_Daemon::State getState()
Get the daemon's state.
Definition: S4U_Daemon.cpp:118
void resumeActor()
Resume the daemon/actor.
Definition: S4U_Daemon.cpp:293
void setSimulation(Simulation *simulation)
Set the service's simulation.
Definition: S4U_Daemon.cpp:377
simgrid::s4u::Mailbox * mailbox
The daemon's mailbox.
Definition: S4U_Daemon.h:55
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:328
void runMainMethod()
Method that run's the user-defined main method (that's called by the S4U actor class)
Definition: S4U_Daemon.cpp:239
State
Daemon states.
Definition: S4U_Daemon.h:99
std::string getName()
Retrieve the process name.
Definition: S4U_Daemon.cpp:336
Simulation * simulation
a pointer to the simulation object
Definition: S4U_Daemon.h:125
@ UP
UP state: the daemon has been started and is still running.
Definition: S4U_Daemon.h:101