Illustrated C/C++ source sheets, symbol index, API relationship graph, compiler console and debug trace

LIVE AI / FLEXIBLE SENSING / FLIGHT CONTEXT

Sensoraia API

Live AI and sensing, connected to the flight.
See, listen, inspect and return supported results while airborne.

Loading...
Searching...
No Matches
binary_output.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 OpenUAS
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/**
19 * @file binary_output.h
20 * @brief Publish immutable result files without exposing partial contents.
21 * @details A sibling temporary file allows readers to see either no result or
22 * the complete renamed result. Existing targets are rejected because survey
23 * products are evidence; silently replacing one could conceal a prior run.
24 * This helper provides atomic visibility on the same filesystem, not an fsync
25 * durability guarantee.
26 */
27#ifndef PANGEA_BINARY_OUTPUT_H
28#define PANGEA_BINARY_OUTPUT_H
29
30#include "application_runtime.h"
31
32/**
33 * @brief Write bytes to a new path and publish them by same-directory rename.
34 * @param[in] path Final output path; it and its `.partial` sibling must not exist.
35 * @param[in] data Address of the bytes to write; may be null only when @p size is zero.
36 * @param[in] size Number of bytes to publish.
37 * @throws std::runtime_error If output exists, writing fails, or rename fails.
38 * @note Rename prevents readers from observing a partially written target;
39 * use the durable checkpoint helpers when crash/power-loss durability matters.
40 */
41inline void saveBinary(const fs::path& path, const void* data, std::size_t size) {
42 const fs::path temporary = path.string() + ".partial";
43 if (fs::exists(path) || fs::exists(temporary))
44 throw std::runtime_error("Refusing to overwrite output: " + path.u8string());
45 try {
46 // Only the completed sibling is renamed into the public name.
47 std::ofstream output(temporary, std::ios::binary);
48 output.write(static_cast<const char*>(data), static_cast<std::streamsize>(size));
49 output.close();
50 if (!output) throw std::runtime_error("Cannot write output: " + path.u8string());
51 std::error_code ec;
52 fs::rename(temporary, path, ec);
53 if (ec) throw std::runtime_error("Publish output failed: " + ec.message());
54 } catch (...) {
55 std::error_code error;
56 fs::remove(temporary, error);
57 if (error) std::cerr << "WARNING: Cannot clean partial output: " << error.message() << '\n';
58 throw;
59 }
60}
61
62#endif
Shared logging and operating-system checks for the survey executable.
void saveBinary(const fs::path &path, const void *data, std::size_t size)
Write bytes to a new path and publish them by same-directory rename.
size_t size
Definition chdk_pipe.c:143
struct jpeg_error_mgr error
Definition lwir_image.c:60
static FILE * output
Definition pose_log.c:77