FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
boot.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#include <string>
12#include <vector>
13
14#include "../std/expected.hpp"
15#include "db.hpp"
16
25namespace ns_db::ns_boot
26{
27
28class Boot
29{
30 private:
31 std::string m_program;
32 std::vector<std::string> m_args;
33 public:
34 Boot();
35 [[maybe_unused]] std::string const& get_program() const { return m_program; }
36 [[maybe_unused]] std::vector<std::string> const& get_args() const { return m_args; }
37 [[maybe_unused]] void set_program(std::string_view str_program) { m_program = str_program; }
38 [[maybe_unused]] void set_args(std::vector<std::string> const& vec_args) { m_args = vec_args; }
39 friend Value<Boot> deserialize(std::string_view str_raw_json) noexcept;
40 friend Value<std::string> serialize(Boot const& boot) noexcept;
41};
42
46inline Boot::Boot()
47 : m_program()
48 , m_args()
49{}
50
57[[maybe_unused]] [[nodiscard]] inline Value<Boot> deserialize(std::string_view str_raw_json) noexcept
58{
59 Boot boot;
60 return_if(str_raw_json.empty(), Error("D::Empty json data"));
61 // Open DB
62 auto db = Pop(ns_db::from_string(str_raw_json));
63 // Parse program (optional, defaults to empty string)
64 boot.m_program = Pop(db("program").template value<std::string>());
65 // Parse args (optional, defaults to empty vector)
66 boot.m_args = Pop(db("args").value<std::vector<std::string>>());
67 return boot;
68}
69
76[[maybe_unused]] [[nodiscard]] inline Value<std::string> serialize(Boot const& boot) noexcept
77{
78 auto db = ns_db::Db();
79 db("program") = boot.m_program;
80 db("args") = boot.m_args;
81 return db.dump();
82}
83
84} // namespace ns_db::ns_boot
85
86/* vim: set expandtab fdm=marker ts=2 sw=2 tw=100 et :*/
Value< int > boot(int argc, char **argv)
Boots the main flatimage program and the portal process.
Definition boot.cpp:40
A type-safe wrapper around nlohmann::json for database operations.
Definition db.hpp:64
friend Value< std::string > serialize(Boot const &boot) noexcept
Serializes a Boot class into a json string.
Definition boot.hpp:76
friend Value< Boot > deserialize(std::string_view str_raw_json) noexcept
Deserializes JSON string into a Binds object.
Definition bind.hpp:184
Boot()
Construct a new Boot:: Boot object.
Definition boot.hpp:46
A database that interfaces with nlohmann json.
Enhanced error handling framework built on std::expected.
Boot command configuration storage.
Value< std::string > serialize(Boot const &boot) noexcept
Serializes a Boot class into a json string.
Definition boot.hpp:76
Value< Boot > deserialize(std::string_view str_raw_json) noexcept
Deserializes a json string into a Boot class.
Definition boot.hpp:57
Value< Db > from_string(S &&s)
Parses a JSON string and creates a Db object.
Definition db.hpp:496
Enhanced expected type with integrated logging capabilities.
Definition expected.hpp:44