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 "trigger_base_type.h"
16 #include "securec.h"
17 #include "intell_voice_log.h"
18
19 #define LOG_TAG "TriggerBaseType"
20
21 namespace OHOS {
22 namespace IntellVoiceTrigger {
TriggerModel(int32_t uuid,int32_t version,TriggerModelType type)23 TriggerModel::TriggerModel(int32_t uuid, int32_t version, TriggerModelType type)
24 : uuid_(uuid), version_(version), type_(type)
25 {}
26
~TriggerModel()27 TriggerModel::~TriggerModel()
28 {
29 }
30
SetData(const uint8_t * data,uint32_t size)31 bool TriggerModel::SetData(const uint8_t *data, uint32_t size)
32 {
33 if (size == 0) {
34 INTELL_VOICE_LOG_ERROR("size is invalid");
35 return false;
36 }
37 data_.resize(size);
38
39 if (memcpy_s(data_.data(), data_.size(), data, size) != 0) {
40 INTELL_VOICE_LOG_ERROR("memcpy_s error");
41 return false;
42 }
43 return true;
44 }
45
SetData(std::vector<uint8_t> & data)46 bool TriggerModel::SetData(std::vector<uint8_t> &data)
47 {
48 if (data.size() == 0) {
49 INTELL_VOICE_LOG_ERROR("size is invalid");
50 return false;
51 }
52 data_.swap(data);
53 return true;
54 }
55
Print()56 void TriggerModel::Print()
57 {
58 INTELL_VOICE_LOG_INFO("trigger model type:%{public}d", type_);
59 INTELL_VOICE_LOG_INFO("trigger model uuid:%{public}d", uuid_);
60 INTELL_VOICE_LOG_INFO("trigger model vendor uuid:%{public}d", vendorUuid_);
61 INTELL_VOICE_LOG_INFO("trigger model version:%{public}d", version_);
62 INTELL_VOICE_LOG_INFO("trigger model data size:%{public}zu", data_.size());
63 }
64 } // namespace IntellVoiceTrigger
65 } // namespace OHOS