SMACC2
Loading...
Searching...
No Matches
smacc2_client_library
ros_publisher_client
include
ros_publisher_client
client_behaviors
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
21
#include <
ros_publisher_client/cl_ros_publisher.hpp
>
22
#include <
smacc2/smacc_client_behavior.hpp
>
23
24
namespace
cl_ros_publisher
25
{
26
class
CbDefaultPublishLoop
:
public
smacc2::SmaccClientBehavior
,
public
smacc2::ISmaccUpdatable
27
{
28
private
:
29
std::function<void()>
deferedPublishFn_
;
30
ClRosPublisher
*
client_
;
31
32
public
:
33
CbDefaultPublishLoop
() :
deferedPublishFn_
(nullptr) {}
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
{
53
deferedPublishFn_
();
54
}
55
}
56
57
void
onExit
()
override
{}
58
};
59
}
// namespace cl_ros_publisher
cl_ros_publisher.hpp
cl_ros_publisher::CbDefaultPublishLoop
Definition:
cb_default_publish_loop.hpp:27
cl_ros_publisher::CbDefaultPublishLoop::setMessage
void setMessage(const TMessage &data)
Definition:
cb_default_publish_loop.hpp:42
cl_ros_publisher::CbDefaultPublishLoop::CbDefaultPublishLoop
CbDefaultPublishLoop(const TMessage &data)
Definition:
cb_default_publish_loop.hpp:36
cl_ros_publisher::CbDefaultPublishLoop::client_
ClRosPublisher * client_
Definition:
cb_default_publish_loop.hpp:30
cl_ros_publisher::CbDefaultPublishLoop::onEntry
void onEntry() override
Definition:
cb_default_publish_loop.hpp:47
cl_ros_publisher::CbDefaultPublishLoop::CbDefaultPublishLoop
CbDefaultPublishLoop()
Definition:
cb_default_publish_loop.hpp:33
cl_ros_publisher::CbDefaultPublishLoop::onExit
void onExit() override
Definition:
cb_default_publish_loop.hpp:57
cl_ros_publisher::CbDefaultPublishLoop::deferedPublishFn_
std::function< void()> deferedPublishFn_
Definition:
cb_default_publish_loop.hpp:29
cl_ros_publisher::CbDefaultPublishLoop::update
virtual void update()
Definition:
cb_default_publish_loop.hpp:49
cl_ros_publisher::ClRosPublisher
Definition:
cl_ros_publisher.hpp:28
cl_ros_publisher::ClRosPublisher::publish
void publish(const MessageType &msg)
Definition:
cl_ros_publisher.hpp:40
smacc2::ISmaccClientBehavior::requiresClient
void requiresClient(SmaccClientType *&storage)
Definition:
smacc_client_behavior_impl.hpp:67
smacc2::ISmaccUpdatable
Definition:
smacc_updatable.hpp:33
smacc2::SmaccClientBehavior
Definition:
smacc_client_behavior.hpp:27
cl_ros_publisher
Definition:
cl_ros_publisher.hpp:26
smacc_client_behavior.hpp
Generated by
1.9.5