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 #include "base/logging.h"     // LOG() stdout and android log
21 #include "osi/include/log.h"  // android log only
22 #include "stack/include/sdp_api.h"
23 #include "types/bluetooth/uuid.h"
24 #include "types/raw_address.h"
25 
26 using namespace bluetooth::test::headless;
27 
SdpDb(unsigned int max_records)28 SdpDb::SdpDb(unsigned int max_records) : max_records_(max_records) {
29   db_ = (tSDP_DISCOVERY_DB*)malloc(max_records_ * sizeof(tSDP_DISC_REC) +
30                                    sizeof(tSDP_DISCOVERY_DB));
31 }
32 
~SdpDb()33 SdpDb::~SdpDb() { free(db_); }
34 
RawPointer()35 tSDP_DISCOVERY_DB* SdpDb::RawPointer() { return db_; }
36 
Length() const37 uint32_t SdpDb::Length() const {
38   return max_records_ * sizeof(tSDP_DISC_REC) + sizeof(tSDP_DISCOVERY_DB);
39 }
40 
Print(FILE * filep) const41 void SdpDb::Print(FILE* filep) const {
42   fprintf(filep, "memory size:0x%x free:0x%x\n", db_->mem_size, db_->mem_free);
43   fprintf(filep, "number of filters:%hd\n", db_->num_uuid_filters);
44   for (int i = 0; i < db_->num_uuid_filters; i++) {
45     fprintf(filep, "  uuid:%s\n", db_->uuid_filters[i].ToString().c_str());
46   }
47   fprintf(filep, "raw data size:0x%x used:0x%x\n", db_->raw_size,
48           db_->raw_used);
49 }
50