$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 
24 #include <functional> // for function
25 
26 #include <boost/optional.hpp> // for optional<>
27 #include <fable/json.hpp> // for Json
28 #include <fable/utility/boost_optional.hpp> // for to_json
29 
30 #include <cloe/component.hpp> // for Component
31 #include <cloe/component/object.hpp> // for Object
32 
33 namespace cloe {
34 
35 class VehicleStateModel : public Component {
36  public:
37  using Component::Component;
38  VehicleStateModel() : Component("vehicle_state") {}
39  virtual ~VehicleStateModel() noexcept = default;
40 
44  virtual void set_vehicle_state(const Object& obj) { vehicle_state_ = obj; }
45 
51  const boost::optional<Object>& vehicle_state() {
54  }
55  return vehicle_state_;
56  }
57 
66  }
67  return static_cast<bool>(vehicle_state_);
68  }
69 
73  void register_vehicle_state_callback(const std::function<void(void)>& c) {
75  }
76 
83  fable::Json active_state() const override {
84  return fable::Json{
85  {"vehicle_state", vehicle_state_},
86  };
87  }
88 
89  Duration process(const Sync& sync) override {
90  auto t = Component::process(sync);
91  vehicle_state_.reset();
92  return t;
93  }
94 
95  void reset() override {
97  vehicle_state_.reset();
98  }
99 
100  protected:
106  boost::optional<Object> vehicle_state_;
107 
122  std::function<void(void)> vehicle_state_callback_;
123 };
124 
125 } // namespace cloe
Definition: component.hpp:143
Duration process(const Sync &sync) override
Definition: component.hpp:181
void reset() override
Definition: component.hpp:186
Definition: sync.hpp:34
Definition: vehicle_state_model.hpp:35
std::function< void(void)> vehicle_state_callback_
Definition: vehicle_state_model.hpp:122
Duration process(const Sync &sync) override
Definition: vehicle_state_model.hpp:89
boost::optional< Object > vehicle_state_
Definition: vehicle_state_model.hpp:106
bool is_vehicle_state()
Definition: vehicle_state_model.hpp:63
void reset() override
Definition: vehicle_state_model.hpp:95
fable::Json active_state() const override
Definition: vehicle_state_model.hpp:83
virtual void set_vehicle_state(const Object &obj)
Definition: vehicle_state_model.hpp:44
const boost::optional< Object > & vehicle_state()
Definition: vehicle_state_model.hpp:51
void register_vehicle_state_callback(const std::function< void(void)> &c)
Definition: vehicle_state_model.hpp:73
std::chrono::nanoseconds Duration
Definition: cloe_fwd.hpp:36
nlohmann::json Json
Definition: fable_fwd.hpp:35
Definition: object.hpp:51