aboutsummaryrefslogtreecommitdiffstats
path: root/package/fonera-mp3/src/lib/mp3_states.h
blob: 073c28bb13242990ba413e9caa1112068e84571d (plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* FOXMP3 
* Copyright (c) 2006 acmesystems.it - john@acmesystems.it
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
*
* Feedback, Bugs...  info@acmesystems.it 
*
*/

typedef struct _EVENT {
	unsigned char *name;
} EVENT;

typedef struct _EVENT_PARAM {
	int numeric;
	unsigned char *text;
} EVENT_PARAM;

typedef void (*STATE_ENTER)(int state_last, int event, EVENT_PARAM *param);
typedef void (*STATE_LEAVE)(int state_new, int event);

typedef struct _STATE {
	unsigned char *name;
	STATE_ENTER enter;
	STATE_LEAVE leave;
} STATE;

typedef struct _TRANSITION {
	int old_state;
	int event;
	int new_state;
} TRANSITION;

// a = id, b = name, c = enter, d = leave
#define STATE_ADD(a, b, c, d) { 			\
		if((a > 0) && (a < MAX_STATE_COUNT)){	\
			states[a].name = strdup(b); 	\
			states[a].enter = c; 		\
			states[a].leave = d; 		\
		} 					\
	}

// a = old, b = event, c = new 
#define TRANSITION_ADD(a, b, c) { 					\
		if((transition_count >= 0) && 				\
			(transition_count < MAX_TRANSITION_COUNT)){	\
			transitions[transition_count].old_state = a;	\
			transitions[transition_count].event = b; 	\
			transitions[transition_count].new_state = c; 	\
			transition_count++;				\
		} 							\
	}

// a = id, b = name
#define EVENT_ADD(a, b) { 				\
		if((a > 0) && (a < MAX_EVENT_COUNT)){	\
			events[a].name = strdup(b); 	\
		} 					\
	}
#define MAX_EVENT_COUNT 	20
#define MAX_STATE_COUNT 	20
#define MAX_TRANSITION_COUNT	60
	
#define MP3_STATE_NONE			0
#define MP3_STATE_STARTUP		1
#define MP3_STATE_IDLE			2
#define MP3_STATE_FILE_START		3
#define MP3_STATE_FILE_HANDLE		4	
#define MP3_STATE_STREAM_START		5
#define MP3_STATE_STREAM_HANDLE		6
#define MP3_STATE_ERROR			7
#define MP3_STATE_SHUTDOWN		8
#define MP3_STATE_DEFAULT		9

#define MP3_EVENT_TIMEOUT		1
#define MP3_EVENT_FILE			2
#define MP3_EVENT_STREAM		3
#define MP3_EVENT_STOP			4
#define MP3_EVENT_ERROR			5
#define MP3_EVENT_SHUTDOWN		6
#define MP3_EVENT_END			7

#define MP3_EVENT_GENERIC_VOLUME	0
#define MP3_EVENT_GENERIC_STATE		1
#define MP3_EVENT_GENERIC_BASS		2
#define MP3_EVENT_GENERIC_PLAYTIME	3

void state_startup_enter(int state_last, int event, EVENT_PARAM *param);
void state_idle_enter(int state_last, int event, EVENT_PARAM *param);
void state_file_startup_enter(int state_last, int event, EVENT_PARAM *param);
void state_file_startup_leave(int state_new, int event);
void state_file_handle_enter(int state_last, int event, EVENT_PARAM *param);
void state_file_handle_leave(int state_new, int event);
void state_stream_startup_enter(int state_last, int event, EVENT_PARAM *param);
void state_stream_startup_leave(int state_last, int event);
void state_stream_handle_enter(int state_last, int event, EVENT_PARAM *param);
void state_stream_handle_leave(int state_new, int event);
void state_error_enter(int state_last, int event, EVENT_PARAM *param);
void state_shutdown_enter(int state_last, int event, EVENT_PARAM *param);
void state_generic_event(unsigned int event, unsigned char in_int, 
		unsigned char *out_uchar);