SLProject  4.3.020
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SENSRecorder Class Reference

#include <SENSRecorder.h>

Inheritance diagram for SENSRecorder:
[legend]

Public Member Functions

 SENSRecorder (const std::string &outputDir)
 
 ~SENSRecorder ()
 
bool activateGps (SENSGps *sensor)
 
bool deactivateGps ()
 
bool activateOrientation (SENSOrientation *sensor)
 
bool deactivateOrientation ()
 
bool activateCamera (SENSCamera *sensor)
 
bool deactivateCamera ()
 
bool start ()
 
void stop ()
 Stops a running recording session. More...
 
bool getGpsHandlerError (std::string &errorMsg)
 
bool getOrientationHandlerError (std::string &errorMsg)
 
bool getCameraHandlerError (std::string &errorMsg)
 
bool isRunning () const
 
const std::string & outputDir () const
 
- Public Member Functions inherited from SENSGpsListener
virtual ~SENSGpsListener ()
 
- Public Member Functions inherited from SENSOrientationListener
virtual ~SENSOrientationListener ()
 
- Public Member Functions inherited from SENSCameraListener
virtual ~SENSCameraListener ()
 

Private Member Functions

void onGps (const SENSTimePt &timePt, const SENSGps::Location &loc) override
 gps listener callback More...
 
void onOrientation (const SENSTimePt &timePt, const SENSOrientation::Quat &ori) override
 orientation listener callback More...
 
void onFrame (const SENSTimePt &timePt, cv::Mat frame) override
 camera listener callback More...
 
void onCameraConfigChanged (const SENSCameraConfig &config) override
 

Private Attributes

std::string _outputDir
 
SENSGpsRecorderDataHandler_gpsDataHandler = nullptr
 
SENSOrientationRecorderDataHandler_orientationDataHandler = nullptr
 
SENSCameraRecorderDataHandler_cameraDataHandler = nullptr
 
SENSGps_gps = nullptr
 
SENSOrientation_orientation = nullptr
 
SENSCamera_camera = nullptr
 
std::atomic_bool _running {false}
 

Detailed Description

SENSRecorder This class records implemented sensor classes to file. The output directory has to be transfered during instantiation. Activate or deactivate a sensor by calling activate or deactivate methods. The functions return true on success, a change is only possible if the recorder is not running (use isRunning method). Call start() and stop() to start or stop recording of sensors. The SENSRecorder listens to sensors and informs SENSRecorderDataHandler backends about new data. The SENSRecorderDataHandler stores values to file.

Definition at line 18 of file SENSRecorder.h.

Constructor & Destructor Documentation

◆ SENSRecorder()

SENSRecorder::SENSRecorder ( const std::string &  outputDir)

Definition at line 4 of file SENSRecorder.cpp.

6 {
8  {
12  }
13  else
14  Utils::log("SENS", "SENSRecorder: Directory does not exist: %s", outputDir.c_str());
15 }
SENSOrientationRecorderDataHandler * _orientationDataHandler
Definition: SENSRecorder.h:58
const std::string & outputDir() const
Definition: SENSRecorder.h:44
std::string _outputDir
Definition: SENSRecorder.h:55
SENSCameraRecorderDataHandler * _cameraDataHandler
Definition: SENSRecorder.h:59
SENSGpsRecorderDataHandler * _gpsDataHandler
Definition: SENSRecorder.h:57
bool dirExists(const string &path)
Returns true if a directory exists.
Definition: Utils.cpp:789
void log(const char *tag, const char *format,...)
logs a formatted string platform independently
Definition: Utils.cpp:1100

◆ ~SENSRecorder()

SENSRecorder::~SENSRecorder ( )

Definition at line 17 of file SENSRecorder.cpp.

18 {
19  stop();
20 
21  if (_gpsDataHandler)
22  delete _gpsDataHandler;
26  delete _cameraDataHandler;
27 }
void stop()
Stops a running recording session.

Member Function Documentation

◆ activateCamera()

bool SENSRecorder::activateCamera ( SENSCamera sensor)

Definition at line 76 of file SENSRecorder.cpp.

77 {
78  if (!_running && sensor)
79  {
81  _camera = sensor;
82  return true;
83  }
84  else
85  return false;
86 }
std::atomic_bool _running
Definition: SENSRecorder.h:65
bool deactivateCamera()
SENSCamera * _camera
Definition: SENSRecorder.h:63

