• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 
16 #include "asset_adapter.h"
17 
18 #include "distributed_device_profile_errors.h"
19 #include "distributed_device_profile_log.h"
20 
21 namespace OHOS {
22 namespace DistributedDeviceProfile {
23 IMPLEMENT_SINGLE_INSTANCE(AssetAdapter);
24 namespace {
25     const std::string TAG = "AssetAdapter";
26 }
27 
PutAsset(const AssetAttr * attr,uint32_t attrCnt)28 int32_t AssetAdapter::PutAsset(const AssetAttr *attr, uint32_t attrCnt)
29 {
30     int32_t ret = AssetAdd(attr, attrCnt);
31     if (ret == SEC_ASSET_DUPLICATED) {
32         HILOGE("add duplicated");
33         return DP_ASSET_DUPLICATED;
34     }
35     if (ret != SEC_ASSET_SUCCESS) {
36         HILOGE("asset add fail, error code is %{public}d", ret);
37         return DP_PUT_ASSET_ERROR;
38     }
39     return DP_SUCCESS;
40 }
41 
UpdateAsset(const AssetAttr * query,uint32_t queryCnt,const AssetAttr * attrToUpdate,uint32_t updateCnt)42 int32_t AssetAdapter::UpdateAsset(const AssetAttr* query, uint32_t queryCnt,
43     const AssetAttr* attrToUpdate, uint32_t updateCnt)
44 {
45     int32_t ret = AssetUpdate(query, queryCnt, attrToUpdate, updateCnt);
46     if (ret == SEC_ASSET_NOT_FOUND) {
47         HILOGE("not find asset");
48         return DP_GET_ASSET_NOT_FIND;
49     }
50     if (ret != SEC_ASSET_SUCCESS) {
51         HILOGE("asset update fail, error code is %{public}d", ret);
52         return DP_UPDATE_ASSET_ERROR;
53     }
54     return DP_SUCCESS;
55 }
56 
GetAsset(const AssetAttr * query,uint32_t queryCnt,AssetResultSet * resultSet)57 int32_t AssetAdapter::GetAsset(const AssetAttr* query, uint32_t queryCnt, AssetResultSet* resultSet)
58 {
59     int32_t ret = AssetQuery(query, queryCnt, resultSet);
60     if (ret == SEC_ASSET_NOT_FOUND) {
61         HILOGE("not find asset");
62         return DP_GET_ASSET_NOT_FIND;
63     }
64     if (ret != SEC_ASSET_SUCCESS) {
65         HILOGE("asset get fail, error code is %{public}d", ret);
66         AssetFreeResultSet(resultSet);
67         return DP_GET_ASSET_ERROE;
68     }
69     return DP_SUCCESS;
70 }
71 
DeleteAsset(const AssetAttr * query,uint32_t queryCnt)72 int32_t AssetAdapter::DeleteAsset(const AssetAttr* query, uint32_t queryCnt)
73 {
74     int32_t ret = AssetRemove(query, queryCnt);
75     if (ret != SEC_ASSET_SUCCESS) {
76         HILOGE("asset remove fail, error code is %{public}d", ret);
77         return DP_DELETE_ASSET_ERROR;
78     }
79     return DP_SUCCESS;
80 }
81 
ParseAttr(const AssetResult * result,AssetTag tag)82 AssetAttr* AssetAdapter::ParseAttr(const AssetResult *result, AssetTag tag)
83 {
84     AssetAttr* aeestResult = AssetParseAttr(result, tag);
85     if (aeestResult == nullptr) {
86         HILOGE("asset parse fail");
87         return nullptr;
88     }
89     return aeestResult;
90 }
91 
FreeResultSet(AssetResultSet * resultSet)92 void AssetAdapter::FreeResultSet(AssetResultSet *resultSet)
93 {
94     AssetFreeResultSet(resultSet);
95 }
96 
97 } // namespace DistributedDeviceProfile
98 } // namespace OHOS
99