• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 LIBABCKIT_H
17 #define LIBABCKIT_H
18 
19 #ifndef __cplusplus
20 #include <stdbool.h>
21 #include <stddef.h>
22 #else
23 #include <cstddef>
24 #endif
25 
26 #include "./statuses.h"
27 #include "./api_version.h"
28 #include "./declarations.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /**
35  * @brief Struct that holds the pointers to the top-level Abckit API.
36  */
37 struct AbckitApi {
38     /**
39      * @brief Version of the Abckit API. Used for versioning the support for certain binary file features.
40      */
41     int apiVersion;
42 
43     /**
44      * @brief Returns status of last abckit API call.
45      * @return `AbckitStatus`.
46      */
47     enum AbckitStatus (*getLastError)(void);  // NOLINT(modernize-redundant-void-arg)
48 
49     /**
50      * @brief Opens abc file from given `path`.
51      * @return Pointer to the `AbckitFile`.
52      * @param [ in ] path - Path to abc file.
53      * @param [ in ] len - length of `path`.
54      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if `path` is NULL.
55      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if `path` doesn't point to a valid abc file.
56      * @note Allocates
57      */
58     AbckitFile *(*openAbc)(const char *path, size_t len);
59 
60     /**
61      * @brief Writes `file` to the specified `path`.
62      * @return None.
63      * @param [ in ] file - File to write.
64      * @param [ in ] path - Path where file will be written.
65      * @param [ in ] len - length of `path`.
66      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if `file` is NULL.
67      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if `path` is NULL.
68      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if `path` is not valid.
69      * @note Allocates
70      */
71     void (*writeAbc)(AbckitFile *file, const char *path, size_t len);
72 
73     /**
74      * @brief Closes file, frees resources.
75      * @return None.
76      * @param [ in ] file - File to close.
77      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if `file` is NULL.
78      */
79     void (*closeFile)(AbckitFile *file);
80 
81     /**
82      * @brief Destroys graph, frees resources.
83      * @return None.
84      * @param [ in ] graph - Graph to destroy.
85      * @note Set `ABCKIT_STATUS_BAD_ARGUMENT` error if `graph` is NULL.
86      */
87     void (*destroyGraph)(AbckitGraph *graph);
88 };
89 
90 /**
91  * @brief Instantiates Abckit API.
92  * @return Instance of the `AbckitApi` struct with valid function pointers.
93  * @param [ in ] version - Version of the API to instantiate.
94  * @note Set `ABCKIT_STATUS_UNKNOWN_API_VERSION` error if `version` value is not in the `AbckitApiVersion` enum.
95  */
96 struct AbckitApi const *AbckitGetApiImpl(enum AbckitApiVersion version);
97 
98 #ifdef __cplusplus
99 }
100 #endif
101 
102 #endif /* LIBABCKIT_H */
103