MythTV master
Public Slots | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
MediaMonitor Class Referenceabstract

#include <libmythui/mediamonitor.h>

Inheritance diagram for MediaMonitor:
[legend]
Collaboration diagram for MediaMonitor:
[legend]

Public Slots

void mediaStatusChanged (MythMediaStatus oldStatus, MythMediaDevice *pMedia) const
 Slot which is called when the device status changes and posts a media event to the mainwindow. More...
 

Public Member Functions

virtual void deleteLater (void)
 
bool IsActive (void) const
 
virtual void StartMonitoring (void)
 Start the monitoring thread if needed. More...
 
void StopMonitoring (void)
 Stop the monitoring thread if needed. More...
 
void ChooseAndEjectMedia (void)
 Unmounts and ejects removable media devices. More...
 
void EjectMedia (const QString &path)
 
bool ValidateAndLock (MythMediaDevice *pMedia)
 Validates the MythMediaDevice and increments its reference count. More...
 
void Unlock (MythMediaDevice *pMedia)
 decrements the MythMediaDevices reference count More...
 
QList< MythMediaDevice * > GetRemovable (bool showMounted=false, bool showUsable=false)
 Generate a list of removable drives. More...
 
QList< MythMediaDevice * > GetMedias (unsigned mediatypes)
 Ask for available media. More...
 
MythMediaDeviceGetMedia (const QString &path)
 Get media device by pathname. More...
 
void RegisterMediaHandler (const QString &destination, const QString &description, MediaCallback callback, int mediaType, const QString &extensions)
 Register a handler for media related events. More...
 
void JumpToMediaHandler (MythMediaDevice *pMedia, bool forcePlayback=false)
 Find a relevant jump point for this type of media. More...
 
virtual QStringList GetCDROMBlockDevices (void)=0
 

Static Public Member Functions

static MediaMonitorGetMediaMonitor (void)
 
static QString GetMountPath (const QString &devPath)
 If the device is being monitored, return its mountpoint. More...
 
static void SetCDSpeed (const char *device, int speed)
 
static QString defaultCDdevice ()
 CDDevice, user-selected drive, or /dev/cdrom. More...
 
static QString defaultVCDdevice ()
 VCDDeviceLocation, user-selected drive, or /dev/cdrom. More...
 
static QString defaultDVDdevice ()
 DVDDeviceLocation, user-selected drive, or /dev/dvd. More...
 
static QString defaultCDWriter ()
 CDWriterDeviceLocation, user-selected drive, or /dev/cdrom. More...
 
static QString defaultDVDWriter ()
 MythArchiveDVDLocation, user-selected drive, or /dev/dvd. More...
 
static void ejectOpticalDisc (void)
 Eject a disk, unmount a drive, open a tray. More...
 

Protected Member Functions

 MediaMonitor (QObject *par, unsigned long interval, bool allowEject)
 Lookup some settings, and do OS-specific stuff in sub-classes. More...
 
 ~MediaMonitor () override=default
 
void CheckDevices (void)
 Poll the devices in our list. More...
 
virtual void CheckDeviceNotifications (void)
 
virtual bool AddDevice (MythMediaDevice *pDevice)=0
 
bool RemoveDevice (const QString &dev)
 Remove a device from the media monitor. More...
 
bool shouldIgnore (const MythMediaDevice *device)
 Check user preferences to see if this device should be monitored. More...
 
bool eventFilter (QObject *obj, QEvent *event) override
 Installed into the main window's event chain, so that the main thread can safely jump to plugin code. More...
 
QString listDevices (void)
 A string summarising the current devices, for debugging. More...
 
MythMediaDeviceselectDrivePopup (const QString &label, bool &canceled, bool showMounted=false, bool showUsable=false)
 List removable drives, let the user select one. More...
 

Static Protected Member Functions

static void AttemptEject (MythMediaDevice *device)
 
static QString defaultDevice (const QString &setting, const QString &label, const char *hardCodedDefault)
 

Protected Attributes

QRecursiveMutex m_devicesLock
 
QList< MythMediaDevice * > m_devices
 
QList< MythMediaDevice * > m_removedDevices
 
QMap< MythMediaDevice *, int > m_useCount
 
QStringList m_ignoreList
 
bool volatile m_active {false}
 Was MonitorThread started? More...
 
QWaitCondition m_wait
 
MonitorThreadm_thread {nullptr}
 
unsigned long m_monitorPollingInterval
 
bool m_allowEject
 
QMap< QString, MHDatam_handlerMap
 Registered Media Handlers. More...
 

Static Protected Attributes

static MediaMonitors_monitor = nullptr
 

