Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Put everything in position to re-fork the verified App
[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   void (*const free_event_fun)(event*) = [](event* evt) {
22     event_del(evt);
23     event_free(evt);
24   };
25   std::unique_ptr<event, decltype(&event_free)> socket_event_{nullptr, free_event_fun};
26   std::unique_ptr<event, decltype(&event_free)> signal_event_{nullptr, free_event_fun};
27   std::unique_ptr<event_base, decltype(&event_base_free)> base_{nullptr, &event_base_free};
28   std::unique_ptr<RemoteProcessMemory> remote_memory_;
29
30   Channel channel_;
31   bool running_ = false;
32   pid_t pid_;
33
34   void setup_events(); // Part of the initialization
35   void clear_memory_cache();
36   void handle_waitpid();
37
38 public:
39   explicit CheckerSide(const std::vector<char*>& args);
40
41   // No copy:
42   CheckerSide(CheckerSide const&) = delete;
43   CheckerSide& operator=(CheckerSide const&) = delete;
44   CheckerSide& operator=(CheckerSide&&) = delete;
45
46   /* Communicating with the application */
47   Channel const& get_channel() const { return channel_; }
48   Channel& get_channel() { return channel_; }
49
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();
54
55   /* Interacting with the application process */
56   pid_t get_pid() const { return pid_; }
57   bool running() const { return running_; }
58   void terminate() { running_ = false; }
59   RemoteProcessMemory& get_remote_memory() { return *remote_memory_.get(); }
60 };
61
62 } // namespace simgrid::mc
63
64 #endif