recorder.h
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of Willow Garage, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 ********************************************************************/
34 
35 #ifndef ROSBAG_RECORDER_H
36 #define ROSBAG_RECORDER_H
37 
38 #include <sys/stat.h>
39 #if !defined(_MSC_VER)
40  #include <termios.h>
41  #include <unistd.h>
42 #endif
43 #include <ctime>
44 
45 #include <queue>
46 #include <string>
47 #include <vector>
48 #include <list>
49 
50 #include <boost/thread/condition.hpp>
51 #include <boost/thread/mutex.hpp>
52 #include <boost/regex.hpp>
53 
54 #include <ros/ros.h>
55 #include <ros/time.h>
56 
57 #include <std_msgs/Empty.h>
58 #include <std_msgs/String.h>
60 
61 #include "rosbag/bag.h"
62 #include "rosbag/stream.h"
63 #include "rosbag/macros.h"
64 
65 namespace Aws
66 {
67 namespace Rosbag
68 {
69 namespace Utils
70 {
71 
73 {
74 public:
75  OutgoingMessage(std::string _topic, topic_tools::ShapeShifter::ConstPtr _msg, boost::shared_ptr<ros::M_string> _connection_header, ros::Time _time);
76  OutgoingMessage() = default;
77  std::string topic;
81 };
82 
84 {
85 public:
86  OutgoingQueue(std::string _filename, std::shared_ptr<std::queue<OutgoingMessage>> _queue, ros::Time _time);
87 
88  std::string filename;
89  std::shared_ptr<std::queue<OutgoingMessage>> queue;
91 };
92 
94 {
95  RecorderOptions() = default;
96 
97  bool trigger {false};
98  bool record_all {false};
99  bool regex {false};
100  bool do_exclude {false};
101  bool quiet {false};
102  bool append_date {true};
103  bool snapshot {false};
104  bool verbose {false};
105  bool publish {false};
107  std::string prefix {""};
108  std::string name {""};
109  boost::regex exclude_regex {};
110  uint32_t buffer_size {1048576 * 256};
111  uint32_t chunk_size {1024 * 768};
112  uint32_t limit {0};
113  bool split {false};
114  uint64_t max_size {0};
115  uint32_t max_splits {0};
116  ros::Duration max_duration {-1.0};
117  std::string node {""};
118  uint64_t min_space {1024 * 1024 * 1024};
119  std::string min_space_str {"1G"};
121 
122  std::vector<std::string> topics;
123 };
124 
126 {
127 public:
128  explicit Recorder(RecorderOptions options);
129 
130  void DoTrigger();
131 
132  bool IsSubscribed(std::string const& topic) const;
133 
134  boost::shared_ptr<ros::Subscriber> Subscribe(ros::NodeHandle & nh, std::string const& topic);
135 
136  int Run();
137 
138 private:
139  void PrintUsage();
140 
141  void UpdateFilenames();
142  void StartWriting();
143  void StopWriting();
144 
145  bool CheckLogging();
146  bool ScheduledCheckDisk();
147  bool CheckDisk();
148 
149  void SnapshotTrigger(std_msgs::Empty::ConstPtr trigger);
150  // void doQueue(topic_tools::ShapeShifter::ConstPtr msg, std::string const& topic, boost::shared_ptr<ros::Subscriber> subscriber, boost::shared_ptr<int> count);
151  void DoQueue(const ros::MessageEvent<topic_tools::ShapeShifter const>& msg_event,
152  std::string const& topic,
153  ros::Subscriber * subscriber,
154  const boost::shared_ptr<int>& count);
155  void DoRecord();
156  void CheckNumSplits();
157  bool CheckSize();
158  bool CheckDuration(const ros::Time& t);
159  void DoRecordSnapshotter();
160  void DoCheckMaster(ros::TimerEvent const& e, ros::NodeHandle& node_handle);
161 
162  bool ShouldSubscribeToTopic(std::string const& topic, bool from_node = false);
163 
164  template<class T>
165  static std::string TimeToStr(T ros_t);
166 
167 private:
170 
172 
173  std::string target_filename_;
174  std::string write_filename_;
175  std::list<std::string> current_files_;
176 
177  std::set<std::string> currently_recording_;
178  std::vector<boost::shared_ptr<ros::Subscriber>> subscribers_;
179 
181 
182  boost::condition_variable_any queue_condition_;
183  boost::mutex queue_mutex_;
184  std::shared_ptr<std::queue<OutgoingMessage>> queue_;
185  uint64_t queue_size_;
186 
187  uint64_t split_count_;
188 
189  std::queue<OutgoingQueue> queue_queue_;
190 
192 
194 
196  boost::mutex check_disk_mutex_;
199 
201 };
202 
203 } // namespace Utils
204 } // namespace Rosbag
205 } // namespace Aws
206 
207 #endif
def PrintUsage(message)
ros::WallTime check_disk_next_
Definition: recorder.h:197
uint64_t split_count_
split count
Definition: recorder.h:187
topic_tools::ShapeShifter::ConstPtr msg
Definition: recorder.h:78
std::list< std::string > current_files_
Definition: recorder.h:175
std::shared_ptr< std::queue< OutgoingMessage > > queue
Definition: recorder.h:89
RecorderOptions options_
Definition: recorder.h:168
int exit_code_
eventual exit code
Definition: recorder.h:180
std::string target_filename_
Definition: recorder.h:173
boost::mutex queue_mutex_
mutex for queue
Definition: recorder.h:183
std::set< std::string > currently_recording_
set of currenly recording topics
Definition: recorder.h:177
boost::condition_variable_any queue_condition_
conditional variable for queue
Definition: recorder.h:182
#define ROSBAG_DECL
uint64_t queue_size_
queue size
Definition: recorder.h:185
options
std::queue< OutgoingQueue > queue_queue_
queue of queues to be used by the snapshot recorders
Definition: recorder.h:189
std::vector< boost::shared_ptr< ros::Subscriber > > subscribers_
Definition: recorder.h:178
ros::Publisher pub_begin_write_
Definition: recorder.h:200
std::shared_ptr< std::queue< OutgoingMessage > > queue_
queue for storing
Definition: recorder.h:184
boost::mutex check_disk_mutex_
Definition: recorder.h:196
std::vector< std::string > topics
Definition: recorder.h:122
ros::WallTime warn_next_
Definition: recorder.h:198
boost::shared_ptr< ros::M_string > connection_header
Definition: recorder.h:79
ros::TransportHints transport_hints
Definition: recorder.h:120


rosbag_cloud_recorders
Author(s): AWS RoboMaker
autogenerated on Tue Jun 1 2021 02:51:27