SMACC2
Loading...
Searching...
No Matches
cb_sequence.hpp
Go to the documentation of this file.
1// Copyright 2021 RobosoftAI Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15/*****************************************************************************************************************
16 *
17 * Authors: Pablo Inigo Blasco, Brett Aldrich
18 *
19 ******************************************************************************************************************/
20
21#pragma once
22
23#include <functional>
24#include <rclcpp/rclcpp.hpp>
26
27namespace smacc2
28{
29namespace client_behaviors
30{
32{
33public:
34 CbSequence();
35
36 // template <typename TOrthogonal, typename TBehavior>
37 // static void configure_orthogonal_runtime(
38 // std::function<void(TBehavior & bh, MostDerived &)> initializationFunction)
39 // {
40 // configure_orthogonal_internal<TOrthogonal, TBehavior>([=](ISmaccState * state) {
41 // // auto bh = std::make_shared<TBehavior>(args...);
42 // // auto bh = state->configure<TOrthogonal, TBehavior>();
43 // initializationFunction(*bh, *(static_cast<MostDerived *>(state)));
44 // });
45 // }
46
47 void onEntry() override;
48
49 // template <typename TOrthogonal, typename TSourceObject>
50 // void onOrthogonalAllocation()
51 // {
52 // smacc2::SmaccAsyncClientBehavior::onOrthogonalAllocation<TOrthogonal, TSourceObject>();
53 // }
54
55 void onExit() override { sequenceNodes_.clear(); }
56
57 template <typename TOrthogonal, typename TBehavior, typename... Args>
58 CbSequence * then(Args &&... args)
59 {
60 std::function<std::shared_ptr<smacc2::SmaccAsyncClientBehavior>()> delayedCBFactoryFn =
61 [this, args...]()
62 {
63 RCLCPP_INFO(
64 getLogger(), "[CbSequence] then creating new sub behavior %s ",
65 demangleSymbol<TBehavior>().c_str());
66 auto createdBh = std::shared_ptr<TBehavior>(new TBehavior(args...));
67
68 this->getCurrentState()->getOrthogonal<TOrthogonal>()->addClientBehavior(createdBh);
69 createdBh->template onOrthogonalAllocation<TOrthogonal, TBehavior>();
70
71 return createdBh;
72 };
73
74 sequenceNodes_.push_back(delayedCBFactoryFn);
75
76 return this;
77 }
78
79private:
80 void onSubNodeSuccess();
81 void onSubNodeAbort();
83
84 std::list<std::function<std::shared_ptr<smacc2::SmaccAsyncClientBehavior>()>> sequenceNodes_;
85 boost::signals2::connection conn_;
86 boost::signals2::connection conn2_;
87
88 std::shared_ptr<smacc2::SmaccAsyncClientBehavior> bh_;
89 std::atomic<int> consume_{0};
90};
91} // namespace client_behaviors
92} // namespace smacc2
virtual rclcpp::Logger getLogger() const
TOrthogonal * getOrthogonal()
CbSequence * then(Args &&... args)
Definition: cb_sequence.hpp:58
boost::signals2::connection conn_
Definition: cb_sequence.hpp:85
boost::signals2::connection conn2_
Definition: cb_sequence.hpp:86
std::list< std::function< std::shared_ptr< smacc2::SmaccAsyncClientBehavior >()> > sequenceNodes_
Definition: cb_sequence.hpp:84
std::shared_ptr< smacc2::SmaccAsyncClientBehavior > bh_
Definition: cb_sequence.hpp:88