◆ activateGps()

bool SENSRecorder::activateGps ( SENSGps sensor)

Definition at line 30 of file SENSRecorder.cpp.

31 {
32  if (!_running && sensor)
33  {
34  deactivateGps();
35  _gps = sensor;
36  return true;
37  }
38  else
39  return false;
40 }
SENSGps * _gps
Definition: SENSRecorder.h:61
bool deactivateGps()

◆ activateOrientation()

bool SENSRecorder::activateOrientation ( SENSOrientation sensor)

Definition at line 52 of file SENSRecorder.cpp.

53 {
54  if (!_running && sensor)
55  {
57  _orientation = sensor;
58  return true;
59  }
60  else
61  return false;
62 }
bool deactivateOrientation()
SENSOrientation * _orientation
Definition: SENSRecorder.h:62

◆ deactivateCamera()

bool SENSRecorder::deactivateCamera ( )

Definition at line 88 of file SENSRecorder.cpp.

89 {
90  if (!_running && _camera)
91  {
92  _camera = nullptr;
93  return true;
94  }
95  else
96  return true;
97 }

◆ deactivateGps()

bool SENSRecorder::deactivateGps ( )

Definition at line 41 of file SENSRecorder.cpp.

42 {
43  if (!_running && _gps)
44  {
45  _gps = nullptr;
46  return true;
47  }
48  else
49  return false;
50 }

◆ deactivateOrientation()

bool SENSRecorder::deactivateOrientation ( )

Definition at line 64 of file SENSRecorder.cpp.

65 {
66  if (!_running && _orientation)
67  {
68  _orientation = nullptr;
69  return true;
70  }
71  else
72  return true;
73 }

◆ getCameraHandlerError()

bool SENSRecorder::getCameraHandlerError ( std::string &  errorMsg)

Definition at line 177 of file SENSRecorder.cpp.

178 {
180  return true;
181  else
182  return false;
183 }
bool getErrorMsg(std::string &msg)
get error msg (valid if function returns true)
void errorMsg(const char *tag, const char *msg, const int line, const char *file)
Platform independent error message output.
Definition: Utils.cpp:1165

◆ getGpsHandlerError()

bool SENSRecorder::getGpsHandlerError ( std::string &  errorMsg)

Definition at line 161 of file SENSRecorder.cpp.

162 {
164  return true;
165  else
166  return false;
167 }

◆ getOrientationHandlerError()

bool SENSRecorder::getOrientationHandlerError ( std::string &  errorMsg)

Definition at line 169 of file SENSRecorder.cpp.

170 {
172  return true;
173  else
174  return false;
175 }

◆ isRunning()

bool SENSRecorder::isRunning ( ) const
inline

Definition at line 43 of file SENSRecorder.h.

43 { return _running; }

◆ onCameraConfigChanged()

void SENSRecorder::onCameraConfigChanged ( const SENSCameraConfig config)
overrideprivatevirtual

Implements SENSCameraListener.

Definition at line 206 of file SENSRecorder.cpp.

207 {
208  if (_cameraDataHandler)
210 }
void updateConfig(const SENSCameraConfig &config)
Config config
The configuration set in App::run.
Definition: AppAndroid.cpp:34

◆ onFrame()

void SENSRecorder::onFrame ( const SENSTimePt timePt,
cv::Mat  frame 
)
overrideprivatevirtual

camera listener callback

Implements SENSCameraListener.

Definition at line 199 of file SENSRecorder.cpp.

200 {
201  auto newData = std::make_pair(frame, timePt);
202  if (_cameraDataHandler)
203  _cameraDataHandler->add(std::move(newData));
204 }
void add(T &&item)
add new value to store queue

◆ onGps()

void SENSRecorder::onGps ( const SENSTimePt timePt,
const SENSGps::Location loc 
)
overrideprivatevirtual

gps listener callback

Implements SENSGpsListener.

Definition at line 185 of file SENSRecorder.cpp.

186 {
187  auto newData = std::make_pair(loc, timePt);
188  if (_gpsDataHandler)
189  _gpsDataHandler->add(std::move(newData));
190 }

◆ onOrientation()

