Ocean
Ocean::Devices::Factory Class Reference

This class implements a factory able to create instances of devices. More...

Inheritance diagram for Ocean::Devices::Factory:

Data Structures

class  DeviceDescriptor
 This class stores information to describe and to creator a device. More...
 

Public Member Functions

const std::string & name () const
 Returns the name of this factory. More...
 

Protected Types

typedef Callback< Device *, const std::string &, const Device::DeviceType & > InstanceFunction
 Definition of a callback function creating a specific device. More...
 
typedef std::vector< DeviceDescriptorDeviceDescriptors
 Definition of a vector holding device descriptor objects. More...
 

Protected Member Functions

 Factory (const Factory &factory)=delete
 Disabled copy constructor. More...
 
 Factory (const std::string &name)
 Creates a new factory. More...
 
virtual ~Factory ()
 Destructs this factory. More...
 
virtual Strings devices () const
 Returns a list of available devices. More...
 
virtual Strings devices (const Device::DeviceType type) const
 Returns a list of available devices matching a specified major device type. More...
 
virtual Device::DeviceType deviceType (const std::string &device) const
 Returns the type of a specified device. More...
 
virtual DeviceRef device (const std::string &name, const bool useExclusive=false) const
 Creates a new device by its name or returns an existing one if an exclusive use is not necessary. More...
 
virtual DeviceRef device (const Device::DeviceType type, const bool useExclusive=false)
 Creates a new device defined by a major and a minor device type or returns an existing one if an exclusive use is not necessary. More...
 
DeviceRef adapterDevice (const Device::DeviceType type, const std::string &name)
 Returns a new adapter measurement device, which is exclusive always. More...
 
Factoryoperator= (const Factory &factory)=delete
 Disabled copy operator. More...
 
bool registerDevice (const std::string &deviceName, const Device::DeviceType deviceType, const InstanceFunction &deviceInstanceFunction)
 Registes a device at this factory. More...
 
bool unregisterDevice (const std::string &deviceName)
 Unregisters a previously registered device from this factory. More...
 

Static Protected Member Functions

static bool registerFactory (std::unique_ptr< Factory > &&factory)
 Registers a factory at the manager. More...
 
static bool unregisterFactory (const std::string &factory)
 Unregisters a factory at the manager. More...
 
static DeviceRef createDevice (const DeviceDescriptor &deviceDescriptor, bool useExclusive)
 Creates a new device by a given device triple. More...
 

Private Attributes

std::string name_
 The factory's name. More...
 
DeviceDescriptors deviceDescriptors_
 Vector holding all registered devices with name and type. More...
 
Lock lock_
 Factory lock. More...
 

Friends

class Manager
 
struct std::default_delete< Factory >
 

Detailed Description

This class implements a factory able to create instances of devices.

Member Typedef Documentation

◆ DeviceDescriptors

Definition of a vector holding device descriptor objects.

◆ InstanceFunction

typedef Callback<Device*, const std::string&, const Device::DeviceType&> Ocean::Devices::Factory::InstanceFunction
protected

Definition of a callback function creating a specific device.

Constructor & Destructor Documentation

◆ Factory() [1/2]

Ocean::Devices::Factory::Factory ( const Factory factory)
protecteddelete

Disabled copy constructor.

Parameters
factoryObject which would be copied

◆ Factory() [2/2]

Ocean::Devices::Factory::Factory ( const std::string &  name)
explicitprotected

Creates a new factory.

Parameters
nameThe name of the factory to create

◆ ~Factory()

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

Destructs this factory.

Member Function Documentation

◆ adapterDevice()

DeviceRef Ocean::Devices::Factory::adapterDevice ( const Device::DeviceType  type,
const std::string &  name 
)
protected

Returns a new adapter measurement device, which is exclusive always.

Parameters
typeType of the device to return
nameUnique name of the resulting adapter device, this name will be assigned to the new adapter device

◆ createDevice()

static DeviceRef Ocean::Devices::Factory::createDevice ( const DeviceDescriptor deviceDescriptor,
bool  useExclusive 
)
staticprotected

Creates a new device by a given device triple.

Parameters
deviceDescriptorThe descriptor of the device to be created
useExclusiveDetermines whether the device will be used exclusively
Returns
New device if succeeded

◆ device() [1/2]

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

Creates a new device defined by a major and a minor device type or returns an existing one if an exclusive use is not necessary.

Parameters
typeType of the device to return
useExclusiveDetermines whether the device will be used exclusively
Returns
Requested device

◆ device() [2/2]

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

Creates a new device by its name or returns an existing one if an exclusive use is not necessary.

Parameters
nameThe name of the device to create
useExclusiveDetermines whether the device will be used exclusively
Returns
Requested device

◆ devices() [1/2]

virtual Strings Ocean::Devices::Factory::devices ( ) const
protectedvirtual

Returns a list of available devices.

Returns
Device list

◆ devices() [2/2]

virtual Strings Ocean::Devices::Factory::devices ( const Device::DeviceType  type) const
protectedvirtual

Returns a list of available devices matching a specified major device type.

Parameters
typeType to return device names for
Returns
Device list

◆ deviceType()

virtual Device::DeviceType Ocean::Devices::Factory::deviceType ( const std::string &  device) const
protectedvirtual

Returns the type of a specified device.

Parameters
deviceName of the device to return the type for
Returns
Device type holding major and minor type

◆ name()

const std::string & Ocean::Devices::Factory::name ( ) const
inline

Returns the name of this factory.

◆ operator=()

Factory& Ocean::Devices::Factory::operator= ( const Factory factory)
protecteddelete

Disabled copy operator.

Parameters
factoryObject which would be copied
Returns
Reference to this object

◆ registerDevice()

bool Ocean::Devices::Factory::registerDevice ( const std::string &  deviceName,
const Device::DeviceType  deviceType,
const InstanceFunction deviceInstanceFunction 
)
protected

Registes a device at this factory.

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

◆ registerFactory()

static bool Ocean::Devices::Factory::registerFactory ( std::unique_ptr< Factory > &&  factory)
staticprotected

Registers a factory at the manager.

Each factory should be registered at most once.

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

◆ unregisterDevice()

bool Ocean::Devices::Factory::unregisterDevice ( const std::string &  deviceName)
protected

Unregisters a previously registered device from this factory.

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
registerDevice().

◆ unregisterFactory()

static bool Ocean::Devices::Factory::unregisterFactory ( const std::string &  factory)
staticprotected

Unregisters a factory at the manager.

Beware: All devices created by the factory must be released before,
otherwise the factory cannot be unregistered.

Parameters
factoryName of the factory to unregister
Returns
True, if the factory could be unregistered

Friends And Related Function Documentation

◆ Manager

friend class Manager
friend

◆ std::default_delete< Factory >

friend struct std::default_delete< Factory >
friend

Field Documentation

◆ deviceDescriptors_

DeviceDescriptors Ocean::Devices::Factory::deviceDescriptors_
private

Vector holding all registered devices with name and type.

◆ lock_

Lock Ocean::Devices::Factory::lock_
mutableprivate

Factory lock.

◆ name_

std::string Ocean::Devices::Factory::name_
private

The factory's name.


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