1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #include "history_info_mgr.h"
16
17 #include "string_util.h"
18
19 #define LOG_TAG "HistoryInfoMgr"
20
21 namespace OHOS {
22 namespace IntellVoiceUtils {
23 constexpr int DECIMAL_NOTATION = 10;
24
HistoryInfoMgr()25 HistoryInfoMgr::HistoryInfoMgr()
26 : ServiceDbHelper("intell_voice_service_manager", "local_intell_voice_history_mgr_storeId")
27 {
28 }
29
SetIntKVPair(std::string key,int32_t value)30 void HistoryInfoMgr::SetIntKVPair(std::string key, int32_t value)
31 {
32 SetValue(key, StringUtil::Int2String(value));
33 }
34
GetIntKVPair(std::string key)35 int32_t HistoryInfoMgr::GetIntKVPair(std::string key)
36 {
37 std::string value = GetValue(key);
38 return static_cast<int32_t>(strtol(value.c_str(), nullptr, DECIMAL_NOTATION));
39 }
40
SetStringKVPair(std::string key,std::string value)41 void HistoryInfoMgr::SetStringKVPair(std::string key, std::string value)
42 {
43 SetValue(key, value);
44 }
45
GetStringKVPair(std::string key)46 std::string HistoryInfoMgr::GetStringKVPair(std::string key)
47 {
48 return GetValue(key);
49 }
50
DeleteKey(const std::vector<std::string> & keyList)51 void HistoryInfoMgr::DeleteKey(const std::vector<std::string> &keyList)
52 {
53 for (auto key : keyList) {
54 Delete(key);
55 }
56 }
57 }
58 }