SmartSpectra C++ SDK
Measure human vitals from video with SmartSpectra C++ SDK.
Loading...
Searching...
No Matches
status_code_provider_impl.hpp
1
2// status_code_provider_impl.hpp
3// Created by greg on 2/19/25.
4// Copyright (C) 2025 Presage Security, Inc.
5//
6// This program is free software; you can redistribute it and/or
7// modify it under the terms of the GNU Lesser General Public
8// License as published by the Free Software Foundation; either
9// version 3 of the License, or (at your option) any later version.
10//
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// Lesser General Public License for more details.
15//
16// You should have received a copy of the GNU Lesser General Public License
17// along with this program; if not, write to the Free Software Foundation,
18// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
21// === standard library includes (if any) ===
22// === third-party includes (if any) ===
23// === local includes (if any) ===
24#include "status_code_provider.hpp"
25
26#pragma once
27
28namespace presage::smartspectra::grpc_bindings {
29
30template<container::settings::IntegrationMode TIntegrationMode>
31StatusCodeProvider<TIntegrationMode>::StatusCodeProvider(std::shared_ptr<BackgroundContainer> container) {
32 SwapContainer(container);
33}
34
35template<container::settings::IntegrationMode TIntegrationMode>
36void StatusCodeProvider<TIntegrationMode>::SwapContainer(std::shared_ptr<BackgroundContainer> new_container) {
37 this->container.reset();
38 this->container = std::move(new_container);
39 if (this->container == nullptr) {
40 this->Finish(grpc::Status(
41 grpc::StatusCode::FAILED_PRECONDITION,
42 "Physiology Preprocessing is not running, unable to get status codes."
43 ));
44 return;
45 }
46 auto status = this->container->SetOnStatusChange(
47 [this](presage::physiology::StatusValue status_output) {
48 this->EnqueueWrite(status_output);
49 return absl::OkStatus();
50 }
51 );
52
53 if (!status.ok()) {
54 this->Finish(rpc::abslStatusToGrpc(status));
55 } else {
56 // Send the current status immediately if this is after initial construction
57 // This handles the case when the container is swapped after initial setup
58 auto status_code = this->container->GetStatusCode();
59 auto current_time = std::chrono::system_clock::now().time_since_epoch();
60 int64_t timestamp = std::chrono::duration_cast<std::chrono::microseconds>(current_time).count();
61 this->gap_status = physiology::BuildStatusValue(status_code, timestamp);
62 this->StartWrite(&this->gap_status);
63 }
64}
65
66} // namespace presage::smartspectra::grpc_bindings