Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[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 #include <xbt/base.h>
20  
21 #include "mc_process.h"
22 #include "mc_exit.h"
23
24 SG_BEGIN_DECL()
25
26 #define MC_SERVER_ERROR SIMGRID_ERROR
27
28 typedef struct s_mc_server s_mc_server_t, *mc_server_t;
29
30 extern mc_server_t mc_server;
31
32 XBT_PRIVATE void MC_server_wait_client(simgrid::mc::Process* process);
33 XBT_PRIVATE void MC_server_simcall_handle(simgrid::mc::Process* process, unsigned long pid, int value);
34
35 XBT_PRIVATE void MC_server_loop(mc_server_t server);
36
37 SG_END_DECL()
38
39 #ifdef __cplusplus
40
41 struct s_mc_server {
42 private:
43   pid_t pid;
44   int socket;
45   struct pollfd fds[2];
46 public:
47   s_mc_server(pid_t pid, int socket);
48   void start();
49   void shutdown();
50   void exit();
51   void resume(simgrid::mc::Process* process);
52   void loop();
53   bool handle_events();
54 protected:
55   void handle_signals();
56   void handle_waitpid();
57   void on_signal(const struct signalfd_siginfo* info);
58 };
59
60 #endif
61
62 #endif