vulp  2.3.0
ObserverPipeline.cpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: Apache-2.0
2 // Copyright 2022 Stéphane Caron
3 
5 
6 #include <palimpsest/exceptions/KeyError.h>
7 
8 #include "vulp/exceptions/ObserverError.h"
9 
10 namespace vulp::observation {
11 
12 using palimpsest::exceptions::KeyError;
13 using vulp::exceptions::ObserverError;
14 
15 void ObserverPipeline::reset(const Dictionary& config) {
16  for (auto observer : observers_) {
17  observer->reset(config);
18  }
19 }
20 
21 void ObserverPipeline::run(Dictionary& observation) {
22  for (auto source : sources_) {
23  source->write(observation);
24  }
25  for (auto observer : observers_) {
26  try {
27  observer->read(observation);
28  observer->write(observation);
29  } catch (const KeyError& e) {
30  throw ObserverError(observer->prefix(), e.key());
31  } catch (const std::exception& e) {
32  spdlog::error("[ObserverPipeline] Observer {} threw an exception: {}",
33  observer->prefix(), e.what());
34  throw;
35  }
36  }
37 }
38 
39 } // namespace vulp::observation
void reset(const Dictionary &config)
Reset observers.
void run(Dictionary &observation)
Run observer pipeline on an observation dictionary.
State observation.