Kodi Documentation 22.0
Kodi is an open source media player and entertainment hub.
Loading...
Searching...
No Matches
PERIPHERALS::CPeripherals Class Reference

#include <Peripherals.h>

Inheritance diagram for PERIPHERALS::CPeripherals:
ISettingCallback Observable KODI::MESSAGING::IMessageTarget PERIPHERALS::IEventScannerCallback ANNOUNCEMENT::IAnnouncer

Public Member Functions

 CPeripherals (CInputManager &inputManager, KODI::GAME::CControllerManager &controllerProfiles)
 
 ~CPeripherals () override
 
void Initialise ()
 Initialise the peripherals manager.
 
void Clear ()
 Clear all data known by the peripherals manager.
 
PeripheralPtr GetPeripheralAtLocation (const std::string &strLocation, PeripheralBusType busType=PERIPHERAL_BUS_UNKNOWN) const
 Get the instance of the peripheral at the given location.
 
bool HasPeripheralAtLocation (const std::string &strLocation, PeripheralBusType busType=PERIPHERAL_BUS_UNKNOWN) const
 Check whether a peripheral is present at the given location.
 
PeripheralBusPtr GetBusWithDevice (const std::string &strLocation) const
 Get the bus that holds the device with the given location.
 
bool SupportsFeature (PeripheralFeature feature) const
 Check if any busses support the given feature.
 
int GetPeripheralsWithFeature (PeripheralVector &results, const PeripheralFeature feature, PeripheralBusType busType=PERIPHERAL_BUS_UNKNOWN) const
 Get all peripheral instances that have the given feature.
 
size_t GetNumberOfPeripherals () const
 
bool HasPeripheralWithFeature (const PeripheralFeature feature, PeripheralBusType busType=PERIPHERAL_BUS_UNKNOWN) const
 Check whether there is at least one device present with the given feature.
 
void OnDeviceAdded (const CPeripheralBus &bus, const CPeripheral &peripheral)
 Called when a device has been added to a bus.
 
void OnDeviceDeleted (const CPeripheralBus &bus, const CPeripheral &peripheral)
 Called when a device has been deleted from a bus.
 
void CreatePeripheral (CPeripheralBus &bus, const PeripheralScanResult &result)
 Creates a new instance of a peripheral.
 
void GetSettingsFromMapping (CPeripheral &peripheral) const
 Add the settings that are defined in the mappings file to the peripheral (if there is anything defined).
 
void TriggerDeviceScan (const PeripheralBusType type=PERIPHERAL_BUS_UNKNOWN)
 Trigger a device scan on all known busses.
 
PeripheralBusPtr GetBusByType (const PeripheralBusType type) const
 Get the instance of a bus given it's type.
 
void GetDirectory (const std::string &strPath, CFileItemList &items) const
 Get all fileitems for a path.
 
PeripheralPtr GetByPath (const std::string &strPath) const
 Get the instance of a peripheral given it's path.
 
bool OnAction (const CAction &action)
 Try to let one of the peripherals handle an action.
 
bool IsMuted ()
 Check whether there's a peripheral that reports to be muted.
 
bool ToggleMute ()
 Try to toggle the mute status via a peripheral.
 
bool ToggleDeviceState (const CecStateChange mode=STATE_SWITCH_TOGGLE)
 Try to toggle the playing device state via a peripheral.
 
bool Mute ()
 Try to mute the audio via a peripheral.
 
bool UnMute ()
 Try to unmute the audio via a peripheral.
 
bool GetNextKeypress (float frameTime, CKey &key)
 Try to get a keypress from a peripheral.
 
EventPollHandlePtr RegisterEventPoller ()
 Register with the event scanner to control scan timing.
 
EventLockHandlePtr RegisterEventLock ()
 Register with the event scanner to disable event processing.
 
void OnUserNotification ()
 
void TestFeature (PeripheralFeature feature)
 Request peripherals with the specified feature to perform a quick test.
 
