Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/runtime/system.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: 17 мар. 2019 г.
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_RUNTIME_SYSTEM_H_
23 #define LSP_PLUG_IN_RUNTIME_SYSTEM_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26 #include <lsp-plug.in/runtime/LSPString.h>
27 #include <lsp-plug.in/common/types.h>
28 #include <lsp-plug.in/common/status.h>
29 #include <lsp-plug.in/io/Path.h>
30 #include <lsp-plug.in/lltl/parray.h>
31
32 namespace lsp
33 {
34 namespace system
35 {
36 /**
37 * Time information
38 */
39 typedef struct time_t
40 {
41 uint64_t seconds; /* The value in seconds */
42 uint32_t nanos; /* The value in nanoseconds between 0 and 10^9-1 */
43 } time_t;
44
45 /**
46 * System timestamp in milliseconds
47 */
48 typedef uint64_t time_millis_t;
49
50 /**
51 * Local time information
52 */
53 typedef struct localtime_t
54 {
55 int32_t year; /* Year */
56 uint8_t month; /* Month, starting with 1 */
57 uint8_t mday; /* Day of month, starting from 1 */
58 uint8_t wday; /* Day of week, starting from 1 */
59 uint8_t hour; /* Hour of a day, 0-23 */
60 uint8_t min; /* Minute of an hour, 0-59 */
61 uint8_t sec; /* Second of a minute, 0-59 */
62 uint32_t nanos; /* Number of nanoseconds */
63 } localtime_t;
64
65 enum volume_flags_t
66 {
67 VF_DUMMY = 1 << 0,
68 VF_REMOTE = 1 << 1,
69 VF_DRIVE = 1 << 2
70 };
71
72 typedef struct volume_info_t
73 {
74 LSPString device; /* Name of associated device */
75 LSPString root; /* Directory on filesystem of device used (for bind) */
76 LSPString target; /* Target mount point on the file system */
77 LSPString name; /* Name of the file system */
78 size_t flags; /* See volume_flags_t */
79 } volume_info_t;
80
81 /**
82 * Get environment variable
83 * @param name environment variable name
84 * @param dst string to store environment variable value, NULL for check-only
85 * @return status of operation or STATUS_NOT_FOUND if there is no environment variable
86 */
87 status_t get_env_var(const LSPString *name, LSPString *dst);
88
89 /**
90 * Get environment variable
91 * @param name environment variable name in UTF-8
92 * @param dst string to store environment variable value, NULL for check-only
93 * @return status of operation or STATUS_NOT_FOUND if there is no environment variable
94 */
95 status_t get_env_var(const char *name, LSPString *dst);
96
97 /**
98 * Set environment variable
99 * @param name environment variable name
100 * @param value environment variable value, NULL value deletes the variable
101 * @return status of operation or STATUS_NOT_FOUND if there is no environment variable
102 */
103 status_t set_env_var(const LSPString *name, const LSPString *value);
104
105 /**
106 * Set environment variable
107 * @param name environment variable name in UTF-8
108 * @param value environment variable value in UTF-8, NULL value deletes the variable
109 * @return status of operation or STATUS_NOT_FOUND if there is no environment variable
110 */
111 status_t set_env_var(const char *name, const char *value);
112
113 /**
114 * Set environment variable
115 * @param name environment variable name in UTF-8
116 * @param value environment variable value, NULL value deletes the variable
117 * @return status of operation or STATUS_NOT_FOUND if there is no environment variable
118 */
119 status_t set_env_var(const char *name, const LSPString *value);
120
121 /**
122 * Remove environment variable
123 * @param name variable to remove in UTF-8
124 * @return status of operation
125 */
126 status_t remove_env_var(const char *name);
127
128 /**
129 * Remove environment variable
130 * @param name variable to remove
131 * @return status of operation
132 */
133 status_t remove_env_var(const LSPString *name);
134
135 /**
136 * Get current user's home directory
137 * @param homedir pointer to string to store home directory path
138 * @return status of operation
139 */
140 status_t get_home_directory(LSPString *homedir);
141
142 /**
143 * Get current user's home directory
144 * @param homedir pointer to string to store home directory path
145 * @return status of operation
146 */
147 status_t get_home_directory(io::Path *homedir);
148
149 /**
150 * Get user's local configuration path
151 * @param path string to store user's configuration path
152 * @return status of operation
153 */
154 status_t get_user_config_path(LSPString *path);
155
156 /**
157 * Get user's local configuration path
158 * @param path string to store user's configuration path
159 * @return status of operation
160 */
161 status_t get_user_config_path(io::Path *path);
162
163 /**
164 * Get current high-precision time
165 * @param time pointer to structure to store time value
166 */
167 void get_time(time_t *time);
168
169 /**
170 * Get current time in milliseconds
171 * @return current time in milliseconds
172 */
173 time_millis_t get_time_millis();
174
175 /**
176 * Convert time structure to the local time
177 * @param local pointer to store the result
178 * @param time time structure to convert, use current time if NULL
179 */
180 void get_localtime(localtime_t *local, const time_t *time = NULL);
181
182 /**
183 * Sleep for a specified amount of milliseconds
184 * @param delay the amount of milliseconds to sleep
185 */
186 status_t sleep_msec(size_t delay);
187
188 /**
189 * Get current user login
190 * @param user pointer to store current user login
191 * @return status of operation
192 */
193 status_t get_user_login(LSPString *user);
194
195 /**
196 * Get temporary directory
197 * @param path pointer to store result
198 * @return status of operation
199 */
200 status_t get_temporary_dir(LSPString *path);
201
202 /**
203 * Get temporary directory
204 * @param path pointer to store result
205 * @return status of operation
206 */
207 status_t get_temporary_dir(io::Path *path);
208
209 /**
210 * Get system temporary directory
211 * @param path pointer to store result
212 * @return status of operation
213 */
214 status_t get_system_temporary_dir(LSPString *path);
215
216 /**
217 * Get system temporary directory
218 * @param path pointer to store result
219 * @return status of operation
220 */
221 status_t get_system_temporary_dir(io::Path *path);
222
223 /**
224 * Get current directiory
225 * @param path path to store current directory
226 * @return status of operation
227 */
228 status_t get_current_dir(LSPString *path);
229
230 /**
231 * Get current directiory
232 * @param path path to store current directory
233 * @return status of operation
234 */
235 status_t get_current_dir(io::Path *path);
236
237 /**
238 * Follow ther URL (open in the matching program)
239 * @param url URL to follow
240 * @return status of operation
241 */
242 status_t follow_url(const char *url);
243
244 /**
245 * Follow ther URL (open in the matching program)
246 * @param url URL to follow
247 * @return status of operation
248 */
249 status_t follow_url(const LSPString *url);
250
251 /**
252 * Launch detached process
253 * @param program the name of the process to launch
254 * @param args NULL-terminated list of arguments
255 * @return status of operation
256 */
257 status_t exec_detached(const char *program, const char * const *args = NULL);
258
259 /**
260 * Launch detached process
261 * @param program the name of the process to launch
262 * @param args NULL-terminated list of arguments
263 * @return status of operation
264 */
265 status_t exec_detached(const LSPString *program, const LSPString * const *args = NULL);
266
267 /**
268 * Obtain information about available system volumes
269 * @param volumes pointer to array to store volume information
270 * @return status of operation
271 */
272 status_t get_volume_info(lltl::parray<volume_info_t> *volumes);
273
274 /**
275 * Free information about available system volumes
276 * @param volumes pointer to array that stores volume information
277 */
278 void free_volume_info(lltl::parray<volume_info_t> *volumes);
279
280 /**
281 * Get system virtual memory page size
282 * @return system virtual memory page size
283 */
284 size_t page_size();
285
286 /**
287 * Get number of processors available on the system
288 * @return number of processors available on the system
289 */
290 size_t system_cores();
291
292 } /* namespace system */
293 } /* namespace lsp */
294
295
296 #endif /* LSP_PLUG_IN_RUNTIME_SYSTEM_H_ */