LogRecord.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _GAZEBO_UTIL_LOGRECORD_HH_
18 #define _GAZEBO_UTIL_LOGRECORD_HH_
19 
20 #include <fstream>
21 #include <set>
22 #include <string>
23 
24 #include "gazebo/msgs/msgs.hh"
26 #include "gazebo/util/system.hh"
27 
28 #define GZ_LOG_VERSION "1.0"
29 
30 namespace gazebo
31 {
32  namespace util
33  {
37  {
39  public: std::string encoding = "zlib";
40 
42  public: std::string path;
43 
46  public: double period = -1;
47 
49  public: std::string filter;
50 
53  public: bool recordResources = false;
54  };
55 
56  // Forward declare private data class
57  class LogRecordPrivate;
58 
61 
79  class GZ_UTIL_VISIBLE LogRecord : public SingletonT<LogRecord>
80  {
82  private: LogRecord();
83 
85  private: virtual ~LogRecord();
86 
93  public: bool Init(const std::string &_subdir);
94 
107  public: void Add(const std::string &_name, const std::string &_filename,
108  std::function<bool (std::ostringstream &)> _logCallback);
109 
118  public: bool Remove(const std::string &_name);
119 
121  public: void Stop();
122 
124  public: void Notify();
125 
130  public: void SetPaused(const bool _paused);
131 
135  public: bool Paused() const;
136 
139  public: double Period() const;
140 
143  public: void SetPeriod(const double _period);
144 
147  public: std::string Filter() const;
148 
151  public: void SetFilter(const std::string &_filter);
152 
156  public: bool RecordResources() const;
157 
160  public: void SetRecordResources(const bool _record);
161 
164  // \return True if logger is ready to start.
165  public: bool IsReadyToStart() const;
166 
169  public: bool Running() const;
170 
173  public: bool Start(const LogRecordParams &_params);
174 
178  public: bool Start(const std::string &_encoding="zlib",
179  const std::string &_path="");
180 
184  public: const std::string &Encoding() const;
185 
189  public: std::string Filename(const std::string &_name = "") const;
190 
194  public: unsigned int FileSize(const std::string &_name = "") const;
195 
198  public: void SetBasePath(const std::string &_path);
199 
202  public: std::string BasePath() const;
203 
206  public: common::Time RunTime() const;
207 
209  public: void Fini();
210 
213  public: bool FirstUpdate() const;
214 
217  public: bool SaveModels(const std::set<std::string> &models);
218 
222  public: bool SaveFiles(const std::set<std::string> &resources);
223 
226  public: void Write(const bool _force = false);
227 
230  public: unsigned int BufferSize() const;
231 
236  private: void Update();
237 
239  private: void RunUpdate();
240 
242  private: void RunWrite();
243 
245  private: void ClearLogs();
246 
248  private: void PublishLogStatus();
249 
252  private: void OnLogControl(ConstLogControlPtr &_data);
253 
257  private: void Cleanup();
258 
260  private: void OnPause(const bool _pause);
261 
263  private: friend class SingletonT<LogRecord>;
264 
267  private: std::unique_ptr<LogRecordPrivate> dataPtr;
268  };
270  }
271 }
272 #endif
Forward declarations for the common classes.
Definition: Animation.hh:26
double period
Recording period.
Definition: LogRecord.hh:46
bool recordResources
Recording resources.
Definition: LogRecord.hh:53
Singleton template class.
Definition: SingletonT.hh:33
std::string encoding
The type of encoding (txt, zlib, or bz2).
Definition: LogRecord.hh:39
addtogroup gazebo_util
Definition: LogRecord.hh:79
Log recording parameters.
Definition: LogRecord.hh:36
std::string filter
Log filter string.
Definition: LogRecord.hh:49
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
std::string path
Path in which to store log files.
Definition: LogRecord.hh:42
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44