• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #pragma once
20 
21 #include <hardware/bluetooth.h>
22 #include <stdint.h>
23 #include <stdlib.h>
24 
25 #include "btcore/include/device_class.h"
26 
27 // Copies an array of consecutive properties of |count| to a newly
28 // allocated array. |properties| must not be NULL.
29 bt_property_t *property_copy_array(const bt_property_t *properties, size_t count);
30 
31 // Copies |src| to |dest|. Returns the value of |dest|.
32 // |src| and |dest| must not be NULL.
33 bt_property_t *property_copy(bt_property_t *dest, const bt_property_t *src);
34 
35 // Returns true if the value of the two properties |p1| and |p2| are equal.
36 // |p1| and |p2| must not be NULL.
37 bool property_equals(const bt_property_t *p1, const bt_property_t *p2);
38 
39 // Property resource allocations. Caller is expected to free |property|
40 // using |property_free| or |property_free_array|.
41 // Parameter must not be NULL. A copy of the parameter is made and
42 // stored in the property.
43 bt_property_t *property_new_addr(const bt_bdaddr_t *addr);
44 bt_property_t *property_new_device_class(const bt_device_class_t *dc);
45 bt_property_t *property_new_device_type(bt_device_type_t device_type);
46 bt_property_t *property_new_discovery_timeout(const uint32_t timeout);
47 bt_property_t *property_new_name(const char *name);
48 bt_property_t *property_new_rssi(const int8_t rssi);
49 bt_property_t *property_new_scan_mode(bt_scan_mode_t scan_mode);
50 bt_property_t *property_new_uuids(const bt_uuid_t *uuid, size_t count);
51 
52 // Property resource frees both property and value.
53 void property_free(bt_property_t *property);
54 void property_free_array(bt_property_t *properties, size_t count);
55 
56 // Value check convenience methods. The contents of the property are
57 // checked for the respective validity and returns true, false otherwise.
58 // |property| must not be NULL.
59 bool property_is_addr(const bt_property_t *property);
60 bool property_is_device_class(const bt_property_t *property);
61 bool property_is_device_type(const bt_property_t *property);
62 bool property_is_discovery_timeout(const bt_property_t *property);
63 bool property_is_name(const bt_property_t *property);
64 bool property_is_rssi(const bt_property_t *property);
65 bool property_is_scan_mode(const bt_property_t *property);
66 bool property_is_uuids(const bt_property_t *property);
67 
68 // Value conversion convenience methods. The contents of the property are
69 // properly typed and returned to the caller. |property| must not be NULL.
70 const bt_bdaddr_t *property_as_addr(const bt_property_t *property);
71 const bt_device_class_t *property_as_device_class(const bt_property_t *property);
72 bt_device_type_t property_as_device_type(const bt_property_t *property);
73 uint32_t property_as_discovery_timeout(const bt_property_t *property);
74 const bt_bdname_t *property_as_name(const bt_property_t *property);
75 int8_t property_as_rssi(const bt_property_t *property);
76 bt_scan_mode_t property_as_scan_mode(const bt_property_t *property);
77 const bt_uuid_t *property_as_uuids(const bt_property_t *property, size_t *count);
78