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 
31 GZ_SINGLETON_DECLARE(GZ_UTIL_VISIBLE, gazebo, util, LogRecord)
32 
33 namespace gazebo
34 {
35  namespace util
36  {
40  {
42  public: std::string encoding = "zlib";
43 
45  public: std::string path;
46 
49  public: double period = -1;
50 
52  public: std::string filter;
53  };
54 
55  // Forward declare private data class
56  class LogRecordPrivate;
57 
60 
78  class GZ_UTIL_VISIBLE LogRecord : public SingletonT<LogRecord>
79  {
81  private: LogRecord();
82 
84  private: virtual ~LogRecord();
85 
92  public: bool Init(const std::string &_subdir);
93 
106  public: void Add(const std::string &_name, const std::string &_filename,
107  std::function<bool (std::ostringstream &)> _logCallback);
108 
117  public: bool Remove(const std::string &_name);
118 
120  public: void Stop();
121 
123  public: void Notify();
124 
129  public: void SetPaused(const bool _paused);
130 
134  public: bool Paused() const;
135 
138  public: double Period() const;
139 
142  public: void SetPeriod(const double _period);
143 
146  public: std::string Filter() const;
147 
150  public: void SetFilter(const std::string &_filter);
151 
155  public: bool RecordResources() const;
156 
159  public: void SetRecordResources(const bool _record);
160 
163  // \return True if logger is ready to start.
164  public: bool IsReadyToStart() const;
165 
168  public: bool Running() const;
169 
172  public: bool Start(const LogRecordParams &_params);
173 
177  public: bool Start(const std::string &_encoding="zlib",
178  const std::string &_path="");
179 
183  public: const std::string &Encoding() const;
184 
188  public: std::string Filename(const std::string &_name = "") const;
189 
193  public: unsigned int FileSize(const std::string &_name = "") const;
194 
197  public: void SetBasePath(const std::string &_path);
198 
201  public: std::string BasePath() const;
202 
205  public: common::Time RunTime() const;
206 
208  public: void Fini();
209 
212  public: bool FirstUpdate() const;
213 
216  public: bool SaveModels(const std::set<std::string> &models);
217 
221  public: bool SaveFiles(const std::set<std::string> &resources);
222 
225  public: void Write(const bool _force = false);
226 
229  public: unsigned int BufferSize() const;
230 
235  private: void Update();
236 
238  private: void RunUpdate();
239 
241  private: void RunWrite();
242 
244  private: void ClearLogs();
245 
247  private: void PublishLogStatus();
248 
251  private: void OnLogControl(ConstLogControlPtr &_data);
252 
256  private: void Cleanup();
257 
259  private: void OnPause(const bool _pause);
260 
262  private: friend class SingletonT<LogRecord>;
263 
266  private: std::unique_ptr<LogRecordPrivate> dataPtr;
267  };
269  }
270 }
271 #endif
Forward declarations for the common classes.
Definition: Animation.hh:26
A Time class, can be used to hold wall- or sim-time. stored as sec and nano-sec.
Definition: Time.hh:47
std::string filter
Log filter string.
Definition: LogRecord.hh:52
Singleton template class.
Definition: SingletonT.hh:33
util
Definition: LogRecord.hh:31
double period
Recording period.
Definition: LogRecord.hh:49
std::string encoding
The type of encoding (txt, zlib, or bz2).
Definition: LogRecord.hh:42
addtogroup gazebo_util
Definition: LogRecord.hh:78
std::string path
Path in which to store log files.
Definition: LogRecord.hh:45
Log recording parameters.
Definition: LogRecord.hh:39
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition: SingletonT.hh:61
gazebo
Definition: LogRecord.hh:31