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

#include <PeripheralBus.h>

Inheritance diagram for PERIPHERALS::CPeripheralBus:
CThread PERIPHERALS::CPeripheralBusAddon PERIPHERALS::CPeripheralBusAndroid PERIPHERALS::CPeripheralBusApplication PERIPHERALS::CPeripheralBusCEC PERIPHERALS::CPeripheralBusGCController PERIPHERALS::CPeripheralBusUSB PERIPHERALS::CPeripheralBusUSB PERIPHERALS::CPeripheralBusUSB PERIPHERALS::CPeripheralBusUSB PERIPHERALS::CPeripheralBusUSB

Public Member Functions

 CPeripheralBus (const std::string &threadname, CPeripherals &manager, PeripheralBusType type)
 
 ~CPeripheralBus (void) override
 
PeripheralBusType Type (void) const
 
bool NeedsPolling (void) const
 
virtual bool InitializeProperties (CPeripheral &peripheral)
 Initialize the properties of a peripheral with a known location.
 
virtual PeripheralPtr GetPeripheral (const std::string &strLocation) const
 Get the instance of the peripheral at the given location.
 
virtual bool HasPeripheral (const std::string &strLocation) const
 Check whether a peripheral is present at the given location.
 
virtual bool SupportsFeature (PeripheralFeature feature) const
 Check if the bus supports the given feature.
 
virtual unsigned int GetPeripheralsWithFeature (PeripheralVector &results, const PeripheralFeature feature) const
 Get all peripheral instances that have the given feature.
 
virtual unsigned int GetNumberOfPeripherals () const
 
virtual unsigned int GetNumberOfPeripheralsWithId (const int iVendorId, const int iProductId) const
 
virtual void GetFeatures (std::vector< PeripheralFeature > &features) const
 Get all features that are supported by devices on this bus.
 
virtual bool HasFeature (const PeripheralFeature feature) const
 Check whether there is at least one device present with the given feature.
 
virtual void OnDeviceAdded (const std::string &strLocation)
 Callback method for when a device has been added. Will perform a device scan.
 
virtual void OnDeviceChanged (const std::string &strLocation)
 Callback method for when a device has been changed. Will perform a device scan.
 
virtual void OnDeviceRemoved (const std::string &strLocation)
 Callback method for when a device has been removed. Will perform a device scan.
 
virtual void Initialise (void)
 Initialise this bus and start a polling thread if this bus needs polling.
 
virtual void Clear (void)
 Stop the polling thread and clear all known devices on this bus.
 
virtual void TriggerDeviceScan (void)
 Scan for devices.
 
virtual void GetDirectory (const std::string &strPath, CFileItemList &items) const
 Get all fileitems for a path.
 
virtual PeripheralPtr GetByPath (const std::string &strPath) const
 Get the instance of a peripheral given it's path.
 
virtual void Register (const PeripheralPtr &peripheral)
 Register a new peripheral on this bus.
 
virtual bool FindComPort (std::string &strLocation)
 
virtual void ProcessEvents (void)
 Poll for events.
 
virtual void EnableButtonMapping ()
 Initialize button mapping.
 
virtual void PowerOff (const std::string &strLocation)
 Power off the specified device.
 

Protected Member Functions

void Process (void) override
 
virtual bool ScanForDevices (void)
 
virtual void UnregisterRemovedDevices (const PeripheralScanResults &results)
 
virtual void RegisterNewDevices (const PeripheralScanResults &results)
 
virtual bool PerformDeviceScan (PeripheralScanResults &results)=0
 Scan for devices on this bus and add them to the results list. This will have to be implemented for each bus.
 
- Protected Member Functions inherited from CThread
 CThread (const char *ThreadName)
 
virtual void OnStartup ()
 
virtual void OnExit ()
 
WaitResponse AbortableWait (CEvent &event, std::chrono::milliseconds duration=std::chrono::milliseconds(-1))
 
 CThread (IRunnable *pRunnable, const char *ThreadName)
 
virtual ~CThread ()
 
void Create (bool bAutoDelete=false)
 
template<typename Rep , typename Period >
void Sleep (std::chrono::duration< Rep, Period > duration)
 
bool IsAutoDelete () const
 
virtual void StopThread (bool bWait=true)
 
bool IsRunning () const
 
bool IsCurrentThread () const
 
bool Join (std::chrono::milliseconds duration)
 
bool SetPriority (const ThreadPriority &priority)
 Set the threads priority. This uses the platforms native threading library to do so.
 
virtual void OnException ()
 

Protected Attributes

PeripheralVector m_peripherals
 
std::chrono::milliseconds m_iRescanTime
 
bool m_bNeedsPolling
 
CPeripheralsm_manager
 
const PeripheralBusType m_type
 
CCriticalSection m_critSection
 
CEvent m_triggerEvent
 
- Protected Attributes inherited from CThread
std::atomic< boolm_bStop
 

Additional Inherited Members

- Protected Types inherited from CThread
enum  WaitResponse { WAIT_INTERRUPTED = -1 , WAIT_SIGNALED = 0 , WAIT_TIMEDOUT = 1 }
 
- Static Protected Member Functions inherited from CThread
static const std::thread::id GetCurrentThreadId ()
 
static CThreadGetCurrentThread ()
 

Detailed Description

This represents a bus on the system. By default, this bus instance will scan for changes every 5 seconds. If this bus only has to be updated after a notification sent by the system, set m_bNeedsPolling to false in the constructor, and implement the OnDeviceAdded(), OnDeviceChanged() and OnDeviceRemoved() methods.

The PerformDeviceScan() method has to be implemented by each specific bus implementation.

Constructor & Destructor Documentation

◆ CPeripheralBus()

CPeripheralBus::CPeripheralBus ( const std::string & threadname,
CPeripherals & manager,
PeripheralBusType type )

◆ ~CPeripheralBus()

PERIPHERALS::CPeripheralBus::~CPeripheralBus ( void )
inlineoverride

Member Function Documentation

◆ Clear()

void CPeripheralBus::Clear ( void )
virtual

Stop the polling thread and clear all known devices on this bus.

Reimplemented in PERIPHERALS::CPeripheralBusUSB.

◆ EnableButtonMapping()

virtual void PERIPHERALS::CPeripheralBus::EnableButtonMapping ( )
inlinevirtual

Initialize button mapping.

Returns
True if button mapping is enabled for this bus

Reimplemented in PERIPHERALS::CPeripheralBusAddon.

◆ FindComPort()

virtual bool PERIPHERALS::CPeripheralBus::FindComPort ( std::string & strLocation)
inlinevirtual

◆ GetByPath()

PeripheralPtr CPeripheralBus::GetByPath ( const std::string & strPath) const
virtual

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.

Reimplemented in PERIPHERALS::CPeripheralBusAddon.

◆ GetDirectory()

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

Get all fileitems for a path.

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

Reimplemented in PERIPHERALS::CPeripheralBusAddon, and PERIPHERALS::CPeripheralBusApplication.

◆ GetFeatures()

void CPeripheralBus::GetFeatures ( std::vector< PeripheralFeature > & features) const
virtual

Get all features that are supported by devices on this bus.

Parameters
featuresAll features.

Reimplemented in PERIPHERALS::CPeripheralBusAddon.

◆ GetNumberOfPeripherals()

unsigned int CPeripheralBus::GetNumberOfPeripherals ( void ) const
virtual

◆ GetNumberOfPeripheralsWithId()

unsigned int CPeripheralBus::GetNumberOfPeripheralsWithId ( const int iVendorId,
const int iProductId ) const
virtual

◆ GetPeripheral()

PeripheralPtr CPeripheralBus::GetPeripheral ( const std::string & strLocation) const
virtual

Get the instance of the peripheral at the given location.

Parameters
strLocationThe location.
Returns
The peripheral or NULL if it wasn't found.

Reimplemented in PERIPHERALS::CPeripheralBusAddon.

◆ GetPeripheralsWithFeature()

unsigned int CPeripheralBus::GetPeripheralsWithFeature ( PeripheralVector & results,
const PeripheralFeature feature ) const
virtual

Get all peripheral instances that have the given feature.

Parameters
resultsThe list of results.
featureThe feature to search for.
Returns
The number of devices that have been found.

Reimplemented in PERIPHERALS::CPeripheralBusAddon.

◆ HasFeature()

bool CPeripheralBus::HasFeature ( const PeripheralFeature feature) const
virtual

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

Parameters
featureThe feature to check for.
Returns
True when at least one device was found with this feature, false otherwise.

Reimplemented in PERIPHERALS::CPeripheralBusAddon.

◆ HasPeripheral()

bool CPeripheralBus::HasPeripheral ( const std::string & strLocation) const
virtual

Check whether a peripheral is present at the given location.

Parameters
strLocationThe location.
Returns
True when a peripheral was found, false otherwise.

◆ Initialise()

void CPeripheralBus::Initialise ( void )
virtual

Initialise this bus and start a polling thread if this bus needs polling.

Reimplemented in PERIPHERALS::CPeripheralBusApplication, PERIPHERALS::CPeripheralBusAndroid, and PERIPHERALS::CPeripheralBusGCController.

◆ InitializeProperties()

bool CPeripheralBus::InitializeProperties ( CPeripheral & peripheral)
virtual

Initialize the properties of a peripheral with a known location.

