stmm-input-doc  0.17.0
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
stmi::DeviceManager Class Referenceabstract

This class manages devices that generate events that listeners will receive. More...

Inheritance diagram for stmi::DeviceManager:
Inheritance graph
[legend]

Public Member Functions

virtual ~DeviceManager () noexcept=default
 
virtual shared_ptr< DevicegetDevice (int32_t nDeviceId) const noexcept=0
 Returns the device with the given id, or null if not found. More...
 
virtual std::vector< Capability::ClassgetCapabilityClasses () const noexcept=0
 The registered capability classes of the device manager. More...
 
virtual std::vector< Capability::ClassgetDeviceCapabilityClasses () const noexcept=0
 The registered capability classes of the device manager's devices. More...
 
template<typename TCapa >
bool getCapability (shared_ptr< TCapa > &refCapa) const noexcept
 Request a registered device manager capability. More...
 
virtual shared_ptr< CapabilitygetCapability (const Capability::Class &oClass) const noexcept=0
 Requests the instance of a capability class. More...
 
virtual shared_ptr< CapabilitygetCapability (int32_t nCapabilityId) const noexcept=0
 Returns the device manager's capability with the given id, or null if not found. More...
 
virtual std::vector< Event::ClassgetEventClasses () const noexcept=0
 The registered event classes the device manager and all its devices can send. More...
 
virtual std::vector< int32_t > getDevicesWithCapabilityClass (const Capability::Class &oCapabilityClass) const noexcept=0
 Returns the ids of the devices that have the given capability class. More...
 
virtual std::vector< int32_t > getDevices () const noexcept=0
 Returns the ids of all the device manager's devices. More...
 
virtual bool isEventClassEnabled (const Event::Class &oEventClass) const noexcept=0
 Tells whether an event class is enabled. More...
 
virtual void enableEventClass (const Event::Class &oEventClass) noexcept=0
 Enables an event class. More...
 
virtual bool addAccessor (const shared_ptr< Accessor > &refAccessor) noexcept=0
 Adds an accessor to the device manager. More...
 
virtual bool removeAccessor (const shared_ptr< Accessor > &refAccessor) noexcept=0
 Removes an accessor from the device manager. More...
 
virtual bool hasAccessor (const shared_ptr< Accessor > &refAccessor) noexcept=0
 Tells whether the device manager has a given accessor. More...
 
virtual bool addEventListener (const shared_ptr< EventListener > &refEventListener, const shared_ptr< CallIf > &refCallIf) noexcept=0
 Adds an event listener with its callif condition to the device manager. More...
 
virtual bool addEventListener (const shared_ptr< EventListener > &refEventListener) noexcept=0
 Adds an event listener to the device manager. More...
 
virtual bool removeEventListener (const shared_ptr< EventListener > &refEventListener, bool bFinalize) noexcept=0
 Removes an event listener from the device manager. More...
 
virtual bool removeEventListener (const shared_ptr< EventListener > &refEventListener) noexcept=0
 Removes an event listener from the device manager. More...
 

Static Public Member Functions

static int64_t getNowTimeMicroseconds () noexcept
 Current time from epoch in microseconds. More...
 

Protected Member Functions

 DeviceManager () noexcept
 

Detailed Description

This class manages devices that generate events that listeners will receive.

Constructor & Destructor Documentation

◆ ~DeviceManager()

virtual stmi::DeviceManager::~DeviceManager ( )
virtualdefaultnoexcept

◆ DeviceManager()

stmi::DeviceManager::DeviceManager ( )
protectednoexcept

Member Function Documentation

◆ addAccessor()

virtual bool stmi::DeviceManager::addAccessor ( const shared_ptr< Accessor > &  refAccessor)
pure virtualnoexcept

Adds an accessor to the device manager.

If the device manager recognizes the accessor and the accessor wasn't already added true is returned, false otherwise.

It's possible to add a null accessor, it's meaning is implementation dependent.

Parameters
refAccessorThe accessor to add. Can be null.
Returns
Whether the accessor was added.

Implemented in stmi::ParentDeviceManager, and stmi::BasicDeviceManager.

◆ addEventListener() [1/2]

virtual bool stmi::DeviceManager::addEventListener ( const shared_ptr< EventListener > &  refEventListener,
const shared_ptr< CallIf > &  refCallIf 
)
pure virtualnoexcept

Adds an event listener with its callif condition to the device manager.

The EventListener callback function (actually its address) identifies the listener being added and is therefore used to remove it with removeEventListener(). The callback function is called for all events originating from this device manager's devices that satisfy the callif condition.

