AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
SQLiteMiscStorage.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 
16 #ifndef ALEXA_CLIENT_SDK_STORAGE_SQLITESTORAGE_INCLUDE_SQLITESTORAGE_SQLITEMISCSTORAGE_H_
17 #define ALEXA_CLIENT_SDK_STORAGE_SQLITESTORAGE_INCLUDE_SQLITESTORAGE_SQLITEMISCSTORAGE_H_
18 
19 #include <mutex>
20 
24 
25 namespace alexaClientSDK {
26 namespace storage {
27 namespace sqliteStorage {
28 
33 public:
41  static std::shared_ptr<avsCommon::sdkInterfaces::storage::MiscStorageInterface> createMiscStorageInterface(
42  const std::shared_ptr<avsCommon::utils::configuration::ConfigurationNode>& configurationRoot);
43 
52  static std::unique_ptr<SQLiteMiscStorage> create(
54 
63  static std::unique_ptr<SQLiteMiscStorage> create(const std::string& databasePath);
64 
69 
72  bool createDatabase() override;
73  bool open() override;
74  bool isOpened() override;
75  void close() override;
76  bool createTable(
78  const std::string& tableName,
79  KeyType keyType,
80  ValueType valueType) override;
81  bool clearTable(const std::string& componentName, const std::string& tableName) override;
82  bool deleteTable(const std::string& componentName, const std::string& tableName) override;
83  bool get(const std::string& componentName, const std::string& tableName, const std::string& key, std::string* value)
84  override;
85  bool add(
86  const std::string& componentName,
87  const std::string& tableName,
88  const std::string& key,
89  const std::string& value) override;
90  bool update(
91  const std::string& componentName,
92  const std::string& tableName,
93  const std::string& key,
94  const std::string& value) override;
95  bool put(
96  const std::string& componentName,
97  const std::string& tableName,
98  const std::string& key,
99  const std::string& value) override;
100  bool remove(const std::string& componentName, const std::string& tableName, const std::string& key) override;
101  bool tableEntryExists(
102  const std::string& componentName,
103  const std::string& tableName,
104  const std::string& key,
105  bool* tableEntryExistsValue) override;
106  bool tableExists(const std::string& componentName, const std::string& tableName, bool* tableExistsValue) override;
107  bool load(
108  const std::string& componentName,
109  const std::string& tableName,
110  std::unordered_map<std::string, std::string>* valueContainer) override;
112 
123 
124 private:
130  SQLiteMiscStorage(const std::string& dbFilePath);
131 
141  bool getKeyValueTypesLocked(
142  const std::string& componentName,
143  const std::string& tableName,
144  KeyType* keyType,
145  ValueType* valueType);
146 
155  std::string checkKeyTypeLocked(const std::string& componentName, const std::string& tableName, KeyType keyType);
156 
165  std::string checkValueTypeLocked(
166  const std::string& componentName,
167  const std::string& tableName,
168  ValueType valueType);
169 
179  std::string checkKeyValueTypeLocked(
180  const std::string& componentName,
181  const std::string& tableName,
182  KeyType keyType,
183  ValueType valueType);
184 
195  bool createDatabaseLocked();
196 
206  bool openLocked();
207 
215  bool isOpenedLocked();
216 
222  void closeLocked();
223 
236  bool createTableLocked(
237  const std::string& componentName,
238  const std::string& tableName,
239  KeyType keyType,
240  ValueType valueType);
241 
251  bool clearTableLocked(const std::string& componentName, const std::string& tableName);
252 
263  bool deleteTableLocked(const std::string& componentName, const std::string& tableName);
264 
276  bool getLocked(
277  const std::string& componentName,
278  const std::string& tableName,
279  const std::string& key,
280  std::string* value);
281 
294  bool addLocked(
295  const std::string& componentName,
296  const std::string& tableName,
297  const std::string& key,
298  const std::string& value);
299 
311  bool updateLocked(
312  const std::string& componentName,
313  const std::string& tableName,
314  const std::string& key,
315  const std::string& value);
316 
331  bool putLocked(
332  const std::string& componentName,
333  const std::string& tableName,
334  const std::string& key,
335  const std::string& value);
336 
347  bool removeLocked(const std::string& componentName, const std::string& tableName, const std::string& key);
348 
360  bool tableEntryExistsLocked(
361  const std::string& componentName,
362  const std::string& tableName,
363  const std::string& key,
364  bool* tableEntryExistsValue);
365 
376  bool tableExistsLocked(const std::string& componentName, const std::string& tableName, bool* tableExistsValue);
377 
388  bool loadLocked(
389  const std::string& componentName,
390  const std::string& tableName,
391  std::unordered_map<std::string, std::string>* valueContainer);
392 
395 
397  std::mutex m_mutex;
398 };
399 
400 } // namespace sqliteStorage
401 } // namespace storage
402 } // namespace alexaClientSDK
403 
404 #endif // ALEXA_CLIENT_SDK_STORAGE_SQLITESTORAGE_INCLUDE_SQLITESTORAGE_SQLITEMISCSTORAGE_H_
ValueType
The type of the value column in Misc DB.
Definition: MiscStorageInterface.h:44
static std::shared_ptr< avsCommon::sdkInterfaces::storage::MiscStorageInterface > createMiscStorageInterface(const std::shared_ptr< avsCommon::utils::configuration::ConfigurationNode > &configurationRoot)
bool update(const std::string &componentName, const std::string &tableName, const std::string &key, const std::string &value) override
SQLiteDatabase & getDatabase()
Provides reference to a database.
::std::string string
Definition: gtest-port.h:1097
bool add(const std::string &componentName, const std::string &tableName, const std::string &key, const std::string &value) override
static std::unique_ptr< SQLiteMiscStorage > create(const avsCommon::utils::configuration::ConfigurationNode &configurationRoot)
static const std::string tableName
Definition: SmartScreenCaptionStateManagerTest.cpp:30
bool deleteTable(const std::string &componentName, const std::string &tableName) override
bool clearTable(const std::string &componentName, const std::string &tableName) override
bool tableEntryExists(const std::string &componentName, const std::string &tableName, const std::string &key, bool *tableEntryExistsValue) override
bool put(const std::string &componentName, const std::string &tableName, const std::string &key, const std::string &value) override
KeyType
The type of the key column in Misc DB.
Definition: MiscStorageInterface.h:36
bool load(const std::string &componentName, const std::string &tableName, std::unordered_map< std::string, std::string > *valueContainer) override
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
static const std::string componentName
Definition: SmartScreenCaptionStateManagerTest.cpp:29
bool tableExists(const std::string &componentName, const std::string &tableName, bool *tableExistsValue) override
bool createTable(const std::string &componentName, const std::string &tableName, KeyType keyType, ValueType valueType) override
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