24#include "status_code_provider.hpp"
28namespace presage::smartspectra::grpc_bindings {
30template<container::settings::IntegrationMode TIntegrationMode>
31StatusCodeProvider<TIntegrationMode>::StatusCodeProvider(std::shared_ptr<BackgroundContainer> container) {
32 SwapContainer(container);
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."
46 auto status = this->container->SetOnStatusChange(
47 [
this](presage::physiology::StatusValue status_output) {
48 this->EnqueueWrite(status_output);
49 return absl::OkStatus();
54 this->Finish(rpc::abslStatusToGrpc(status));
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);