LogRecord.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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  {
33  // Forward declare private data class
34  class LogRecordPrivate;
35 
38 
56  class GZ_UTIL_VISIBLE LogRecord : public SingletonT<LogRecord>
57  {
59  private: LogRecord();
60 
62  private: virtual ~LogRecord();
63 
70  public: bool Init(const std::string &_subdir);
71 
84  public: void Add(const std::string &_name, const std::string &_filename,
85  std::function<bool (std::ostringstream &)> _logCallback);
86 
95  public: bool Remove(const std::string &_name);
96 
98  public: void Stop();
99 
101  public: void Notify();
102 
107  public: void SetPaused(const bool _paused);
108 
113  public: bool GetPaused() const GAZEBO_DEPRECATED(7.0);
114 
118  public: bool Paused() const;
119 
122  // \return True if logger is ready to start.
123  public: bool IsReadyToStart() const;
124 
128  public: bool GetRunning() const GAZEBO_DEPRECATED(7.0);
129 
132  public: bool Running() const;
133 
137  public: bool Start(const std::string &_encoding="zlib",
138  const std::string &_path="");
139 
144  public: const std::string &GetEncoding() const GAZEBO_DEPRECATED(7.0);
145 
149  public: const std::string &Encoding() const;
150 
155  public: std::string GetFilename(const std::string &_name = "") const
156  GAZEBO_DEPRECATED(7.0);
157 
161  public: std::string Filename(const std::string &_name = "") const;
162 
167  public: unsigned int GetFileSize(const std::string &_name = "") const
168  GAZEBO_DEPRECATED(7.0);
169 
173  public: unsigned int FileSize(const std::string &_name = "") const;
174 
177  public: void SetBasePath(const std::string &_path);
178 
182  public: std::string GetBasePath() const GAZEBO_DEPRECATED(7.0);
183 
186  public: std::string BasePath() const;
187 
191  public: common::Time GetRunTime() const GAZEBO_DEPRECATED(7.0);
192 
195  public: common::Time RunTime() const;
196 
198  public: void Fini();
199 
203  public: bool GetFirstUpdate() const GAZEBO_DEPRECATED(7.0);
204 
207  public: bool FirstUpdate() const;
208 
211  public: void Write(const bool _force = false);
212 
216  public: unsigned int GetBufferSize() const GAZEBO_DEPRECATED(7.0);
217 
220  public: unsigned int BufferSize() const;
221 
226  private: void Update();
227 
229  private: void RunUpdate();
230 
232  private: void RunWrite();
233 
235  private: void ClearLogs();
236 
238  private: void PublishLogStatus();
239 
242  private: void OnLogControl(ConstLogControlPtr &_data);
243 
247  private: void Cleanup();
248 
250  private: void OnPause(const bool _pause);
251 
253  private: friend class SingletonT<LogRecord>;
254 
257  private: std::unique_ptr<LogRecordPrivate> dataPtr;
258  };
260  }
261 }
262 #endif
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:48
Singleton template class.
Definition: SingletonT.hh:33
#define GZ_UTIL_VISIBLE
Definition: system.hh:234
addtogroup gazebo_util
Definition: LogRecord.hh:56
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44