FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
notify.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#include <cstdint>
12#include <filesystem>
13
14#include "../std/expected.hpp"
15#include "../macro.hpp"
16#include "reserved.hpp"
17
28{
29
30namespace
31{
32
33namespace fs = std::filesystem;
34
35}
36
44inline Value<void> write(fs::path const& path_file_binary, uint8_t is_notify)
45{
46 uint64_t offset_begin = ns_reserved::FIM_RESERVED_OFFSET_NOTIFY_BEGIN;
47 uint64_t offset_end = ns_reserved::FIM_RESERVED_OFFSET_NOTIFY_END;
48 uint64_t size = offset_end - offset_begin;
49 return_if(size != sizeof(uint8_t), Error("E::Incorrect number of bytes to write notification flag: {} vs {}", size, sizeof(uint8_t)));
50 return ns_reserved::write(path_file_binary, offset_begin, offset_end, reinterpret_cast<char*>(&is_notify), sizeof(uint8_t));
51}
52
59inline Value<uint8_t> read(fs::path const& path_file_binary)
60{
61 uint64_t offset_begin = ns_reserved::FIM_RESERVED_OFFSET_NOTIFY_BEGIN;
62 uint8_t is_notify;
63 ssize_t bytes = Pop(ns_reserved::read(path_file_binary, offset_begin, reinterpret_cast<char*>(&is_notify), sizeof(uint8_t)));
64 log_if(bytes != 1, "E::Possible error to read notify byte, count is {}", bytes);
65 return is_notify;
66}
67
68} // namespace ns_reserved::ns_notify
69
70/* vim: set expandtab fdm=marker ts=2 sw=2 tw=100 et :*/
Enhanced error handling framework built on std::expected.
Simplified macros for common control flow patterns with optional logging.
Desktop notification flag management in reserved space.
Value< uint8_t > read(fs::path const &path_file_binary)
Read a notification flag from the flatimage binary.
Definition notify.hpp:59
Value< void > write(fs::path const &path_file_binary, uint8_t is_notify)
Writes a notification flag to the flatimage binary.
Definition notify.hpp:44
Value< void > write(fs::path const &path_file_binary, uint64_t offset_begin, uint64_t offset_end, const char *data, uint64_t length) noexcept
Writes data to a file in binary format.
Definition reserved.hpp:142
Value< std::streamsize > read(fs::path const &path_file_binary, uint64_t offset, char *data, uint64_t length) noexcept
Reads data from a file in binary format.
Definition reserved.hpp:172
Manages reserved space.
Enhanced expected type with integrated logging capabilities.
Definition expected.hpp:44