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 #ifndef CODE_SIGNATURE_ANALYSIS_KIT_H
17 #define CODE_SIGNATURE_ANALYSIS_KIT_H
18 
19 #include "analysis_model_log.h"
20 #include "code_signature_info.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #define CODE_SIGNATURE_ERROR_TYPE_SIZE 5
27 
28 typedef void (*RetListener)(uint8_t *result, uint32_t resultLen);
29 
30 typedef void (*DbListener)(uint32_t optType, uint8_t *result, uint32_t resultLen);
31 
32 typedef struct ModelManagerApi {
33     int32_t (*execSql)(const char *sql, uint8_t *result, uint32_t resultLen);
34     int32_t (*subscribeDb)(const int64_t *eventId, uint32_t eventIdLen, DbListener listener);
35 } ModelManagerApi;
36 
37 typedef struct ModelApi {
38     int32_t (*init)(ModelManagerApi *api);
39     int32_t (*getResult)(uint8_t *result, uint32_t *resultLen);
40     int32_t (*subscribeResult)(RetListener listener);
41     void (*release)();
42 } ModelApi;
43 
44 /**
45  * @brief Get the model.
46  * @return A pointer to the model.
47  */
48 ModelApi *GetModelApi(void);
49 
50 /**
51  * @brief Init the model.
52  * @param api: The model api.
53  * @return The event id nedd to be subscribed.
54  */
55 int32_t Init(ModelManagerApi *api);
56 
57 /**
58  * @brief Release the model.
59  * @return void.
60  */
61 void Release(void);
62 
63 /**
64  * @brief Get the analysis result.
65  * @param result: The analysis result info.
66  * @return 0 indicates success, others indicate failure.
67  */
68 int32_t GetResult(uint8_t *result, uint32_t *resultLen);
69 
70 /**
71  * @brief Subscribe the analysis result.
72  * @param listener: The analysis result info.
73  * @return 0 indicates success, others indicate failure.
74  */
75 int32_t SubscribeResult(RetListener listener);
76 
77 #ifdef __cplusplus
78 }
79 #endif
80 
81 #endif // CODE_SIGNATURE_ANALYSIS_KIT_H
82