void SENSRecorder::onOrientation ( const SENSTimePt timePt,
const SENSOrientation::Quat ori 
)
overrideprivatevirtual

orientation listener callback

Implements SENSOrientationListener.

Definition at line 192 of file SENSRecorder.cpp.

193 {
194  auto newData = std::make_pair(ori, timePt);
196  _orientationDataHandler->add(std::move(newData));
197 }

◆ outputDir()

const std::string& SENSRecorder::outputDir ( ) const
inline

Definition at line 44 of file SENSRecorder.h.

44 { return _outputDir; }

◆ start()

bool SENSRecorder::start ( )

Start the recording of activated sensors (Registers listeners and starts SENSRecorderDataHandler backends). Returns true on success. Possible reasons for fail are: Output directory does not exist or recorder is already running.

Definition at line 99 of file SENSRecorder.cpp.

100 {
101  if (_running)
102  return false;
103 
104  std::string recordDir = Utils::unifySlashes(_outputDir) + Utils::getDateTime2String() + "_SENSRecorder/";
105  if (!Utils::makeDir(recordDir))
106  {
107  Utils::log("SENS", "SENSRecorder start: could not create record directory: %s", recordDir.c_str());
108  return false;
109  }
110 
111  if (_gps && _gpsDataHandler)
112  {
113  _gpsDataHandler->start(recordDir);
114  _gps->registerListener(this);
115  _running = true;
116  }
117 
119  {
120  _orientationDataHandler->start(recordDir);
122  _running = true;
123  }
124 
126  {
127  _cameraDataHandler->start(recordDir);
128  _camera->registerListener(this);
129  _running = true;
130  }
131 
132  return _running;
133 }
virtual void registerListener(SENSCameraListener *listener)=0
void registerListener(SENSGpsListener *listener)
Definition: SENSGps.cpp:29
void registerListener(SENSOrientationListener *listener)
void start(const std::string &outputDir)
start the store thread
string getDateTime2String()
Returns local time as string like "20190213-154611".
Definition: Utils.cpp:289
string unifySlashes(const string &inputDir, bool withTrailingSlash)
Returns the inputDir string with unified forward slashes, e.g.: "dirA/dirB/".
Definition: Utils.cpp:367
bool makeDir(const string &path)
Creates a directory with given path.
Definition: Utils.cpp:809

◆ stop()

void SENSRecorder::stop ( )

Stops a running recording session.

Definition at line 135 of file SENSRecorder.cpp.

136 {
137  if (_gps)
138  {
139  _gps->unregisterListener(this);
140  if (_gpsDataHandler)
142  }
143 
144  if (_orientation)
145  {
149  }
150 
151  if (_camera)
152  {
154  if (_cameraDataHandler)
156  }
157 
158  _running = false;
159 }
virtual void unregisterListener(SENSCameraListener *listener)=0
void unregisterListener(SENSGpsListener *listener)
Definition: SENSGps.cpp:36
void unregisterListener(SENSOrientationListener *listener)
void stop()
stop the store thread and clear values in queue

Member Data Documentation

◆ _camera

SENSCamera* SENSRecorder::_camera = nullptr
private

Definition at line 63 of file SENSRecorder.h.

◆ _cameraDataHandler

SENSCameraRecorderDataHandler* SENSRecorder::_cameraDataHandler = nullptr
private

Definition at line 59 of file SENSRecorder.h.

◆ _gps

SENSGps* SENSRecorder::_gps = nullptr
private

Definition at line 61 of file SENSRecorder.h.

◆ _gpsDataHandler

SENSGpsRecorderDataHandler* SENSRecorder::_gpsDataHandler = nullptr
private

Definition at line 57 of file SENSRecorder.h.

◆ _orientation

SENSOrientation* SENSRecorder::_orientation = nullptr
private

Definition at line 62 of file SENSRecorder.h.

◆ _orientationDataHandler

SENSOrientationRecorderDataHandler* SENSRecorder::_orientationDataHandler = nullptr
private

Definition at line 58 of file SENSRecorder.h.

◆ _outputDir

std::string SENSRecorder::_outputDir
private

Definition at line 55 of file SENSRecorder.h.

◆ _running

std::atomic_bool SENSRecorder::_running {false}
private

Definition at line 65 of file SENSRecorder.h.


The documentation for this class was generated from the following files: