$darkmode
action.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 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  */
23 #pragma once
24 #ifndef CLOE_CONF_ACTION_HPP_
25 #define CLOE_CONF_ACTION_HPP_
26 
27 #include <memory> // for unique_ptr<>
28 #include <string> // for string
29 #include <utility> // for move
30 #include <vector> // for vector<>
31 
32 #include <cloe/trigger.hpp> // for Action, ActionFactory, TriggerSchema, InlineSchema, Confable
33 
34 namespace cloe {
35 namespace actions {
36 
37 class Configure : public Action {
38  public:
39  Configure(const std::string& name, Confable* ptr, const Conf& c)
40  : Action(name), ptr_(ptr), conf_(c) {
41  conf_.erase("name");
42  }
43  ActionPtr clone() const override { return std::make_unique<Configure>(name(), ptr_, conf_); }
44  void operator()(const Sync&, TriggerRegistrar&) override { ptr_->from_conf(conf_); }
45 
46  protected:
47  void to_json(Json& j) const override { j = *conf_; }
48 
49  private:
50  Confable* ptr_;
51  Conf conf_;
52 };
53 
55  public:
56  using ActionType = Configure;
57  ConfigureFactory(Confable* ptr, const std::string& name, const std::string& desc)
58  : ActionFactory(name, desc), ptr_(ptr) {}
59 
60  TriggerSchema schema() const override {
61  return TriggerSchema{
62  name(),
63  description(),
64  InlineSchema(false),
65  ptr_->schema(),
66  };
67  }
68 
69  ActionPtr make(const Conf& c) const override {
70  return std::make_unique<Configure>(name(), ptr_, c);
71  }
72 
73  private:
74  Confable* ptr_;
75 };
76 
77 } // namespace actions
78 } // namespace cloe
79 
80 #endif // CLOE_CONF_ACTION_HPP_
Definition: conf.hpp:74
Definition: action.hpp:54
Definition: confable.hpp:46
Definition: trigger.hpp:442
Definition: sync.hpp:35
Definition: trigger.hpp:616
size_t erase(const std::string &key)
Definition: conf.cpp:74
ActionPtr clone() const override
Definition: action.hpp:43
TriggerSchema schema() const override
Definition: action.hpp:60
Definition: coordinator.hpp:36
void operator()(const Sync &, TriggerRegistrar &) override
Definition: action.hpp:44
Definition: trigger.hpp:300
std::string name() const
Definition: entity.hpp:68
virtual void from_conf(const Conf &c)
Definition: confable.cpp:66
Definition: action.hpp:37
std::string description() const
Definition: entity.hpp:91
void to_json(Json &j) const override
Definition: action.hpp:47
ActionPtr make(const Conf &c) const override
Definition: action.hpp:69
Definition: trigger.hpp:87
Definition: trigger.hpp:207