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 #include <hardware/bluetooth.h>
32 #include "stack/include/bt_types.h"
34 /*****************************************************************************
36 ******************************************************************************/
38 /* Generic Enter/Exit state machine events */
39 #define BTIF_SM_ENTER_EVT 0xFFFF
40 #define BTIF_SM_EXIT_EVT 0xFFFE
42 /*****************************************************************************
43 ** Type definitions and return values
44 ******************************************************************************/
45 typedef UINT32 btif_sm_state_t;
46 typedef UINT32 btif_sm_event_t;
47 typedef void* btif_sm_handle_t;
48 typedef BOOLEAN(*btif_sm_handler_t)(btif_sm_event_t event, void *data);
50 /*****************************************************************************
53 ** NOTE: THESE APIs SHOULD BE INVOKED ONLY IN THE BTIF CONTEXT
55 ******************************************************************************/
57 /*****************************************************************************
59 ** Function btif_sm_init
61 ** Description Initializes the state machine with the state handlers
62 ** The caller should ensure that the table and the corresponding
63 ** states match. The location that 'p_handlers' points to shall
64 ** be available until the btif_sm_shutdown API is invoked.
66 ** Returns Returns a pointer to the initialized state machine handle.
68 ******************************************************************************/
69 btif_sm_handle_t btif_sm_init(const btif_sm_handler_t *p_handlers,
70 btif_sm_state_t initial_state);
72 /*****************************************************************************
74 ** Function btif_sm_shutdown
76 ** Description Tears down the state machine
80 ******************************************************************************/
81 void btif_sm_shutdown(btif_sm_handle_t handle);
83 /*****************************************************************************
85 ** Function btif_sm_get_state
87 ** Description Fetches the current state of the state machine
89 ** Returns Current state
91 ******************************************************************************/
92 btif_sm_state_t btif_sm_get_state(btif_sm_handle_t handle);
94 /*****************************************************************************
96 ** Function btif_sm_dispatch
98 ** Description Dispatches the 'event' along with 'data' to the current state handler
100 ** Returns Returns BT_STATUS_OK on success, BT_STATUS_FAIL otherwise
102 ******************************************************************************/
103 bt_status_t btif_sm_dispatch(btif_sm_handle_t handle, btif_sm_event_t event,
106 /*****************************************************************************
108 ** Function btif_sm_change_state
110 ** Description Make a transition to the new 'state'. The 'BTIF_SM_EXIT_EVT'
111 ** shall be invoked before exiting the current state. The
112 ** 'BTIF_SM_ENTER_EVT' shall be invoked before entering the new state
115 ** Returns Returns BT_STATUS_OK on success, BT_STATUS_FAIL otherwise
117 ******************************************************************************/
118 bt_status_t btif_sm_change_state(btif_sm_handle_t handle, btif_sm_state_t state);
120 #endif /* BTIF_SM_H */