Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
9daf0dd66edcd667e0709a569f0cdc2ed1ec3108
[simgrid.git] / src / mc / mc_server.h
1 /* Copyright (c) 2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMGRID_MC_SERVER_H
8 #define SIMGRID_MC_SERVER_H
9
10 #include <poll.h>
11
12 #include <stdbool.h>
13
14 #include <sys/signalfd.h>
15 #include <sys/types.h>
16
17 #include <xbt/misc.h>
18 #include <xbt/base.h>
19  
20 #include "src/mc/Process.hpp"
21 #include "mc_exit.h"
22
23 SG_BEGIN_DECL()
24
25 #define MC_SERVER_ERROR SIMGRID_ERROR
26
27 typedef struct s_mc_server s_mc_server_t, *mc_server_t;
28
29 extern mc_server_t mc_server;
30
31 SG_END_DECL()
32
33 #ifdef __cplusplus
34
35 struct s_mc_server {
36 private:
37   pid_t pid;
38   int socket;
39   struct pollfd fds[2];
40 public:
41   s_mc_server(pid_t pid, int socket);
42   void start();
43   void shutdown();
44   void exit();
45   void resume(simgrid::mc::Process& process);
46   void loop();
47   bool handle_events();
48   void wait_client(simgrid::mc::Process& process);
49   void simcall_handle(simgrid::mc::Process& process, unsigned long pid, int value);
50 private:
51   bool handle_message(char* buffer, ssize_t size);
52   void handle_signals();
53   void handle_waitpid();
54   void on_signal(const struct signalfd_siginfo* info);
55 };
56
57 #endif
58
59 #endif