1433d6423SLionel Sambuc #include "log.h"
2433d6423SLionel Sambuc
3433d6423SLionel Sambuc /* State management variables. */
4433d6423SLionel Sambuc #define NR_DEVS 1 /* number of minor devices */
5433d6423SLionel Sambuc EXTERN struct logdevice logdevices[NR_DEVS];
6433d6423SLionel Sambuc
7433d6423SLionel Sambuc /* State management helpers. */
8433d6423SLionel Sambuc static int is_read_pending;
9433d6423SLionel Sambuc static int is_select_callback_pending;
load_state_info(void)10433d6423SLionel Sambuc static void load_state_info(void)
11433d6423SLionel Sambuc {
12433d6423SLionel Sambuc int i, found_pending;
13433d6423SLionel Sambuc struct logdevice *log;
14433d6423SLionel Sambuc
15433d6423SLionel Sambuc /* Check if reads or select callbacks are pending. */
16433d6423SLionel Sambuc is_read_pending = FALSE;
17433d6423SLionel Sambuc is_select_callback_pending = FALSE;
18433d6423SLionel Sambuc found_pending = FALSE;
19433d6423SLionel Sambuc for (i = 0; i < NR_DEVS && !found_pending; i++) {
20433d6423SLionel Sambuc log = &logdevices[i];
21433d6423SLionel Sambuc if(log->log_source != NONE) {
22433d6423SLionel Sambuc is_read_pending = TRUE;
23433d6423SLionel Sambuc }
24433d6423SLionel Sambuc if(log->log_selected) {
25433d6423SLionel Sambuc is_select_callback_pending = TRUE;
26433d6423SLionel Sambuc }
27433d6423SLionel Sambuc
28433d6423SLionel Sambuc found_pending = (is_read_pending && is_select_callback_pending);
29433d6423SLionel Sambuc }
30433d6423SLionel Sambuc }
31433d6423SLionel Sambuc
32433d6423SLionel Sambuc /* Custom states definition. */
33433d6423SLionel Sambuc #define LOG_STATE_SELECT_PROTOCOL_FREE (SEF_LU_STATE_CUSTOM_BASE + 0)
34433d6423SLionel Sambuc #define LOG_STATE_IS_CUSTOM(s) ((s) == LOG_STATE_SELECT_PROTOCOL_FREE)
35433d6423SLionel Sambuc
36433d6423SLionel Sambuc /*===========================================================================*
37433d6423SLionel Sambuc * sef_cb_lu_prepare *
38433d6423SLionel Sambuc *===========================================================================*/
sef_cb_lu_prepare(int state)39433d6423SLionel Sambuc int sef_cb_lu_prepare(int state)
40433d6423SLionel Sambuc {
41433d6423SLionel Sambuc int is_ready;
42433d6423SLionel Sambuc
43433d6423SLionel Sambuc /* Load state information. */
44433d6423SLionel Sambuc load_state_info();
45433d6423SLionel Sambuc
46433d6423SLionel Sambuc /* Check if we are ready for the target state. */
47433d6423SLionel Sambuc is_ready = FALSE;
48433d6423SLionel Sambuc switch(state) {
49433d6423SLionel Sambuc /* Standard states. */
50433d6423SLionel Sambuc case SEF_LU_STATE_REQUEST_FREE:
51433d6423SLionel Sambuc is_ready = (!is_read_pending);
52433d6423SLionel Sambuc break;
53433d6423SLionel Sambuc
54433d6423SLionel Sambuc case SEF_LU_STATE_PROTOCOL_FREE:
55433d6423SLionel Sambuc is_ready = (!is_read_pending && !is_select_callback_pending);
56433d6423SLionel Sambuc break;
57433d6423SLionel Sambuc
58433d6423SLionel Sambuc /* Custom states. */
59433d6423SLionel Sambuc case LOG_STATE_SELECT_PROTOCOL_FREE:
60433d6423SLionel Sambuc is_ready = (!is_select_callback_pending);
61433d6423SLionel Sambuc break;
62433d6423SLionel Sambuc }
63433d6423SLionel Sambuc
64433d6423SLionel Sambuc /* Tell SEF if we are ready. */
65433d6423SLionel Sambuc return is_ready ? OK : ENOTREADY;
66433d6423SLionel Sambuc }
67433d6423SLionel Sambuc
68433d6423SLionel Sambuc /*===========================================================================*
69433d6423SLionel Sambuc * sef_cb_lu_state_isvalid *
70433d6423SLionel Sambuc *===========================================================================*/
sef_cb_lu_state_isvalid(int state,int UNUSED (flags))71*e1f889d2SCristiano Giuffrida int sef_cb_lu_state_isvalid(int state, int UNUSED(flags))
72433d6423SLionel Sambuc {
73433d6423SLionel Sambuc return SEF_LU_STATE_IS_STANDARD(state) || LOG_STATE_IS_CUSTOM(state);
74433d6423SLionel Sambuc }
75433d6423SLionel Sambuc
76433d6423SLionel Sambuc /*===========================================================================*
77433d6423SLionel Sambuc * sef_cb_lu_state_dump *
78433d6423SLionel Sambuc *===========================================================================*/
sef_cb_lu_state_dump(int state)79433d6423SLionel Sambuc void sef_cb_lu_state_dump(int state)
80433d6423SLionel Sambuc {
81433d6423SLionel Sambuc /* Load state information. */
82433d6423SLionel Sambuc load_state_info();
83433d6423SLionel Sambuc
84433d6423SLionel Sambuc sef_lu_dprint("log: live update state = %d\n", state);
85433d6423SLionel Sambuc sef_lu_dprint("log: is_read_pending = %d\n", is_read_pending);
86433d6423SLionel Sambuc sef_lu_dprint("log: is_select_callback_pending = %d\n",
87433d6423SLionel Sambuc is_select_callback_pending);
88433d6423SLionel Sambuc
89433d6423SLionel Sambuc sef_lu_dprint("log: SEF_LU_STATE_WORK_FREE(%d) reached = %d\n",
90433d6423SLionel Sambuc SEF_LU_STATE_WORK_FREE, TRUE);
91433d6423SLionel Sambuc sef_lu_dprint("log: SEF_LU_STATE_REQUEST_FREE(%d) reached = %d\n",
92433d6423SLionel Sambuc SEF_LU_STATE_REQUEST_FREE, (!is_read_pending));
93433d6423SLionel Sambuc sef_lu_dprint("log: SEF_LU_STATE_PROTOCOL_FREE(%d) reached = %d\n",
94433d6423SLionel Sambuc SEF_LU_STATE_PROTOCOL_FREE, (!is_read_pending
95433d6423SLionel Sambuc && !is_select_callback_pending));
96433d6423SLionel Sambuc sef_lu_dprint("log: LOG_STATE_SELECT_PROTOCOL_FREE(%d) reached = %d\n",
97433d6423SLionel Sambuc LOG_STATE_SELECT_PROTOCOL_FREE, (!is_select_callback_pending));
98433d6423SLionel Sambuc }
99433d6423SLionel Sambuc
100