Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
05a395aab4fc38d9529612cbd9c18ccf62f0f793
[simgrid.git] / src / mc / remote / Client.hpp
1 /* Copyright (c) 2015-2017. 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   Channel channel_;
32   static std::unique_ptr<Client> instance_;
33
34 public:
35   Client();
36   explicit Client(int fd) : channel_(fd) {}
37   void handleMessages();
38
39 private:
40   void handleDeadlockCheck(mc_message_t* msg);
41   void handleContinue(mc_message_t* msg);
42   void handleSimcall(s_mc_message_simcall_handle_t* message);
43   void handleRestore(s_mc_message_restore_t* msg);
44   void handleActorEnabled(s_mc_message_actor_enabled_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 instance_.get(); }
63 };
64 }
65 }
66
67 #endif