blob: b11cf7f2fdceb56bf8004e1a5574851b565cad23 [file] [log] [blame]
Sharvil Nanavati3cf59ef2014-04-09 22:20:40 -07001/******************************************************************************
2 *
Jakub Pawlowski5b790fe2017-09-18 09:00:20 -07003 * Copyright 2014 Google, Inc.
Sharvil Nanavati3cf59ef2014-04-09 22:20:40 -07004 *
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
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -070021#include <bluetooth/uuid.h>
Chris Manton5c262242014-10-14 22:00:32 -070022#include <hardware/bluetooth.h>
Chris Manton97c54442015-01-07 13:34:18 -080023#include <stdint.h>
Chris Manton5c262242014-10-14 22:00:32 -070024#include <stdlib.h>
Sharvil Nanavati3cf59ef2014-04-09 22:20:40 -070025
Chris Manton97c54442015-01-07 13:34:18 -080026#include "btcore/include/device_class.h"
27
Chris Manton3252cf02015-01-08 10:47:59 -080028// Copies an array of consecutive properties of |count| to a newly
29// allocated array. |properties| must not be NULL.
Myles Watson911d1ae2016-11-28 16:44:40 -080030bt_property_t* property_copy_array(const bt_property_t* properties,
31 size_t count);
Chris Manton3252cf02015-01-08 10:47:59 -080032
33// Copies |src| to |dest|. Returns the value of |dest|.
34// |src| and |dest| must not be NULL.
Myles Watson911d1ae2016-11-28 16:44:40 -080035bt_property_t* property_copy(bt_property_t* dest, const bt_property_t* src);
Chris Manton97c54442015-01-07 13:34:18 -080036
Chris Manton3252cf02015-01-08 10:47:59 -080037// Returns true if the value of the two properties |p1| and |p2| are equal.
38// |p1| and |p2| must not be NULL.
Myles Watson911d1ae2016-11-28 16:44:40 -080039bool property_equals(const bt_property_t* p1, const bt_property_t* p2);
Sharvil Nanavati3cf59ef2014-04-09 22:20:40 -070040
Chris Manton3252cf02015-01-08 10:47:59 -080041// Property resource allocations. Caller is expected to free |property|
42// using |property_free| or |property_free_array|.
43// Parameter must not be NULL. A copy of the parameter is made and
44// stored in the property.
Jakub Pawlowskia484a882017-06-24 17:30:18 -070045bt_property_t* property_new_addr(const RawAddress* addr);
Myles Watson911d1ae2016-11-28 16:44:40 -080046bt_property_t* property_new_device_class(const bt_device_class_t* dc);
47bt_property_t* property_new_device_type(bt_device_type_t device_type);
48bt_property_t* property_new_discovery_timeout(const uint32_t timeout);
49bt_property_t* property_new_name(const char* name);
50bt_property_t* property_new_rssi(const int8_t rssi);
51bt_property_t* property_new_scan_mode(bt_scan_mode_t scan_mode);
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -070052bt_property_t* property_new_uuids(const bluetooth::Uuid* uuid, size_t count);
Chris Manton3252cf02015-01-08 10:47:59 -080053
54// Property resource frees both property and value.
Myles Watson911d1ae2016-11-28 16:44:40 -080055void property_free(bt_property_t* property);
56void property_free_array(bt_property_t* properties, size_t count);
Chris Manton3252cf02015-01-08 10:47:59 -080057
58// Value check convenience methods. The contents of the property are
59// checked for the respective validity and returns true, false otherwise.
60// |property| must not be NULL.
Myles Watson911d1ae2016-11-28 16:44:40 -080061bool property_is_addr(const bt_property_t* property);
62bool property_is_device_class(const bt_property_t* property);
63bool property_is_device_type(const bt_property_t* property);
64bool property_is_discovery_timeout(const bt_property_t* property);
65bool property_is_name(const bt_property_t* property);
66bool property_is_rssi(const bt_property_t* property);
67bool property_is_scan_mode(const bt_property_t* property);
68bool property_is_uuids(const bt_property_t* property);
Chris Manton3252cf02015-01-08 10:47:59 -080069
70// Value conversion convenience methods. The contents of the property are
71// properly typed and returned to the caller. |property| must not be NULL.
Jakub Pawlowskia484a882017-06-24 17:30:18 -070072const RawAddress* property_as_addr(const bt_property_t* property);
Myles Watson911d1ae2016-11-28 16:44:40 -080073const bt_device_class_t* property_as_device_class(
74 const bt_property_t* property);
75bt_device_type_t property_as_device_type(const bt_property_t* property);
76uint32_t property_as_discovery_timeout(const bt_property_t* property);
77const bt_bdname_t* property_as_name(const bt_property_t* property);
78int8_t property_as_rssi(const bt_property_t* property);
79bt_scan_mode_t property_as_scan_mode(const bt_property_t* property);
Jakub Pawlowski819e2ec2017-07-10 09:56:09 -070080const bluetooth::Uuid* property_as_uuids(const bt_property_t* property,
81 size_t* count);