Ocean
Loading...
Searching...
No Matches
Ocean::Devices::DeviceRefManager Class Reference

This class implements a manager for device references. More...

#include <DeviceRef.h>

Inheritance diagram for Ocean::Devices::DeviceRefManager:

Public Types

using DeviceCallback = Callback< void, Device *, bool >
 Definition of a callback function for devices.
 

Public Member Functions

DeviceRef registerDevice (Device *device, const bool exclusive)
 Registers a new device.
 
DeviceRef device (const std::string &name, const bool allowExclusive=true) const
 Returns a device by a given device name.
 
DeviceRef device (const Device::DeviceType type, const bool exactMatch=false) const
 Returns a specified device by it's device type.
 
DeviceRef device (const Device *device) const
 Returns the reference of a specific device.
 
bool isEmpty () const
 Returns whether no device is registered currently.
 
bool isEmpty (const std::string &library) const
 Returns whether no device is registered created by a specific library.
 
Strings devicesFromLibrary (const std::string &library) const
 Returns the name of all existing devices which belong to a specific library.
 
void addDeviceCallbackFunction (const DeviceCallback &callback)
 Adds a callback function which is called whenever a new device is created or deleted.
 
void removeDeviceCallbackFunction (const DeviceCallback &callback)
 Removes a previously added callback function for device events.
 

Protected Types

using DevicePair = std::pair< DeviceRef, bool >
 Definition of a pair combining a device reference with a state specifying whether the medium is used exclusively.
 
using DeviceMap = std::multimap< std::string, DevicePair >
 Map mapping urls to device references.
 
using DeviceCallbacks = Callbacks< DeviceCallback >
 Definition of device callback functions.
 

Protected Member Functions

virtual ~DeviceRefManager ()
 Destructs the manager.
 
bool isExclusive (const Device *device)
 Returns whether a specified device is registered as exclusive.
 
void unregisterDevice (const Device *device)
 Unregisters a device.
 
- Protected Member Functions inherited from Ocean::Singleton< DeviceRefManager >
 Singleton ()=default
 Default constructor.
 

Protected Attributes

DeviceMap deviceMap_
 Map holding all device references.
 
DeviceCallbacks deviceCallbacks_
 The callback functions for device events.
 
Lock lock_
 Lock for the device map.
 

Friends

class Device
 
class Singleton< DeviceRefManager >
 
class ObjectRef< Device >
 
class Manager
 

Additional Inherited Members

- Static Public Member Functions inherited from Ocean::Singleton< DeviceRefManager >
static DeviceRefManager & get ()
 Returns a reference to the unique object.
 

Detailed Description

This class implements a manager for device references.

Member Typedef Documentation

◆ DeviceCallback

Definition of a callback function for devices.

◆ DeviceCallbacks

Definition of device callback functions.

◆ DeviceMap

using Ocean::Devices::DeviceRefManager::DeviceMap = std::multimap<std::string, DevicePair>
protected

Map mapping urls to device references.

◆ DevicePair

using Ocean::Devices::DeviceRefManager::DevicePair = std::pair<DeviceRef, bool>
protected

Definition of a pair combining a device reference with a state specifying whether the medium is used exclusively.

Constructor & Destructor Documentation

◆ ~DeviceRefManager()

virtual Ocean::Devices::DeviceRefManager::~DeviceRefManager ( )
protectedvirtual

Destructs the manager.

Member Function Documentation

◆ addDeviceCallbackFunction()

void Ocean::Devices::DeviceRefManager::addDeviceCallbackFunction ( const DeviceCallback callback)

Adds a callback function which is called whenever a new device is created or deleted.

The callback function will be called immediately for all already existing devices.

Parameters
callbackThe callback function, must be valid

◆ device() [1/3]

DeviceRef Ocean::Devices::DeviceRefManager::device ( const Device device) const

Returns the reference of a specific device.

In contrast to the name-based lookup, this function identifies the device by its address, so it also works if several devices share the same name.

Parameters
deviceThe device for which the reference will be returned, must be valid
Returns
Device reference of the given device, an empty reference if the device is not registered

◆ device() [2/3]

DeviceRef Ocean::Devices::DeviceRefManager::device ( const Device::DeviceType  type,
const bool  exactMatch = false 
) const

Returns a specified device by it's device type.

Devices which have been created for exclusive usage are skipped, and if several of the remaining devices match it is not defined which of them is returned.

Parameters
typeThe type of the device to return
exactMatchTrue, to return a device with exact matching type; False, if the requested type is part of the device
Returns
Requested device, an empty reference if no matching device exists

◆ device() [3/3]

DeviceRef Ocean::Devices::DeviceRefManager::device ( const std::string &  name,
const bool  allowExclusive = true 
) const

Returns a device by a given device name.

If the device does not exist an empty reference is returned. Several devices can be registered with the same name, in that case it is not defined which of them is returned.

Parameters
nameThe name of the device
allowExclusiveTrue, to also return a device which has been created for exclusive usage; False, to return a shareable device only
Returns
Device reference of the requested device
See also
device(const Device*).

◆ devicesFromLibrary()

Strings Ocean::Devices::DeviceRefManager::devicesFromLibrary ( const std::string &  library) const

Returns the name of all existing devices which belong to a specific library.

Parameters
libraryThe name of the library to which the devices belong, must be valid
Returns
The names of all currently existing devices

◆ isEmpty() [1/2]

bool Ocean::Devices::DeviceRefManager::isEmpty ( ) const
inline

Returns whether no device is registered currently.

Returns
True, if so

◆ isEmpty() [2/2]

bool Ocean::Devices::DeviceRefManager::isEmpty ( const std::string &  library) const

Returns whether no device is registered created by a specific library.

Parameters
libraryThe name of the library to check, must be valid
Returns
True, if so

◆ isExclusive()

bool Ocean::Devices::DeviceRefManager::isExclusive ( const Device device)
protected

Returns whether a specified device is registered as exclusive.

Parameters
deviceDevice to check
Returns
True, if so

◆ registerDevice()

DeviceRef Ocean::Devices::DeviceRefManager::registerDevice ( Device device,
const bool  exclusive 
)

Registers a new device.

Parameters
deviceDevice object to manage
exclusiveState specifying whether the device will be used exclusively
Returns
Device reference

◆ removeDeviceCallbackFunction()

void Ocean::Devices::DeviceRefManager::removeDeviceCallbackFunction ( const DeviceCallback callback)
inline

Removes a previously added callback function for device events.

Parameters
callbackThe callback function, must be valid

◆ unregisterDevice()

void Ocean::Devices::DeviceRefManager::unregisterDevice ( const Device device)
protected

Unregisters a device.

Friends And Related Symbol Documentation

◆ Device

friend class Device
friend

◆ Manager

friend class Manager
friend

◆ ObjectRef< Device >

friend class ObjectRef< Device >
friend

◆ Singleton< DeviceRefManager >

Field Documentation

◆ deviceCallbacks_

DeviceCallbacks Ocean::Devices::DeviceRefManager::deviceCallbacks_
protected

The callback functions for device events.

◆ deviceMap_

DeviceMap Ocean::Devices::DeviceRefManager::deviceMap_
protected

Map holding all device references.

◆ lock_

Lock Ocean::Devices::DeviceRefManager::lock_
mutableprotected

Lock for the device map.


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