SLProject  4.3.020
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SENSOrientation.cpp
Go to the documentation of this file.
1 #include <SENSOrientation.h>
2 #include <Utils.h>
3 #include <iterator>
4 #include <algorithm>
5 #include <fstream>
6 
8 {
9  const std::lock_guard<std::mutex> lock(_orientationMutex);
10  return _orientation;
11 }
12 
14 {
15  //estimate time before running into lock
16  SENSTimePt timePt = SENSClock::now();
17 
18  {
19  const std::lock_guard<std::mutex> lock(_orientationMutex);
20  _orientation = orientation;
21  _timePt = timePt;
22  }
23 
24  {
25  std::lock_guard<std::mutex> lock(_listenerMutex); //to secure new listeners from registerListener, should not be a performance issue
27  l->onOrientation(timePt, orientation);
28  }
29 }
30 
32 {
33  std::lock_guard<std::mutex> lock(_listenerMutex);
34  if (std::find(_listeners.begin(), _listeners.end(), listener) == _listeners.end())
35  _listeners.push_back(listener);
36 }
38 {
39  std::lock_guard<std::mutex> lock(_listenerMutex);
40  for (auto it = _listeners.begin(); it != _listeners.end(); ++it)
41  {
42  if (*it == listener)
43  {
44  _listeners.erase(it);
45  break;
46  }
47  }
48 }
std::chrono::high_resolution_clock::time_point SENSTimePt
Definition: SENS.h:57
void setOrientation(Quat orientation)
void registerListener(SENSOrientationListener *listener)
SENSTimePt _timePt
void unregisterListener(SENSOrientationListener *listener)
Quat getOrientation() const
std::mutex _listenerMutex
std::vector< SENSOrientationListener * > _listeners
std::mutex _orientationMutex