$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 
25 #include <memory> // for unique_ptr<>
26 #include <string> // for string
27 #include <utility> // for move
28 #include <vector> // for vector<>
29 
30 #include <cloe/trigger.hpp> // for Action, ActionFactory, TriggerSchema, InlineSchema, Confable
31 
32 namespace cloe {
33 namespace actions {
34 
35 class Configure : public Action {
36  public:
37  Configure(const std::string& name, Confable* ptr, const Conf& c)
38  : Action(name), ptr_(ptr), conf_(c) {
39  conf_.erase("name");
40  }
41  ActionPtr clone() const override { return std::make_unique<Configure>(name(), ptr_, conf_); }
42  void operator()(const Sync&, TriggerRegistrar&) override { ptr_->from_conf(conf_); }
43 
44  protected:
45  void to_json(Json& j) const override { j = *conf_; }
46 
47  private:
48  Confable* ptr_;
49  Conf conf_;
50 };
51 
53  public:
54  using ActionType = Configure;
55  ConfigureFactory(Confable* ptr, const std::string& name, const std::string& desc)
56  : ActionFactory(name, desc), ptr_(ptr) {}
57 
58  TriggerSchema schema() const override {
59  return TriggerSchema{
60  name(),
61  description(),
62  InlineSchema(false),
63  ptr_->schema(),
64  };
65  }
66 
67  ActionPtr make(const Conf& c) const override {
68  return std::make_unique<Configure>(name(), ptr_, c);
69  }
70 
71  private:
72  Confable* ptr_;
73 };
74 
75 } // namespace actions
76 } // namespace cloe
Definition: trigger.hpp:607
const std::string & description() const
Definition: entity.hpp:90
const std::string & name() const
Definition: entity.hpp:67
Definition: sync.hpp:34
Definition: trigger.hpp:290
Definition: trigger.hpp:433
Definition: action.hpp:52
ActionPtr make(const Conf &c) const override
Definition: action.hpp:67
TriggerSchema schema() const override
Definition: action.hpp:58
Definition: action.hpp:35
void operator()(const Sync &, TriggerRegistrar &) override
Definition: action.hpp:42
ActionPtr clone() const override
Definition: action.hpp:41
Definition: conf.hpp:82
size_t erase(const std::string &key)
Definition: conf.cpp:74
Definition: confable.hpp:98
virtual void from_conf(const Conf &c)
Definition: confable.cpp:70
Schema & schema()
Definition: confable.cpp:47
Definition: trigger.hpp:87
Definition: trigger.hpp:207