1 /******************************************************************************
3 * Copyright (C) 2009-2012 Broadcom Corporation
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 ******************************************************************************/
19 /*****************************************************************************
23 * Description: Generic BTIF state machine API
25 *****************************************************************************/
30 /*****************************************************************************
32 ******************************************************************************/
34 /* Generic Enter/Exit state machine events */
35 #define BTIF_SM_ENTER_EVT 0xFFFF
36 #define BTIF_SM_EXIT_EVT 0xFFFE
39 /*****************************************************************************
40 ** Type definitions and return values
41 ******************************************************************************/
42 typedef UINT32 btif_sm_state_t;
43 typedef UINT32 btif_sm_event_t;
44 typedef void* btif_sm_handle_t;
45 typedef BOOLEAN(*btif_sm_handler_t)(btif_sm_event_t event, void *data);
48 /*****************************************************************************
51 ** NOTE: THESE APIs SHOULD BE INVOKED ONLY IN THE BTIF CONTEXT
53 ******************************************************************************/
55 /*****************************************************************************
57 ** Function btif_sm_init
59 ** Description Initializes the state machine with the state handlers
60 ** The caller should ensure that the table and the corresponding
61 ** states match. The location that 'p_handlers' points to shall
62 ** be available until the btif_sm_shutdown API is invoked.
64 ** Returns Returns a pointer to the initialized state machine handle.
66 ******************************************************************************/
67 btif_sm_handle_t btif_sm_init(const btif_sm_handler_t *p_handlers,
68 btif_sm_state_t initial_state);
70 /*****************************************************************************
72 ** Function btif_sm_shutdown
74 ** Description Tears down the state machine
78 ******************************************************************************/
79 void btif_sm_shutdown(btif_sm_handle_t handle);
81 /*****************************************************************************
83 ** Function btif_sm_get_state
85 ** Description Fetches the current state of the state machine
87 ** Returns Current state
89 ******************************************************************************/
90 btif_sm_state_t btif_sm_get_state(btif_sm_handle_t handle);
92 /*****************************************************************************
94 ** Function btif_sm_dispatch
96 ** Description Dispatches the 'event' along with 'data' to the current state handler
98 ** Returns Returns BT_STATUS_OK on success, BT_STATUS_FAIL otherwise
100 ******************************************************************************/
101 bt_status_t btif_sm_dispatch(btif_sm_handle_t handle, btif_sm_event_t event,
104 /*****************************************************************************
106 ** Function btif_sm_change_state
108 ** Description Make a transition to the new 'state'. The 'BTIF_SM_EXIT_EVT'
109 ** shall be invoked before exiting the current state. The
110 ** 'BTIF_SM_ENTER_EVT' shall be invoked before entering the new state
113 ** Returns Returns BT_STATUS_OK on success, BT_STATUS_FAIL otherwise
115 ******************************************************************************/
116 bt_status_t btif_sm_change_state(btif_sm_handle_t handle, btif_sm_state_t state);
118 #endif /* BTIF_SM_H */