Friends

class MonitorThread
 
class MonitorThreadDarwin
 

Detailed Description

Definition at line 47 of file mediamonitor.h.

Constructor & Destructor Documentation

◆ MediaMonitor()

MediaMonitor::MediaMonitor ( QObject *  par,
unsigned long  interval,
bool  allowEject 
)
protected

Lookup some settings, and do OS-specific stuff in sub-classes.

Bug:
If the user changes the MonitorDrives or IgnoreDevices settings, it will have no effect until the frontend is restarted.

Definition at line 339 of file mediamonitor.cpp.

◆ ~MediaMonitor()

MediaMonitor::~MediaMonitor ( )
overrideprotecteddefault

Member Function Documentation

◆ AddDevice()

virtual bool MediaMonitor::AddDevice ( MythMediaDevice pDevice)
protectedpure virtual

◆ AttemptEject()

void MediaMonitor::AttemptEject ( MythMediaDevice device)
staticprotected

Definition at line 279 of file mediamonitor.cpp.

Referenced by ChooseAndEjectMedia(), and EjectMedia().

◆ CheckDeviceNotifications()

virtual void MediaMonitor::CheckDeviceNotifications ( void  )
inlineprotectedvirtual

Reimplemented in MediaMonitorUnix.

Definition at line 104 of file mediamonitor.h.

Referenced by CheckDevices().

◆ CheckDevices()

void MediaMonitor::CheckDevices ( void  )
protected

Poll the devices in our list.

Definition at line 428 of file mediamonitor.cpp.

◆ ChooseAndEjectMedia()

void MediaMonitor::ChooseAndEjectMedia ( void  )

Unmounts and ejects removable media devices.

If no media devices are known to the MediaMonitor this function does nothing. If a single device is known, it is unmounted and ejected if possible. If multiple devices are known, a popup box is display so the user can choose which device to eject.

Definition at line 251 of file mediamonitor.cpp.

Referenced by ejectOpticalDisc().

◆ defaultCDdevice()

QString MediaMonitor::defaultCDdevice ( )
static

CDDevice, user-selected drive, or /dev/cdrom.

Definition at line 894 of file mediamonitor.cpp.

◆ defaultCDWriter()

QString MediaMonitor::defaultCDWriter ( )
static

CDWriterDeviceLocation, user-selected drive, or /dev/cdrom.

Definition at line 920 of file mediamonitor.cpp.

◆ defaultDevice()

QString MediaMonitor::defaultDevice ( const QString &  setting,
const QString &  label,
const char *  hardCodedDefault 
)
staticprotected

◆ defaultDVDdevice()

QString MediaMonitor::defaultDVDdevice ( )
static

DVDDeviceLocation, user-selected drive, or /dev/dvd.

Definition at line 911 of file mediamonitor.cpp.

Referenced by playDisc().

◆ defaultDVDWriter()

QString MediaMonitor::defaultDVDWriter ( )
static

MythArchiveDVDLocation, user-selected drive, or /dev/dvd.

This should also look for drives with blanks or RWs in them, but Nigel hasn't worked out how to do this tidily (yet).

Definition at line 932 of file mediamonitor.cpp.

◆ defaultVCDdevice()

QString MediaMonitor::defaultVCDdevice ( )
static

VCDDeviceLocation, user-selected drive, or /dev/cdrom.

Definition at line 902 of file mediamonitor.cpp.

◆ deleteLater()

void MediaMonitor::deleteLater ( void  )
virtual

Reimplemented in MediaMonitorUnix.

Definition at line 373 of file mediamonitor.cpp.

Referenced by MediaMonitorUnix::deleteLater(), and main().

◆ EjectMedia()

void MediaMonitor::EjectMedia ( const QString &  path)

Definition at line 271 of file mediamonitor.cpp.

Referenced by Device::Close().

◆ ejectOpticalDisc()

void MediaMonitor::ejectOpticalDisc ( void  )
static

Eject a disk, unmount a drive, open a tray.

If the Media Monitor is enabled, we use its fully-featured routine. Otherwise, we guess a drive and use a primitive OS-specific command

Definition at line 975 of file mediamonitor.cpp.

Referenced by eject_cb().

◆ eventFilter()

bool MediaMonitor::eventFilter ( QObject *  obj,
QEvent *  event 
)
overrideprotected

Installed into the main window's event chain, so that the main thread can safely jump to plugin code.

Definition at line 793 of file mediamonitor.cpp.

◆ GetCDROMBlockDevices()

virtual QStringList MediaMonitor::GetCDROMBlockDevices ( void  )
pure virtual

◆ GetMedia()

MythMediaDevice * MediaMonitor::GetMedia ( const QString &  path)

Get media device by pathname.

Must be locked with ValidateAndLock().

See also
ValidateAndLock(MythMediaDevice *pMedia)
Unlock(MythMediaDevice *pMedia)

Definition at line 534 of file mediamonitor.cpp.

Referenced by Ripper::ejectCD(), EjectMedia(), GetMountPath(), and SetCDSpeed().

◆ GetMediaMonitor()

MediaMonitor * MediaMonitor::GetMediaMonitor ( void  )
static

◆ GetMedias()

QList< MythMediaDevice * > MediaMonitor::GetMedias ( unsigned  mediatypes)

Ask for available media.

Must be locked with ValidateAndLock().

This method returns a list of MythMediaDevice pointers which match the given mediatype.

It is potentially unsafe to use the pointers returned by this function. The devices may be removed and their associated MythMediaDevice objects destroyed. It is the responsibility of the caller to ensure that the pointers are validated and the reference count is incremented by calling MediaMonitor::ValidateAndLock() before the the returned pointer is dereferenced and MediaMonitor::Unlock() when done.

See also
ValidateAndLock(MythMediaDevice *pMedia)
Unlock(MythMediaDevice *pMedia)

Definition at line 605 of file mediamonitor.cpp.

Referenced by ImageManagerFe::DetectLocalDevices(), and playDisc().

◆ GetMountPath()

QString MediaMonitor::GetMountPath ( const QString &  devPath)
static

If the device is being monitored, return its mountpoint.

A convenience function for plugins. (Only currently needed for Mac OS X, which mounts Audio CDs)

Definition at line 558 of file mediamonitor.cpp.

◆ GetRemovable()

QList< MythMediaDevice * > MediaMonitor::GetRemovable ( bool  showMounted = false,
bool  showUsable = false 
)

Generate a list of removable drives.

Has to iterate through all devices to check if any are suitable.

Definition at line 145 of file mediamonitor.cpp.

Referenced by selectDrivePopup().

◆ IsActive()

bool MediaMonitor::IsActive ( void  ) const
inline

Definition at line 55 of file mediamonitor.h.

Referenced by playDisc(), and Ripper::Ripper().

◆ JumpToMediaHandler()

void MediaMonitor::JumpToMediaHandler ( MythMediaDevice pMedia,
bool  forcePlayback = false 
)

Find a relevant jump point for this type of media.

If there's more than one we should show a popup to allow the user to select which one to use, but for now, we're going to just use the first one.

Definition at line 681 of file mediamonitor.cpp.

Referenced by eventFilter(), and playDisc().

◆ listDevices()

QString MediaMonitor::listDevices ( void  )
protected

A string summarising the current devices, for debugging.

Definition at line 944 of file mediamonitor.cpp.

Referenced by MediaMonitorUnix::MediaMonitorUnix(), and MediaMonitorWindows::MediaMonitorWindows().

◆ mediaStatusChanged

void MediaMonitor::mediaStatusChanged ( MythMediaStatus  oldStatus,
MythMediaDevice pMedia 
) const
slot

Slot which is called when the device status changes and posts a media event to the mainwindow.

Definition at line 716 of file mediamonitor.cpp.

Referenced by MediaMonitorDarwin::AddDevice(), MediaMonitorUnix::AddDevice(), and MediaMonitorWindows::AddDevice().

◆ RegisterMediaHandler()

void MediaMonitor::RegisterMediaHandler ( const QString &  destination,
const QString &  description,
MediaCallback  callback,
int  mediaType,
const QString &  extensions 
)

Register a handler for media related events.

This method registers a callback function for when media related events occur. The call must specify the type of media supported by the handler, and (if needed) a list of media file extensions that are supported.

Parameters
destinationA name for this callback function. For example: "MythDVD DVD Media Handler". This argument must be unique as it is also used as the key for creating the map of handler.
descriptionUnused.
callbackThe function to call when an event occurs.
mediaTypeThe type of media supported by this callback. The value must be a bitmask of enums of type MythMediaType.
extensionsA list of file name extensions supported by this callback.

Definition at line 644 of file mediamonitor.cpp.

Referenced by REG_MEDIA_HANDLER().

◆ RemoveDevice()

bool MediaMonitor::RemoveDevice ( const QString &  dev)
protected

Remove a device from the media monitor.

This function is usually called after a hotpluggable device is unplugged.

Parameters
devpath to device special file to remove.
Returns
true if device is removed from the Media Monitor.

Definition at line 392 of file mediamonitor.cpp.

