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


rosbag
Author(s): Tim Field, Jeremy Leibs, James Bowman
autogenerated on Sun Feb 3 2019 03:30:26