ign_publisher.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #include <atomic>
19 #include <chrono>
20 #include <csignal>
21 #include <iostream>
22 #include <thread>
23 #include <ignition/msgs.hh>
24 #include <ignition/transport.hh>
25 #include "../test_utils.h"
26 
28 static std::atomic<bool> g_terminatePub(false);
29 
34 void signal_handler(int _signal)
35 {
36  if (_signal == SIGINT || _signal == SIGTERM)
37  g_terminatePub = true;
38 }
39 
41 int main(int /*argc*/, char **/*argv*/)
42 {
43  // Install a signal handler for SIGINT and SIGTERM.
44  std::signal(SIGINT, signal_handler);
45  std::signal(SIGTERM, signal_handler);
46 
47  // Create a transport node and advertise a topic.
48  ignition::transport::Node node;
49 
50  // ignition::msgs::Image.
51  auto image_pub = node.Advertise<ignition::msgs::Image>("image");
52  ignition::msgs::Image image_msg;
54 
55  // Publish messages at 1Hz.
56  while (!g_terminatePub)
57  {
58  image_pub.Publish(image_msg);
59 
60  std::this_thread::sleep_for(std::chrono::milliseconds(100));
61  }
62 
63  return 0;
64 }
signal_handler
void signal_handler(int _signal)
Function callback executed when a SIGINT or SIGTERM signals are captured. This is used to break the i...
Definition: ign_publisher.cpp:34
main
int main(int, char **)
Definition: ign_publisher.cpp:41
ros_ign_image::testing::createTestMsg
void createTestMsg(std_msgs::Header &_msg)
ROS test utils.
Definition: test_utils.h:87
g_terminatePub
static std::atomic< bool > g_terminatePub(false)
Flag used to break the publisher loop and terminate the program.


ros_ign_image
Author(s):
autogenerated on Sat Mar 11 2023 04:02:19