SMACC2
Loading...
Searching...
No Matches
cb_sequence.hpp
Go to the documentation of this file.
1// Copyright 2025 Robosoft 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 void onEntry() override;
37
38 void onExit() override { sequenceNodes_.clear(); }
39
40 template <typename TOrthogonal, typename TBehavior, typename... Args>
41 CbSequence * then(Args &&... args)
42 {
43 std::function<std::shared_ptr<smacc2::SmaccAsyncClientBehavior>()> delayedCBFactoryFn =
44 [this, args...]()
45 {
46 RCLCPP_INFO(
47 getLogger(), "[CbSequence] then creating new sub behavior %s ",
49 auto createdBh = std::shared_ptr<TBehavior>(new TBehavior(args...));
50
51 this->getCurrentState()->getOrthogonal<TOrthogonal>()->addClientBehavior(createdBh);
53
54 return createdBh;
55 };
56
57 sequenceNodes_.push_back(delayedCBFactoryFn);
58
59 return this;
60 }
61
62private:
63 void onSubNodeSuccess();
64 void onSubNodeAbort();
66
67 std::list<std::function<std::shared_ptr<smacc2::SmaccAsyncClientBehavior>()>> sequenceNodes_;
70
71 std::shared_ptr<smacc2::SmaccAsyncClientBehavior> bh_;
72 std::atomic<int> consume_{0};
73};
74} // namespace client_behaviors
75} // namespace smacc2
virtual rclcpp::Logger getLogger() const
TOrthogonal * getOrthogonal()
CbSequence * then(Args &&... args)
smacc2::SmaccSignalConnection conn_
smacc2::SmaccSignalConnection conn2_
std::list< std::function< std::shared_ptr< smacc2::SmaccAsyncClientBehavior >()> > sequenceNodes_
std::shared_ptr< smacc2::SmaccAsyncClientBehavior > bh_
std::string demangleSymbol()
boost::signals2::connection SmaccSignalConnection