Loop Timing Witness
Native controller and runtime interfaces; hardware qualification pending
Loading...
Searching...
No Matches
exclusive_output.h
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-or-later
2// Commercial license available
3// © Concepts 1996–2026 Miroslav Šotek. All rights reserved.
4// © Code 2020–2026 Miroslav Šotek. All rights reserved.
5// ORCID: 0009-0009-3560-0851
6// Contact: www.anulum.li | protoscience@anulum.li
7// Loop Timing Witness — exclusive native output stream ownership
8
12
13#ifndef WITNESS_EXCLUSIVE_OUTPUT_H
14#define WITNESS_EXCLUSIVE_OUTPUT_H
15#include <cstdio>
16#include "refusal.h"
17#include <stdexcept>
18
19namespace witness {
21enum class OutputFormat {
24};
25
27 std::FILE *file;
28
29 public:
31 ExclusiveOutput(const char *path, OutputFormat format, const char *error)
32 : file(std::fopen(path, format == OutputFormat::binary ? "wbx" : "wx")) {
33 if (!file)
34 throw witness::RuntimeRefused(error);
35 }
36
38 if (file)
39 std::fclose(file);
40 }
41 ExclusiveOutput(const ExclusiveOutput &) = delete;
42 ExclusiveOutput &operator=(const ExclusiveOutput &) = delete;
44 bool is_open() const noexcept { return file != nullptr; }
46 std::FILE *stream(const char *closed_error) const {
47 if (!file)
48 throw witness::RuntimeRefused(closed_error);
49 return file;
50 }
51
52 int close(const char *closed_error) {
53 auto *owned = stream(closed_error);
54 file = nullptr;
55 return std::fclose(owned);
56 }
57};
58} // namespace witness
59#endif
bool is_open() const noexcept
int close(const char *closed_error)
ExclusiveOutput(const char *path, OutputFormat format, const char *error)
std::FILE * stream(const char *closed_error) const