Ocean
Ocean::Devices::Manager Class Reference

This class implements as singleton-based manager which allows to access all available devices. More...

Inheritance diagram for Ocean::Devices::Manager:

Data Structures

class  AdhocFactory
 This class implements an ad-hoc factory for devices which are implemented outside of an own library e.g., during rapid prototyping. More...
 

Public Types

using AdhocInstanceFunction = Factory::InstanceFunction
 Definition of a callback function creating an ad-hoc device. More...
 

Public Member Functions

DeviceRef device (const std::string &name, const bool useExclusive=false)
 Returns a specific device. More...
 
DeviceRef device (const Device::DeviceType type, const bool useExclusive=false)
 Returns a specified device. More...
 
Strings devices () const
 Returns a list with the names of all available devices. More...
 
Strings devices (const Device::DeviceType type) const
 Returns a list with the names of all available devices matching a major and minor device type. More...
 
bool isRegistered (const std::string &library)
 Returns whether a specified library is registered at this manager. More...
 
Strings libraries () const
 Returns the names of all registered libraries. More...
 
std::string objectDescription (const Measurement::ObjectId objectId) const
 Returns the description of an object id. More...
 
void release ()
 Destructs all registered libraries and their corresponding factories. More...
 
bool registerAdhocDevice (const std::string &deviceName, const Device::DeviceType &deviceType, const AdhocInstanceFunction &deviceInstanceFunction)
 Registes an ad-hoc device at this manager. More...
 
bool unregisterAdhocDevice (const std::string &deviceName)
 Unregisters a previously registered ad-hoc device from this manager. More...
 

Static Public Member Functions

static std::string nameAdhocFactory ()
 Returns the name of the ad-hoc factory. More...
 
- Static Public Member Functions inherited from Ocean::Singleton< Manager >
static Manager & get ()
 Returns a reference to the unique object. More...
 

Protected Types

typedef std::vector< std::unique_ptr< Factory > > FactoryUniquePointers
 Definition of a vector holding unique pointers of factories. More...
 
typedef std::unordered_multimap< Measurement::ObjectId, std::string > ObjectIdMultimap
 Definition of an unsorted multimap mapping object ids to descriptions. More...
 

Private Member Functions

 Manager ()
 Creates a new manager object. More...
 
virtual ~Manager ()
 Destructs a manager object. More...
 
Measurement::ObjectId createUniqueObjectId (const std::string &description)
 Creates a unique object id for a new object (e.g., a tracking object like an image, a marker, or a location). More...
 
bool registerFactory (std::unique_ptr< Factory > &&factory)
 Registers a new factory. More...
 
bool unregisterFactory (const std::string &factory)
 Unregisters a factory. More...
 

Private Attributes

ObjectIdMultimap objectIdMultimap_
 The map mapping object ids to descriptions. More...
 
Measurement::ObjectId uniqueObjectIdCounter_ = Measurement::ObjectId(0)
 The counter for unique object ids. More...
 
FactoryUniquePointers factories_
 All registered device factories. More...
 
Lock lock_
 The Manager's lock. More...
 

Friends

class Singleton< Manager >
 
class Factory
 
class Measurement
 

Additional Inherited Members

- Protected Member Functions inherited from Ocean::Singleton< Manager >
 Singleton ()=default
 Default constructor. More...
 

Detailed Description

This class implements as singleton-based manager which allows to access all available devices.

Member Typedef Documentation

◆ AdhocInstanceFunction

Definition of a callback function creating an ad-hoc device.

◆ FactoryUniquePointers

typedef std::vector<std::unique_ptr<Factory> > Ocean::Devices::Manager::FactoryUniquePointers
protected

Definition of a vector holding unique pointers of factories.

◆ ObjectIdMultimap

typedef std::unordered_multimap<Measurement::ObjectId, std::string> Ocean::Devices::Manager::ObjectIdMultimap
protected

Definition of an unsorted multimap mapping object ids to descriptions.

Constructor & Destructor Documentation

◆ Manager()

Ocean::Devices::Manager::Manager ( )
private

Creates a new manager object.

◆ ~Manager()

virtual Ocean::Devices::Manager::~Manager ( )
privatevirtual

Destructs a manager object.

Member Function Documentation

◆ createUniqueObjectId()

Measurement::ObjectId Ocean::Devices::Manager::createUniqueObjectId ( const std::string &  description)
private

Creates a unique object id for a new object (e.g., a tracking object like an image, a marker, or a location).

