1 /* Copyright (c) 2007-2023. 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_MC_REMOTE_EVENTLOOP_HPP
7 #define SIMGRID_MC_REMOTE_EVENTLOOP_HPP
9 #include "src/mc/mc_forward.hpp"
10 #include "src/mc/remote/Channel.hpp"
12 #include <event2/event.h>
16 namespace simgrid::mc {
18 /* CheckerSide: All what the checker needs to interact with a given application process */
23 std::unique_ptr<event_base, decltype(&event_base_free)> base_{nullptr, &event_base_free};
26 bool running_ = false;
28 // When forking (no meminfo), the real app is our grandchild. In this case,
29 // child_checker_ is a CheckerSide to our child that can waitpid our grandchild on our behalf
30 CheckerSide* child_checker_ = nullptr;
32 void setup_events(bool socket_only); // Part of the initialization
33 void handle_dead_child(int status); // Launched when the dying child is the PID we follow
34 void handle_waitpid(); // Launched when receiving a sigchild
37 explicit CheckerSide(int socket, CheckerSide* child_checker);
38 explicit CheckerSide(const std::vector<char*>& args);
42 CheckerSide(CheckerSide const&) = delete;
43 CheckerSide& operator=(CheckerSide const&) = delete;
44 CheckerSide& operator=(CheckerSide&&) = delete;
46 /* Communicating with the application */
47 Channel const& get_channel() const { return channel_; }
48 Channel& get_channel() { return channel_; }
50 bool handle_message(const char* buffer, ssize_t size);
51 void dispatch_events() const;
52 void break_loop() const;
53 void wait_for_requests();
55 /* Create a new CheckerSide by forking the currently existing one, and connect it through the master_socket */
56 std::unique_ptr<CheckerSide> clone(int master_socket, const std::string& master_socket_name);
58 /** Ask the application to run post-mortem analysis, and maybe to stop ASAP */
59 void finalize(bool terminate_asap = false);
61 /* Interacting with the application process */
62 pid_t get_pid() const { return pid_; }
63 bool running() const { return running_; }
64 void terminate() { running_ = false; }
67 } // namespace simgrid::mc