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 <time.h>
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 rosbag {
66 
68 {
69 public:
70  OutgoingMessage(std::string const& _topic, topic_tools::ShapeShifter::ConstPtr _msg, boost::shared_ptr<ros::M_string> _connection_header, ros::Time _time);
71 
72  std::string topic;
76 };
77 
79 {
80 public:
81  OutgoingQueue(std::string const& _filename, std::queue<OutgoingMessage>* _queue, ros::Time _time);
82 
83  std::string filename;
84  std::queue<OutgoingMessage>* queue;
86 };
87 
89 {
91 
92  bool trigger;
93  bool record_all;
94  bool regex;
95  bool do_exclude;
96  bool quiet;
98  bool snapshot;
99  bool verbose;
100  bool publish;
102  std::string prefix;
103  std::string name;
104  boost::regex exclude_regex;
105  uint32_t buffer_size;
106  uint32_t chunk_size;
107  uint32_t limit;
108  bool split;
109  uint64_t max_size;
110  uint32_t max_splits;
112  std::string node;
113  unsigned long long min_space;
114  std::string min_space_str;
116 
117  std::vector<std::string> topics;
118 };
119 
121 {
122 public:
123  Recorder(RecorderOptions const& options);
124 
125  void doTrigger();
126 
127  bool isSubscribed(std::string const& topic) const;
128 
129  boost::shared_ptr<ros::Subscriber> subscribe(std::string const& topic);
130 
131  int run();
132 
133 private:
134  void printUsage();
135 
136  void updateFilenames();
137  void startWriting();
138  void stopWriting();
139 
140  bool checkLogging();
141  bool scheduledCheckDisk();
142  bool checkDisk();
143 
144  void snapshotTrigger(std_msgs::Empty::ConstPtr trigger);
145  // void doQueue(topic_tools::ShapeShifter::ConstPtr msg, std::string const& topic, boost::shared_ptr<ros::Subscriber> subscriber, boost::shared_ptr<int> count);
146  void doQueue(const ros::MessageEvent<topic_tools::ShapeShifter const>& msg_event, std::string const& topic, boost::shared_ptr<ros::Subscriber> subscriber, boost::shared_ptr<int> count);
147  void doRecord();
148  void checkNumSplits();
149  bool checkSize();
150  bool checkDuration(const ros::Time&);
151  void doRecordSnapshotter();
152  void doCheckMaster(ros::TimerEvent const& e, ros::NodeHandle& node_handle);
153 
154  bool shouldSubscribeToTopic(std::string const& topic, bool from_node = false);
155 
156  template<class T>
157  static std::string timeToStr(T ros_t);
158 
159 private:
161 
163 
164  std::string target_filename_;
165  std::string write_filename_;
166  std::list<std::string> current_files_;
167 
168  std::set<std::string> currently_recording_;
170 
172 
173  boost::condition_variable_any queue_condition_;
174  boost::mutex queue_mutex_;
175  std::queue<OutgoingMessage>* queue_;
176  uint64_t queue_size_;
177  uint64_t max_queue_size_;
178 
179  uint64_t split_count_;
180 
181  std::queue<OutgoingQueue> queue_queue_;
182 
184 
186 
188  boost::mutex check_disk_mutex_;
191 
193 };
194 
195 } // namespace rosbag
196 
197 #endif
ros::TransportHints transport_hints
Definition: recorder.h:115
ros::Time last_buffer_warn_
Definition: recorder.h:183
int exit_code_
eventual exit code
Definition: recorder.h:171
void run(class_loader::ClassLoader *loader)
uint64_t queue_size_
queue size
Definition: recorder.h:176
ros::WallTime check_disk_next_
Definition: recorder.h:189
boost::mutex queue_mutex_
mutex for queue
Definition: recorder.h:174
std::string target_filename_
Definition: recorder.h:164
boost::regex exclude_regex
Definition: recorder.h:104
topic_tools::ShapeShifter::ConstPtr msg
Definition: recorder.h:73
std::string write_filename_
Definition: recorder.h:165
ros::Duration max_duration
Definition: recorder.h:111
std::set< std::string > currently_recording_
set of currently recording topics
Definition: recorder.h:168
void subscribe()
std::queue< OutgoingMessage > * queue
Definition: recorder.h:84
ros::WallTime warn_next_
Definition: recorder.h:190
std::string prefix
Definition: recorder.h:102
#define ROSBAG_DECL
RecorderOptions options_
Definition: recorder.h:160
std::list< std::string > current_files_
Definition: recorder.h:166
boost::condition_variable_any queue_condition_
conditional variable for queue
Definition: recorder.h:173
std::string filename
Definition: recorder.h:83
unsigned long long min_space
Definition: recorder.h:113
boost::mutex check_disk_mutex_
Definition: recorder.h:188
bool writing_enabled_
Definition: recorder.h:187
uint64_t split_count_
split count
Definition: recorder.h:179
std::queue< OutgoingQueue > queue_queue_
queue of queues to be used by the snapshot recorders
Definition: recorder.h:181
uint64_t max_queue_size_
max queue size
Definition: recorder.h:177
ros::Publisher pub_begin_write
Definition: recorder.h:192
ros::Time start_time_
Definition: recorder.h:185
int num_subscribers_
used for book-keeping of our number of subscribers
Definition: recorder.h:169
std::queue< OutgoingMessage > * queue_
queue for storing
Definition: recorder.h:175
CompressionType compression
Definition: recorder.h:101
std::vector< std::string > topics
Definition: recorder.h:117
std::string min_space_str
Definition: recorder.h:114
std::string topic
Definition: recorder.h:72
boost::shared_ptr< ros::M_string > connection_header
Definition: recorder.h:74


rosbag
Author(s): Tim Field, Jeremy Leibs, James Bowman, Dirk Thomas
autogenerated on Mon Feb 28 2022 23:34:21