2 #include <boost/statechart/state_machine.hpp>
3 #include <boost/statechart/simple_state.hpp>
4 #include <boost/statechart/transition.hpp>
5 #include <boost/statechart/event.hpp>
6 #include <boost/mpl/list.hpp>
15 namespace sc = boost::statechart;
16 namespace mpl = boost::mpl;
17 struct state_1; // definice stavu
18 struct state_2; // definice stavu
19 struct state_3; // definice stavu
20 struct state_4; // definice stavu
21 struct EvYes : sc::event< EvYes > {};//stisteno A
22 struct EvNo : sc::event< EvNo > {};//stisteno N
23 struct EvTimer : sc::event< EvTimer > {};//vyprsel cas
25 struct DU : sc::state_machine< DU, state_1 > {};//Nastaveni inicializacniho stavu
27 DU Zm; // pro posilani udalosti
29 void* casovac(void* s)
33 Zm.process_event (EvTimer());
37 struct state_1 : sc::simple_state< state_1, DU> // stav
39 state_1() { cout<<"Chcete zformatovat vas disk (a/n) ? \n";}//FSM_Entry
40 ~state_1() {}//FSM_Exit
41 typedef mpl::list< // reakce na udalosti
42 sc::transition< EvYes, state_4 >,
43 sc::transition< EvNo, state_2 > > reactions;
45 struct state_2 : sc::simple_state< state_2, DU >
49 cout<<"Rozmysli si to! \n";
52 if ( pthread_create(&idthread, NULL, casovac, a) != 0)
54 cout << "Chyba pri vytvareni vlakna.";
57 if ( pthread_detach(idthread ) )
59 cout << "Error detaching ..\n";
64 typedef sc::transition< EvTimer, state_3 > reactions;
66 struct state_3 : sc::simple_state< state_3, DU >
69 state_3() { cout<<"Rychle stiskni n nebo ti zformatuju disk. \n";
71 if ( pthread_create(&idthread, NULL, casovac, a) != 0)
73 cout << "Chyba pri vytvareni vlakna.";
76 if ( pthread_detach(idthread ) )
78 cout << "Error detaching ..\n";
84 sc::transition< EvNo, state_1 >,
85 sc::transition< EvTimer, state_4 > > reactions;
87 struct state_4 : sc::simple_state< state_4, DU >
90 cout<<"Formatuji tvuj disk. \n";
93 if ( pthread_create(&idthread, NULL, casovac, a) != 0)
95 cout << "Chyba pri vytvareni vlakna.";
98 if ( pthread_detach(idthread ) )
100 cout << "Error detaching ..\n";
104 ~state_4() { cout<<"HOTOVO.\n";}
105 typedef sc::transition< EvTimer, state_1 > reactions;
108 void *nacitani (void * ptr)
114 if (s == "n") Zm.process_event (EvNo());
115 if (s == "a") Zm.process_event (EvYes());
116 if (s == "exit") break;
124 if ( pthread_create(&idthread, NULL, nacitani, NULL) != 0)
126 cout << "Chyba pri vytvareni vlakna.";
129 pthread_join(idthread, NULL);