SmartSpectra C++ SDK
Measure human vitals from video with SmartSpectra C++ SDK.
Loading...
Searching...
No Matches
log_buffer.hpp
1// log_buffer.hpp
2// Created by Greg on 8/4/2025.
3// Copyright (C) 2025 Presage Security, Inc.
4//
5// SPDX-License-Identifier: LGPL-3.0-or-later
6
7#pragma once
8
9// === standard library includes (if any) ===
10#include <queue>
11#include <string>
12#include <mutex>
13#include <condition_variable>
14#include <atomic>
15#include <optional>
16
17// === third-party includes (if any) ===
18#include "absl/strings/string_view.h"
19
20namespace presage::smartspectra::grpc_bindings {
21class LogBuffer {
22public:
23 explicit LogBuffer(size_t max_size);
24
25 void AddLog(absl::string_view log);
26
27 // Returns log entry, or std::nullopt if shutdown
28 std::optional<std::string> GetLog();
29
30 // Signal shutdown to wake up all waiting threads
31 void Shutdown();
32
33 // Check if buffer is in shutdown state
34 bool IsShutdown() const;
35
36private:
37 std::queue<std::string> queue;
38 std::mutex mutex;
39 std::condition_variable cv;
40 size_t max_size;
41 std::atomic<bool> shutdown_flag{false};
42};
43} // namespace presage::smartspectra::grpc_bindings