1 /*
2  * Copyright 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define LOG_TAG "bt_headless"
18 
19 #include "test/headless/sdp/sdp_db.h"
20 
21 #include "stack/include/sdp_api.h"
22 #include "types/bluetooth/uuid.h"
23 
24 using namespace bluetooth::test::headless;
25 
SdpDb(unsigned int max_records)26 SdpDb::SdpDb(unsigned int max_records) : max_records_(max_records) {
27   db_ = (tSDP_DISCOVERY_DB*)malloc(max_records_ * sizeof(tSDP_DISC_REC) +
28                                    sizeof(tSDP_DISCOVERY_DB));
29 }
30 
~SdpDb()31 SdpDb::~SdpDb() { free(db_); }
32 
RawPointer()33 tSDP_DISCOVERY_DB* SdpDb::RawPointer() { return db_; }
34 
Length() const35 uint32_t SdpDb::Length() const {
36   return max_records_ * sizeof(tSDP_DISC_REC) + sizeof(tSDP_DISCOVERY_DB);
37 }
38 
Print(FILE * filep) const39 void SdpDb::Print(FILE* filep) const {
40   fprintf(filep, "memory size:0x%x free:0x%x\n", db_->mem_size, db_->mem_free);
41   fprintf(filep, "number of filters:%hd\n", db_->num_uuid_filters);
42   for (int i = 0; i < db_->num_uuid_filters; i++) {
43     fprintf(filep, "  uuid:%s\n", db_->uuid_filters[i].ToString().c_str());
44   }
45   fprintf(filep, "raw data size:0x%x used:0x%x\n", db_->raw_size,
46           db_->raw_used);
47 }
48