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 <string>
22 
23 #include "gazebo/msgs/msgs.hh"
25 #include "gazebo/util/system.hh"
26 
27 #define GZ_LOG_VERSION "1.0"
28 
29 namespace gazebo
30 {
31  namespace util
32  {
36  {
38  public: std::string encoding = "zlib";
39 
41  public: std::string path;
42 
45  public: double period = -1;
46 
48  public: std::string filter;
49  };
50 
51  // Forward declare private data class
52  class LogRecordPrivate;
53 
56 
74  class GZ_UTIL_VISIBLE LogRecord : public SingletonT<LogRecord>
75  {
77  private: LogRecord();
78 
80  private: virtual ~LogRecord();
81 
88  public: bool Init(const std::string &_subdir);
89 
102  public: void Add(const std::string &_name, const std::string &_filename,
103  std::function<bool (std::ostringstream &)> _logCallback);
104 
113  public: bool Remove(const std::string &_name);
114 
116  public: void Stop();
117 
119  public: void Notify();
120 
125  public: void SetPaused(const bool _paused);
126 
131  public: bool GetPaused() const GAZEBO_DEPRECATED(7.0);
132 
136  public: bool Paused() const;
137 
140  public: double Period() const;
141 
144  public: void SetPeriod(const double _period);
145 
148  public: std::string Filter() const;
149 
152  public: void SetFilter(const std::string &_filter);
153 
156  // \return True if logger is ready to start.
157  public: bool IsReadyToStart() const;
158 
162  public: bool GetRunning() const GAZEBO_DEPRECATED(7.0);
163 
166  public: bool Running() const;
167 
170  public: bool Start(const LogRecordParams &_params);
171 
175  public: bool Start(const std::string &_encoding="zlib",
176  const std::string &_path="");
177 
182  public: const std::string &GetEncoding() const GAZEBO_DEPRECATED(7.0);
183 
187  public: const std::string &Encoding() const;
188 
193  public: std::string GetFilename(const std::string &_name = "") const
194  GAZEBO_DEPRECATED(7.0);
195 
199  public: std::string Filename(const std::string &_name = "") const;
200 
205  public: unsigned int GetFileSize(const std::string &_name = "") const
206  GAZEBO_DEPRECATED(7.0);
207 
211  public: unsigned int FileSize(const std::string &_name = "") const;
212 
215  public: void SetBasePath(const std::string &_path);
216 
220  public: std::string GetBasePath() const GAZEBO_DEPRECATED(7.0);
221 
224  public: std::string BasePath() const;
225 
229  public: common::Time GetRunTime() const GAZEBO_DEPRECATED(7.0);
230 
233  public: common::Time RunTime() const;
234 
236  public: void Fini();
237 
241  public: bool GetFirstUpdate() const GAZEBO_DEPRECATED(7.0);
242 
245  public: bool FirstUpdate() const;
246 
249  public: void Write(const bool _force = false);
250 
254  public: unsigned int GetBufferSize() const GAZEBO_DEPRECATED(7.0);
255 
258  public: unsigned int BufferSize() const;
259 
264  private: void Update();
265 
267  private: void RunUpdate();
268 
270  private: void RunWrite();
271 
273  private: void ClearLogs();
274 
276  private: void PublishLogStatus();
277 
280  private: void OnLogControl(ConstLogControlPtr &_data);
281 
285  private: void Cleanup();
286 
288  private: void OnPause(const bool _pause);
289 
291  private: friend class SingletonT<LogRecord>;
292 
295  private: std::unique_ptr<LogRecordPrivate> dataPtr;
296  };
298  }
299 }
300 #endif
Forward declarations for the common classes.
Definition: Animation.hh:33
double period
Recording period.
Definition: LogRecord.hh:45
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:50
Singleton template class.
Definition: SingletonT.hh:33
std::string encoding
The type of encoding (txt, zlib, or bz2).
Definition: LogRecord.hh:38
addtogroup gazebo_util
Definition: LogRecord.hh:74
Log recording parameters.
Definition: LogRecord.hh:35
std::string filter
Log filter string.
Definition: LogRecord.hh:48
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:41
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44