Ocean
Loading...
Searching...
No Matches
Ocean::Devices::IOS::MotionManager Class Reference

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>

Inheritance diagram for Ocean::Devices::IOS::MotionManager:

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 Public Member Functions inherited from Ocean::Singleton< MotionManager >
static MotionManager & get ()
 Returns a reference to the unique object.
 

Protected Types

typedef std::unordered_map< ListenerId, DeviceMotionCallbackDeviceMotionListenerMap
 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.
 
- Protected Member Functions inherited from Ocean::Singleton< MotionManager >
 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 >
 

Detailed Description

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.

Member Typedef Documentation

◆ DeviceMotionCallback

Definition of a callback function to subscribe for new device motion samples.

◆ DeviceMotionListenerMap

Type of an unordered map mapping listener ids to callback functions.

◆ ListenerId

Definition of a listener id for a registered callbacks.

Constructor & Destructor Documentation

◆ MotionManager()

Ocean::Devices::IOS::MotionManager::MotionManager ( )
protecteddefault

Protected default constructor.

Member Function Documentation

◆ addListener()

ListenerId Ocean::Devices::IOS::MotionManager::addListener ( const DeviceMotionCallback callback)

Register a new listener.

Parameters
callbackCallback function that occurs each time a new DeviceMotion sample is provided
Returns
Unique id for the registered callback

◆ invalidListenerId()

constexpr MotionManager::ListenerId Ocean::Devices::IOS::MotionManager::invalidListenerId ( )
inlinestaticconstexpr

Returns an invalid listener id.

Returns
Invalid listener id

◆ object()

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.

Returns
The CMMotionManager object
See also
setObject();

◆ removeListener()

void Ocean::Devices::IOS::MotionManager::removeListener ( const ListenerId  listenerId)

Unregister a given listener.

Parameters
listenerIdId returned from addListener, must be valid

◆ setObject()

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.

Parameters
objectThe CMMotionManager object to be set explicitly, must be valid
Returns
True, if this singleton does not hold an own object already and if the provided object is valids

◆ start()

void Ocean::Devices::IOS::MotionManager::start ( )
protected

Internally starts the main DeviceMotion callback with CMMotionMap.

Friends And Related Symbol Documentation

◆ Singleton< MotionManager >

friend class Singleton< MotionManager >
friend

Field Documentation

◆ deviceMotionListenerMap_

DeviceMotionListenerMap Ocean::Devices::IOS::MotionManager::deviceMotionListenerMap_
protected

Map storing the set of registered listeners.

◆ lock_

Lock Ocean::Devices::IOS::MotionManager::lock_
protected

The manager's lock.

◆ motionManager_

CMMotionManager* Ocean::Devices::IOS::MotionManager::motionManager_ = nullptr
protected

The instance of the CMMotionManager object this singleton is responsible for.

◆ nextListenerId_

unsigned int Ocean::Devices::IOS::MotionManager::nextListenerId_ = invalidListenerId()
protected

Counter used to produce a new id when addListener is called.


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