$darkmode
scp_action.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  */
23 #pragma once
24 
25 #include <memory> // for make_unique<>
26 
27 #include <cloe/trigger.hpp> // for Action, ActionFactory
28 
29 #include "scp_transceiver.hpp" // for ScpTransceiver
30 
31 namespace vtd {
32 
33 class ScpAction : public cloe::Action {
34  public:
35  ScpAction(const std::string& name, std::shared_ptr<ScpTransceiver> scp_client, const std::string& msg)
36  : cloe::Action(name), client_(scp_client), xml_(msg) {}
37  cloe::ActionPtr clone() const override { return std::make_unique<ScpAction>(name(), client_, xml_); }
38  void operator()(const cloe::Sync&, cloe::TriggerRegistrar&) override {
39  logger()->info("Sending SCP message: {}", xml_);
40  client_->send(xml_);
41  }
42  bool is_significant() const override { return false; }
43 
44  protected:
45  void to_json(cloe::Json& j) const override {
46  j = cloe::Json{
47  {"xml", xml_},
48  };
49  }
50 
51  private:
52  std::shared_ptr<ScpTransceiver> client_;
53  std::string xml_;
54 };
55 
57  public:
58  using ActionType = ScpAction;
60  std::shared_ptr<ScpTransceiver> scp_client,
61  const std::map<std::string, std::string>& predefined) :
62  cloe::ActionFactory("scp", "send an SCP message to the VTD server"),
63  scp_client_(scp_client),
64  predefined_(predefined) {}
65  cloe::TriggerSchema schema() const override;
66 
84  cloe::ActionPtr make(const cloe::Conf& c) const override;
85 
89  cloe::ActionPtr make(const std::string& s) const override;
90 
91  private:
92  std::shared_ptr<ScpTransceiver> scp_client_;
93  std::map<std::string, std::string> predefined_;
94 };
95 
96 } // namespace vtd
Definition: trigger.hpp:607
Logger logger() const
Definition: trigger.hpp:646
const std::string & name() const
Definition: entity.hpp:67
Definition: sync.hpp:34
Definition: trigger.hpp:290
Definition: trigger.hpp:433
Definition: conf.hpp:82
Definition: scp_action.hpp:56
cloe::TriggerSchema schema() const override
Definition: scp_action.cpp:30
cloe::ActionPtr make(const cloe::Conf &c) const override
Definition: scp_action.cpp:48
Definition: scp_action.hpp:33
cloe::ActionPtr clone() const override
Definition: scp_action.hpp:37
void operator()(const cloe::Sync &, cloe::TriggerRegistrar &) override
Definition: scp_action.hpp:38
bool is_significant() const override
Definition: scp_action.hpp:42
Definition: trigger.hpp:207