source: trunk/src/halTorrentIntStates.hpp @ 686

Revision 686, 3.5 KB checked in by Eoin, 11 years ago (diff)

More advanced state machine being implemented for torrent_internal.

Line 
1
2//         Copyright Eóin O'Callaghan 2009 - 2009.
3// Distributed under the Boost Software License, Version 1.0.
4//    (See accompanying file LICENSE_1_0.txt or copy at
5//          http://www.boost.org/LICENSE_1_0.txt)
6
7#pragma once
8
9#include "halTorrentInternal.hpp"
10
11#ifndef HAL_TORRENT_STATE_LOGGING
12#       define TORRENT_STATE_LOG(s)
13#else
14#       include "../halEvent.hpp"
15#       define TORRENT_STATE_LOG(msg) \
16        hal::event_log.post(boost::shared_ptr<hal::EventDetail>( \
17                        new hal::EventMsg(msg, hal::event_logger::torrent_dev)))
18#endif
19
20#include <boost/statechart/event.hpp>
21#include <boost/statechart/state_machine.hpp>
22#include <boost/statechart/simple_state.hpp>
23#include <boost/statechart/transition.hpp>
24#include <boost/statechart/state.hpp>
25#include <boost/statechart/custom_reaction.hpp>
26
27namespace hal
28{
29
30namespace sc = boost::statechart;
31
32struct stopped;
33
34struct out_of_session : sc::state<out_of_session, torrent_internal, mpl::list< stopped > > 
35{
36        typedef sc::state<out_of_session, torrent_internal, mpl::list< stopped > > base_type;
37
38        typedef mpl::list<
39                sc::custom_reaction< ev_add_to_session >
40        > reactions;
41
42        out_of_session(base_type::my_context ctx);
43        ~out_of_session();     
44
45        sc::result react(const ev_add_to_session& evt);
46};
47
48struct leaving_session : sc::state<leaving_session, torrent_internal> 
49{
50        typedef sc::state<leaving_session, torrent_internal> base_type;
51
52        typedef mpl::list<
53                sc::custom_reaction< ev_add_to_session >,
54                sc::custom_reaction< ev_resume_data_written >
55        > reactions;
56
57        leaving_session(base_type::my_context ctx);
58        ~leaving_session();     
59
60        sc::result react(const ev_resume_data_written& evt);
61        sc::result react(const ev_add_to_session& evt);
62};
63
64struct active;
65struct pausing;
66struct paused;
67struct stopping;
68struct resume_data_idling;
69
70struct in_the_session : sc::state<in_the_session, torrent_internal, mpl::list< resume_data_idling, paused > > 
71{
72        typedef sc::state<in_the_session, torrent_internal, mpl::list< resume_data_idling, paused > > base_type;
73
74        typedef mpl::list<
75                sc::custom_reaction< ev_remove_from_session >
76        > reactions;
77
78        in_the_session(base_type::my_context ctx);
79        ~in_the_session();
80
81        sc::result react(const ev_remove_from_session& evt);
82};
83
84struct resume_data_idling : sc::simple_state<resume_data_idling, in_the_session::orthogonal< 0 > >
85{
86        resume_data_idling();
87        ~resume_data_idling();
88};
89
90struct resume_data_waiting : sc::simple_state<resume_data_waiting, in_the_session::orthogonal< 0 > >
91{
92        resume_data_waiting();
93        ~resume_data_waiting();
94};
95
96struct active : sc::state<active, in_the_session::orthogonal< 1 > >
97{
98        typedef sc::state<active, in_the_session::orthogonal< 1 > > base_type;
99
100        typedef mpl::list<
101                sc::custom_reaction< ev_pause >
102        > reactions;
103
104        active(base_type::my_context ctx);
105        ~active();
106
107        sc::result react(const ev_pause& evt);
108};
109
110struct pausing : sc::simple_state<pausing, in_the_session::orthogonal< 1 > >
111{
112        typedef sc::transition< ev_paused_alert, paused > reactions;
113
114        pausing();
115        ~pausing();
116};
117
118struct paused : sc::state<paused, in_the_session::orthogonal< 1 > >
119{
120        typedef sc::state<paused, in_the_session::orthogonal< 1 > > base_type;
121
122        paused(base_type::my_context ctx);
123        ~paused();
124};
125
126struct stopping : sc::simple_state<stopping, in_the_session::orthogonal< 1 > >
127{
128        stopping();
129        ~stopping();
130};
131
132struct stopped : sc::simple_state<stopped, out_of_session>
133{
134        stopped();
135        ~stopped();
136};
137
138}; // namespace hal
Note: See TracBrowser for help on using the repository browser.