$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_); }
39  logger()->info("Sending SCP message: {}", xml_);
40  client_->send(xml_);
41  return cloe::CallbackResult::Ok;
42  }
43  bool is_significant() const override { return false; }
44 
45  protected:
46  void to_json(cloe::Json& j) const override {
47  j = cloe::Json{
48  {"xml", xml_},
49  };
50  }
51 
52  private:
53  std::shared_ptr<ScpTransceiver> client_;
54  std::string xml_;
55 };
56 
58  public:
59  using ActionType = ScpAction;
61  std::shared_ptr<ScpTransceiver> scp_client,
62  const std::map<std::string, std::string>& predefined) :
63  cloe::ActionFactory("scp", "send an SCP message to the VTD server"),
64  scp_client_(scp_client),
65  predefined_(predefined) {}
66  cloe::TriggerSchema schema() const override;
67 
85  cloe::ActionPtr make(const cloe::Conf& c) const override;
86 
90  cloe::ActionPtr make(const std::string& s) const override;
91 
92  private:
93  std::shared_ptr<ScpTransceiver> scp_client_;
94  std::map<std::string, std::string> predefined_;
95 };
96 
97 } // namespace vtd
Definition: trigger.hpp:619
Logger logger() const
Definition: trigger.hpp:658
const std::string & name() const
Definition: entity.hpp:67
Definition: sync.hpp:34
Definition: trigger.hpp:290
Definition: trigger.hpp:437
Definition: conf.hpp:76
Definition: scp_action.hpp:57
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::CallbackResult operator()(const cloe::Sync &, cloe::TriggerRegistrar &) override
Definition: scp_action.hpp:38
cloe::ActionPtr clone() const override
Definition: scp_action.hpp:37
bool is_significant() const override
Definition: scp_action.hpp:43
Definition: trigger.hpp:207
CallbackResult
Definition: trigger.hpp:514