SMACC2
Loading...
Searching...
No Matches
smacc2_client_library
ros_publisher_client
include
ros_publisher_client
client_behaviors
cb_publish_once.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
#include <
ros_publisher_client/cl_ros_publisher.hpp
>
23
#include <
smacc2/smacc_client_behavior.hpp
>
24
25
namespace
cl_ros_publisher
26
{
27
template
<
typename
RosMsgType>
28
class
CbPublishOnce
:
public
smacc2::SmaccClientBehavior
29
{
30
private
:
31
std::function<void()>
deferedPublishFn
;
32
ClRosPublisher
*
client_
;
33
34
public
:
35
CbPublishOnce
() :
deferedPublishFn
(nullptr) {}
36
37
template
<
typename
TMessage>
38
CbPublishOnce
(
const
TMessage & data)
39
{
40
this->
setMessage
(data);
41
}
42
43
template
<
typename
TMessage>
44
void
setMessage
(
const
TMessage & data)
45
{
46
deferedPublishFn
= [
this
, data]() { this->client_->
publish
(data); };
47
}
48
49
void
onEntry
()
override
50
{
51
this->
requiresClient
(client_);
52
53
if
(
deferedPublishFn
!=
nullptr
)
deferedPublishFn
();
54
}
55
56
void
onExit
()
override
{}
57
};
58
}
// namespace cl_ros_publisher
cl_ros_publisher.hpp
cl_ros_publisher::CbPublishOnce
Definition
cb_publish_once.hpp:29
cl_ros_publisher::CbPublishOnce::CbPublishOnce
CbPublishOnce(const TMessage &data)
Definition
cb_publish_once.hpp:38
cl_ros_publisher::CbPublishOnce::deferedPublishFn
std::function< void()> deferedPublishFn
Definition
cb_publish_once.hpp:31
cl_ros_publisher::CbPublishOnce::CbPublishOnce
CbPublishOnce()
Definition
cb_publish_once.hpp:35
cl_ros_publisher::CbPublishOnce::onEntry
void onEntry() override
Definition
cb_publish_once.hpp:49
cl_ros_publisher::CbPublishOnce::client_
ClRosPublisher * client_
Definition
cb_publish_once.hpp:32
cl_ros_publisher::CbPublishOnce::setMessage
void setMessage(const TMessage &data)
Definition
cb_publish_once.hpp:44
cl_ros_publisher::CbPublishOnce::onExit
void onExit() override
Definition
cb_publish_once.hpp:56
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::SmaccClientBehavior
Definition
smacc_client_behavior.hpp:27
cl_ros_publisher
Definition
cl_ros_publisher.hpp:26
smacc_client_behavior.hpp
Generated by
1.9.8