SMACC2
Loading...
Searching...
No Matches
cb_default_publish_loop.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#pragma once
23
24namespace cl_ros_publisher
25{
27{
28private:
29 std::function<void()> deferedPublishFn_;
31
32public:
34
35 template <typename TMessage>
36 CbDefaultPublishLoop(const TMessage & data)
37 {
38 this->setMessage(data);
39 }
40
41 template <typename TMessage>
42 void setMessage(const TMessage & data)
43 {
44 deferedPublishFn_ = [this, data]() { this->client_->publish(data); };
45 }
46
47 void onEntry() override { this->requiresClient(client_); }
48
49 virtual void update()
50 {
51 if (deferedPublishFn_ != nullptr)
52 {
54 }
55 }
56
57 void onExit() override {}
58};
59} // namespace cl_ros_publisher
void publish(const MessageType &msg)
void requiresClient(SmaccClientType *&storage)