$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_); }
43  ptr_->from_conf(conf_);
44  return CallbackResult::Ok;
45  }
46 
47  protected:
48  void to_json(Json& j) const override { j = *conf_; }
49 
50  private:
51  Confable* ptr_;
52  Conf conf_;
53 };
54 
56  public:
57  using ActionType = Configure;
58  ConfigureFactory(Confable* ptr, const std::string& name, const std::string& desc)
59  : ActionFactory(name, desc), ptr_(ptr) {}
60 
61  TriggerSchema schema() const override {
62  return TriggerSchema{
63  name(),
64  description(),
65  InlineSchema(false),
66  ptr_->schema(),
67  };
68  }
69 
70  ActionPtr make(const Conf& c) const override {
71  return std::make_unique<Configure>(name(), ptr_, c);
72  }
73 
74  private:
75  Confable* ptr_;
76 };
77 
78 } // namespace actions
79 } // namespace cloe
Definition: trigger.hpp:619
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:437
Definition: action.hpp:55
ActionPtr make(const Conf &c) const override
Definition: action.hpp:70
TriggerSchema schema() const override
Definition: action.hpp:61
Definition: action.hpp:35
CallbackResult operator()(const Sync &, TriggerRegistrar &) override
Definition: action.hpp:42
ActionPtr clone() const override
Definition: action.hpp:41
Definition: conf.hpp:81
size_t erase(const std::string &key)
Definition: conf.cpp:74
Definition: confable.hpp:98
Schema & schema()
Definition: confable.cpp:47
virtual void from_conf(const Conf &c)
Definition: confable.cpp:70
Definition: trigger.hpp:87
Definition: trigger.hpp:207
CallbackResult
Definition: trigger.hpp:514