$darkmode
vehicle_state_model.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2022 Robert Bosch GmbH
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * SPDX-License-Identifier: Apache-2.0
17  */
22 #pragma once
23 #ifndef CLOE_COMPONENT_VEHICLE_STATE_MODEL_HPP_
24 #define CLOE_COMPONENT_VEHICLE_STATE_MODEL_HPP_
25 
26 #include <functional> // for function
27 
28 #include <boost/optional.hpp> // for optional<>
29 
30 #include <fable/json/with_boost.hpp> // for to_json
31 #include <cloe/component.hpp> // for Component, Json
32 #include <cloe/component/object.hpp> // for Object
33 
34 namespace cloe {
35 
36 class VehicleStateModel : public Component {
37  public:
38  using Component::Component;
39  VehicleStateModel() : Component("vehicle_state") {}
40  virtual ~VehicleStateModel() noexcept = default;
41 
45  virtual void set_vehicle_state(const Object& obj) { vehicle_state_ = obj; }
46 
52  const boost::optional<Object>& vehicle_state() {
55  }
56  return vehicle_state_;
57  }
58 
67  }
68  return static_cast<bool>(vehicle_state_);
69  }
70 
74  void register_vehicle_state_callback(const std::function<void(void)>& c) {
76  }
77 
84  Json active_state() const override {
85  return Json{
86  {"vehicle_state", vehicle_state_},
87  };
88  }
89 
90  Duration process(const Sync& sync) override {
91  auto t = Component::process(sync);
92  vehicle_state_.reset();
93  return t;
94  }
95 
96  void reset() override {
98  vehicle_state_.reset();
99  }
100 
101  protected:
107  boost::optional<Object> vehicle_state_;
108 
123  std::function<void(void)> vehicle_state_callback_;
124 };
125 
126 } // namespace cloe
127 
128 #endif // CLOE_COMPONENT_VEHICLE_STATE_MODEL_HPP_
const boost::optional< Object > & vehicle_state()
Definition: vehicle_state_model.hpp:52
std::function< void(void)> vehicle_state_callback_
Definition: vehicle_state_model.hpp:123
Json active_state() const override
Definition: vehicle_state_model.hpp:84
virtual void set_vehicle_state(const Object &obj)
Definition: vehicle_state_model.hpp:45
boost::optional< Object > vehicle_state_
Definition: vehicle_state_model.hpp:107
void reset() override
Definition: vehicle_state_model.hpp:96
Definition: object.hpp:51
Definition: sync.hpp:35
Definition: coordinator.hpp:36
Duration process(const Sync &sync) override
Definition: component.hpp:182
std::chrono::nanoseconds Duration
Definition: duration.hpp:45
void register_vehicle_state_callback(const std::function< void(void)> &c)
Definition: vehicle_state_model.hpp:74
Definition: vehicle_state_model.hpp:36
Definition: component.hpp:144
Duration process(const Sync &sync) override
Definition: vehicle_state_model.hpp:90
bool is_vehicle_state()
Definition: vehicle_state_model.hpp:64
void reset() override
Definition: component.hpp:187