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  {
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 
112  public: bool Paused() const;
113 
116  // \return True if logger is ready to start.
117  public: bool IsReadyToStart() const;
118 
121  public: bool Running() const;
122 
126  public: bool Start(const std::string &_encoding="zlib",
127  const std::string &_path="");
128 
132  public: const std::string &Encoding() const;
133 
137  public: std::string Filename(const std::string &_name = "") const;
138 
142  public: unsigned int FileSize(const std::string &_name = "") const;
143 
146  public: void SetBasePath(const std::string &_path);
147 
150  public: std::string BasePath() const;
151 
154  public: common::Time RunTime() const;
155 
157  public: void Fini();
158 
161  public: bool FirstUpdate() const;
162 
165  public: void Write(const bool _force = false);
166 
169  public: unsigned int BufferSize() const;
170 
175  private: void Update();
176 
178  private: void RunUpdate();
179 
181  private: void RunWrite();
182 
184  private: void ClearLogs();
185 
187  private: void PublishLogStatus();
188 
191  private: void OnLogControl(ConstLogControlPtr &_data);
192 
196  private: void Cleanup();
197 
199  private: void OnPause(const bool _pause);
200 
202  private: friend class SingletonT<LogRecord>;
203 
206  private: std::unique_ptr<LogRecordPrivate> dataPtr;
207  };
209  }
210 }
211 #endif
Forward declarations for the common classes.
Definition: Animation.hh:33
Singleton template class.
Definition: SingletonT.hh:33
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