void PowerOffDevices ()
 Request all devices with power-off support to power down.
 
bool SupportsCEC () const
 
void ProcessEvents (void) override
 
void EnableButtonMapping ()
 Initialize button mapping.
 
PeripheralAddonPtr GetAddonWithButtonMap (const CPeripheral *device)
 Get an add-on that can provide button maps for a device.
 
void ResetButtonMaps (const std::string &controllerId)
 Reset all button maps to the defaults for all devices and the given controller.
 
void RegisterJoystickButtonMapper (KODI::JOYSTICK::IButtonMapper *mapper)
 Register a button mapper interface.
 
void UnregisterJoystickButtonMapper (KODI::JOYSTICK::IButtonMapper *mapper)
 Unregister a button mapper interface.
 
void OnSettingChanged (const std::shared_ptr< const CSetting > &setting) override
 The value of the given setting has changed.
 
void OnSettingAction (const std::shared_ptr< const CSetting > &setting) override
 The given setting has been activated.
 
void OnApplicationMessage (KODI::MESSAGING::ThreadMessage *pMsg) override
 This gets called whenever a message matching the registered message mask is processed.
 
int GetMessageMask () override
 Should return the message mask that it wishes to receive messages for.
 
void Announce (ANNOUNCEMENT::AnnouncementFlag flag, const std::string &sender, const std::string &message, const CVariant &data) override
 
CInputManagerGetInputManager ()
 Access the input manager passed to the constructor.
 
KODI::GAME::CControllerManagerGetControllerProfiles ()
 Access controller profiles through the construction parameter.
 
CCriticalSection & GetAddonInstallMutex ()
 Get a mutex that allows for add-on install tasks to block on each other.
 
- Public Member Functions inherited from ISettingCallback
virtual ~ISettingCallback ()=default
 
virtual bool OnSettingChanging (const std::shared_ptr< const CSetting > &setting)
 The value of the given setting is being changed.
 
virtual bool OnSettingUpdate (const std::shared_ptr< CSetting > &setting, const char *oldSettingId, const TiXmlNode *oldSettingNode)
 The given setting needs to be updated.
 
virtual void OnSettingPropertyChanged (const std::shared_ptr< const CSetting > &setting, const char *propertyName)
 The given property of the given setting has changed.
 
- Public Member Functions inherited from Observable
 Observable ()=default
 
virtual ~Observable ()=default
 
Observableoperator= (const Observable &observable)
 
virtual void RegisterObserver (Observer *obs)
 Register an observer.
 
virtual void UnregisterObserver (Observer *obs)
 Unregister an observer.
 
virtual void NotifyObservers (const ObservableMessage message=ObservableMessageNone)
 Send a message to all observers when m_bObservableChanged is true.
 
virtual void SetChanged (bool bSetTo=true)
 Mark an observable changed.
 
virtual bool IsObserving (const Observer &obs) const
 Check whether this observable is being observed by an observer.
 
- Public Member Functions inherited from KODI::MESSAGING::IMessageTarget
virtual ~IMessageTarget ()=default
 
- Public Member Functions inherited from PERIPHERALS::IEventScannerCallback
virtual ~IEventScannerCallback (void)=default
 
- Public Member Functions inherited from ANNOUNCEMENT::IAnnouncer
 IAnnouncer ()=default
 
virtual ~IAnnouncer ()=default
 

Additional Inherited Members

- Protected Member Functions inherited from Observable
void SendMessage (const ObservableMessage message)
 Send a message to all observer when m_bObservableChanged is true.
 
- Protected Attributes inherited from Observable
std::atomic< boolm_bObservableChanged {false}
 
std::vector< Observer * > m_observers
 
CCriticalSection m_obsCritSection
 

Constructor & Destructor Documentation

◆ CPeripherals()

CPeripherals::CPeripherals ( CInputManager & inputManager,
KODI::GAME::CControllerManager & controllerProfiles )
explicit

◆ ~CPeripherals()

CPeripherals::~CPeripherals ( )
override

Member Function Documentation

◆ Announce()

void CPeripherals::Announce ( ANNOUNCEMENT::AnnouncementFlag flag,
const std::string & sender,
const std::string & message,
const CVariant & data )
overridevirtual

◆ Clear()

void CPeripherals::Clear ( )

Clear all data known by the peripherals manager.

◆ CreatePeripheral()

void CPeripherals::CreatePeripheral ( CPeripheralBus & bus,
const PeripheralScanResult & result )

Creates a new instance of a peripheral.

Parameters
busThe bus on which this peripheral is present.
resultThe scan result from the device scanning code.
Returns
The new peripheral or NULL if it could not be created.

◆ EnableButtonMapping()

void CPeripherals::EnableButtonMapping ( )

Initialize button mapping.

This command enables button mapping on all busses. Button maps allow connect events from the driver to the higher-level features used by controller profiles.

If user input is required, a blocking dialog may be shown.

◆ GetAddonInstallMutex()

CCriticalSection & PERIPHERALS::CPeripherals::GetAddonInstallMutex ( )
inline

Get a mutex that allows for add-on install tasks to block on each other.

◆ GetAddonWithButtonMap()

PeripheralAddonPtr CPeripherals::GetAddonWithButtonMap ( const CPeripheral * device)

Get an add-on that can provide button maps for a device.

Returns
An add-on that provides button maps, or empty if no add-on is found

◆ GetBusByType()

PeripheralBusPtr CPeripherals::GetBusByType ( const PeripheralBusType type) const

Get the instance of a bus given it's type.

Parameters
typeThe bus type.
Returns
The bus or NULL if it wasn't found.

◆ GetBusWithDevice()

PeripheralBusPtr CPeripherals::GetBusWithDevice ( const std::string & strLocation) const

Get the bus that holds the device with the given location.

Parameters
strLocationThe location.
Returns
The bus or NULL if no device was found.

◆ GetByPath()

PeripheralPtr CPeripherals::GetByPath ( const std::string & strPath) const

Get the instance of a peripheral given it's path.

Parameters
strPathThe path to the peripheral.
Returns
The peripheral or NULL if it wasn't found.

◆ GetControllerProfiles()

KODI::GAME::CControllerManager & PERIPHERALS::CPeripherals::GetControllerProfiles ( )
inline

Access controller profiles through the construction parameter.

◆ GetDirectory()

void CPeripherals::GetDirectory ( const std::string & strPath,
CFileItemList & items ) const

Get all fileitems for a path.

Parameters
strPathThe path to the directory to get the items from.
itemsThe item list.

◆ GetInputManager()

CInputManager & PERIPHERALS::CPeripherals::GetInputManager ( )
inline

Access the input manager passed to the constructor.

◆ GetMessageMask()

int CPeripherals::GetMessageMask ( )
overridevirtual

Should return the message mask that it wishes to receive messages for.

The message mask is defined in "messaging/ApplicationMessenger.h" pick the next one available when creating a new

Implements KODI::MESSAGING::IMessageTarget.

◆ GetNextKeypress()

bool CPeripherals::GetNextKeypress ( float frameTime,
CKey & key )

Try to get a keypress from a peripheral.

Todo
CEC only supports toggling the mute status at this time
Parameters
frameTimeThe current frametime.
keyThe fetched key.
Returns
True when a keypress was fetched, false otherwise.

◆ GetNumberOfPeripherals()

size_t CPeripherals::GetNumberOfPeripherals ( ) const

◆ GetPeripheralAtLocation()

PeripheralPtr CPeripherals::GetPeripheralAtLocation ( const std::string & strLocation,
PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN ) const

Get the instance of the peripheral at the given location.

Parameters
strLocationThe location.
busTypeThe bus to query. Default (PERIPHERAL_BUS_UNKNOWN) searches all busses.
Returns
The peripheral or NULL if it wasn't found.