If the listener was already added, even with a different callif, the function has no effect and false is returned.

The device manager keeps a weak reference (std::weak_ptr) to the listener. This means that the caller has to keep a strong reference to the listener, otherwise it will be removed automatically.

A null callback condition refCallIf means that the callback function is called for all events. The device manager keeps a strong reference to the callif object as long as the listener remains in the device manager.

The event parameter passed to the callback function can be queued (outlive the callback) or modified if its interface allows it. To get the registered class of the event use Event::getEventClass() and statically cast to it. Note: don't use typeid(*refEvent) since it isn't necessarily equal to refEvent->getEventClass().getTypeInfo().

See also
class Event.

Example:

void createListeners()
    ...
    // The listener has to be stored in a member variable otherwise it will
    // automatically be removed from the device manager.
    m_refKeyEventListener = std::make_shared<stmi::EventListener>(
        [this](const shared_ptr<stmi::Event>& refEvent)
        {
            // Because of the callif condition below we know that refEvent
            // is a stmi::KeyEvent
            auto pKeyEvent = static_cast<stmi::KeyEvent*>(refEvent.get());
            ...
        });
    m_refDeviceManager->addEventListener(m_refKeyEventListener
                      , std::make_shared<stmi::CallIfEventClass>(typeid(stmi::KeyEvent)));
    ...
}
Parameters
refEventListenerThe listener to be added. Cannot be null.
refCallIfThe callif condition to call back the listener. Can be null.
Returns
Whether the listener was added.

Implemented in stmi::ParentDeviceManager, and stmi::BasicDeviceManager.

◆ addEventListener() [2/2]

virtual bool stmi::DeviceManager::addEventListener ( const shared_ptr< EventListener > &  refEventListener)
pure virtualnoexcept

Adds an event listener to the device manager.

Shortcut of addEventListener(refEventListener, shared_ptr<CallIf>{}).

Parameters
refEventListenerThe listener to be added. Cannot be null.
Returns
Whether the listener was added.

Implemented in stmi::ParentDeviceManager, and stmi::BasicDeviceManager.

◆ enableEventClass()

virtual void stmi::DeviceManager::enableEventClass ( const Event::Class oEventClass)
pure virtualnoexcept

Enables an event class.

See also
isEventClassEnabled(const Event::Class&)
Parameters
oEventClassThe event class to enable.

Implemented in stmi::ParentDeviceManager, and stmi::BasicDeviceManager.

◆ getCapability() [1/3]

template<typename TCapa >
bool stmi::DeviceManager::getCapability ( shared_ptr< TCapa > &  refCapa) const
inlinenoexcept

Request a registered device manager capability.

Parameters
refCapa[out] The registered DeviceManagerCapability subclass or null if not supported by device manager.
Returns
Whether the device manager has the requested capability.

◆ getCapability() [2/3]

virtual shared_ptr<Capability> stmi::DeviceManager::getCapability ( const Capability::Class oClass) const
pure virtualnoexcept

Requests the instance of a capability class.

If the device manager doesn't have the capability null is returned.

Parameters
oClassThe requested registered device manager capability class.
Returns
The capability or null.

Implemented in stmi::ParentDeviceManager, and stmi::StdDeviceManager.

◆ getCapability() [3/3]

virtual shared_ptr<Capability> stmi::DeviceManager::getCapability ( int32_t  nCapabilityId) const
pure virtualnoexcept

Returns the device manager's capability with the given id, or null if not found.

Implemented in stmi::ParentDeviceManager, and stmi::StdDeviceManager.

◆ getCapabilityClasses()

virtual std::vector<Capability::Class> stmi::DeviceManager::getCapabilityClasses ( ) const
pure virtualnoexcept

The registered capability classes of the device manager.

Example: the vector {DeviceMgmtCapability::getClass()} is returned.

Returns
The set of registered device manager capability classes.

Implemented in stmi::ParentDeviceManager, stmi::BasicDeviceManager, and stmi::StdDeviceManager.

◆ getDevice()

virtual shared_ptr<Device> stmi::DeviceManager::getDevice ( int32_t  nDeviceId) const
pure virtualnoexcept

Returns the device with the given id, or null if not found.

Implemented in stmi::ParentDeviceManager, and stmi::BasicDeviceManager.

◆ getDeviceCapabilityClasses()

virtual std::vector<Capability::Class> stmi::DeviceManager::getDeviceCapabilityClasses ( ) const
pure virtualnoexcept

The registered capability classes of the device manager's devices.

The capability classes include those that managed devices potentially have, independently from the currently available devices.

Example: a device manager that handles mice and touch pads will return {PointerCapability::getClass(), TouchCapability::getClass()} even though no touch device is connected.

Returns
The set of registered device capability classes.

Implemented in stmi::ParentDeviceManager, and stmi::BasicDeviceManager.

◆ getDevices()

virtual std::vector<int32_t> stmi::DeviceManager::getDevices ( ) const
pure virtualnoexcept

Returns the ids of all the device manager's devices.

Returns
The set of device ids.

Implemented in stmi::ParentDeviceManager, and stmi::BasicDeviceManager.

◆ getDevicesWithCapabilityClass()

virtual std::vector<int32_t> stmi::DeviceManager::getDevicesWithCapabilityClass ( const Capability::Class oCapabilityClass) const
pure virtualnoexcept

Returns the ids of the devices that have the given capability class.

Parameters
oCapabilityClassThe registered capability class.
Returns
The set of device ids.

Implemented in stmi::ParentDeviceManager, and stmi::BasicDeviceManager.

◆ getEventClasses()

virtual std::vector<Event::Class> stmi::DeviceManager::getEventClasses ( ) const
pure virtualnoexcept

The registered event classes the device manager and all its devices can send.

The event classes include those that managed devices potentially can send, independently from the currently available devices.

Returns
The set of registered event classes.

Implemented in stmi::ParentDeviceManager, and stmi::BasicDeviceManager.

◆ getNowTimeMicroseconds()

static int64_t stmi::DeviceManager::getNowTimeMicroseconds ( )
inlinestaticnoexcept

Current time from epoch in microseconds.

Helper function used to set timestamp of events.

Returns
The time in microseconds.
See also
Event::getTimeUsec()

◆ hasAccessor()

virtual bool stmi::DeviceManager::hasAccessor ( const shared_ptr< Accessor > &  refAccessor)
pure virtualnoexcept

Tells whether the device manager has a given accessor.

Note that the implementation might return whether the thing (usually a window) wrapped by an accessor was already added to the device manager rather than the accessor instance itself. In general if this function returns true, calling addAccessor with the same accessor should return false.

Parameters
refAccessorThe accessor. Can be null.
Returns
Whether the accessor was added (and not yet removed) to the device manager.

Implemented in stmi::ParentDeviceManager, and stmi::BasicDeviceManager.

◆ isEventClassEnabled()

virtual bool stmi::DeviceManager::isEventClassEnabled ( const Event::Class oEventClass) const
pure virtualnoexcept

Tells whether an event class is enabled.

If an event class is disabled the device manager (with all its devices) won't send events of that class to listeners.

Parameters
oEventClassThe registered event class.
Returns
Tells whether the event class is enabled.

Implemented in stmi::ParentDeviceManager, and stmi::BasicDeviceManager.

◆ removeAccessor()

virtual bool stmi::DeviceManager::removeAccessor ( const shared_ptr< Accessor > &  refAccessor)
pure virtualnoexcept

Removes an accessor from the device manager.

If the accessor wasn't previously (successfully) added with addAccessor(const shared_ptr<Accessor>&), false is returned.

Parameters
refAccessorThe accessor to remove. Can be null.
Returns
Whether the accessor was removed.

Implemented in stmi::ParentDeviceManager, and stmi::BasicDeviceManager.

◆ removeEventListener() [1/2]

virtual bool stmi::DeviceManager::removeEventListener ( const shared_ptr< EventListener > &  refEventListener,
bool  bFinalize 
)
pure virtualnoexcept

Removes an event listener from the device manager.

If the listener wasn't found, false is returned, true otherwise. To be found the event listener must have been added with addEventListener() and not deleted since then. Beware! A copy of the event listener can't be used to remove it.

Optionally finalization events are sent to the listener before its removal. Example: if a device's key is pressed when this function is called, a RELEASE_CANCEL event is sent to the listener being removed.

Parameters
refEventListenerThe listener to remove. Cannot be null.
bFinalizeWhether to send closing events to the listener.
Returns
Whether listener was removed.

Implemented in stmi::ParentDeviceManager, and stmi::BasicDeviceManager.

◆ removeEventListener() [2/2]

virtual bool stmi::DeviceManager::removeEventListener ( const shared_ptr< EventListener > &  refEventListener)
pure virtualnoexcept

Removes an event listener from the device manager.

Shortcut of removeEventListener(refEventListener, false).

Parameters
refEventListenerThe listener to remove. Cannot be null.

Implemented in stmi::ParentDeviceManager, and stmi::BasicDeviceManager.