Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/fmt/lspc/File.h

raw
1 /*
2 * Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2025 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 14 янв. 2018 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef LSP_PLUG_IN_FMT_LSPC_FILE_H_
23 #define LSP_PLUG_IN_FMT_LSPC_FILE_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26 #include <lsp-plug.in/runtime/LSPString.h>
27 #include <lsp-plug.in/fmt/lspc/ChunkReader.h>
28 #include <lsp-plug.in/fmt/lspc/ChunkWriter.h>
29 #include <lsp-plug.in/io/Path.h>
30
31 namespace lsp
32 {
33 namespace lspc
34 {
35 class File
36 {
37 protected:
38 friend class ChunkReader;
39 friend class ChunkWriter;
40
41 protected:
42 Resource *pFile; // Shared resource
43 bool bWrite; // Read/Write mode
44 size_t nHdrSize; // Size of header
45
46 protected:
47 Resource *create_resource(fhandle_t fd);
48
49 public:
50 explicit File();
51 File(const File &) = delete;
52 File(File &&) = delete;
53 virtual ~File();
54
55 File & operator = (const File &) = delete;
56 File & operator = (File &&) = delete;
57
58 public:
59 /** Open file for reading
60 *
61 * @param path location of the file
62 * @return status of operation
63 */
64 status_t open(const char *path);
65
66 /** Open file for reading
67 *
68 * @param path location of the file
69 * @return status of operation
70 */
71 status_t open(const LSPString *path);
72
73 /** Open file for reading
74 *
75 * @param path location of the file
76 * @return status of operation
77 */
78 status_t open(const io::Path *path);
79
80 /** Open file for writing
81 *
82 * @param path location of the file
83 * @return status of operation
84 */
85 status_t create(const char *path);
86
87 /** Open file for reading
88 *
89 * @param path location of the file
90 * @return status of operation
91 */
92 status_t create(const LSPString *path);
93
94 /** Open file for reading
95 *
96 * @param path location of the file
97 * @return status of operation
98 */
99 status_t create(const io::Path *path);
100
101 /** Close the file
102 *
103 * @return status of operation
104 */
105 status_t close();
106
107 public:
108 /** Write chunk
109 *
110 * @param magic magic number of the chunk type
111 * @return pointer to chunk writer
112 */
113 ChunkWriter *write_chunk(uint32_t magic);
114
115 /** Read chunk
116 *
117 * @param uid magic number of the chunk type
118 * @return pointer to chunk reader
119 */
120 ChunkReader *read_chunk(uint32_t uid);
121
122 /** Read chunk of specific type
123 *
124 * @param uid unique chunk identifier
125 * @param magic magic number of the chunk type
126 * @return pointer to chunk reader
127 */
128 ChunkReader *read_chunk(uint32_t uid, uint32_t magic);
129
130 /**
131 * Find LSPC chunk in file by magic
132 * @param magic chunk magic
133 * @param id pointer to return chunk number that can be used in the search of
134 * next chunk with the same magic signature
135 * @param start_id minimum accepted identifier of chunk
136 * @return pointer to chunk reader
137 */
138 ChunkReader *find_chunk(uint32_t magic, uint32_t *id, uint32_t start_id = 1);
139
140 /**
141 * Enumerate all chunk identifiers with the specified magic number
142 * @param magic chunk magic number
143 * @param list pointer to store the list of chunks, should be free()'d after use by caller
144 * @return number of chunks in list or negative error code
145 */
146 ssize_t enumerate_chunks(uint32_t magic, chunk_id_t **list);
147
148 /**
149 * Enumerate all chunk identifiers of any type present in the file
150 * @param list pointer to store the list of chunks, should be free()'d after use by caller
151 * @return number of chunks in list or negative error code
152 */
153 ssize_t enumerate_chunks(chunk_info_t **list);
154
155 /**
156 * Find LSPC chunk in file by magic
157 * @param magic chunk magic
158 * @param start_id start identifier of chunk
159 * @return pointer to chunk reader
160 */
161 inline ChunkReader *find_chunk(uint32_t magic, uint32_t start_id = 1) { return find_chunk(magic, NULL, start_id); }
162 };
163
164 } /* namespace lspc */
165 } /* namespace lsp */
166
167 #endif /* LSP_PLUG_IN_FMT_LSPC_FILE_H_ */