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 std::string process_name;
47 std::string initial_mailbox_name;
49 std::string mailbox_name;
55 S4U_Daemon(std::string hostname, std::string process_name_prefix, std::string mailbox_prefix);
60 virtual ~S4U_Daemon();
62 void startDaemon(
bool _daemonized,
bool _auto_restart);
64 void createLifeSaver(std::shared_ptr<S4U_Daemon> reference);
66 virtual void cleanup(
bool has_returned_from_main,
int return_value);
72 virtual int main() = 0;
74 bool hasReturnedFromMain();
77 bool isSetToAutoRestart();
78 void setupOnExitFunction();
80 std::pair<bool, int> join();
87 std::string getName();
99 S4U_Daemon::State getState();
102 LifeSaver *life_saver =
nullptr;
105 Simulation *simulation;
111 friend class S4U_DaemonActor;
112 void runMainMethod();
116 void acquireDaemonLock();
118 void releaseDaemonLock();
121 unsigned int num_starts = 0;
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