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 
67 class ROSBAG_DECL OutgoingMessage
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;
74  boost::shared_ptr<ros::M_string> connection_header;
75  ros::Time time;
76 };
77 
78 class ROSBAG_DECL OutgoingQueue
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;
85  ros::Time time;
86 };
87 
88 struct ROSBAG_DECL RecorderOptions
89 {
90  RecorderOptions();
91 
92  bool trigger;
93  bool record_all;
94  bool regex;
95  bool do_exclude;
96  bool quiet;
97  bool append_date;
98  bool snapshot;
99  bool verbose;
100  bool publish;
101  bool repeat_latched;
102  CompressionType compression;
103  std::string prefix;
104  std::string name;
105  boost::regex exclude_regex;
106  uint32_t buffer_size;
107  uint32_t chunk_size;
108  uint32_t limit;
109  bool split;
110  uint64_t max_size;
111  uint32_t max_splits;
112  ros::Duration max_duration;
113  std::string node;
114  unsigned long long min_space;
115  std::string min_space_str;
116  ros::TransportHints transport_hints;
117 
118  std::vector<std::string> topics;
119 };
120 
121 class ROSBAG_DECL Recorder
122 {
123 public:
124  Recorder(RecorderOptions const& options);
125 
126  void doTrigger();
127 
128  bool isSubscribed(std::string const& topic) const;
129 
131 
132  int run();
133 
134 private:
135  void printUsage();
136 
137  void updateFilenames();
138  void startWriting();
139  void stopWriting();
140 
141  bool checkLogging();
142  bool scheduledCheckDisk();
143  bool checkDisk();
144 
145  void snapshotTrigger(std_msgs::Empty::ConstPtr trigger);
146  // void doQueue(topic_tools::ShapeShifter::ConstPtr msg, std::string const& topic, boost::shared_ptr<ros::Subscriber> subscriber, boost::shared_ptr<int> count);
147  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);
148  void doRecord();
149  void checkNumSplits();
150  bool checkSize();
151  bool checkDuration(const ros::Time&);
152  void doRecordSnapshotter();
153  void doCheckMaster(ros::TimerEvent const& e, ros::NodeHandle& node_handle);
154 
155  bool shouldSubscribeToTopic(std::string const& topic, bool from_node = false);
156 
157  template<class T>
158  static std::string timeToStr(T ros_t);
159 
160 private:
161  RecorderOptions options_;
162 
163  Bag bag_;
164 
165  std::string target_filename_;
166  std::string write_filename_;
167  std::list<std::string> current_files_;
168 
169  std::set<std::string> currently_recording_;
170  int num_subscribers_;
171 
172  int exit_code_;
173 
174  std::map<std::pair<std::string, std::string>, OutgoingMessage> latched_msgs_;
175 
176  boost::condition_variable_any queue_condition_;
177  boost::mutex queue_mutex_;
178  std::queue<OutgoingMessage>* queue_;
179  uint64_t queue_size_;
180  uint64_t max_queue_size_;
181 
182  uint64_t split_count_;
183 
184  std::queue<OutgoingQueue> queue_queue_;
185 
186  ros::Time last_buffer_warn_;
187 
188  ros::Time start_time_;
189 
190  bool writing_enabled_;
191  boost::mutex check_disk_mutex_;
192  ros::WallTime check_disk_next_;
193  ros::WallTime warn_next_;
194 
195  ros::Publisher pub_begin_write;
196 };
197 
198 } // namespace rosbag
199 
200 #endif
rosbag::Bag
ros::Publisher
run
void run(class_loader::ClassLoader *loader)
boost::shared_ptr< ShapeShifter const >
rosbag::RecorderOptions
Definition: recorder.h:120
ros.h
time.h
ros::TransportHints
rosbag::OutgoingMessage
Definition: recorder.h:99
bag.h
subscribe
void subscribe()
ros::TimerEvent
ros::WallTime
rosbag::compression::CompressionType
CompressionType
shape_shifter.h
ros::Time
ROSBAG_DECL
#define ROSBAG_DECL
rosbag::Recorder
Definition: recorder.h:153
rosbag
macros.h
ros::Duration
ros::NodeHandle
ros::MessageEvent
stream.h


rosbag
Author(s): Tim Field, Jeremy Leibs, James Bowman, Dirk Thomas , Jacob Perron
autogenerated on Sat Sep 14 2024 03:00:07