Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Prefer C++ headers, and C++-style void-arg declarations.
[simgrid.git] / src / mc / remote / CheckerSide.cpp
1 /* Copyright (c) 2007-2020. 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 #include "src/mc/remote/CheckerSide.hpp"
7 #include <csignal>
8 #include <sys/wait.h>
9
10 namespace simgrid {
11 namespace mc {
12
13 CheckerSide::~CheckerSide()
14 {
15   if (socket_event_ != nullptr)
16     event_free(socket_event_);
17   if (signal_event_ != nullptr)
18     event_free(signal_event_);
19   if (base_ != nullptr)
20     event_base_free(base_);
21 }
22
23 void CheckerSide::start(void (*handler)(int, short, void*))
24 {
25   base_ = event_base_new();
26
27   socket_event_ = event_new(base_, get_channel().get_socket(), EV_READ | EV_PERSIST, handler, this);
28   event_add(socket_event_, NULL);
29
30   signal_event_ = event_new(base_, SIGCHLD, EV_SIGNAL | EV_PERSIST, handler, this);
31   event_add(signal_event_, NULL);
32 }
33
34 void CheckerSide::dispatch()
35 {
36   event_base_dispatch(base_);
37 }
38
39 void CheckerSide::break_loop()
40 {
41   event_base_loopbreak(base_);
42 }
43
44 } // namespace mc
45 } // namespace simgrid