AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
SQLiteBluetoothStorage.h
Go to the documentation of this file.
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
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  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0/
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 #ifndef ACSDKBLUETOOTH_SQLITEBLUETOOTHSTORAGE_H_
16 #define ACSDKBLUETOOTH_SQLITEBLUETOOTHSTORAGE_H_
17 
18 #include <mutex>
19 #include <unordered_map>
20 #include <unordered_set>
21 #include <vector>
22 
28 
29 namespace alexaClientSDK {
30 namespace acsdkBluetooth {
31 
34 public:
42  static std::shared_ptr<BluetoothStorageInterface> createBluetoothStorageInterface(
43  const std::shared_ptr<avsCommon::utils::configuration::ConfigurationNode>& configurationRoot);
44 
53  static std::unique_ptr<SQLiteBluetoothStorage> create(
55 
58  bool createDatabase() override;
59  bool open() override;
60  void close() override;
61  bool clear() override;
62  bool getUuid(const std::string& mac, std::string* uuid) override;
63  bool getCategory(const std::string& uuid, std::string* category) override;
64  bool getMac(const std::string& uuid, std::string* mac) override;
65  bool getMacToUuid(std::unordered_map<std::string, std::string>* macToUuid) override;
66  bool getMacToCategory(std::unordered_map<std::string, std::string>* macToCategory) override;
67  bool getUuidToMac(std::unordered_map<std::string, std::string>* uuidToMac) override;
68  bool getUuidToCategory(std::unordered_map<std::string, std::string>* uuidToCategory) override;
69  bool getOrderedMac(bool ascending, std::list<std::string>* macs) override;
70  bool insertByMac(const std::string& mac, const std::string& uuid, bool overwrite = true) override;
71  bool updateByCategory(const std::string& uuid, const std::string& category) override;
72  bool remove(const std::string& mac) override;
74 
75 private:
81  SQLiteBluetoothStorage(const std::string& filepath);
82 
86  void closeLocked();
87 
97  bool getSingleRowLocked(
98  std::unique_ptr<storage::sqliteStorage::SQLiteStatement>& statement,
99  std::unordered_map<std::string, std::string>* row);
100 
111  bool getMappingsLocked(
112  const std::string& key,
113  const std::string& value,
114  std::unordered_map<std::string, std::string>* mappings);
115 
126  bool getAssociatedDataLocked(
127  const std::string& constraintKey,
128  const std::string& constraintVal,
129  const std::string& resultKey,
130  std::string* resultVal);
131 
142  bool updateValueLocked(
143  const std::string& constraintKey,
144  const std::string& constraintVal,
145  const std::string& updateKey,
146  const std::string& updateVal);
147 
158  bool insertEntryLocked(
159  const std::string& operation,
160  const std::string& uuid,
161  const std::string& mac,
162  const std::string& category);
163 
169  bool isDatabaseMigratedLocked();
170 
177  bool migrateDatabaseLocked();
178 
180  std::mutex m_databaseMutex;
181 
184 };
185 
186 } // namespace acsdkBluetooth
187 } // namespace alexaClientSDK
188 
189 #endif // ACSDKBLUETOOTH_SQLITEBLUETOOTHSTORAGE_H_
bool getUuidToCategory(std::unordered_map< std::string, std::string > *uuidToCategory) override
bool getUuid(const std::string &mac, std::string *uuid) override
::std::string string
Definition: gtest-port.h:1097
bool getMacToCategory(std::unordered_map< std::string, std::string > *macToCategory) override
bool getMacToUuid(std::unordered_map< std::string, std::string > *macToUuid) override
A concrete implementation of BluetoothStorageInterface using SQLite.
Definition: SQLiteBluetoothStorage.h:33
bool insertByMac(const std::string &mac, const std::string &uuid, bool overwrite=true) override
bool getOrderedMac(bool ascending, std::list< std::string > *macs) override
A storage interface used for Bluetooth that should provide UUID to MAC mappings and maintain insertio...
Definition: BluetoothStorageInterface.h:26
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
static std::shared_ptr< BluetoothStorageInterface > createBluetoothStorageInterface(const std::shared_ptr< avsCommon::utils::configuration::ConfigurationNode > &configurationRoot)
bool getMac(const std::string &uuid, std::string *mac) override
static std::unique_ptr< SQLiteBluetoothStorage > create(const avsCommon::utils::configuration::ConfigurationNode &configurationRoot)
bool getCategory(const std::string &uuid, std::string *category) override
bool updateByCategory(const std::string &uuid, const std::string &category) override
bool getUuidToMac(std::unordered_map< std::string, std::string > *uuidToMac) override
void close() override
Close the database.
static const std::string key
The database key to be used by the protocol given the METADATA object.
Definition: SharedAVSSettingProtocolTest.cpp:58

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0