Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
7a54eccc1a3732a5254044a6ac6143959236c3f0
[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 <stdint.h>
13 #include <stdbool.h>
14
15 #include <sys/signalfd.h>
16 #include <sys/types.h>
17
18 #include <xbt/misc.h>
19  
20 #include "mc_process.h"
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 XBT_INTERNAL void MC_server_wait_client(simgrid::mc::Process* process);
32 XBT_INTERNAL void MC_server_simcall_handle(simgrid::mc::Process* process, unsigned long pid, int value);
33
34 XBT_INTERNAL void MC_server_loop(mc_server_t server);
35
36 SG_END_DECL()
37
38 #ifdef __cplusplus
39
40 struct s_mc_server {
41 private:
42   pid_t pid;
43   int socket;
44   struct pollfd fds[2];
45 public:
46   s_mc_server(pid_t pid, int socket);
47   void start();
48   void shutdown();
49   void exit();
50   void resume(simgrid::mc::Process* process);
51   void loop();
52   bool handle_events();
53 protected:
54   void handle_signals();
55   void handle_waitpid();
56   void on_signal(const struct signalfd_siginfo* info);
57 };
58
59 #endif
60
61 #endif