bag_player.h
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2013, Open Source Robotics Foundation
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_BAG_PLAYER_H
36 #define ROSBAG_BAG_PLAYER_H
37 
38 #include <boost/foreach.hpp>
39 
40 #include "rosbag/bag.h"
41 #include "rosbag/view.h"
42 
43 namespace rosbag
44 {
45 
46 
47 // A helper struct
49 {
50  virtual ~BagCallback() {};
51  virtual void call(MessageInstance m) = 0;
52 };
53 
54 // A helper class for the callbacks
55 template<class T>
56 class BagCallbackT : public BagCallback
57 {
58 public:
60 
62  cb_(cb)
63  {}
64 
66  cb_(m.instantiate<T>());
67  }
68 
69 private:
71 };
72 #ifdef _MSC_VER
73 //#pragma warning( disable : 4290 ) // Suppress warning C4290:C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
74 #endif
75 /* A class for playing back bag files at an API level. It supports
76  relatime, as well as accelerated and slowed playback. */
77 class BagPlayer
78 {
79 public:
80  /* Constructor expecting the filename of a bag */
81  BagPlayer(const std::string &filename);
82 
83  /* Register a callback for a specific topic and type */
84  template<class T>
85  void register_callback(const std::string &topic,
86  typename BagCallbackT<T>::Callback f);
87 
88  /* Unregister a callback for a topic already registered */
89  void unregister_callback(const std::string &topic);
90 
91  /* Set the time in the bag to start.
92  * Default is the first message */
93  void set_start(const rs2rosinternal::Time &start);
94 
95  /* Set the time in the bag to stop.
96  * Default is the last message */
97  void set_end(const rs2rosinternal::Time &end);
98 
99  /* Set the speed to playback. 1.0 is the default.
100  * 2.0 would be twice as fast, 0.5 is half realtime. */
101  void set_playback_speed(double scale);
102 
103  /* Start playback of the bag file using the parameters previously
104  set */
105  void start_play();
106 
107  /* Get the current time of the playback */
109 
110  // Destructor
111  virtual ~BagPlayer();
112 
113 
114  // The bag file interface loaded in the constructor.
116 
117 private:
118  rs2rosinternal::Time real_time(const rs2rosinternal::Time &msg_time);
119 
120  std::map<std::string, BagCallback *> cbs_;
126 };
127 
128 template<class T>
129 void BagPlayer::register_callback(const std::string &topic,
130  typename BagCallbackT<T>::Callback cb) {
131  cbs_[topic] = new BagCallbackT<T>(cb);
132 }
133 
134 }
135 
136 #endif
virtual void call(MessageInstance m)=0
std::map< std::string, BagCallback * > cbs_
Definition: bag_player.h:120
GLuint GLuint end
std::mutex m
BagCallbackT(Callback cb)
Definition: bag_player.h:61
rs2rosinternal::Time bag_start_
Definition: bag_player.h:121
void register_callback(const std::string &topic, typename BagCallbackT< T >::Callback f)
Definition: bag_player.h:129
void call(MessageInstance m)
Definition: bag_player.h:65
A class pointing into a bag file.
Time representation. May either represent wall clock time or ROS clock time.
Definition: time.h:177
GLuint start
virtual ~BagCallback()
Definition: bag_player.h:50
rs2rosinternal::Time bag_end_
Definition: bag_player.h:122
double playback_speed_
Definition: bag_player.h:124
rs2rosinternal::Time last_message_time_
Definition: bag_player.h:123
Definition: bag.h:66
rs2rosinternal::Time play_start_
Definition: bag_player.h:125
GLdouble f
double get_time()
Definition: rs_internal.hpp:62
std::shared_ptr< T > instantiate() const
Templated call to instantiate a message.


librealsense2
Author(s): LibRealSense ROS Team
autogenerated on Thu Dec 22 2022 03:41:42