◆ GetPeripheralsWithFeature()

int CPeripherals::GetPeripheralsWithFeature ( PeripheralVector & results,
const PeripheralFeature feature,
PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN ) const

Get all peripheral instances that have the given feature.

Parameters
resultsThe list of results.
featureThe feature to search for.
busTypeThe bus to query. Default (PERIPHERAL_BUS_UNKNOWN) searches all busses.
Returns
The number of devices that have been found.

◆ GetSettingsFromMapping()

void CPeripherals::GetSettingsFromMapping ( CPeripheral & peripheral) const

Add the settings that are defined in the mappings file to the peripheral (if there is anything defined).

Parameters
peripheralThe peripheral to get the settings for.

◆ HasPeripheralAtLocation()

bool CPeripherals::HasPeripheralAtLocation ( const std::string & strLocation,
PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN ) const

Check whether a peripheral is present at the given location.

Parameters
strLocationThe location.
busTypeThe bus to query. Default (PERIPHERAL_BUS_UNKNOWN) searches all busses.
Returns
True when a peripheral was found, false otherwise.

◆ HasPeripheralWithFeature()

bool CPeripherals::HasPeripheralWithFeature ( const PeripheralFeature feature,
PeripheralBusType busType = PERIPHERAL_BUS_UNKNOWN ) const

Check whether there is at least one device present with the given feature.

Parameters
featureThe feature to check for.
busTypeThe bus to query. Default (PERIPHERAL_BUS_UNKNOWN) searches all busses.
Returns
True when at least one device was found with this feature, false otherwise.

◆ Initialise()

void CPeripherals::Initialise ( )

Initialise the peripherals manager.

◆ IsMuted()

bool CPeripherals::IsMuted ( )

Check whether there's a peripheral that reports to be muted.

Returns
True when at least one peripheral reports to be muted, false otherwise.

◆ Mute()

bool PERIPHERALS::CPeripherals::Mute ( )
inline

Try to mute the audio via a peripheral.

Returns
True when this change was handled by a peripheral (and should not be handled by anything else), false otherwise.

◆ OnAction()

bool CPeripherals::OnAction ( const CAction & action)

Try to let one of the peripherals handle an action.

Parameters
actionThe change to handle.
Returns
True when this change was handled by a peripheral (and should not be handled by anything else), false otherwise.

◆ OnApplicationMessage()

void CPeripherals::OnApplicationMessage ( KODI::MESSAGING::ThreadMessage * msg)
overridevirtual

This gets called whenever a message matching the registered message mask is processed.

There are no ordering guarantees here so implementations should never rely on a certain ordering of messages.

Cleaning up any pointers stored in the message payload is not specified and is decided by the implementer of the message. In general prefer to delete any data in this method to keep the callsites cleaner and simpler but if data is to be passed back it's perfectly valid to handle it any way that fits the situation as long as it's documented along with the message.

To return a simple value the result parameter of

See also
ThreadMessage can be used as it will be used as the return value for
CApplicationMessenger::SendMsg. It is up to the implementer to decide if this is to be used and it should be documented along with any new message implemented.

Implements KODI::MESSAGING::IMessageTarget.

◆ OnDeviceAdded()

void CPeripherals::OnDeviceAdded ( const CPeripheralBus & bus,
const CPeripheral & peripheral )

Called when a device has been added to a bus.

Parameters
busThe bus the device was added to.
peripheralThe peripheral that has been added.
Todo
Improve device notifications in v18

◆ OnDeviceDeleted()

void CPeripherals::OnDeviceDeleted ( const CPeripheralBus & bus,
const CPeripheral & peripheral )

Called when a device has been deleted from a bus.

Parameters
busThe bus from which the device removed.
peripheralThe peripheral that has been removed.
Todo
Improve device notifications in v18

◆ OnSettingAction()

void CPeripherals::OnSettingAction ( const std::shared_ptr< const CSetting > & setting)
overridevirtual