Referenced by MediaMonitorUnix::CheckDeviceNotifications().

◆ selectDrivePopup()

MythMediaDevice * MediaMonitor::selectDrivePopup ( const QString &  label,
bool canceled,
bool  showMounted = false,
bool  showUsable = false 
)
protected

List removable drives, let the user select one.

prevent drawing a list if there is only one drive, et cetera

Definition at line 172 of file mediamonitor.cpp.

Referenced by ChooseAndEjectMedia(), and defaultDevice().

◆ SetCDSpeed()

void MediaMonitor::SetCDSpeed ( const char *  device,
int  speed 
)
static

Definition at line 91 of file mediamonitor.cpp.

Referenced by MythDVDBuffer::SetDVDSpeed().

◆ shouldIgnore()

bool MediaMonitor::shouldIgnore ( const MythMediaDevice device)
protected

Check user preferences to see if this device should be monitored.

Definition at line 765 of file mediamonitor.cpp.

Referenced by MediaMonitorDarwin::AddDevice(), and MediaMonitorUnix::AddDevice().

◆ StartMonitoring()

void MediaMonitor::StartMonitoring ( void  )
virtual

Start the monitoring thread if needed.

Reimplemented in MediaMonitorDarwin.

Definition at line 448 of file mediamonitor.cpp.

Referenced by main(), and Ripper::~Ripper().

◆ StopMonitoring()

void MediaMonitor::StopMonitoring ( void  )

Stop the monitoring thread if needed.

Definition at line 471 of file mediamonitor.cpp.

Referenced by deleteLater(), and Ripper::Ripper().

◆ Unlock()

void MediaMonitor::Unlock ( MythMediaDevice pMedia)

◆ ValidateAndLock()

bool MediaMonitor::ValidateAndLock ( MythMediaDevice pMedia)

Validates the MythMediaDevice and increments its reference count.

Returns true if pMedia device is valid, otherwise returns false. If this function returns false the caller should gracefully recover.

NOTE: This function can block.

See also
Unlock(MythMediaDevice *pMedia), GetMedias(unsigned mediatypes)

Definition at line 494 of file mediamonitor.cpp.

Referenced by defaultDevice(), ImageManagerFe::DetectLocalDevices(), ImageManagerFe::DeviceEvent(), Ripper::ejectCD(), GetMountPath(), and SetCDSpeed().

Friends And Related Function Documentation

◆ MonitorThread

friend class MonitorThread
friend

Definition at line 50 of file mediamonitor.h.

Referenced by StartMonitoring().

◆ MonitorThreadDarwin

friend class MonitorThreadDarwin
friend

Definition at line 51 of file mediamonitor.h.

Referenced by MediaMonitorDarwin::StartMonitoring().

Member Data Documentation

◆ m_active

bool volatile MediaMonitor::m_active {false}
protected

◆ m_allowEject

bool MediaMonitor::m_allowEject
protected

◆ m_devices

QList<MythMediaDevice*> MediaMonitor::m_devices
protected

◆ m_devicesLock

QRecursiveMutex MediaMonitor::m_devicesLock
protected

◆ m_handlerMap

QMap<QString, MHData> MediaMonitor::m_handlerMap
protected

Registered Media Handlers.

Definition at line 135 of file mediamonitor.h.

Referenced by eventFilter(), JumpToMediaHandler(), and RegisterMediaHandler().

◆ m_ignoreList

QStringList MediaMonitor::m_ignoreList
protected

Definition at line 127 of file mediamonitor.h.

Referenced by MediaMonitor(), and shouldIgnore().

◆ m_monitorPollingInterval

unsigned long MediaMonitor::m_monitorPollingInterval
protected

Definition at line 132 of file mediamonitor.h.

Referenced by StartMonitoring(), and MediaMonitorDarwin::StartMonitoring().

◆ m_removedDevices

QList<MythMediaDevice*> MediaMonitor::m_removedDevices
protected

Definition at line 123 of file mediamonitor.h.

Referenced by RemoveDevice(), and Unlock().

◆ m_thread

MonitorThread* MediaMonitor::m_thread {nullptr}
protected

◆ m_useCount

QMap<MythMediaDevice*, int> MediaMonitor::m_useCount
protected

◆ m_wait

QWaitCondition MediaMonitor::m_wait
protected

Definition at line 130 of file mediamonitor.h.

Referenced by StopMonitoring().

◆ s_monitor

MediaMonitor * MediaMonitor::s_monitor = nullptr
staticprotected

Definition at line 137 of file mediamonitor.h.

Referenced by defaultDevice(), GetMediaMonitor(), and GetMountPath().


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