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 #ifndef INTELL_VOICE_TRIGGER_DB_HELPER_H
16 #define INTELL_VOICE_TRIGGER_DB_HELPER_H
17 #include <string>
18 #include <mutex>
19 
20 #include "rdb_errno.h"
21 #include "rdb_helper.h"
22 #include "rdb_open_callback.h"
23 #include "trigger_base_type.h"
24 
25 namespace OHOS {
26 namespace IntellVoiceTrigger {
27 class TriggerDbHelper {
28 public:
29     TriggerDbHelper();
30     ~TriggerDbHelper();
31     bool UpdateGenericTriggerModel(std::shared_ptr<GenericTriggerModel> model);
32     std::shared_ptr<GenericTriggerModel> GetGenericTriggerModel(const int32_t modelUuid);
33     void DeleteGenericTriggerModel(const int32_t modelUuid);
34 
35 private:
36     bool GetVendorUuid(std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &set, int32_t &vendorUuid) const;
37     bool GetBlob(std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &set, std::vector<uint8_t> &data) const;
38     bool GetModelVersion(std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &set, int32_t &version) const;
39     bool GetModelType(std::shared_ptr<OHOS::NativeRdb::AbsSharedResultSet> &set, int32_t &type) const;
40 
41 private:
42     std::mutex mutex_;
43     std::shared_ptr<OHOS::NativeRdb::RdbStore> store_ = nullptr;
44 };
45 }
46 }
47 #endif
48