FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
interface.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#include <filesystem>
12#include <set>
13#include <string>
14#include <vector>
15
18#include "../std/enum.hpp"
19#include "../db/bind.hpp"
20#include "cmd/desktop.hpp"
21
32{
33
34namespace
35{
36
37namespace fs = std::filesystem;
38
39}
40
41struct CmdRoot
42{
43 std::string program;
44 std::vector<std::string> args;
45};
46
47struct CmdExec
48{
49 std::string program;
50 std::vector<std::string> args;
51};
52
53ENUM(CmdPermsOp,ADD,CLEAR,DEL,LIST,SET);
55{
56 using Permission = ns_reserved::ns_permissions::Permission;
57 struct Add
58 {
59 std::set<Permission> permissions;
60 };
61 struct Clear
62 {
63 };
64 struct Del
65 {
66 std::set<Permission> permissions;
67 };
68 struct List
69 {
70 };
71 struct Set
72 {
73 std::set<Permission> permissions;
74 };
75 std::variant<Add,Clear,Del,List,Set> sub_cmd;
76};
77
78ENUM(CmdEnvOp,ADD,CLEAR,DEL,LIST,SET);
79struct CmdEnv
80{
81 struct Add
82 {
83 std::vector<std::string> variables;
84 };
85 struct Clear
86 {
87 };
88 struct Del
89 {
90 std::vector<std::string> variables;
91 };
92 struct List
93 {
94 };
95 struct Set
96 {
97 std::vector<std::string> variables;
98 };
99 std::variant<Add,Clear,Del,List,Set> sub_cmd;
100};
101
102ENUM(CmdDesktopOp,CLEAN,DUMP,ENABLE,SETUP);
103ENUM(CmdDesktopDump,ENTRY,ICON,MIMETYPE);
105{
106 struct Clean
107 {
108 };
109 struct Dump
110 {
111 struct Icon
112 {
113 fs::path path_file_icon;
114 };
115 struct Entry
116 {
117 };
118 struct MimeType
119 {
120 };
121 std::variant<Icon,Entry,MimeType> sub_cmd;
122 };
123 struct Enable
124 {
125 std::set<ns_desktop::IntegrationItem> set_enable;
126 };
127 struct Setup
128 {
129 std::filesystem::path path_file_setup;
130 };
131 std::variant<Clean,Dump,Enable,Setup> sub_cmd;
132};
133
134ENUM(CmdBootOp,SET,SHOW,CLEAR);
136{
137 struct Clear
138 {
139 };
140 struct Set
141 {
142 std::string program;
143 std::vector<std::string> args;
144 };
145 struct Show
146 {
147 };
148 std::variant<Clear,Set,Show> sub_cmd;
149};
150
151ENUM(CmdRemoteOp,SET,SHOW,CLEAR);
153{
154 struct Clear
155 {
156 };
157 struct Set
158 {
159 std::string url;
160 };
161 struct Show
162 {
163 };
164 std::variant<Clear,Set,Show> sub_cmd;
165};
166
167ENUM(CmdRecipeOp,FETCH,INFO,INSTALL);
169{
170 struct Fetch
171 {
172 std::vector<std::string> recipes;
173 };
174 struct Info
175 {
176 std::vector<std::string> recipes;
177 };
178 struct Install
179 {
180 std::vector<std::string> recipes;
181 };
182 std::variant<Fetch,Info,Install> sub_cmd;
183};
184
185ENUM(CmdLayerOp,ADD,COMMIT,CREATE,LIST);
186ENUM(CmdLayerCommitOp,BINARY,LAYER,FILE);
188{
189 struct Add
190 {
191 fs::path path_file_src;
192 };
193 struct Commit
194 {
195 struct Binary
196 {
197 };
198 struct Layer
199 {
200 };
201 struct File
202 {
203 fs::path path_file_dst;
204 };
205 std::variant<Binary,Layer,File> sub_cmd;
206 };
207 struct Create
208 {
209 fs::path path_dir_src;
210 fs::path path_file_target;
211 };
212 struct List
213 {
214 };
215 std::variant<Add,Commit,Create,List> sub_cmd;
216};
217
218ENUM(CmdBindOp,ADD,DEL,LIST);
220{
221 struct Add
222 {
223 ns_db::ns_bind::Type type;
224 fs::path path_src;
225 fs::path path_dst;
226 };
227 struct Del
228 {
229 uint64_t index;
230 };
231 struct List
232 {
233 };
234 std::variant<Add,Del,List> sub_cmd;
235};
236
237ENUM(CmdNotifySwitch,ON,OFF);
239{
240 CmdNotifySwitch status;
241};
242
243ENUM(CmdCaseFoldSwitch,ON,OFF);
245{
246 CmdCaseFoldSwitch status;
247};
248
249ENUM(CmdInstanceOp,EXEC,LIST);
251{
252 struct Exec
253 {
254 int32_t id;
255 std::vector<std::string> args;
256 };
257 struct List
258 {
259 };
260 std::variant<Exec,List> sub_cmd;
261};
262
263ENUM(CmdOverlayOp,SET,SHOW);
265{
266 struct Set
267 {
268 ns_reserved::ns_overlay::OverlayType overlay;
269 };
270 struct Show
271 {
272 };
273 std::variant<Set,Show> sub_cmd;
274};
275
276ENUM(CmdUnshareOp,ADD,CLEAR,DEL,LIST,SET);
278{
279 using Unshare = ns_reserved::ns_unshare::Unshare;
280 struct Add
281 {
282 std::set<Unshare> unshares;
283 };
284 struct Clear
285 {
286 };
287 struct Del
288 {
289 std::set<Unshare> unshares;
290 };
291 struct List
292 {
293 };
294 struct Set
295 {
296 std::set<Unshare> unshares;
297 };
298 std::variant<Add,Clear,Del,List,Set> sub_cmd;
299};
300
301ENUM(CmdVersionOp,SHORT,FULL,DEPS);
303{
304 struct Short
305 {
306 std::string dump()
307 {
308 return FIM_VERSION;
309 }
310 };
311 struct Full
312 {
313 Value<std::string> dump()
314 {
315 ns_db::Db db;
316 db("VERSION") = FIM_VERSION;
317 db("COMMIT") = FIM_COMMIT;
318 db("DISTRIBUTION") = FIM_DIST;
319 db("TIMESTAMP") = FIM_TIMESTAMP;
320 return Pop(db.dump());
321 }
322 };
323 struct Deps
324 {
325 // This placeholder is replaced before compiling
326 Value<std::string> dump()
327 {
328 constexpr static char str_raw_json[] =
329 {
330 #embed FIM_FILE_META
331 };
332 return Pop(Pop(ns_db::from_string(str_raw_json)).dump());
333 }
334 };
335 std::variant<Short,Full,Deps> sub_cmd;
336};
337
339{
340};
341
343{
344};
345
346using CmdType = std::variant<CmdRoot
347 , CmdExec
348 , CmdPerms
349 , CmdEnv
350 , CmdDesktop
351 , CmdLayer
352 , CmdBind
353 , CmdNotify
355 , CmdBoot
356 , CmdRemote
357 , CmdRecipe
359 , CmdOverlay
360 , CmdUnshare
361 , CmdNone
362 , CmdExit
363 , CmdVersion
364>;
365
366}
A type-safe wrapper around nlohmann::json for database operations.
Definition db.hpp:64
Value< std::string > dump()
Serializes the current JSON data to a formatted string.
Definition db.hpp:277
Used to manage the bindings from the host to the sandbox.
Custom enumeration class.
Value< Db > from_string(S &&s)
Parses a JSON string and creates a Db object.
Definition db.hpp:496
Command interface definitions and argument structures.
Manages the desktop integration.
Manages the permissions reserved space.
Manages the unshare namespace options reserved space.
Enhanced expected type with integrated logging capabilities.
Definition expected.hpp:44