forked from endurodave/StateMachine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.cpp
94 lines (81 loc) · 2.56 KB
/
Player.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "Player.h"
#include <iostream>
using namespace std;
Player::Player() :
StateMachine(ST_MAX_STATES)
{
}
void Player::OpenClose()
{
BEGIN_TRANSITION_MAP // - Current State -
TRANSITION_MAP_ENTRY (ST_OPEN) // ST_EMPTY
TRANSITION_MAP_ENTRY (ST_EMPTY) // ST_OPEN
TRANSITION_MAP_ENTRY (ST_OPEN) // ST_STOPPED
TRANSITION_MAP_ENTRY (ST_OPEN) // ST_PAUSED
TRANSITION_MAP_ENTRY (ST_OPEN) // ST_PLAYING
END_TRANSITION_MAP(NULL)
}
void Player::Play()
{
BEGIN_TRANSITION_MAP // - Current State -
TRANSITION_MAP_ENTRY (EVENT_IGNORED) // ST_EMPTY
TRANSITION_MAP_ENTRY (EVENT_IGNORED) // ST_OPEN
TRANSITION_MAP_ENTRY (ST_PLAYING) // ST_STOPPED
TRANSITION_MAP_ENTRY (EVENT_IGNORED) // ST_PAUSED
TRANSITION_MAP_ENTRY (EVENT_IGNORED) // ST_PLAYING
END_TRANSITION_MAP(NULL)
}
void Player::Stop()
{
BEGIN_TRANSITION_MAP // - Current State -
TRANSITION_MAP_ENTRY (EVENT_IGNORED) // ST_EMPTY
TRANSITION_MAP_ENTRY (EVENT_IGNORED) // ST_OPEN
TRANSITION_MAP_ENTRY (ST_STOPPED) // ST_STOPPED
TRANSITION_MAP_ENTRY (ST_STOPPED) // ST_PAUSED
TRANSITION_MAP_ENTRY (ST_STOPPED) // ST_PLAYING
END_TRANSITION_MAP(NULL)
}
void Player::Pause()
{
BEGIN_TRANSITION_MAP // - Current State -
TRANSITION_MAP_ENTRY (EVENT_IGNORED) // ST_EMPTY
TRANSITION_MAP_ENTRY (EVENT_IGNORED) // ST_OPEN
TRANSITION_MAP_ENTRY (EVENT_IGNORED) // ST_STOPPED
TRANSITION_MAP_ENTRY (EVENT_IGNORED) // ST_PAUSED
TRANSITION_MAP_ENTRY (ST_PAUSED) // ST_PLAYING
END_TRANSITION_MAP(NULL)
}
void Player::EndPause()
{
BEGIN_TRANSITION_MAP // - Current State -
TRANSITION_MAP_ENTRY (EVENT_IGNORED) // ST_EMPTY
TRANSITION_MAP_ENTRY (EVENT_IGNORED) // ST_OPEN
TRANSITION_MAP_ENTRY (EVENT_IGNORED) // ST_STOPPED
TRANSITION_MAP_ENTRY (ST_PLAYING) // ST_PAUSED
TRANSITION_MAP_ENTRY (EVENT_IGNORED) // ST_PLAYING
END_TRANSITION_MAP(NULL)
}
STATE_DEFINE(Player, Empty, NoEventData)
{
static BOOL CD_DetectedToggle = FALSE;
CD_DetectedToggle = CD_DetectedToggle == FALSE ? TRUE : FALSE;
cout << "Player::ST_Empty" << endl;
if (CD_DetectedToggle == TRUE)
InternalEvent(ST_STOPPED);
}
STATE_DEFINE(Player, Open, NoEventData)
{
cout << "Player::ST_Open" << endl;
}
STATE_DEFINE(Player, Stopped, NoEventData)
{
cout << "Player::ST_Stopped" << endl;
}
STATE_DEFINE(Player, Paused, NoEventData)
{
cout << "Player::ST_Paused" << endl;
}
STATE_DEFINE(Player, Playing, NoEventData)
{
cout << "Player::ST_Playing" << endl;
}