Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
reduce some overly verbose comments
[simgrid.git] / src / mc / mc_client_api.cpp
1 /* Copyright (c) 2008-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 #include <xbt/log.h>
8 #include <xbt/fifo.h>
9 #include <xbt/sysdep.h>
10 #include <simgrid/modelchecker.h>
11
12 #include "src/mc/mc_record.h"
13 #include "src/mc/mc_private.h"
14 #include "src/mc/mc_ignore.h"
15 #include "src/mc/mc_protocol.h"
16 #include "src/mc/mc_client.h"
17 #include "src/mc/ModelChecker.hpp"
18
19 /** \file mc_client_api.cpp
20  *
21  *  This is the implementation of the API used by the user simulated program to
22  *  communicate with the MC (declared in modelchecker.h).
23  */
24
25 extern "C" {
26
27 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_client_api, mc,
28   "Public API for the model-checked application");
29
30 }
31
32 // MC_random() is in mc_base.cpp
33
34 void MC_assert(int prop)
35 {
36   if (MC_is_active() && !prop) {
37     MC_client_send_simple_message(MC_MESSAGE_ASSERTION_FAILED);
38     MC_client_handle_messages();
39   }
40 }
41
42 void MC_cut(void)
43 {
44   user_max_depth_reached = 1;
45 }
46
47 void MC_ignore(void* addr, size_t size)
48 {
49   xbt_assert(mc_mode != MC_MODE_SERVER);
50   if (mc_mode != MC_MODE_CLIENT)
51     return;
52
53   s_mc_ignore_memory_message_t message;
54   message.type = MC_MESSAGE_IGNORE_MEMORY;
55   message.addr = (std::uintptr_t) addr;
56   message.size = size;
57   MC_client_send_message(&message, sizeof(message));
58 }
59
60 void MC_automaton_new_propositional_symbol(const char *id, int(*fct)(void))
61 {
62   xbt_assert(mc_mode != MC_MODE_SERVER);
63   if (mc_mode != MC_MODE_CLIENT)
64     return;
65
66   xbt_die("Support for client-side function proposition is not implemented: "
67     "use MC_automaton_new_propositional_symbol_pointer instead."
68   );
69 }
70
71 void MC_automaton_new_propositional_symbol_pointer(const char *name, int* value)
72 {
73   xbt_assert(mc_mode != MC_MODE_SERVER);
74   if (mc_mode != MC_MODE_CLIENT)
75     return;
76
77   s_mc_register_symbol_message_t message;
78   message.type = MC_MESSAGE_REGISTER_SYMBOL;
79   if (strlen(name) + 1 > sizeof(message.name))
80     xbt_die("Symbol is too long");
81   strncpy(message.name, name, sizeof(message.name));
82   message.callback = nullptr;
83   message.data = value;
84   MC_client_send_message(&message, sizeof(message));
85 }