Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move more of the CheckerSide creation logic to the object constructor
[simgrid.git] / src / mc / remote / CheckerSide.hpp
1 /* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved.          */
2
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. */
5
6 #ifndef SIMGRID_MC_REMOTE_EVENTLOOP_HPP
7 #define SIMGRID_MC_REMOTE_EVENTLOOP_HPP
8
9 #include "src/mc/mc_forward.hpp"
10 #include "src/mc/remote/Channel.hpp"
11
12 #include <event2/event.h>
13 #include <functional>
14 #include <memory>
15
16 namespace simgrid::mc {
17
18 /* CheckerSide: All what the checker needs to interact with a given application process */
19
20 class CheckerSide {
21   std::unique_ptr<event_base, decltype(&event_base_free)> base_{nullptr, &event_base_free};
22   std::unique_ptr<event, decltype(&event_free)> socket_event_{nullptr, &event_free};
23   std::unique_ptr<event, decltype(&event_free)> signal_event_{nullptr, &event_free};
24   std::unique_ptr<RemoteProcessMemory> remote_memory_;
25   Channel channel_;
26
27   bool running_ = false;
28   pid_t pid_;
29
30   void setup_events(); // Part of the initialization
31
32 public:
33   explicit CheckerSide(const std::vector<char*>& args);
34
35   // No copy:
36   CheckerSide(CheckerSide const&) = delete;
37   CheckerSide& operator=(CheckerSide const&) = delete;
38   CheckerSide& operator=(CheckerSide&&) = delete;
39
40   /* Communicating with the application */
41   Channel const& get_channel() const { return channel_; }
42   Channel& get_channel() { return channel_; }
43
44   bool handle_message(const char* buffer, ssize_t size);
45   void dispatch_events() const;
46   void break_loop() const;
47   void wait_for_requests();
48
49   /* Interacting with the application process */
50   pid_t get_pid() const { return pid_; }
51   bool running() const { return running_; }
52   void terminate() { running_ = false; }
53   void handle_waitpid();
54   RemoteProcessMemory& get_remote_memory() { return *remote_memory_.get(); }
55   void clear_memory_cache();
56 };
57
58 } // namespace simgrid::mc
59
60 #endif