• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #pragma once
18 
19 #include <map>
20 #include <unordered_set>
21 
22 #include "common/lru.h"
23 #include "osi/include/config.h"
24 #include "osi/include/log.h"
25 #include "raw_address.h"
26 
27 class BtifConfigCache {
28  public:
29   explicit BtifConfigCache(size_t capacity);
30   ~BtifConfigCache();
31 
32   void Clear();
33   void Init(std::unique_ptr<config_t> source);
34   const std::list<section_t>& GetPersistentSections();
35   config_t PersistentSectionCopy();
36   bool HasSection(const std::string& section_name);
37   bool HasUnpairedSection(const std::string& section_name);
38   bool HasPersistentSection(const std::string& section_name);
39   bool HasKey(const std::string& section_name, const std::string& key);
40   bool RemoveKey(const std::string& section_name, const std::string& key);
41   void RemovePersistentSectionsWithKey(const std::string& key);
42 
43   // Setters and getters
44   void SetString(std::string section_name, std::string key, std::string value);
45   std::optional<std::string> GetString(const std::string& section_name,
46                                        const std::string& key);
47   void SetInt(std::string section_name, std::string key, int value);
48   std::optional<int> GetInt(const std::string& section_name,
49                             const std::string& key);
50   void SetUint64(std::string section_name, std::string key, uint64_t value);
51   std::optional<uint64_t> GetUint64(const std::string& section_name,
52                                     const std::string& key);
53   void SetBool(std::string section_name, std::string key, bool value);
54   std::optional<bool> GetBool(const std::string& section_name,
55                               const std::string& key);
56 
57  private:
58   bluetooth::common::LruCache<std::string, section_t> unpaired_devices_cache_;
59   config_t paired_devices_list_;
60 };
61