Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge s4u wait_any
[simgrid.git] / src / mc / 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/mc_protocol.h"
20 #include "src/mc/Channel.hpp"
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 public:
35   Client();
36   explicit Client(int fd) : active_(true), channel_(fd) {}
37   void handleMessages();
38   Channel const& getChannel() const { return channel_; }
39   Channel& getChannel() { return channel_; }
40   void mainLoop(void);
41   void reportAssertionFailure(const char* description = nullptr);
42   void ignoreMemory(void* addr, std::size_t size);
43   void ignoreHeap(void* addr, std::size_t size);
44   void unignoreHeap(void* addr, std::size_t size);
45   void declareSymbol(const char *name, int* value);
46 #if HAVE_UCONTEXT_H
47   void declareStack(void *stack, size_t size, smx_process_t process, ucontext_t* context);
48 #endif
49
50   // Singleton :/
51   // TODO, remove the singleton antipattern.
52   static Client* initialize();
53   static Client* get()
54   {
55     return client_.get();
56   }
57 };
58
59 }
60 }
61
62 SG_BEGIN_DECL()
63
64 #if HAVE_MC
65 void MC_ignore(void* addr, std::size_t size);
66 #endif
67
68 SG_END_DECL()
69
70 #endif