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;
48 std::string process_name;
55 simgrid::s4u::Mailbox *mailbox;
57 simgrid::s4u::Mailbox *recv_mailbox;
62 static simgrid::s4u::Mailbox *getRunningActorRecvMailbox();
64 S4U_Daemon(std::string hostname, std::string process_name_prefix);
69 virtual ~S4U_Daemon();
71 void startDaemon(
bool _daemonized,
bool _auto_restart);
73 void createLifeSaver(std::shared_ptr<S4U_Daemon> reference);
75 virtual void cleanup(
bool has_returned_from_main,
int return_value);
81 virtual int main() = 0;
83 bool hasReturnedFromMain();
86 bool isSetToAutoRestart();
87 void setupOnExitFunction();
89 std::pair<bool, int> join();
96 std::string getName();
108 S4U_Daemon::State getState();
111 LifeSaver *life_saver =
nullptr;
114 void acquireDaemonLock();
117 void releaseDaemonLock();
119 Simulation *getSimulation();
121 void setSimulation(Simulation *simulation);
125 Simulation *simulation;
131 friend class S4U_DaemonActor;
132 void runMainMethod();
139 unsigned int num_starts = 0;
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