Ocean
|
This class implements a simple wrapper for the CMMotionManager object as an application must not create more than one instance of a CMMotionManager object. More...
#include <MotionManager.h>
Public Types | |
typedef unsigned int | ListenerId |
Definition of a listener id for a registered callbacks. | |
typedef Callback< void, CMDeviceMotion * > | DeviceMotionCallback |
Definition of a callback function to subscribe for new device motion samples. | |
Public Member Functions | |
CMMotionManager * | object () |
Returns the instance of the CMMotionManager object hold by this singleton. | |
bool | setObject (CMMotionManager *object) |
Sets the instance of the CMMotionManager object explicitly as the application holds the instance already. | |
ListenerId | addListener (const DeviceMotionCallback &callback) |
Register a new listener. | |
void | removeListener (const ListenerId listenerId) |
Unregister a given listener. | |
Static Public Member Functions | |
static constexpr ListenerId | invalidListenerId () |
Returns an invalid listener id. | |
![]() | |
static MotionManager & | get () |
Returns a reference to the unique object. | |
Protected Types | |
typedef std::unordered_map< ListenerId, DeviceMotionCallback > | DeviceMotionListenerMap |
Type of an unordered map mapping listener ids to callback functions. | |
Protected Member Functions | |
MotionManager ()=default | |
Protected default constructor. | |
void | start () |
Internally starts the main DeviceMotion callback with CMMotionMap. | |
![]() | |
Singleton ()=default | |
Default constructor. | |
Protected Attributes | |
CMMotionManager * | motionManager_ = nullptr |
The instance of the CMMotionManager object this singleton is responsible for. | |
DeviceMotionListenerMap | deviceMotionListenerMap_ |
Map storing the set of registered listeners. | |
unsigned int | nextListenerId_ = invalidListenerId() |
Counter used to produce a new id when addListener is called. | |
Lock | lock_ |
The manager's lock. | |
Friends | |
class | Singleton< MotionManager > |
This class implements a simple wrapper for the CMMotionManager object as an application must not create more than one instance of a CMMotionManager object.
This class is implemented as a singleton and the actual CMMotionManager object can be set explicitly (if already existing in the application), or will be created automatically.
The manager is thread-safe.
typedef Callback<void, CMDeviceMotion*> Ocean::Devices::IOS::MotionManager::DeviceMotionCallback |
Definition of a callback function to subscribe for new device motion samples.
|
protected |
Type of an unordered map mapping listener ids to callback functions.
typedef unsigned int Ocean::Devices::IOS::MotionManager::ListenerId |
Definition of a listener id for a registered callbacks.
|
protecteddefault |
Protected default constructor.
ListenerId Ocean::Devices::IOS::MotionManager::addListener | ( | const DeviceMotionCallback & | callback | ) |
Register a new listener.
callback | Callback function that occurs each time a new DeviceMotion sample is provided |
|
inlinestaticconstexpr |
Returns an invalid listener id.
CMMotionManager * Ocean::Devices::IOS::MotionManager::object | ( | ) |
Returns the instance of the CMMotionManager object hold by this singleton.
In the case the object hasn't been set explicitly an object will be created the first time this function is called.
void Ocean::Devices::IOS::MotionManager::removeListener | ( | const ListenerId | listenerId | ) |
Unregister a given listener.
listenerId | Id returned from addListener, must be valid |
bool Ocean::Devices::IOS::MotionManager::setObject | ( | CMMotionManager * | object | ) |
Sets the instance of the CMMotionManager object explicitly as the application holds the instance already.
Do not call this function twice.
object | The CMMotionManager object to be set explicitly, must be valid |
|
protected |
Internally starts the main DeviceMotion callback with CMMotionMap.
|
friend |
|
protected |
Map storing the set of registered listeners.
|
protected |
The manager's lock.
|
protected |
The instance of the CMMotionManager object this singleton is responsible for.
|
protected |
Counter used to produce a new id when addListener is called.