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
16 #include "cf_param_parse.h"
17
18 #include "securec.h"
19
20 #include "cf_log.h"
21 #include "cf_memory.h"
22 #include "cf_param.h"
23 #include "cf_result.h"
24
CfConstructParamSetOut(const CfParam * params,uint32_t cnt,CfParamSet ** out)25 int32_t CfConstructParamSetOut(const CfParam *params, uint32_t cnt, CfParamSet **out)
26 {
27 CfParamSet *tmp = NULL;
28 int32_t ret = CfInitParamSet(&tmp);
29 if (ret != CF_SUCCESS) {
30 CF_LOG_E("init out paramset failed");
31 return ret;
32 }
33
34 ret = CfAddParams(tmp, params, cnt);
35 if (ret != CF_SUCCESS) {
36 CF_LOG_E("add out param failed");
37 CfFreeParamSet(&tmp);
38 return ret;
39 }
40
41 ret = CfBuildParamSet(&tmp);
42 if (ret != CF_SUCCESS) {
43 CF_LOG_E("build out paramSet failed");
44 CfFreeParamSet(&tmp);
45 return ret;
46 }
47
48 *out = tmp;
49 return CF_SUCCESS;
50 }
51
CfConstructArrayParamSetOut(const CfBlobArray * array,CfParamSet ** out)52 int32_t CfConstructArrayParamSetOut(const CfBlobArray *array, CfParamSet **out)
53 {
54 CfParamSet *tmp = NULL;
55 int32_t ret;
56 do {
57 ret = CfInitParamSet(&tmp);
58 if (ret != CF_SUCCESS) {
59 CF_LOG_E("init out paramset failed");
60 break;
61 }
62
63 CfParam typeParam = { .tag = CF_TAG_RESULT_TYPE, .int32Param = CF_TAG_TYPE_BYTES };
64 ret = CfAddParams(tmp, &typeParam, 1);
65 if (ret != CF_SUCCESS) {
66 CF_LOG_E("add out param type failed");
67 break;
68 }
69
70 for (uint32_t i = 0; i < array->count; ++i) {
71 CfParam param = { .tag = CF_TAG_RESULT_BYTES, .blob = array->data[i] };
72 ret = CfAddParams(tmp, ¶m, 1);
73 if (ret != CF_SUCCESS) {
74 CF_LOG_E("add out param data failed");
75 break;
76 }
77 }
78
79 ret = CfBuildParamSet(&tmp);
80 if (ret != CF_SUCCESS) {
81 CF_LOG_E("build out paramSet failed");
82 break;
83 }
84
85 *out = tmp;
86 return CF_SUCCESS;
87 } while (0);
88
89 CfFreeParamSet(&tmp);
90 return ret;
91 }