Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
6f5e019ee9a252aa93d16472fed1cd33034dbce2
[simgrid.git] / examples / msg / mc / example_automaton.c
1 #include "xbt/automaton.h"
2 #include "xbt/automatonparse_promela.h"
3 #include "example_automaton.h"
4 #include "msg/msg.h"
5
6 #include "y.tab.c"
7
8 #define N 3
9
10 XBT_LOG_NEW_DEFAULT_CATEGORY(example, "Example with automaton");
11
12 extern xbt_automaton_t automaton;
13
14
15 int d=1;
16 int r=0;
17 int e=1;
18
19 int predD(){
20   return d;
21 }
22
23 int predR(){
24   return r;
25 }
26
27 int predE(){
28   return e;
29 }
30
31 int server(int argc, char *argv[])
32 {
33   m_task_t task = NULL;
34   int count = 0;
35   while (count < N) {
36     if (task) {
37       MSG_task_destroy(task);
38       task = NULL;
39     }
40     MSG_task_receive(&task, "mymailbox");
41     count++;
42   }
43   //MC_assert(atoi(MSG_task_get_name(task)) == 3);
44
45   XBT_INFO("OK");
46   return 0;
47 }
48
49 int client(int argc, char *argv[])
50 {
51
52   m_task_t task =
53       MSG_task_create(argv[1], 0 /*comp cost */ , 10000 /*comm size */ ,
54                       NULL /*arbitrary data */ );
55
56   MSG_task_send(task, "mymailbox");
57   
58   XBT_INFO("Sent!");
59   return 0;
60 }
61
62
63
64 int main(int argc, char **argv){
65   init();
66   yyparse();
67   automaton = get_automaton();
68   xbt_propositional_symbol_t ps = xbt_new_propositional_symbol(automaton,"d", &predD); 
69   ps = xbt_new_propositional_symbol(automaton,"e", &predE); 
70   ps = xbt_new_propositional_symbol(automaton,"r", &predR); 
71   
72   //display_automaton();
73
74   MSG_global_init(&argc, argv);
75
76   MSG_create_environment("platform.xml");
77
78   MSG_function_register("server", server);
79
80   MSG_function_register("client", client);
81
82   MSG_launch_application("deploy_bugged1.xml");
83
84   MSG_main_with_automaton(automaton);
85
86   MSG_clean();
87
88   return 0;
89
90 }