Reimplemented in PERIPHERALS::CPeripheralBusAddon, PERIPHERALS::CPeripheralBusAndroid, and PERIPHERALS::CPeripheralBusGCController.

◆ NeedsPolling()

bool PERIPHERALS::CPeripheralBus::NeedsPolling ( void ) const
inline
Returns
True if this bus needs to be polled for changes, false if this bus performs updates via callbacks

◆ OnDeviceAdded()

void CPeripheralBus::OnDeviceAdded ( const std::string & strLocation)
virtual

Callback method for when a device has been added. Will perform a device scan.

Parameters
strLocationThe location of the device that has been added.

◆ OnDeviceChanged()

void CPeripheralBus::OnDeviceChanged ( const std::string & strLocation)
virtual

Callback method for when a device has been changed. Will perform a device scan.

Parameters
strLocationThe location of the device that has been changed.

◆ OnDeviceRemoved()

void CPeripheralBus::OnDeviceRemoved ( const std::string & strLocation)
virtual

Callback method for when a device has been removed. Will perform a device scan.

Parameters
strLocationThe location of the device that has been removed.

◆ PerformDeviceScan()

virtual bool PERIPHERALS::CPeripheralBus::PerformDeviceScan ( PeripheralScanResults & results)
protectedpure virtual

Scan for devices on this bus and add them to the results list. This will have to be implemented for each bus.

Parameters
resultsThe result list.
Returns
True when the scan was successful, false otherwise.

Implemented in PERIPHERALS::CPeripheralBusUSB, PERIPHERALS::CPeripheralBusUSB, PERIPHERALS::CPeripheralBusUSB, PERIPHERALS::CPeripheralBusAddon, PERIPHERALS::CPeripheralBusApplication, PERIPHERALS::CPeripheralBusCEC, PERIPHERALS::CPeripheralBusAndroid, PERIPHERALS::CPeripheralBusUSB, PERIPHERALS::CPeripheralBusGCController, and PERIPHERALS::CPeripheralBusUSB.

◆ PowerOff()

virtual void PERIPHERALS::CPeripheralBus::PowerOff ( const std::string & strLocation)
inlinevirtual

Power off the specified device.

Parameters
strLocationThe device's location

Reimplemented in PERIPHERALS::CPeripheralBusAddon.

◆ Process()

void CPeripheralBus::Process ( void )
overrideprotectedvirtual

Reimplemented from CThread.

Reimplemented in PERIPHERALS::CPeripheralBusUSB.

◆ ProcessEvents()

virtual void PERIPHERALS::CPeripheralBus::ProcessEvents ( void )
inlinevirtual

◆ Register()

void CPeripheralBus::Register ( const PeripheralPtr & peripheral)
virtual

Register a new peripheral on this bus.

Parameters
peripheralThe peripheral to register.

Reimplemented in PERIPHERALS::CPeripheralBusAddon.

◆ RegisterNewDevices()

void CPeripheralBus::RegisterNewDevices ( const PeripheralScanResults & results)
protectedvirtual

◆ ScanForDevices()

bool CPeripheralBus::ScanForDevices ( void )
protectedvirtual

◆ SupportsFeature()

virtual bool PERIPHERALS::CPeripheralBus::SupportsFeature ( PeripheralFeature feature) const
inlinevirtual

Check if the bus supports the given feature.

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

Reimplemented in PERIPHERALS::CPeripheralBusAddon.

◆ TriggerDeviceScan()

void CPeripheralBus::TriggerDeviceScan ( void )
virtual

Scan for devices.

◆ Type()

PeripheralBusType PERIPHERALS::CPeripheralBus::Type ( void ) const
inline
Returns
The bus type

◆ UnregisterRemovedDevices()

void CPeripheralBus::UnregisterRemovedDevices ( const PeripheralScanResults & results)
protectedvirtual

Member Data Documentation

◆ m_bNeedsPolling

bool PERIPHERALS::CPeripheralBus::m_bNeedsPolling
protected
Initial value:
=
true

true when this bus needs to be polled for new devices, false when it uses callbacks to notify this bus of changed

◆ m_critSection

CCriticalSection PERIPHERALS::CPeripheralBus::m_critSection
mutableprotected

◆ m_iRescanTime

std::chrono::milliseconds PERIPHERALS::CPeripheralBus::m_iRescanTime
protected

◆ m_manager

CPeripherals& PERIPHERALS::CPeripheralBus::m_manager
protected

◆ m_peripherals

PeripheralVector PERIPHERALS::CPeripheralBus::m_peripherals
protected

◆ m_triggerEvent

CEvent PERIPHERALS::CPeripheralBus::m_triggerEvent
protected

◆ m_type

const PeripheralBusType PERIPHERALS::CPeripheralBus::m_type
protected

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