OSDN Git Service

Replace BT_HDR => BT_HDR_RIGID
[android-x86/system-bt.git] / bta / dm / bta_dm_main.cc
1 /******************************************************************************
2  *
3  *  Copyright 2003-2012 Broadcom Corporation
4  *
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:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  ******************************************************************************/
18
19 /******************************************************************************
20  *
21  *  This is the main implementation file for the BTA device manager.
22  *
23  ******************************************************************************/
24
25 #include "bt_trace.h"
26 #include "bta/dm/bta_dm_int.h"
27 #include "stack/include/bt_types.h"
28
29 /*****************************************************************************
30  * Constants and types
31  ****************************************************************************/
32
33 tBTA_DM_CB bta_dm_cb;
34 tBTA_DM_SEARCH_CB bta_dm_search_cb;
35 tBTA_DM_DI_CB bta_dm_di_cb;
36
37 /*******************************************************************************
38  *
39  * Function         bta_dm_sm_search_disable
40  *
41  * Description     unregister BTA SEARCH DM
42  *
43  *
44  * Returns          void
45  *
46  ******************************************************************************/
47 void bta_dm_search_sm_disable() { bta_sys_deregister(BTA_ID_DM_SEARCH); }
48
49 void bta_dm_search_set_state(uint8_t state) { bta_dm_search_cb.state = state; }
50 uint8_t bta_dm_search_get_state() { return bta_dm_search_cb.state; }
51
52 /*******************************************************************************
53  *
54  * Function         bta_dm_search_sm_execute
55  *
56  * Description      State machine event handling function for DM
57  *
58  *
59  * Returns          void
60  *
61  ******************************************************************************/
62 bool bta_dm_search_sm_execute(BT_HDR_RIGID* p_msg) {
63   APPL_TRACE_EVENT("bta_dm_search_sm_execute state:%d, event:0x%x",
64                    bta_dm_search_cb.state, p_msg->event);
65
66   tBTA_DM_MSG* message = (tBTA_DM_MSG*)p_msg;
67   switch (bta_dm_search_cb.state) {
68     case BTA_DM_SEARCH_IDLE:
69       switch (p_msg->event) {
70         case BTA_DM_API_SEARCH_EVT:
71           bta_dm_search_set_state(BTA_DM_SEARCH_ACTIVE);
72           bta_dm_search_start(message);
73           break;
74         case BTA_DM_API_DISCOVER_EVT:
75           bta_dm_search_set_state(BTA_DM_DISCOVER_ACTIVE);
76           bta_dm_discover(message);
77           break;
78         case BTA_DM_SDP_RESULT_EVT:
79           bta_dm_free_sdp_db();
80           break;
81         case BTA_DM_DISC_CLOSE_TOUT_EVT:
82           bta_dm_close_gatt_conn(message);
83           break;
84       }
85       break;
86     case BTA_DM_SEARCH_ACTIVE:
87       switch (p_msg->event) {
88         case BTA_DM_REMT_NAME_EVT:
89           bta_dm_rmt_name(message);
90           break;
91         case BTA_DM_SDP_RESULT_EVT:
92           bta_dm_sdp_result(message);
93           break;
94         case BTA_DM_SEARCH_CMPL_EVT:
95           bta_dm_search_cmpl();
96           break;
97         case BTA_DM_DISCOVERY_RESULT_EVT:
98           bta_dm_search_result(message);
99           break;
100         case BTA_DM_DISC_CLOSE_TOUT_EVT:
101           bta_dm_close_gatt_conn(message);
102           break;
103       }
104       break;
105     case BTA_DM_SEARCH_CANCELLING:
106       switch (p_msg->event) {
107         case BTA_DM_API_SEARCH_EVT:
108           bta_dm_queue_search(message);
109           break;
110         case BTA_DM_API_DISCOVER_EVT:
111           bta_dm_queue_disc(message);
112           break;
113         case BTA_DM_SDP_RESULT_EVT:
114         case BTA_DM_REMT_NAME_EVT:
115         case BTA_DM_SEARCH_CMPL_EVT:
116         case BTA_DM_DISCOVERY_RESULT_EVT:
117           bta_dm_search_set_state(BTA_DM_SEARCH_IDLE);
118           bta_dm_free_sdp_db();
119           bta_dm_search_cancel_notify();
120           bta_dm_search_cancel_cmpl();
121           break;
122       }
123       break;
124     case BTA_DM_DISCOVER_ACTIVE:
125       switch (p_msg->event) {
126         case BTA_DM_REMT_NAME_EVT:
127           bta_dm_disc_rmt_name(message);
128           break;
129         case BTA_DM_SDP_RESULT_EVT:
130           bta_dm_sdp_result(message);
131           break;
132         case BTA_DM_SEARCH_CMPL_EVT:
133           bta_dm_search_cmpl();
134           break;
135         case BTA_DM_DISCOVERY_RESULT_EVT:
136           bta_dm_disc_result(message);
137           break;
138       }
139       break;
140   }
141   return true;
142 }