Parameters
descriptionThe description of the new object, must be valid
Returns
The unique id which is unique across all devices

◆ device() [1/2]

DeviceRef Ocean::Devices::Manager::device ( const Device::DeviceType  type,
const bool  useExclusive = false 
)

Returns a specified device.

Parameters
typeThe major type of the device to return
useExclusiveTrue, if the caller would like to use this device exclusively; False, if the device can be shared
Returns
The requested device, if available

◆ device() [2/2]

DeviceRef Ocean::Devices::Manager::device ( const std::string &  name,
const bool  useExclusive = false 
)

Returns a specific device.

Parameters
nameThe name of the device to return, must be valid
useExclusiveTrue, if the caller would like to use this device exclusively; False, if the device can be shared
Returns
The requested device, if available

◆ devices() [1/2]

Strings Ocean::Devices::Manager::devices ( ) const

Returns a list with the names of all available devices.

Returns
Device names

◆ devices() [2/2]

Strings Ocean::Devices::Manager::devices ( const Device::DeviceType  type) const

Returns a list with the names of all available devices matching a major and minor device type.

Parameters
typeType of the device to return
Returns
Device names

◆ isRegistered()

bool Ocean::Devices::Manager::isRegistered ( const std::string &  library)

Returns whether a specified library is registered at this manager.

Parameters
libraryName of the library to check
Returns
True, if so

◆ libraries()

Strings Ocean::Devices::Manager::libraries ( ) const

Returns the names of all registered libraries.

Returns
Registered library names

◆ nameAdhocFactory()

static std::string Ocean::Devices::Manager::nameAdhocFactory ( )
static

Returns the name of the ad-hoc factory.

The ad-hoc factory is for devices which are implemented outside of an own library e.g., during rapid prototyping.

Returns
The name of the ad-hoc factor

◆ objectDescription()

std::string Ocean::Devices::Manager::objectDescription ( const Measurement::ObjectId  objectId) const

Returns the description of an object id.

Parameters
objectIdThe object id for which the description will be returned
Returns
The description of the object, empty if the object id is unknown

◆ registerAdhocDevice()

bool Ocean::Devices::Manager::registerAdhocDevice ( const std::string &  deviceName,
const Device::DeviceType deviceType,
const AdhocInstanceFunction deviceInstanceFunction 
)

Registes an ad-hoc device at this manager.

In general, devices should be implemented in an own decicated plugin-based library. However, for prototyping an ad-hoc device cames with the same features as a device implemented in a dedicatd library without the overhead of writing the code for the plugin mechanisms etc.

Parameters
deviceNameUnique name of the device to register
deviceTypeType of the device
deviceInstanceFunctionFunction creating an instance of the device
See also
unregisterAdhocDevice().

◆ registerFactory()

bool Ocean::Devices::Manager::registerFactory ( std::unique_ptr< Factory > &&  factory)
private

Registers a new factory.

Parameters
factoryThe factory to register
Returns
True, if the factory hasn't been registered before

◆ release()

void Ocean::Devices::Manager::release ( )

Destructs all registered libraries and their corresponding factories.

◆ unregisterAdhocDevice()

bool Ocean::Devices::Manager::unregisterAdhocDevice ( const std::string &  deviceName)

Unregisters a previously registered ad-hoc device from this manager.

Beware: Ensure that the device is not used anymore before unregistering it.

Parameters
deviceNameThe name of the device to unregister, must be valid
Returns
True, if succeeded
See also
registerAdhocDevice().

◆ unregisterFactory()

bool Ocean::Devices::Manager::unregisterFactory ( const std::string &  factory)
private

Unregisters a factory.

Parameters
factoryName of the factory to unregister
Returns
True, if succeeded

Friends And Related Function Documentation

◆ Factory

friend class Factory
friend

◆ Measurement

friend class Measurement
friend

◆ Singleton< Manager >

friend class Singleton< Manager >
friend

Field Documentation

◆ factories_

FactoryUniquePointers Ocean::Devices::Manager::factories_
private

All registered device factories.

◆ lock_

Lock Ocean::Devices::Manager::lock_
mutableprivate

The Manager's lock.

◆ objectIdMultimap_

ObjectIdMultimap Ocean::Devices::Manager::objectIdMultimap_
private

The map mapping object ids to descriptions.

◆ uniqueObjectIdCounter_

Measurement::ObjectId Ocean::Devices::Manager::uniqueObjectIdCounter_ = Measurement::ObjectId(0)
private

The counter for unique object ids.


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