The given setting has been activated.

This callback is triggered whenever the given setting has been activated. This callback is only fired for CSettingAction settings.

Parameters
settingThe setting which has been activated.

Reimplemented from ISettingCallback.

◆ OnSettingChanged()

void CPeripherals::OnSettingChanged ( const std::shared_ptr< const CSetting > & setting)
overridevirtual

The value of the given setting has changed.

This callback is triggered whenever the value of a setting has been successfully changed (i.e. none of the OnSettingChanging() handlers) has reverted the change.

Parameters
settingThe setting whose value has been changed

Reimplemented from ISettingCallback.

◆ OnUserNotification()

void CPeripherals::OnUserNotification ( )

◆ PowerOffDevices()

void CPeripherals::PowerOffDevices ( )

Request all devices with power-off support to power down.

◆ ProcessEvents()

void CPeripherals::ProcessEvents ( void )
overridevirtual

◆ RegisterEventLock()

EventLockHandlePtr CPeripherals::RegisterEventLock ( )

Register with the event scanner to disable event processing.

Returns
A handle that unregisters itself when expired

◆ RegisterEventPoller()

EventPollHandlePtr CPeripherals::RegisterEventPoller ( )

Register with the event scanner to control scan timing.

Returns
A handle that unregisters itself when expired

◆ RegisterJoystickButtonMapper()

void CPeripherals::RegisterJoystickButtonMapper ( KODI::JOYSTICK::IButtonMapper * mapper)

Register a button mapper interface.

Parameters
mapperThe button mapper

Clients implementing the IButtonMapper interface call CPeripherals::RegisterJoystickButtonMapper to register themselves as eligible for button mapping commands.

When registering the mapper is forwarded to all peripherals. See CPeripheral::RegisterJoystickButtonMapper for what is done to the mapper after being given to the peripheral.

◆ ResetButtonMaps()

void CPeripherals::ResetButtonMaps ( const std::string & controllerId)

Reset all button maps to the defaults for all devices and the given controller.

Parameters
controllerIdThe controller profile to reset
Todo
Add a device parameter to allow resetting button maps per-device

◆ SupportsCEC()

bool PERIPHERALS::CPeripherals::SupportsCEC ( ) const
inline

◆ SupportsFeature()

bool CPeripherals::SupportsFeature ( PeripheralFeature feature) const

Check if any busses support the given feature.

Parameters
featureThe feature to check for
Returns
True if a bus supports the feature, false otherwise

◆ TestFeature()

void CPeripherals::TestFeature ( PeripheralFeature feature)

Request peripherals with the specified feature to perform a quick test.

Returns
true if any peripherals support the feature, false otherwise

◆ ToggleDeviceState()

bool CPeripherals::ToggleDeviceState ( const CecStateChange mode = STATE_SWITCH_TOGGLE)

Try to toggle the playing device state via a peripheral.

Parameters
modeWhether to activate, put on standby or toggle the source.
Returns
True when the playing device has been switched on, false otherwise.

◆ ToggleMute()

bool CPeripherals::ToggleMute ( )

Try to toggle the mute status via a peripheral.

Returns
True when this change was handled by a peripheral (and should not be handled by anything else), false otherwise.

◆ TriggerDeviceScan()

void CPeripherals::TriggerDeviceScan ( const PeripheralBusType type = PERIPHERAL_BUS_UNKNOWN)

Trigger a device scan on all known busses.

◆ UnMute()

bool PERIPHERALS::CPeripherals::UnMute ( )
inline

Try to unmute the audio via a peripheral.

Todo
CEC only supports toggling the mute status at this time
Returns
True when this change was handled by a peripheral (and should not be handled by anything else), false otherwise.

◆ UnregisterJoystickButtonMapper()

void CPeripherals::UnregisterJoystickButtonMapper ( KODI::JOYSTICK::IButtonMapper * mapper)

Unregister a button mapper interface.

Parameters
mapperThe button mapper

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