Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
149140e46f3d792f55e0f48fac93346bd273133e
[simgrid.git] / src / mc / remote / Client.hpp
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_CLIENT_H
8 #define SIMGRID_MC_CLIENT_H
9
10 #include "src/internal_config.h"
11
12 #include <cstddef>
13 #include <memory>
14
15 #include <xbt/base.h>
16
17 #include <simgrid/simix.h>
18
19 #include "src/mc/remote/Channel.hpp"
20 #include "src/mc/remote/mc_protocol.h"
21
22 namespace simgrid {
23 namespace mc {
24
25 /** Model-checked-side of the communication protocol
26  *
27  *  Send messages to the model-checker and handles message from it.
28  */
29 class XBT_PUBLIC() Client {
30 private:
31   bool active_ = false;
32   Channel channel_;
33   static std::unique_ptr<Client> client_;
34
35 public:
36   Client();
37   explicit Client(int fd) : active_(true), channel_(fd) {}
38   void handleMessages();
39
40 private:
41   void handleDeadlockCheck(mc_message_t* msg);
42   void handleContinue(mc_message_t* msg);
43   void handleSimcall(s_mc_message_simcall_handle_t* message);
44   void handleRestore(s_mc_message_restore_t* msg);
45
46 public:
47   Channel const& getChannel() const { return channel_; }
48   Channel& getChannel() { return channel_; }
49   void mainLoop();
50   void reportAssertionFailure(const char* description = nullptr);
51   void ignoreMemory(void* addr, std::size_t size);
52   void ignoreHeap(void* addr, std::size_t size);
53   void unignoreHeap(void* addr, std::size_t size);
54   void declareSymbol(const char* name, int* value);
55 #if HAVE_UCONTEXT_H
56   void declareStack(void* stack, size_t size, smx_actor_t process, ucontext_t* context);
57 #endif
58
59   // Singleton :/
60   // TODO, remove the singleton antipattern.
61   static Client* initialize();
62   static Client* get() { return client_.get(); }
63 };
64 }
65 }
66
67 #endif