1 /******************************************************************************
2 *
3 * Copyright (C) 2014 Google, Inc.
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 #include "base.h"
20 #include "support/adapter.h"
21 #include "support/callbacks.h"
22 #include "support/property.h"
23
24 static bt_state_t state;
25 static int property_count = 0;
26 static bt_property_t *properties = NULL;
27 static bt_discovery_state_t discovery_state;
28
adapter_get_state()29 bt_state_t adapter_get_state() {
30 return state;
31 }
32
adapter_get_property_count()33 int adapter_get_property_count() {
34 return property_count;
35 }
36
adapter_get_property(bt_property_type_t type)37 bt_property_t *adapter_get_property(bt_property_type_t type) {
38 for (int i = 0; i < property_count; ++i) {
39 if (properties[i].type == type) {
40 return &properties[i];
41 }
42 }
43
44 return NULL;
45 }
46
adapter_get_discovery_state()47 bt_discovery_state_t adapter_get_discovery_state() {
48 return discovery_state;
49 }
50
51 // callback
adapter_state_changed(bt_state_t new_state)52 void adapter_state_changed(bt_state_t new_state) {
53 state = new_state;
54 CALLBACK_RET();
55 }
56
57 // callback
adapter_properties(bt_status_t status,int num_properties,bt_property_t * new_properties)58 void adapter_properties(bt_status_t status,
59 int num_properties,
60 bt_property_t *new_properties) {
61 property_free_array(properties, property_count);
62 properties = property_copy_array(new_properties, num_properties);
63 property_count = num_properties;
64
65 CALLBACK_RET();
66 }
67
68 // callback
discovery_state_changed(bt_discovery_state_t state)69 void discovery_state_changed(bt_discovery_state_t state) {
70 discovery_state = state;
71 CALLBACK_RET();
72 }
73